diff --git a/lib/sequencer/unit/import/common/model/save.rb b/lib/sequencer/unit/import/common/model/save.rb index de0595bf1..ea8d12646 100644 --- a/lib/sequencer/unit/import/common/model/save.rb +++ b/lib/sequencer/unit/import/common/model/save.rb @@ -6,11 +6,14 @@ class Sequencer module Common module Model class Save < Sequencer::Unit::Base + prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure - uses :instance, :dry_run + uses :instance, :action, :dry_run provides :instance + skip_action :skipped, :failed, :unchanged + def process return if dry_run return if instance.blank? diff --git a/spec/lib/sequencer/unit/import/common/model/save_spec.rb b/spec/lib/sequencer/unit/import/common/model/save_spec.rb new file mode 100644 index 000000000..d9894c8fe --- /dev/null +++ b/spec/lib/sequencer/unit/import/common/model/save_spec.rb @@ -0,0 +1,47 @@ +require 'rails_helper' + +RSpec.describe Sequencer::Unit::Import::Common::Model::Save, sequencer: :unit do + let(:user) { instance_double('User') } + + before { allow(user).to receive(:save!) } + + context 'for action: :created' do + it 'calls #save!' do + process(action: :created, instance: user, dry_run: false) + + expect(user).to have_received(:save!) + end + end + + context 'for action: :updated' do + it 'calls #save!' do + process(action: :updated, instance: user, dry_run: false) + + expect(user).to have_received(:save!) + end + end + + context 'for action: :unchanged' do + it 'avoids calling #save!' do + process(action: :unchanged, instance: user, dry_run: false) + + expect(user).not_to have_received(:save!) + end + end + + context 'for action: :skipped' do + it 'avoids calling #save!' do + process(action: :skipped, instance: user, dry_run: false) + + expect(user).not_to have_received(:save!) + end + end + + context 'for action: :failed' do + it 'avoids calling #save!' do + process(action: :failed, instance: user, dry_run: false) + + expect(user).not_to have_received(:save!) + end + end +end