Avoid saving users during LDAP import if unchanged (fixes #2187)

This commit is contained in:
Ryan Lue 2018-08-15 18:05:54 +08:00
parent c6e6423dd0
commit 1f3da97cc9
2 changed files with 51 additions and 1 deletions

View file

@ -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?

View 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