updates_ticket_organization_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe User::UpdatesTicketOrganization, type: :model do
  4. subject(:ticket) { build(:ticket, customer: customer, organization: nil) }
  5. let(:customer) { create(:customer, :with_org) }
  6. context 'when ticket is created' do
  7. it 'automatically adopts the organization of its #customer' do
  8. expect { ticket.save }
  9. .to change(ticket, :organization).to(customer.organization)
  10. end
  11. end
  12. context 'when #customer.organization is updated' do
  13. context 'when set to nil' do
  14. it 'automatically updates to #customer’s new value' do
  15. ticket.save
  16. expect { customer.update(organization: nil) }
  17. .to change { ticket.reload.organization }.to(nil)
  18. end
  19. end
  20. context 'when #customer.organization is updated to a different organization' do
  21. let(:old_org) { customer.organization }
  22. let(:new_org) { create(:organization) }
  23. it 'automatically updates to #customer’s new value' do
  24. ticket.save
  25. expect { customer.update(organization: new_org) }
  26. .to change { ticket.reload.organization }.to(new_org)
  27. end
  28. it 'has made all changes with user id 1' do
  29. expect(ticket.updated_by.id).to eq 1
  30. end
  31. # https://github.com/zammad/zammad/issues/3952
  32. it 'does not send notifications' do
  33. allow(NotificationFactory::Mailer).to receive(:send)
  34. customer.update(organization: old_org)
  35. expect(NotificationFactory::Mailer).not_to have_received(:send)
  36. end
  37. end
  38. end
  39. end