trabajo-afectivo/spec/models/user/updates_ticket_organization_spec.rb

52 lines
1.6 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
require 'rails_helper'
RSpec.describe User::UpdatesTicketOrganization, type: :model do
subject(:ticket) { build(:ticket, customer: customer, organization: nil) }
let(:customer) { create(:customer, :with_org) }
context 'when ticket is created' do
it 'automatically adopts the organization of its #customer' do
expect { ticket.save }
.to change(ticket, :organization).to(customer.organization)
end
end
context 'when #customer.organization is updated' do
context 'when set to nil' do
it 'automatically updates to #customers new value' do
ticket.save
expect { customer.update(organization: nil) }
.to change { ticket.reload.organization }.to(nil)
end
end
context 'when #customer.organization is updated to a different organization' do
let(:old_org) { customer.organization }
let(:new_org) { create(:organization) }
it 'automatically updates to #customers new value' do
ticket.save
expect { customer.update(organization: new_org) }
.to change { ticket.reload.organization }.to(new_org)
end
it 'has made all changes with user id 1' do
expect(ticket.updated_by.id).to eq 1
end
# https://github.com/zammad/zammad/issues/3952
it 'does not send notifications' do
allow(NotificationFactory::Mailer).to receive(:send)
customer.update(organization: old_org)
expect(NotificationFactory::Mailer).not_to have_received(:send)
end
end
end
end