queue_spec.rb 1.3 KB

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