Avoid saving users during LDAP import if unchanged (fixes #2187)
This commit is contained in:
parent
c6e6423dd0
commit
1f3da97cc9
2 changed files with 51 additions and 1 deletions
|
@ -6,11 +6,14 @@ class Sequencer
|
||||||
module Common
|
module Common
|
||||||
module Model
|
module Model
|
||||||
class Save < Sequencer::Unit::Base
|
class Save < Sequencer::Unit::Base
|
||||||
|
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
|
||||||
include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
|
include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
|
||||||
|
|
||||||
uses :instance, :dry_run
|
uses :instance, :action, :dry_run
|
||||||
provides :instance
|
provides :instance
|
||||||
|
|
||||||
|
skip_action :skipped, :failed, :unchanged
|
||||||
|
|
||||||
def process
|
def process
|
||||||
return if dry_run
|
return if dry_run
|
||||||
return if instance.blank?
|
return if instance.blank?
|
||||||
|
|
47
spec/lib/sequencer/unit/import/common/model/save_spec.rb
Normal file
47
spec/lib/sequencer/unit/import/common/model/save_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue