save_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sequencer::Unit::Import::Common::Model::Save, sequencer: :unit do
  4. let(:user) { instance_double(User) }
  5. before { allow(user).to receive(:save!) }
  6. context 'for action: :created' do
  7. it 'calls #save!' do
  8. process(action: :created, instance: user, dry_run: false)
  9. expect(user).to have_received(:save!)
  10. end
  11. end
  12. context 'for action: :updated' do
  13. it 'calls #save!' do
  14. process(action: :updated, instance: user, dry_run: false)
  15. expect(user).to have_received(:save!)
  16. end
  17. end
  18. context 'for action: :unchanged' do
  19. it 'avoids calling #save!' do
  20. process(action: :unchanged, instance: user, dry_run: false)
  21. expect(user).not_to have_received(:save!)
  22. end
  23. end
  24. context 'for action: :skipped' do
  25. it 'avoids calling #save!' do
  26. process(action: :skipped, instance: user, dry_run: false)
  27. expect(user).not_to have_received(:save!)
  28. end
  29. end
  30. context 'for action: :failed' do
  31. it 'avoids calling #save!' do
  32. process(action: :failed, instance: user, dry_run: false)
  33. expect(user).not_to have_received(:save!)
  34. end
  35. end
  36. context 'for BulkImportInfo flag' do
  37. it 'enables BulkImportInfo' do
  38. expect(BulkImportInfo).to receive(:enable)
  39. process(action: :created, instance: user, dry_run: false)
  40. end
  41. it 'ensures BulkImportInfo is disabled' do
  42. expect(BulkImportInfo).to receive(:disable)
  43. process(action: :created, instance: user, dry_run: false)
  44. end
  45. end
  46. end