Skip to content

Commit 023a1a4

Browse files
committed
Add specs
1 parent 6dbf828 commit 023a1a4

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

spec/requests/partners_requests_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,22 @@
468468
end
469469
end
470470

471+
context "csv file with a partner email already in another organization" do
472+
let(:file) { fixture_file_upload("partners_with_six_fields.csv", "text/csv") }
473+
474+
before do
475+
other_org = create(:organization)
476+
create(:partner, name: "Existing Partner", email: "[email protected]", organization: other_org)
477+
end
478+
479+
subject { post import_csv_partners_path, params: { file: file } }
480+
481+
it "shows an error for the partner in another organization" do
482+
subject
483+
expect(flash[:error]).to match(/has already been taken/)
484+
end
485+
end
486+
471487
context "csv file with wrong headers" do
472488
let(:file) { fixture_file_upload("wrong_headers.csv", "text/csv") }
473489
subject { post import_csv_partners_path, params: { file: file } }

spec/services/partner_create_service_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@
3030
end
3131
end
3232

33+
context 'when the partner email already exists in a different organization' do
34+
let(:other_organization) { create(:organization) }
35+
36+
before do
37+
create(:partner, email: partner_attrs[:email], organization: other_organization)
38+
end
39+
40+
it 'should contain an error about the partner being with a different organization' do
41+
result = subject
42+
expect(result.errors[:email]).to include("has already been taken")
43+
end
44+
45+
it 'should not create a new partner' do
46+
expect { subject }.not_to change { Partner.count }
47+
end
48+
end
49+
3350
context 'when the arguments are valid' do
3451
it 'should create a new partner record with the organization provided' do
3552
expect { subject }.to change { organization.partners.count }.by(1)
@@ -103,4 +120,3 @@
103120
end
104121
end
105122
end
106-

0 commit comments

Comments
 (0)