diff options
Diffstat (limited to 'spec/models/customer_relations/organization_spec.rb')
-rw-r--r-- | spec/models/customer_relations/organization_spec.rb | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/spec/models/customer_relations/organization_spec.rb b/spec/models/customer_relations/organization_spec.rb index d19a0bdf6c7..7fab9fd0e80 100644 --- a/spec/models/customer_relations/organization_spec.rb +++ b/spec/models/customer_relations/organization_spec.rb @@ -10,7 +10,7 @@ RSpec.describe CustomerRelations::Organization, type: :model do end describe 'validations' do - subject { build(:organization) } + subject { build(:crm_organization) } it { is_expected.to validate_presence_of(:group) } it { is_expected.to validate_presence_of(:name) } @@ -21,13 +21,13 @@ RSpec.describe CustomerRelations::Organization, type: :model do describe '#root_group' do context 'when root group' do - subject { build(:organization, group: group) } + subject { build(:crm_organization, group: group) } it { is_expected.to be_valid } end context 'when subgroup' do - subject { build(:organization, group: create(:group, parent: group)) } + subject { build(:crm_organization, group: create(:group, parent: group)) } it { is_expected.to be_invalid } end @@ -43,23 +43,25 @@ RSpec.describe CustomerRelations::Organization, type: :model do end describe '#find_by_name' do - let!(:organiztion1) { create(:organization, group: group, name: 'Test') } - let!(:organiztion2) { create(:organization, group: create(:group), name: 'Test') } + let!(:crm_organiztion1) { create(:crm_organization, group: group, name: 'Test') } + let!(:crm_organiztion2) { create(:crm_organization, group: create(:group), name: 'Test') } it 'strips name' do - expect(described_class.find_by_name(group.id, 'TEST')).to eq([organiztion1]) + expect(described_class.find_by_name(group.id, 'TEST')).to eq([crm_organiztion1]) end end describe '#self.move_to_root_group' do let!(:old_root_group) { create(:group) } - let!(:organizations) { create_list(:organization, 4, group: old_root_group) } + let!(:crm_organizations) { create_list(:crm_organization, 4, group: old_root_group) } let!(:new_root_group) { create(:group) } - let!(:contact1) { create(:contact, group: new_root_group, organization: organizations[0]) } - let!(:contact2) { create(:contact, group: new_root_group, organization: organizations[1]) } + let!(:contact1) { create(:contact, group: new_root_group, organization: crm_organizations[0]) } + let!(:contact2) { create(:contact, group: new_root_group, organization: crm_organizations[1]) } - let!(:dupe_organization1) { create(:organization, group: new_root_group, name: organizations[1].name) } - let!(:dupe_organization2) { create(:organization, group: new_root_group, name: organizations[3].name.upcase) } + let!(:dupe_crm_organization1) { create(:crm_organization, group: new_root_group, name: crm_organizations[1].name) } + let!(:dupe_crm_organization2) do + create(:crm_organization, group: new_root_group, name: crm_organizations[3].name.upcase) + end before do old_root_group.update!(parent: new_root_group) @@ -67,22 +69,22 @@ RSpec.describe CustomerRelations::Organization, type: :model do end it 'moves organizations with unique names and deletes the rest' do - expect(organizations[0].reload.group_id).to eq(new_root_group.id) - expect(organizations[2].reload.group_id).to eq(new_root_group.id) - expect { organizations[1].reload }.to raise_error(ActiveRecord::RecordNotFound) - expect { organizations[3].reload }.to raise_error(ActiveRecord::RecordNotFound) + expect(crm_organizations[0].reload.group_id).to eq(new_root_group.id) + expect(crm_organizations[2].reload.group_id).to eq(new_root_group.id) + expect { crm_organizations[1].reload }.to raise_error(ActiveRecord::RecordNotFound) + expect { crm_organizations[3].reload }.to raise_error(ActiveRecord::RecordNotFound) end it 'updates contact.organization_id for dupes and leaves the rest untouched' do - expect(contact1.reload.organization_id).to eq(organizations[0].id) - expect(contact2.reload.organization_id).to eq(dupe_organization1.id) + expect(contact1.reload.organization_id).to eq(crm_organizations[0].id) + expect(contact2.reload.organization_id).to eq(dupe_crm_organization1.id) end end describe '.search' do - let_it_be(:organization_a) do + let_it_be(:crm_organization_a) do create( - :organization, + :crm_organization, group: group, name: "DEF", description: "ghi_st", @@ -90,9 +92,9 @@ RSpec.describe CustomerRelations::Organization, type: :model do ) end - let_it_be(:organization_b) do + let_it_be(:crm_organization_b) do create( - :organization, + :crm_organization, group: group, name: "ABC_st", description: "JKL", @@ -106,7 +108,7 @@ RSpec.describe CustomerRelations::Organization, type: :model do let(:search_term) { "" } it 'returns all group organizations' do - expect(found_organizations).to contain_exactly(organization_a, organization_b) + expect(found_organizations).to contain_exactly(crm_organization_a, crm_organization_b) end end @@ -114,42 +116,42 @@ RSpec.describe CustomerRelations::Organization, type: :model do context 'when searching for name' do let(:search_term) { "aBc" } - it { is_expected.to contain_exactly(organization_b) } + it { is_expected.to contain_exactly(crm_organization_b) } end context 'when searching for description' do let(:search_term) { "ghI" } - it { is_expected.to contain_exactly(organization_a) } + it { is_expected.to contain_exactly(crm_organization_a) } end context 'when searching for name and description' do let(:search_term) { "_st" } - it { is_expected.to contain_exactly(organization_a, organization_b) } + it { is_expected.to contain_exactly(crm_organization_a, crm_organization_b) } end end end describe '.search_by_state' do - let_it_be(:organization_a) { create(:organization, group: group, state: "inactive") } - let_it_be(:organization_b) { create(:organization, group: group, state: "active") } + let_it_be(:crm_organization_a) { create(:crm_organization, group: group, state: "inactive") } + let_it_be(:crm_organization_b) { create(:crm_organization, group: group, state: "active") } context 'when searching for organizations state' do it 'returns only inactive organizations' do - expect(group.organizations.search_by_state(:inactive)).to contain_exactly(organization_a) + expect(group.organizations.search_by_state(:inactive)).to contain_exactly(crm_organization_a) end it 'returns only active organizations' do - expect(group.organizations.search_by_state(:active)).to contain_exactly(organization_b) + expect(group.organizations.search_by_state(:active)).to contain_exactly(crm_organization_b) end end end describe '.counts_by_state' do before do - create_list(:organization, 3, group: group) - create_list(:organization, 2, group: group, state: 'inactive') + create_list(:crm_organization, 3, group: group) + create_list(:crm_organization, 2, group: group, state: 'inactive') end it 'returns correct organization counts' do @@ -168,20 +170,20 @@ RSpec.describe CustomerRelations::Organization, type: :model do end describe 'sorting' do - let_it_be(:organization_a) { create(:organization, group: group, name: "c", description: "1") } - let_it_be(:organization_b) { create(:organization, group: group, name: "a") } - let_it_be(:organization_c) { create(:organization, group: group, name: "b", description: "2") } + let_it_be(:crm_organization_a) { create(:crm_organization, group: group, name: "c", description: "1") } + let_it_be(:crm_organization_b) { create(:crm_organization, group: group, name: "a") } + let_it_be(:crm_organization_c) { create(:crm_organization, group: group, name: "b", description: "2") } describe '.sort_by_name' do it 'sorts them by name in ascendent order' do - expect(group.organizations.sort_by_name).to eq([organization_b, organization_c, organization_a]) + expect(group.organizations.sort_by_name).to eq([crm_organization_b, crm_organization_c, crm_organization_a]) end end describe '.sort_by_field' do it 'sorts them by description in descending order' do expect(group.organizations.sort_by_field('description', :desc)) - .to eq([organization_c, organization_a, organization_b]) + .to eq([crm_organization_c, crm_organization_a, crm_organization_b]) end end end |