-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set _position after updating rank order with inferred value (#193)
* Set _position after updating the rank order due to a non-integer position setting * Fix for dynamic method names in tests * Update needs to be of row_position, not row column itself * Use previously_changed? because this is after_save * Adjust Appraisals, gemspec and CI matrix for Rails 5.2+ only support * Rails 7 requires Ruby 2.7+ * Try setting position to relative rank in rank_at if needed * Remove unnecessary additional callback * Handle rebalance rank setting (happens before position is set) * Don't use rank_at when rebalancing, instead, mutate the column directly --------- Co-authored-by: Brendon Muir <brendon@spike.net.nz>
- Loading branch information
1 parent
680a8e4
commit f9145d4
Showing
13 changed files
with
99 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ pkg/* | |
*.gem | ||
.bundle | ||
*.un~ | ||
*.swp | ||
|
||
Gemfile.lock | ||
*.gemfile.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require "spec_helper" | ||
|
||
describe Duck do | ||
before do | ||
5.times do |i| | ||
Duck.create(name: "Duck #{i + 1}") | ||
end | ||
end | ||
|
||
describe "updating a duck order with last" do | ||
it "should maintain the order after creating a new duck" do | ||
duck = Duck.first | ||
duck.update(row_position: :last) | ||
expect(duck.row_rank).to eq(4) | ||
|
||
Duck.create(name: "Wacky") | ||
|
||
expect(duck.row_rank).to eq(4) | ||
|
||
duck.update(pond: 'Shin') | ||
expect(duck.row_rank).to eq(4) | ||
end | ||
end | ||
|
||
describe "updating a duck order with first" do | ||
it "should maintain the order after creating a new duck" do | ||
duck = Duck.last | ||
duck.update(row_position: :first) | ||
expect(duck.row_rank).to eq(0) | ||
|
||
Duck.create(name: "Wacky") | ||
|
||
expect(duck.row_rank).to eq(0) | ||
|
||
duck.update(pond: 'Shin') | ||
expect(duck.row_rank).to eq(0) | ||
end | ||
end | ||
|
||
describe "updating a duck order with up" do | ||
it "should maintain the order after creating a new duck" do | ||
duck_id = Duck.ranker(:row).with(Duck.new).current_at_position(2).instance.id | ||
duck = Duck.find(duck_id) | ||
duck.update(row_position: :up) | ||
expect(duck.row_rank).to eq(1) | ||
|
||
Duck.create(name: "Wacky") | ||
|
||
expect(duck.row_rank).to eq(1) | ||
|
||
duck.update(pond: 'Shin') | ||
expect(duck.row_rank).to eq(1) | ||
end | ||
end | ||
|
||
describe "updating a duck order with down" do | ||
it "should maintain the order after creating a new duck" do | ||
duck_id = Duck.ranker(:row).with(Duck.new).current_at_position(2).instance.id | ||
duck = Duck.find(duck_id) | ||
duck.update(row_position: :down) | ||
expect(duck.row_rank).to eq(3) | ||
|
||
Duck.create(name: "Wacky") | ||
|
||
expect(duck.row_rank).to eq(3) | ||
|
||
duck.update(pond: 'Shin') | ||
expect(duck.row_rank).to eq(3) | ||
end | ||
end | ||
end |