|
1 | 1 | require "rails_helper" |
2 | 2 |
|
3 | 3 | RSpec.describe "casa_org/edit", type: :view do |
| 4 | + let(:organization) { build_stubbed(:casa_org) } |
| 5 | + |
4 | 6 | before do |
5 | 7 | assign(:contact_type_groups, []) |
6 | 8 | assign(:contact_types, []) |
|
13 | 15 | assign(:custom_org_links, []) |
14 | 16 | assign(:placement_types, []) |
15 | 17 |
|
| 18 | + allow(view).to receive(:current_organization).and_return(organization) |
| 19 | + |
16 | 20 | sign_in build_stubbed(:casa_admin) |
17 | 21 | end |
18 | 22 |
|
19 | 23 | it "has casa org edit page text" do |
20 | | - organization = build_stubbed(:casa_org) |
21 | | - allow(view).to receive(:current_organization).and_return(organization) |
22 | | - |
23 | 24 | render template: "casa_org/edit" |
24 | 25 |
|
25 | 26 | expect(rendered).to have_text "Editing CASA Organization" |
|
28 | 29 | end |
29 | 30 |
|
30 | 31 | it "has contact topic content" do |
31 | | - organization = build_stubbed(:casa_org) |
32 | | - allow(view).to receive(:current_organization).and_return(organization) |
33 | 32 | contact_topic = build_stubbed(:contact_topic, question: "Test Question", details: "Test details") |
34 | 33 | assign(:contact_topics, [contact_topic]) |
35 | 34 |
|
|
45 | 44 | end |
46 | 45 |
|
47 | 46 | it "has contact types content" do |
48 | | - organization = build_stubbed(:casa_org) |
49 | | - allow(view).to receive(:current_organization).and_return(organization) |
50 | 47 | contact_type = build_stubbed(:contact_type, name: "Contact type 1") |
51 | 48 | assign(:contact_types, [contact_type]) |
52 | 49 |
|
|
62 | 59 | end |
63 | 60 |
|
64 | 61 | it "has contact type groups content" do |
65 | | - organization = build_stubbed(:casa_org) |
66 | | - allow(view).to receive(:current_organization).and_return(organization) |
67 | 62 | contact_type_group = build_stubbed(:contact_type_group, casa_org: organization, name: "Contact type group 1") |
68 | 63 | assign(:contact_type_groups, [contact_type_group]) |
69 | 64 |
|
|
78 | 73 | end |
79 | 74 |
|
80 | 75 | it "has hearing types content" do |
81 | | - organization = build_stubbed(:casa_org) |
82 | | - allow(view).to receive(:current_organization).and_return(organization) |
83 | 76 | hearing_type = build_stubbed(:hearing_type, casa_org: organization, name: "Hearing type 1") |
84 | 77 | assign(:hearing_types, [hearing_type]) |
85 | 78 |
|
|
94 | 87 | end |
95 | 88 |
|
96 | 89 | it "has judge content" do |
97 | | - organization = build_stubbed(:casa_org) |
98 | | - allow(view).to receive(:current_organization).and_return(organization) |
99 | 90 | judge = build_stubbed(:judge, casa_org: organization, name: "Joey Tom") |
100 | 91 | assign(:judges, [judge]) |
101 | 92 |
|
|
105 | 96 | end |
106 | 97 |
|
107 | 98 | it "has placement types content" do |
108 | | - organization = build_stubbed(:casa_org) |
109 | | - allow(view).to receive(:current_organization).and_return(organization) |
110 | 99 | placement_type = build_stubbed(:placement_type, name: "Placement type 1") |
111 | 100 | placement_type_2 = build_stubbed(:placement_type, name: "Placement type 2") |
112 | 101 | assign(:placement_types, [placement_type, placement_type_2]) |
|
123 | 112 | end |
124 | 113 |
|
125 | 114 | it "does not show download prompt with no custom template" do |
126 | | - organization = build_stubbed(:casa_org) |
127 | | - allow(view).to receive(:current_organization).and_return(organization) |
128 | | - |
129 | 115 | render template: "casa_org/edit" |
130 | 116 |
|
131 | 117 | expect(rendered).not_to have_text("Download Current Template") |
132 | 118 | end |
133 | 119 |
|
134 | 120 | it "has sent emails content" do |
135 | | - organization = build_stubbed(:casa_org) |
136 | 121 | admin = build_stubbed(:casa_admin, casa_org: organization) |
137 | | - allow(view).to receive(:current_organization).and_return(organization) |
138 | 122 | without_partial_double_verification do |
139 | 123 | allow(view).to receive(:to_user_timezone).and_return(Time.zone.local(2021, 1, 2, 12, 30, 0)) |
140 | 124 | end |
|
152 | 136 | end |
153 | 137 |
|
154 | 138 | context "with a template uploaded" do |
155 | | - it "renders a prompt to download current template" do |
156 | | - organization = create(:casa_org) |
157 | | - allow(view).to receive(:current_organization).and_return(organization) |
| 139 | + # NOTE(@abachman): Use create instead of build_stubbed because ActiveStorage |
| 140 | + # needs to save to the DB |
| 141 | + let(:organization) { create(:casa_org) } |
158 | 142 |
|
| 143 | + it "renders a prompt to download current template" do |
159 | 144 | organization.court_report_template.attach(io: File.open("#{Rails.root.join("app/documents/templates/default_report_template.docx")}"), filename: 'default_report_template |
160 | 145 | .docx', content_type: "application/docx") |
161 | 146 |
|
|
169 | 154 | context "enabled" do |
170 | 155 | it "has option to enable additional expenses" do |
171 | 156 | allow(Flipper).to receive(:enabled?).with(:show_additional_expenses).and_return(true) |
172 | | - organization = build_stubbed(:casa_org) |
173 | | - allow(view).to receive(:current_organization).and_return(organization) |
174 | 157 |
|
175 | 158 | render template: "casa_org/edit" |
176 | 159 |
|
|
181 | 164 | context "disabled" do |
182 | 165 | it "has option to enable additional expenses" do |
183 | 166 | allow(Flipper).to receive(:enabled?).with(:show_additional_expenses).and_return(false) |
184 | | - organization = build_stubbed(:casa_org) |
185 | | - allow(view).to receive(:current_organization).and_return(organization) |
186 | 167 |
|
187 | 168 | render template: "casa_org/edit" |
188 | 169 |
|
|
0 commit comments