|
6 | 6 | let(:checklist) { create(:better_together_checklist) } |
7 | 7 | # create a few items |
8 | 8 | let!(:parent) { create(:better_together_checklist_item, checklist: checklist) } |
| 9 | + # capture existing item ids so newly created items can be found without relying on a `label` column |
| 10 | + let!(:existing_item_ids) { checklist.checklist_items.pluck(:id) } |
9 | 11 |
|
10 | 12 | context 'when creating a nested child' do |
11 | 13 | before do |
|
26 | 28 | end |
27 | 29 |
|
28 | 30 | let(:created) do |
29 | | - BetterTogether::ChecklistItem.where(checklist: checklist, parent: parent).find_by(label: 'nested child') || |
| 31 | + BetterTogether::ChecklistItem.where(checklist: checklist, |
| 32 | + parent: parent).where.not(id: existing_item_ids).first || |
30 | 33 | BetterTogether::ChecklistItem.i18n.find_by(label: 'nested child') |
31 | 34 | end |
32 | 35 |
|
|
39 | 42 | end |
40 | 43 | end |
41 | 44 |
|
42 | | - context 'when reordering siblings' do |
| 45 | + context 'when reordering siblings' do # rubocop:todo RSpec/MultipleMemoizedHelpers |
43 | 46 | let!(:a) { create(:better_together_checklist_item, checklist: checklist, parent: parent, position: 0) } |
44 | 47 | let!(:b) { create(:better_together_checklist_item, checklist: checklist, parent: parent, position: 1) } |
45 | 48 | let!(:top) { create(:better_together_checklist_item, checklist: checklist, position: 0) } |
|
81 | 84 | end |
82 | 85 |
|
83 | 86 | let(:created_localized) do |
84 | | - BetterTogether::ChecklistItem.where(checklist: checklist, parent: parent).find_by(label: 'localized child') |
| 87 | + BetterTogether::ChecklistItem.where(checklist: checklist, parent: parent).where.not(id: existing_item_ids).first |
85 | 88 | end |
86 | 89 |
|
87 | 90 | it 'creates a localized child record' do |
|
0 commit comments