-
Notifications
You must be signed in to change notification settings - Fork 66
Upgrade act as list gem, implement tests to check deal position behaviour and fix bug when change deal between stages from position 1 #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
432b1c5
Update acts_as_list gem
YukioArie 25e5027
Implement tests to check deal position behaviour
YukioArie 03c8699
Remove deals positions behaviour tests in deals controller
YukioArie fdfaf83
Gerenate migration to fix bug when moving an deal between stages when…
YukioArie f7dca40
Improve and add tests
YukioArie f4a2ac1
Update spec/models/deals_spec.rb
douglara f3f53e8
Update spec/models/deals_spec.rb
douglara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
11 changes: 11 additions & 0 deletions
11
db/migrate/20260213000000_remove_default_and_null_from_position_on_deals_and_stages.rb
This file contains hidden or 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,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class RemoveDefaultAndNullFromPositionOnDealsAndStages < ActiveRecord::Migration[7.1] | ||
| def change | ||
| change_column_default :deals, :position, from: 1, to: nil | ||
| change_column_null :deals, :position, true | ||
|
|
||
| change_column_default :stages, :position, from: 1, to: nil | ||
| change_column_null :stages, :position, true | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,134 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Deal do | ||
| let!(:account) { create(:account) } | ||
| let(:last_event) { Event.last } | ||
|
|
||
| describe 'position' do | ||
| let!(:pipeline) { create(:pipeline) } | ||
| let!(:stage1) { create(:stage, pipeline:) } | ||
| let!(:stage2) { create(:stage, pipeline:) } | ||
|
|
||
| let!(:stage1_position1) { create(:deal, stage: stage1, position: 1) } | ||
| let!(:stage1_position2) { create(:deal, stage: stage1, position: 2) } | ||
| let!(:stage1_position3) { create(:deal, stage: stage1, position: 3) } | ||
|
|
||
| let!(:stage2_position1) { create(:deal, stage: stage2, position: 1) } | ||
| let!(:stage2_position2) { create(:deal, stage: stage2, position: 2) } | ||
| let!(:stage2_position3) { create(:deal, stage: stage2, position: 3) } | ||
|
|
||
| context 'moving between stages' do | ||
| it 'move stage1_position1 to stage2 position 1 and create deal_stage_change event' do | ||
| expect do | ||
| Deal::CreateOrUpdate.new(stage1_position1, { stage: stage2, position: 1 }).call | ||
| end.to change(Event, :count).by(1) | ||
|
|
||
| expect(stage1_position2.reload.position).to eq 1 | ||
| expect(stage1_position3.reload.position).to eq 2 | ||
|
|
||
| expect(stage1_position1.reload.stage_id).to eq stage2.id | ||
|
|
||
| expect(stage1_position1.position).to eq 1 | ||
| expect(stage2_position1.reload.position).to eq 2 | ||
| expect(stage2_position2.reload.position).to eq 3 | ||
| expect(stage2_position3.reload.position).to eq 4 | ||
| expect(last_event.kind).to eq('deal_stage_change') | ||
| end | ||
|
|
||
| it 'move stage1_position1 to stage2 position 2 and create deal_stage_change event' do | ||
| expect do | ||
| Deal::CreateOrUpdate.new(stage1_position1, { stage: stage2, position: 2 }).call | ||
| end.to change(Event, :count).by(1) | ||
|
|
||
| expect(stage1_position2.reload.position).to eq 1 | ||
| expect(stage1_position3.reload.position).to eq 2 | ||
|
|
||
| expect(stage1_position1.reload.stage_id).to eq stage2.id | ||
|
|
||
| expect(stage2_position1.reload.position).to eq 1 | ||
| expect(stage1_position1.position).to eq 2 | ||
| expect(stage2_position2.reload.position).to eq 3 | ||
| expect(stage2_position3.reload.position).to eq 4 | ||
| expect(last_event.kind).to eq('deal_stage_change') | ||
| end | ||
|
|
||
| it 'move stage1_position1 to stage2 position 3 and create deal_stage_change event' do | ||
| expect do | ||
| Deal::CreateOrUpdate.new(stage1_position1, { stage: stage2, position: 3 }).call | ||
| end.to change(Event, :count).by(1) | ||
|
|
||
| expect(stage1_position2.reload.position).to eq 1 | ||
| expect(stage1_position3.reload.position).to eq 2 | ||
|
|
||
| expect(stage1_position1.reload.stage_id).to eq stage2.id | ||
|
|
||
| expect(stage2_position1.reload.position).to eq 1 | ||
| expect(stage2_position2.reload.position).to eq 2 | ||
| expect(stage1_position1.position).to eq 3 | ||
| expect(stage2_position3.reload.position).to eq 4 | ||
| expect(last_event.kind).to eq('deal_stage_change') | ||
| end | ||
|
|
||
| it 'move stage1_position1 to stage2 position 250 and create deal_stage_change event' do | ||
| expect do | ||
| Deal::CreateOrUpdate.new(stage1_position1, { stage: stage2, position: 250 }).call | ||
| end.to change(Event, :count).by(1) | ||
|
|
||
| expect(stage1_position2.reload.position).to eq 1 | ||
| expect(stage1_position3.reload.position).to eq 2 | ||
|
|
||
| expect(stage1_position1.reload.stage_id).to eq stage2.id | ||
|
|
||
| expect(stage2_position1.reload.position).to eq 1 | ||
| expect(stage2_position2.reload.position).to eq 2 | ||
| expect(stage2_position3.reload.position).to eq 3 | ||
| expect(stage1_position1.position).to eq 250 | ||
| expect(last_event.kind).to eq('deal_stage_change') | ||
| end | ||
| end | ||
|
|
||
| context 'moving within the same stage' do | ||
| it 'move stage1_position1 to position 2' do | ||
| Deal::CreateOrUpdate.new(stage1_position1, { position: 2 }).call | ||
|
|
||
| expect(stage1_position1.reload.position).to eq 2 | ||
| expect(stage1_position2.reload.position).to eq 1 | ||
| expect(stage1_position3.reload.position).to eq 3 | ||
| end | ||
|
|
||
| it 'move stage1_position1 to position 3' do | ||
| Deal::CreateOrUpdate.new(stage1_position1, { position: 3 }).call | ||
|
|
||
| expect(stage1_position1.reload.position).to eq 3 | ||
| expect(stage1_position2.reload.position).to eq 1 | ||
| expect(stage1_position3.reload.position).to eq 2 | ||
| end | ||
| end | ||
|
|
||
| context 'create a deal' do | ||
| context 'when position is not provided' do | ||
| it 'places the new deal at the end of the stage' do | ||
| new_deal = build(:deal, stage: stage1) | ||
| new_deal = Deal::CreateOrUpdate.new(new_deal, {}).call | ||
|
|
||
| expect(stage1_position1.reload.position).to eq 1 | ||
| expect(stage1_position2.reload.position).to eq 2 | ||
| expect(stage1_position3.reload.position).to eq 3 | ||
| expect(new_deal.reload.position).to eq 4 | ||
| end | ||
| end | ||
|
|
||
| context 'when position is provided' do | ||
| it 'inserts the new deal at the specified position' do | ||
| new_deal = build(:deal, stage: stage1, position: 2) | ||
| new_deal = Deal::CreateOrUpdate.new(new_deal, {}).call | ||
|
|
||
| expect(stage1_position1.reload.position).to eq 1 | ||
| expect(new_deal.reload.position).to eq 2 | ||
| expect(stage1_position2.reload.position).to eq 3 | ||
| expect(stage1_position3.reload.position).to eq 4 | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Criei esse pr, pois esse teste está falhando.
E se analisar, parece ser um bug da gem
act_as_list.Fiz o update da gem para a ultima versão, mas esse teste ainda está falhando.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abri uma issue no repostorio da gem
act_as_list, e o rapaz que me respondeu falou que esse bug acontece pq as positions estão com default: 1. Removendo o default, esse bug é corrigido. Fiz isso nesse commit fdfaf83 e esse teste parou de falhar.Segue o q o rapaz comentou:
So yes, you do have a default of 1 for that column. You'll need to remove this. It's best if this column doesn't have a default. What is happening is that acts_as_list can't see that the column value is being set explicitly so it's adding the record to the end of the table. Let me know how you get on