Skip to content

Commit

Permalink
Update Condition's deep copy method and condition_spec.rb RSpec test.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Pinto committed Aug 16, 2024
1 parent 78e372f commit 3b49358
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/models/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class Condition < ApplicationRecord
def deep_copy(**options)
copy = dup
copy.question_id = options.fetch(:question_id, nil)
copy.option_list = options.fetch(:option_list, option_list)
copy.remove_data = options.fetch(:remove_data, remove_data)
copy.action_type = options.fetch(:action_type, action_type)

# TODO: why call validate false here
copy.save!(validate: false) if options.fetch(:save, false)
copy
Expand Down
13 changes: 7 additions & 6 deletions spec/models/condition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,23 @@
action_type: 'remove',
remove_data: [7, 8, 9])
end
let!(:options) { { option_list: [100, 101], action_type: 'remove', remove_data: [200, 220] } }

subject { condition.deep_copy }
subject { condition.deep_copy(**options) }

it 'creates a new record' do
expect(subject).not_to eql(condition)
end
it 'copies the option_list attribute' do
expect(subject.option_list).to contain_exactly(1, 5)
it 'replaces the option_list attribute with passed option_list' do
expect(subject.option_list).to contain_exactly(100, 101)
end

it 'copies the action_type attribute' do
it 'replaces the action_type attribute with passed in action_type' do
expect(subject.action_type).to eql('remove')
end

it 'copies the remove_data attribute' do
expect(subject.remove_data).to contain_exactly(7, 8, 9)
it 'replaces the remove_data attribute with passed in remove_data' do
expect(subject.remove_data).to contain_exactly(200, 220)
end
end
end

0 comments on commit 3b49358

Please sign in to comment.