Skip to content

Commit 55c9312

Browse files
compwronclaude
andauthored
refactor(tests): clean up notes_spec shared examples after #6927 (#6939)
Follow-up to the shared-examples extraction. Scope shared_examples to this describe block (drop the RSpec. prefix that registered them globally and made the generic names "create"/"edit"/"update"/"delete" collide-prone), document the implicit let(:user) contract callers must satisfy, fix the "belongs for volunteer" typo regression, normalize expect { } to expect do…end for consistency with the new code, hoist the repeated let(:organization), and standardize context names to use articles ("as an admin"/"as a supervisor"/"as a volunteer"). Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 63311c5 commit 55c9312

1 file changed

Lines changed: 19 additions & 24 deletions

File tree

spec/requests/notes_spec.rb

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
require "rails_helper"
22

33
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) }
65

6+
shared_examples "create" do
7+
# Caller must define: let(:user)
78
context "when in the same organization" do
89
it "can create a note for volunteer" do
910
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
@@ -33,13 +34,12 @@
3334
end
3435
end
3536

36-
RSpec.shared_examples "edit" do
37-
let(:organization) { create(:casa_org) }
38-
37+
shared_examples "edit" do
38+
# Caller must define: let(:user)
3939
context "when in the same organization" do
4040
let(:volunteer) { create(:volunteer, :with_assigned_supervisor, casa_org: organization) }
4141

42-
it "is successful if note belongs for volunteer" do
42+
it "is successful if note belongs to volunteer" do
4343
note = create(:note, notable: volunteer)
4444

4545
sign_in user
@@ -73,9 +73,8 @@
7373
end
7474
end
7575

76-
RSpec.shared_examples "update" do
77-
let(:organization) { create(:casa_org) }
78-
76+
shared_examples "update" do
77+
# Caller must define: let(:user)
7978
context "when in the same organization" do
8079
it "updates note and redirects to edit volunteer page" do
8180
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
@@ -104,9 +103,8 @@
104103
end
105104
end
106105

107-
RSpec.shared_examples "delete" do
108-
let(:organization) { create(:casa_org) }
109-
106+
shared_examples "delete" do
107+
# Caller must define: let(:user)
110108
context "when in the same organization" do
111109
it "can delete notes about a volunteer" do
112110
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
@@ -138,7 +136,7 @@
138136
end
139137

140138
describe "POST /create" do
141-
context "when logged in as admin" do
139+
context "when logged in as an admin" do
142140
it_behaves_like "create" do
143141
let(:user) { create(:casa_admin, casa_org: organization) }
144142
end
@@ -150,37 +148,35 @@
150148
end
151149
end
152150

153-
context "when logged in as volunteer" do
151+
context "when logged in as a volunteer" do
154152
it "cannot create a note" do
155-
organization = create(:casa_org)
156153
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
157154

158155
sign_in volunteer
159-
expect {
156+
expect do
160157
post volunteer_notes_path(volunteer), params: {note: {content: "Very nice!"}}
161-
}.not_to change(Note, :count)
158+
end.not_to change(Note, :count)
162159
expect(response).to redirect_to root_path
163160
end
164161
end
165162
end
166163

167164
describe "GET /edit" do
168-
context "when logged in as admin" do
165+
context "when logged in as an admin" do
169166
it_behaves_like "edit" do
170167
let(:user) { create(:casa_admin, casa_org: organization) }
171168
end
172169
end
173170

174-
context "when logged in as supervisor" do
171+
context "when logged in as a supervisor" do
175172
it_behaves_like "edit" do
176173
let(:user) { create(:supervisor, casa_org: organization) }
177174
end
178175
end
179176

180-
context "when logged in as volunteer" do
177+
context "when logged in as a volunteer" do
181178
context "when note belongs to volunteer" do
182179
it "redirects to root path" do
183-
organization = create(:casa_org)
184180
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
185181
note = create(:note, notable: volunteer)
186182

@@ -209,7 +205,6 @@
209205
context "when logged in as a volunteer" do
210206
context "when updating note belonging to volunteer" do
211207
it "does not update note and redirects to root path" do
212-
organization = create(:casa_org)
213208
volunteer = create(:volunteer, casa_org: organization)
214209
note = create(:note, notable: volunteer, content: "Good job.")
215210

@@ -242,9 +237,9 @@
242237
note = create(:note, notable: volunteer)
243238

244239
sign_in volunteer
245-
expect {
240+
expect do
246241
delete volunteer_note_path(volunteer, note)
247-
}.not_to change(Note, :count)
242+
end.not_to change(Note, :count)
248243
expect(response).to redirect_to root_path
249244
end
250245
end

0 commit comments

Comments
 (0)