From fdcc0fbfc3a78760ddb4d08ccd33bd251f251a59 Mon Sep 17 00:00:00 2001 From: Karina Date: Wed, 13 Sep 2023 15:26:00 +0300 Subject: [PATCH] Fix specs for new record position --- spec/integration/multiple_fields_spec.rb | 84 ++++++++++++++---------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/spec/integration/multiple_fields_spec.rb b/spec/integration/multiple_fields_spec.rb index 942753a..7a055d9 100644 --- a/spec/integration/multiple_fields_spec.rb +++ b/spec/integration/multiple_fields_spec.rb @@ -14,27 +14,30 @@ describe 'inserting' do let(:newbie) { MultipleFieldsOrderable.create! } - before { @position = newbie.position } + before do + @position = newbie.position + @record = MultipleFieldsOrderable.find(newbie.id) + end it 'top' do - newbie.move_to! :top + @record.move_to! :top expect(serial_nos).to eq([1, 2, 3, 4, 5, 6]) - expect(newbie.serial_no).to eq(1) - expect(newbie.position).to eq(@position) + expect(@record.serial_no).to eq(1) + expect(@record.position).to eq(@position) end it 'bottom' do - newbie.move_to! :bottom + @record.move_to! :bottom expect(serial_nos).to eq([1, 2, 3, 4, 5, 6]) - expect(newbie.serial_no).to eq(6) - expect(newbie.position).to eq(@position) + expect(@record.serial_no).to eq(6) + expect(@record.position).to eq(@position) end it 'middle' do - newbie.move_to! 4 + @record.move_to! 4 expect(serial_nos).to eq([1, 2, 3, 4, 5, 6]) - expect(newbie.serial_no).to eq(4) - expect(newbie.position).to eq(@position) + expect(@record.serial_no).to eq(4) + expect(@record.position).to eq(@position) end end @@ -163,27 +166,30 @@ describe 'inserting' do let(:newbie) { MultipleFieldsOrderable.create! } - before { @position = newbie.position } + before do + @position = newbie.position + @record = MultipleFieldsOrderable.find(newbie.id) + end it 'top' do - newbie.move_serial_no_to! :top + @record.move_serial_no_to! :top expect(serial_nos).to eq([1, 2, 3, 4, 5, 6]) - expect(newbie.serial_no).to eq(1) - expect(newbie.position).to eq(@position) + expect(@record.serial_no).to eq(1) + expect(@record.position).to eq(@position) end it 'bottom' do - newbie.move_serial_no_to! :bottom + @record.move_serial_no_to! :bottom expect(serial_nos).to eq([1, 2, 3, 4, 5, 6]) - expect(newbie.serial_no).to eq(6) - expect(newbie.position).to eq(@position) + expect(@record.serial_no).to eq(6) + expect(@record.position).to eq(@position) end it 'middle' do - newbie.move_serial_no_to! 4 + @record.move_serial_no_to! 4 expect(serial_nos).to eq([1, 2, 3, 4, 5, 6]) - expect(newbie.serial_no).to eq(4) - expect(newbie.position).to eq(@position) + expect(@record.serial_no).to eq(4) + expect(@record.position).to eq(@position) end end @@ -316,27 +322,30 @@ describe 'inserting' do let(:newbie) { MultipleFieldsOrderable.create! } - before { @serial_no = newbie.serial_no } + before do + @serial_no = newbie.serial_no + @record = MultipleFieldsOrderable.find(newbie.id) + end it 'top' do - newbie.move_position_to! :top + @record.move_position_to! :top expect(positions).to eq([0, 1, 2, 3, 4, 5]) - expect(newbie.position).to eq(0) - expect(newbie.serial_no).to eq(@serial_no) + expect(@record.position).to eq(0) + expect(@record.serial_no).to eq(@serial_no) end it 'bottom' do - newbie.move_position_to! :bottom + @record.move_position_to! :bottom expect(positions).to eq([0, 1, 2, 3, 4, 5]) - expect(newbie.position).to eq(5) - expect(newbie.serial_no).to eq(@serial_no) + expect(@record.position).to eq(5) + expect(@record.serial_no).to eq(@serial_no) end it 'middle' do - newbie.move_position_to! 4 + @record.move_position_to! 4 expect(positions).to eq([0, 1, 2, 3, 4, 5]) - expect(newbie.position).to eq(4) - expect(newbie.serial_no).to eq(@serial_no) + expect(@record.position).to eq(4) + expect(@record.serial_no).to eq(@serial_no) end end @@ -458,23 +467,26 @@ describe 'inserting' do it 'top' do newbie = MultipleFieldsOrderable.create! group_id: 1 - newbie.move_groups_to! :top + record = MultipleFieldsOrderable.find(newbie.id) + record.move_groups_to! :top expect(all_groups).to eq([1, 2, 3, 1, 2, 3]) - expect(newbie.groups).to eq(1) + expect(record.groups).to eq(1) end it 'bottom' do newbie = MultipleFieldsOrderable.create! group_id: 2 - newbie.move_groups_to! :bottom + record = MultipleFieldsOrderable.find(newbie.id) + record.move_groups_to! :bottom expect(all_groups).to eq([1, 2, 1, 2, 3, 4]) - expect(newbie.groups).to eq(4) + expect(record.groups).to eq(4) end it 'middle' do newbie = MultipleFieldsOrderable.create! group_id: 2 - newbie.move_groups_to! 2 + record = MultipleFieldsOrderable.find(newbie.id) + record.move_groups_to! 2 expect(all_groups).to eq([1, 2, 1, 2, 3, 4]) - expect(newbie.groups).to eq(2) + expect(record.groups).to eq(2) end end