Skip to content

Commit f247021

Browse files
authored
Merge pull request #6364 from Kerman07/update-contact-types-new-spec
test: update contact_types/new_spec.rb and add new spec for uniqueness validation within the same group
2 parents 3221220 + 97fe4bd commit f247021

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
1+
# frozen_string_literal: true
2+
13
require "rails_helper"
24

35
RSpec.describe "contact_types/new", type: :system do
46
let!(:organization) { create(:casa_org) }
5-
let!(:admin) { create(:casa_admin, casa_org_id: organization.id) }
7+
let!(:admin) { create(:casa_admin, casa_org: organization) }
68
let!(:contact_type_group) { create(:contact_type_group, casa_org: organization, name: "Contact type group 1") }
7-
let!(:contact_type) { create(:contact_type, name: "Contact type 1") }
89

910
before do
1011
sign_in admin
11-
12-
visit new_contact_type_path(contact_type)
12+
visit new_contact_type_path
1313
end
1414

15-
it "errors with invalid name" do
16-
fill_in "Name", with: ""
17-
click_on "Submit"
15+
context "with valid data" do
16+
it "creates contact type successfully" do
17+
fill_in "Name", with: "New Contact Type test"
18+
click_on "Submit"
1819

19-
expect(page).to have_text("Name can't be blank")
20+
expect(page).to have_text("Contact Type was successfully created.")
21+
end
2022
end
2123

22-
it "creates with valid data" do
23-
fill_in "Name", with: "New Contact Type test"
24-
click_on "Submit"
24+
context "with invalid data" do
25+
it "shows error when name is blank" do
26+
fill_in "Name", with: ""
27+
click_on "Submit"
28+
29+
expect(page).to have_text("Name can't be blank")
30+
end
31+
32+
it "shows error when name is not unique within group" do
33+
create(:contact_type, name: "Existing Name", contact_type_group:)
34+
35+
fill_in "Name", with: "Existing Name"
36+
select "Contact type group 1", from: "contact_type_contact_type_group_id"
37+
click_on "Submit"
2538

26-
expect(page).to have_text("Contact Type was successfully created.")
39+
expect(page).to have_text("Name should be unique per contact type group")
40+
end
2741
end
2842
end

0 commit comments

Comments
 (0)