Skip to content

Instantly share code, notes, and snippets.

@fabn
Created October 9, 2014 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabn/cd37fb680cd94d840801 to your computer and use it in GitHub Desktop.
Save fabn/cd37fb680cd94d840801 to your computer and use it in GitHub Desktop.
Full output
Category 1 (id: 1, position: 1, depth: 0, ancestry: )
├── Category 2 (id: 2, position: 1, depth: 1, ancestry: 1)
│ ├── Category 3 (id: 3, position: 1, depth: 2, ancestry: 1/2)
│ └── Category 4 (id: 4, position: 2, depth: 2, ancestry: 1/2)
└── Category 5 (id: 5, position: 2, depth: 1, ancestry: 1)
├── Category 6 (id: 6, position: 1, depth: 2, ancestry: 1/5)
└── Category 7 (id: 7, position: 2, depth: 2, ancestry: 1/5)
"Saving category 5 with the following changes: "
{
"ancestry" => [
[0] "1",
[1] nil
],
"ancestry_depth" => [
├── Category 2 (id: 2, position: 1, depth: 1, ancestry: 1)
│ ├── Category 3 (id: 3, position: 1, depth: 2, ancestry: 1/2)
│ └── Category 4 (id: 4, position: 2, depth: 2, ancestry: 1/2)
└── Category 5 (id: 5, position: 2, depth: 1, ancestry: 1)
├── Category 6 (id: 6, position: 1, depth: 2, ancestry: 1/5)
└── Category 7 (id: 7, position: 2, depth: 2, ancestry: 1/5)
"Saving category 5 with the following changes: "
{
"ancestry" => [
[0] "1",
[1] nil
],
"ancestry_depth" => [
[0] 1,
[1] 0
]
}
D, [2014-10-09T20:29:37.765173 #66228] DEBUG -- : Category Load (0.1ms) SELECT "categories".* FROM "categories" WHERE (("categories"."ancestry" LIKE '1/5/%' OR "categories"."ancestry" = '1/5'))
"Saving category 6 with the following changes: "
{
"ancestry" => [
[0] "1/5",
[1] "5"
]
}
"Executing check_scope for 6"
D, [2014-10-09T20:29:37.766282 #66228] DEBUG -- : Category Load (0.1ms) SELECT "categories".* FROM "categories" WHERE ("categories"."ancestry" = '1/5' AND position > 1) ORDER BY categories.position ASC LIMIT 1
D, [2014-10-09T20:29:37.766600 #66228] DEBUG -- : SQL (0.1ms) UPDATE "categories" SET position = (position - 1) WHERE ("categories"."ancestry" = '1/5' AND position > 1)
D, [2014-10-09T20:29:37.766923 #66228] DEBUG -- : SQL (0.1ms) UPDATE "categories" SET position = (position + 1) WHERE ("categories"."ancestry" = '5' AND position >= 1)
D, [2014-10-09T20:29:37.767455 #66228] DEBUG -- : SQL (0.1ms) UPDATE "categories" SET "ancestry" = ?, "ancestry_depth" = ?, "updated_at" = ? WHERE "categories"."id" = 6 [["ancestry", "5"], ["ancestry_depth", 1], ["updated_at", "2014-10-09 18:29:37.765593"]]
D, [2014-10-09T20:29:37.767958 #66228] DEBUG -- : (0.1ms) SELECT COUNT(*) FROM "categories" WHERE ("categories"."ancestry" = '5' AND position = 1)
"Saving category 7 with the following changes: "
{
"ancestry" => [
[0] "1/5",
[1] "5"
]
}
"Executing check_scope for 7"
D, [2014-10-09T20:29:37.768942 #66228] DEBUG -- : Category Load (0.1ms) SELECT "categories".* FROM "categories" WHERE ("categories"."ancestry" = '1/5' AND position > 2) ORDER BY categories.position ASC LIMIT 1
D, [2014-10-09T20:29:37.769251 #66228] DEBUG -- : SQL (0.1ms) UPDATE "categories" SET position = (position + 1) WHERE ("categories"."ancestry" = '5' AND position >= 2)
D, [2014-10-09T20:29:37.769585 #66228] DEBUG -- : SQL (0.1ms) UPDATE "categories" SET "ancestry" = ?, "ancestry_depth" = ?, "updated_at" = ? WHERE "categories"."id" = 7 [["ancestry", "5"], ["ancestry_depth", 1], ["updated_at", "2014-10-09 18:29:37.768399"]]
D, [2014-10-09T20:29:37.769943 #66228] DEBUG -- : (0.1ms) SELECT COUNT(*) FROM "categories" WHERE ("categories"."ancestry" = '5' AND position = 2)
"Executing check_scope for 5"
D, [2014-10-09T20:29:37.770630 #66228] DEBUG -- : Category Load (0.1ms) SELECT "categories".* FROM "categories" WHERE ("categories"."ancestry" = '1' AND position > 2) ORDER BY categories.position ASC LIMIT 1
D, [2014-10-09T20:29:37.770924 #66228] DEBUG -- : SQL (0.1ms) UPDATE "categories" SET position = (position + 1) WHERE ("categories"."ancestry" IS NULL AND position >= 2)
D, [2014-10-09T20:29:37.771277 #66228] DEBUG -- : SQL (0.1ms) UPDATE "categories" SET "ancestry" = ?, "ancestry_depth" = ?, "updated_at" = ? WHERE "categories"."id" = 5 [["ancestry", nil], ["ancestry_depth", 0], ["updated_at", "2014-10-09 18:29:37.770078"]]
D, [2014-10-09T20:29:37.771630 #66228] DEBUG -- : (0.1ms) SELECT COUNT(*) FROM "categories" WHERE ("categories"."ancestry" IS NULL AND position = 2)
After moving node to top level
Category 1 (id: 1, position: 1, depth: 0, ancestry: )
└── Category 2 (id: 2, position: 1, depth: 1, ancestry: 1)
├── Category 3 (id: 3, position: 1, depth: 2, ancestry: 1/2)
└── Category 4 (id: 4, position: 2, depth: 2, ancestry: 1/2)
Category 5 (id: 5, position: 2, depth: 0, ancestry: )
├── Category 6 (id: 6, position: 1, depth: 1, ancestry: 5)
└── Category 7 (id: 7, position: 1, depth: 1, ancestry: 5)
should keep order consistent on rearrange (FAILED - 1)
Failures:
1) Category should keep order consistent on rearrange
Failure/Error: expect(node_to_move.reload.children.map(&:position)).to eq(1.upto(breadth).to_a)
expected: [1, 2]
got: [1, 1]
(compared using ==)
# ./spec/models/category_spec.rb:33:in `block (2 levels) in <top (required)>'
Finished in 0.0518 seconds (files took 1.68 seconds to load)
1 example, 1 failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment