From 875918404d21acfffb12f811851c25f074f80e58 Mon Sep 17 00:00:00 2001 From: Linda Goldstein Date: Mon, 4 May 2026 22:54:13 -0700 Subject: [PATCH] refactor(tests): clean up notes_spec shared examples after #6927 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- spec/requests/notes_spec.rb | 43 ++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/spec/requests/notes_spec.rb b/spec/requests/notes_spec.rb index 5133e8466e..892dc82782 100644 --- a/spec/requests/notes_spec.rb +++ b/spec/requests/notes_spec.rb @@ -1,9 +1,10 @@ require "rails_helper" RSpec.describe "/volunteers/notes", type: :request do - RSpec.shared_examples "create" do - let(:organization) { create(:casa_org) } + let(:organization) { create(:casa_org) } + shared_examples "create" do + # Caller must define: let(:user) context "when in the same organization" do it "can create a note for volunteer" do volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) @@ -33,13 +34,12 @@ end end - RSpec.shared_examples "edit" do - let(:organization) { create(:casa_org) } - + shared_examples "edit" do + # Caller must define: let(:user) context "when in the same organization" do let(:volunteer) { create(:volunteer, :with_assigned_supervisor, casa_org: organization) } - it "is successful if note belongs for volunteer" do + it "is successful if note belongs to volunteer" do note = create(:note, notable: volunteer) sign_in user @@ -73,9 +73,8 @@ end end - RSpec.shared_examples "update" do - let(:organization) { create(:casa_org) } - + shared_examples "update" do + # Caller must define: let(:user) context "when in the same organization" do it "updates note and redirects to edit volunteer page" do volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) @@ -104,9 +103,8 @@ end end - RSpec.shared_examples "delete" do - let(:organization) { create(:casa_org) } - + shared_examples "delete" do + # Caller must define: let(:user) context "when in the same organization" do it "can delete notes about a volunteer" do volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) @@ -138,7 +136,7 @@ end describe "POST /create" do - context "when logged in as admin" do + context "when logged in as an admin" do it_behaves_like "create" do let(:user) { create(:casa_admin, casa_org: organization) } end @@ -150,37 +148,35 @@ end end - context "when logged in as volunteer" do + context "when logged in as a volunteer" do it "cannot create a note" do - organization = create(:casa_org) volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) sign_in volunteer - expect { + expect do post volunteer_notes_path(volunteer), params: {note: {content: "Very nice!"}} - }.not_to change(Note, :count) + end.not_to change(Note, :count) expect(response).to redirect_to root_path end end end describe "GET /edit" do - context "when logged in as admin" do + context "when logged in as an admin" do it_behaves_like "edit" do let(:user) { create(:casa_admin, casa_org: organization) } end end - context "when logged in as supervisor" do + context "when logged in as a supervisor" do it_behaves_like "edit" do let(:user) { create(:supervisor, casa_org: organization) } end end - context "when logged in as volunteer" do + context "when logged in as a volunteer" do context "when note belongs to volunteer" do it "redirects to root path" do - organization = create(:casa_org) volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization) note = create(:note, notable: volunteer) @@ -209,7 +205,6 @@ context "when logged in as a volunteer" do context "when updating note belonging to volunteer" do it "does not update note and redirects to root path" do - organization = create(:casa_org) volunteer = create(:volunteer, casa_org: organization) note = create(:note, notable: volunteer, content: "Good job.") @@ -242,9 +237,9 @@ note = create(:note, notable: volunteer) sign_in volunteer - expect { + expect do delete volunteer_note_path(volunteer, note) - }.not_to change(Note, :count) + end.not_to change(Note, :count) expect(response).to redirect_to root_path end end