|
1 | 1 | require "rails_helper" |
2 | 2 |
|
3 | 3 | RSpec.describe "/volunteers/notes", type: :request do |
4 | | - RSpec.shared_examples "create" do |
5 | | - let(:organization) { create(:casa_org) } |
| 4 | + let(:organization) { create(:casa_org) } |
6 | 5 |
|
| 6 | + shared_examples "create" do |
| 7 | + # Caller must define: let(:user) |
7 | 8 | context "when in the same organization" do |
8 | 9 | it "can create a note for volunteer" do |
9 | 10 | volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) |
|
33 | 34 | end |
34 | 35 | end |
35 | 36 |
|
36 | | - RSpec.shared_examples "edit" do |
37 | | - let(:organization) { create(:casa_org) } |
38 | | - |
| 37 | + shared_examples "edit" do |
| 38 | + # Caller must define: let(:user) |
39 | 39 | context "when in the same organization" do |
40 | 40 | let(:volunteer) { create(:volunteer, :with_assigned_supervisor, casa_org: organization) } |
41 | 41 |
|
42 | | - it "is successful if note belongs for volunteer" do |
| 42 | + it "is successful if note belongs to volunteer" do |
43 | 43 | note = create(:note, notable: volunteer) |
44 | 44 |
|
45 | 45 | sign_in user |
|
73 | 73 | end |
74 | 74 | end |
75 | 75 |
|
76 | | - RSpec.shared_examples "update" do |
77 | | - let(:organization) { create(:casa_org) } |
78 | | - |
| 76 | + shared_examples "update" do |
| 77 | + # Caller must define: let(:user) |
79 | 78 | context "when in the same organization" do |
80 | 79 | it "updates note and redirects to edit volunteer page" do |
81 | 80 | volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) |
|
104 | 103 | end |
105 | 104 | end |
106 | 105 |
|
107 | | - RSpec.shared_examples "delete" do |
108 | | - let(:organization) { create(:casa_org) } |
109 | | - |
| 106 | + shared_examples "delete" do |
| 107 | + # Caller must define: let(:user) |
110 | 108 | context "when in the same organization" do |
111 | 109 | it "can delete notes about a volunteer" do |
112 | 110 | volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) |
|
138 | 136 | end |
139 | 137 |
|
140 | 138 | describe "POST /create" do |
141 | | - context "when logged in as admin" do |
| 139 | + context "when logged in as an admin" do |
142 | 140 | it_behaves_like "create" do |
143 | 141 | let(:user) { create(:casa_admin, casa_org: organization) } |
144 | 142 | end |
|
150 | 148 | end |
151 | 149 | end |
152 | 150 |
|
153 | | - context "when logged in as volunteer" do |
| 151 | + context "when logged in as a volunteer" do |
154 | 152 | it "cannot create a note" do |
155 | | - organization = create(:casa_org) |
156 | 153 | volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) |
157 | 154 |
|
158 | 155 | sign_in volunteer |
159 | | - expect { |
| 156 | + expect do |
160 | 157 | post volunteer_notes_path(volunteer), params: {note: {content: "Very nice!"}} |
161 | | - }.not_to change(Note, :count) |
| 158 | + end.not_to change(Note, :count) |
162 | 159 | expect(response).to redirect_to root_path |
163 | 160 | end |
164 | 161 | end |
165 | 162 | end |
166 | 163 |
|
167 | 164 | describe "GET /edit" do |
168 | | - context "when logged in as admin" do |
| 165 | + context "when logged in as an admin" do |
169 | 166 | it_behaves_like "edit" do |
170 | 167 | let(:user) { create(:casa_admin, casa_org: organization) } |
171 | 168 | end |
172 | 169 | end |
173 | 170 |
|
174 | | - context "when logged in as supervisor" do |
| 171 | + context "when logged in as a supervisor" do |
175 | 172 | it_behaves_like "edit" do |
176 | 173 | let(:user) { create(:supervisor, casa_org: organization) } |
177 | 174 | end |
178 | 175 | end |
179 | 176 |
|
180 | | - context "when logged in as volunteer" do |
| 177 | + context "when logged in as a volunteer" do |
181 | 178 | context "when note belongs to volunteer" do |
182 | 179 | it "redirects to root path" do |
183 | | - organization = create(:casa_org) |
184 | 180 | volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) |
185 | 181 | note = create(:note, notable: volunteer) |
186 | 182 |
|
|
209 | 205 | context "when logged in as a volunteer" do |
210 | 206 | context "when updating note belonging to volunteer" do |
211 | 207 | it "does not update note and redirects to root path" do |
212 | | - organization = create(:casa_org) |
213 | 208 | volunteer = create(:volunteer, casa_org: organization) |
214 | 209 | note = create(:note, notable: volunteer, content: "Good job.") |
215 | 210 |
|
|
242 | 237 | note = create(:note, notable: volunteer) |
243 | 238 |
|
244 | 239 | sign_in volunteer |
245 | | - expect { |
| 240 | + expect do |
246 | 241 | delete volunteer_note_path(volunteer, note) |
247 | | - }.not_to change(Note, :count) |
| 242 | + end.not_to change(Note, :count) |
248 | 243 | expect(response).to redirect_to root_path |
249 | 244 | end |
250 | 245 | end |
|
0 commit comments