writes_to_ticket_history_examples.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. RSpec.shared_examples 'TagWritesToTicketHistory' do
  2. subject { create(described_class.name.underscore) }
  3. # The concern is for the tag model, but the shared example needs to be loaded in the ticket test.
  4. it 'can only be loaded for tickets' do
  5. expect(described_class).to eq Ticket
  6. end
  7. it 'creates a ticket history entry for tag_add' do # rubocop:disable RSpec/ExampleLength
  8. subject.tag_add('foo', 1)
  9. expect(subject.history_get.last).to include(
  10. 'object' => described_class.name,
  11. 'o_id' => subject.id,
  12. 'type' => 'added',
  13. 'attribute' => 'tag',
  14. 'value_to' => 'foo',
  15. 'value_from' => nil
  16. )
  17. end
  18. it 'creates a ticket history entry for tag_remove' do # rubocop:disable RSpec/ExampleLength
  19. subject.tag_add('foo', 1)
  20. subject.tag_remove('foo', 1)
  21. expect(subject.history_get.last).to include(
  22. 'object' => described_class.name,
  23. 'o_id' => subject.id,
  24. 'type' => 'removed',
  25. 'attribute' => 'tag',
  26. 'value_to' => 'foo',
  27. 'value_from' => nil
  28. )
  29. end
  30. end