-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathout_of_state_controller_spec.rb
More file actions
98 lines (78 loc) · 3.15 KB
/
out_of_state_controller_spec.rb
File metadata and controls
98 lines (78 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require "rails_helper"
RSpec.describe OutOfStateController, type: :controller do
# Only NC has counties
let(:state_with_counties) { LocationData::States::NORTH_CAROLINA }
def all_nc_counties
LocationData::Counties.for_state(state_with_counties).values
end
def supported_counties
all_nc_counties.select { |c| c[:is_supported] }
end
def unsupported_counties
all_nc_counties.reject { |c| c[:is_supported] }
end
def county_name(county)
county[:name]
end
describe ".not_listed?" do
it "returns true when state is NOT_LISTED" do
screener = create(:screener, state: LocationData::States::NOT_LISTED)
expect(described_class.not_listed?(screener)).to eq(true)
end
it "returns false for a normal state" do
screener = create(:screener, state: state_with_counties)
expect(described_class.not_listed?(screener)).to eq(false)
end
end
describe ".county_not_supported?" do
it "returns false when county is nil" do
screener = create(:screener, state: state_with_counties, county: nil)
expect {
described_class.county_not_supported?(screener)
}.to raise_error(ArgumentError, /county_key is required/)
end
it "returns false for supported counties" do
county = supported_counties.first
screener = create(:screener, state: state_with_counties, county: county_name(county))
expect(described_class.county_not_supported?(screener)).to eq(false)
end
it "returns true for unsupported counties" do
county = unsupported_counties.first
screener = create(:screener, state: state_with_counties, county: county_name(county))
expect(described_class.county_not_supported?(screener)).to eq(true)
end
end
describe ".show?" do
it "returns true if state is NOT_LISTED" do
screener = create(:screener, state: LocationData::States::NOT_LISTED)
expect(described_class.show?(screener)).to eq(true)
end
it "returns true if county is not supported" do
county = unsupported_counties.first
screener = create(:screener, state: state_with_counties, county: county_name(county))
expect(described_class.show?(screener)).to eq(true)
end
it "returns false when county is supported" do
county = supported_counties.first
screener = create(:screener, state: state_with_counties, county: county_name(county))
expect(described_class.show?(screener)).to eq(false)
end
end
describe "#edit" do
render_views
it "not_listed? view" do
screener = create(:screener, state: LocationData::States::NOT_LISTED)
sign_in screener
get :edit
expect(response.body).to include(I18n.t("views.out_of_state.edit.title_help_text_html"))
end
it "county specific view" do
county = supported_counties.first
screener = create(:screener, state: state_with_counties, county: county_name(county))
sign_in screener
get :edit
expect(response.body).not_to include(I18n.t("views.out_of_state.edit.title_help_text_html"))
expect(response.body).to include(I18n.t("views.out_of_state.edit.contact_redirect", seconds: controller.redirect_delay_seconds))
end
end
end