state_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. require 'rails_helper'
  2. RSpec.describe Import::OTRS::State do
  3. def creates_with(zammad_structure)
  4. expect(import_object).to receive(:find_by).and_return(nil)
  5. expect(import_object).to receive(:new).with(zammad_structure).and_call_original
  6. expect_any_instance_of(import_object).to receive(:save)
  7. expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
  8. start_import_test
  9. end
  10. def updates_with(zammad_structure)
  11. expect(import_object).to receive(:find_by).and_return(existing_object)
  12. expect(existing_object).to receive(:update!).with(zammad_structure)
  13. expect(import_object).not_to receive(:new)
  14. start_import_test
  15. end
  16. def load_state_json(file)
  17. json_fixture("import/otrs/state/#{file}")
  18. end
  19. let(:import_object) { Ticket::State }
  20. let(:existing_object) { instance_double(import_object) }
  21. let(:start_import_test) { described_class.new(object_structure) }
  22. context 'closed' do
  23. let(:object_structure) { load_state_json('default') }
  24. let(:zammad_structure) do
  25. {
  26. created_by_id: 1,
  27. updated_by_id: 1,
  28. active: '1',
  29. state_type_id: 5,
  30. updated_at: '2014-04-28 10:53:18',
  31. created_at: '2014-04-28 10:53:18',
  32. name: 'closed successful',
  33. id: '2',
  34. note: 'Ticket is closed successful.'
  35. }
  36. end
  37. it 'creates' do
  38. creates_with(zammad_structure)
  39. end
  40. it 'updates' do
  41. updates_with(zammad_structure)
  42. end
  43. end
  44. end