organization_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. require 'rails_helper'
  2. require 'models/application_model_examples'
  3. require 'models/concerns/can_csv_import_examples'
  4. require 'models/concerns/has_history_examples'
  5. require 'models/concerns/has_search_index_backend_examples'
  6. require 'models/concerns/has_xss_sanitized_note_examples'
  7. require 'models/concerns/has_object_manager_attributes_validation_examples'
  8. RSpec.describe Organization, type: :model do
  9. it_behaves_like 'ApplicationModel', can_assets: { associations: :members }
  10. it_behaves_like 'CanCsvImport', unique_attributes: 'name'
  11. it_behaves_like 'HasHistory'
  12. it_behaves_like 'HasSearchIndexBackend', indexed_factory: :organization
  13. it_behaves_like 'HasXssSanitizedNote', model_factory: :organization
  14. it_behaves_like 'HasObjectManagerAttributesValidation'
  15. subject(:organization) { create(:organization) }
  16. describe 'Class methods:' do
  17. describe '.where_or_cis' do
  18. it 'finds instance by querying multiple attributes case insensitive' do
  19. # search for Zammad Foundation
  20. organizations = described_class.where_or_cis(%i[name note], '%zammad%')
  21. expect(organizations).not_to be_blank
  22. end
  23. end
  24. end
  25. describe 'Callbacks, Observers, & Async Transactions -' do
  26. describe 'Touching associations on update:' do
  27. let!(:member) { create(:customer_user, organization: organization) }
  28. let!(:member_ticket) { create(:ticket, customer: member) }
  29. context 'when member associations are added' do
  30. let(:user) { create(:customer_user) }
  31. it 'is touched, and touches its other members (but not their tickets)' do
  32. expect { organization.members.push(user) }
  33. .to change { organization.reload.updated_at }
  34. end
  35. end
  36. end
  37. end
  38. end