Skip to content

Commit c4b64a2

Browse files
authored
Merge pull request #6531 from AudTheCodeWitch/acook/6321/update-judges-new-spec
System Test Overhaul spec/system/judges/new_spec.rb
2 parents 9d04353 + 1d0dbea commit c4b64a2

File tree

1 file changed

+70
-8
lines changed

1 file changed

+70
-8
lines changed

spec/system/judges/new_spec.rb

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,87 @@
1+
# frozen_string_literal: true
2+
13
require "rails_helper"
4+
require "faker"
25

36
RSpec.describe "judges/new", type: :system do
47
let(:organization) { create(:casa_org) }
58
let(:admin) { create(:casa_admin, casa_org_id: organization.id) }
9+
let(:active_name) { Faker::Name.unique.name }
10+
let(:inactive_name) { Faker::Name.unique.name }
611

712
before do
813
sign_in admin
9-
1014
visit new_judge_path
1115
end
1216

13-
it "adds new judge" do
14-
fill_in "Name", with: ""
15-
click_on "Submit"
17+
# rubocop:disable RSpec/ExampleLength
18+
it "creates an active judge with valid name", :aggregate_failures do
19+
submit_judge_form(name: active_name, active: true)
20+
expect(page).to have_text("Judge was successfully created.")
21+
expect(page).to have_text(active_name)
1622

17-
expect(page).to have_text("Name can't be blank")
23+
judge = Judge.find_by(name: active_name)
24+
expect(judge).not_to be_nil
25+
expect(judge.active).to be true
26+
end
27+
# rubocop:enable RSpec/ExampleLength
1828

19-
fill_in "Name", with: "Joey Shmoey"
20-
click_on "Submit"
29+
# rubocop:disable RSpec/ExampleLength
30+
it "creates an inactive judge with valid name", :aggregate_failures do
31+
submit_judge_form(name: inactive_name, active: false)
32+
expect(page).to have_text("Judge was successfully created.")
33+
expect(page).to have_text(inactive_name)
34+
35+
judge = Judge.find_by(name: inactive_name)
36+
expect(judge).not_to be_nil
37+
expect(judge.active).to be false
38+
end
39+
# rubocop:enable RSpec/ExampleLength
2140

41+
# rubocop:disable RSpec/ExampleLength
42+
it "creates a judge with a very long name", :aggregate_failures do
43+
long_name = Faker::Lorem.characters(number: 255)
44+
submit_judge_form(name: long_name)
2245
expect(page).to have_text("Judge was successfully created.")
23-
expect(page).to have_text("Joey Shmoey")
46+
expect(page).to have_text(long_name)
47+
48+
judge = Judge.find_by(name: long_name)
49+
expect(judge).not_to be_nil
50+
end
51+
# rubocop:enable RSpec/ExampleLength
52+
53+
# rubocop:disable RSpec/ExampleLength
54+
it "creates a judge with special characters in the name", :aggregate_failures do
55+
special_name = "#{Faker::Lorem.characters(number: 30, min_alpha: 10, min_numeric: 5)}!@#$%^&*()"
56+
submit_judge_form(name: special_name)
57+
expect(page).to have_text("Judge was successfully created.")
58+
expect(page).to have_text(special_name)
59+
60+
judge = Judge.find_by(name: special_name)
61+
expect(judge).not_to be_nil
62+
end
63+
# rubocop:enable RSpec/ExampleLength
64+
65+
context "when validations fail" do
66+
it "shows validation error when name is blank" do
67+
submit_judge_form(name: "")
68+
expect(page).to have_text("Name can't be blank")
69+
end
70+
71+
it "does not allow duplicate judge names in the same organization", :aggregate_failures do
72+
duplicate_name = Faker::Name.unique.name
73+
create(:judge, name: duplicate_name, casa_org: organization)
74+
submit_judge_form(name: duplicate_name)
75+
expect(page).to have_text("Name has already been taken")
76+
expect(Judge.where(name: duplicate_name, casa_org: organization).count).to eq 1
77+
end
78+
end
79+
80+
private
81+
82+
def submit_judge_form(name:, active: true)
83+
fill_in "Name", with: name
84+
active ? check("Active?") : uncheck("Active?")
85+
click_on "Submit"
2486
end
2587
end

0 commit comments

Comments
 (0)