summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-11-07 06:51:48 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-11-07 06:51:48 +0000
commit1b788c66a1b1861d8dcca14785d22c59e31713fd (patch)
tree90bcb8aca6fba513bda4296b0143febce1f4a21f /spec/models
parent6da118095b6d3b7a1cf306a82841cb265d7d8016 (diff)
parentbb55bcddb80adf017d82758587761f413674d985 (diff)
downloadgitlab-ce-1b788c66a1b1861d8dcca14785d22c59e31713fd.tar.gz
Merge branch 'sh-fix-issue-52649' into 'master'
Fix statement timeouts in RemoveRestrictedTodos migration Closes #52649 See merge request gitlab-org/gitlab-ce!22795
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/concerns/each_batch_spec.rb51
1 files changed, 28 insertions, 23 deletions
diff --git a/spec/models/concerns/each_batch_spec.rb b/spec/models/concerns/each_batch_spec.rb
index 951690a217b..17224c09693 100644
--- a/spec/models/concerns/each_batch_spec.rb
+++ b/spec/models/concerns/each_batch_spec.rb
@@ -14,40 +14,45 @@ describe EachBatch do
5.times { create(:user, updated_at: 1.day.ago) }
end
- it 'yields an ActiveRecord::Relation when a block is given' do
- model.each_batch do |relation|
- expect(relation).to be_a_kind_of(ActiveRecord::Relation)
+ shared_examples 'each_batch handling' do |kwargs|
+ it 'yields an ActiveRecord::Relation when a block is given' do
+ model.each_batch(kwargs) do |relation|
+ expect(relation).to be_a_kind_of(ActiveRecord::Relation)
+ end
end
- end
- it 'yields a batch index as the second argument' do
- model.each_batch do |_, index|
- expect(index).to eq(1)
+ it 'yields a batch index as the second argument' do
+ model.each_batch(kwargs) do |_, index|
+ expect(index).to eq(1)
+ end
end
- end
- it 'accepts a custom batch size' do
- amount = 0
+ it 'accepts a custom batch size' do
+ amount = 0
- model.each_batch(of: 1) { amount += 1 }
+ model.each_batch(kwargs.merge({ of: 1 })) { amount += 1 }
- expect(amount).to eq(5)
- end
+ expect(amount).to eq(5)
+ end
- it 'does not include ORDER BYs in the yielded relations' do
- model.each_batch do |relation|
- expect(relation.to_sql).not_to include('ORDER BY')
+ it 'does not include ORDER BYs in the yielded relations' do
+ model.each_batch do |relation|
+ expect(relation.to_sql).not_to include('ORDER BY')
+ end
end
- end
- it 'allows updating of the yielded relations' do
- time = Time.now
+ it 'allows updating of the yielded relations' do
+ time = Time.now
- model.each_batch do |relation|
- relation.update_all(updated_at: time)
- end
+ model.each_batch do |relation|
+ relation.update_all(updated_at: time)
+ end
- expect(model.where(updated_at: time).count).to eq(5)
+ expect(model.where(updated_at: time).count).to eq(5)
+ end
end
+
+ it_behaves_like 'each_batch handling', {}
+ it_behaves_like 'each_batch handling', { order_hint: :updated_at }
end
end