Skip to content

Commit ac44c7c

Browse files
costajohntcompwron
authored andcommitted
fix: make volunteer policy spec org assignments explicit
The volunteer policy spec relied on implicit casa_org assignment from the factory default (CasaOrg.first || create(:casa_org)), which hits the database even inside build_stubbed. When FactoryBot's auto- incrementing stub IDs collide with real DB record IDs, ActiveRecord's equality check (class + ID) causes same_org? to return incorrect results non-deterministically. Introduce explicit let(:casa_org) and let(:other_org) shared across all stubbed users and records, bypassing the factory's DB-hitting default entirely and guaranteeing deterministic org identity. Resolves #6770
1 parent afb0cd1 commit ac44c7c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

spec/policies/volunteer_policy_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
RSpec.describe VolunteerPolicy do
44
subject { described_class }
55

6-
let(:admin) { build_stubbed(:casa_admin) }
7-
let(:supervisor) { build_stubbed(:supervisor) }
8-
let(:volunteer) { build_stubbed(:volunteer) }
6+
let(:casa_org) { build_stubbed(:casa_org) }
7+
let(:other_org) { build_stubbed(:casa_org) }
8+
let(:admin) { build_stubbed(:casa_admin, casa_org: casa_org) }
9+
let(:supervisor) { build_stubbed(:supervisor, casa_org: casa_org) }
10+
let(:volunteer) { build_stubbed(:volunteer, casa_org: casa_org) }
911

1012
permissions :edit? do
1113
context "same org" do
12-
let(:record) { build_stubbed(:volunteer, casa_org: admin.casa_org) }
14+
let(:record) { build_stubbed(:volunteer, casa_org: casa_org) }
1315

1416
context "when user is a casa admin" do
1517
it "allows for same org" do
@@ -31,7 +33,7 @@
3133
end
3234

3335
context "different org" do
34-
let(:record) { build_stubbed(:volunteer, casa_org: build_stubbed(:casa_org)) }
36+
let(:record) { build_stubbed(:volunteer, casa_org: other_org) }
3537

3638
context "when user is a casa admin" do
3739
it "does not allow for different org" do
@@ -55,15 +57,15 @@
5557

5658
permissions :index?, :activate?, :create?, :datatable?, :deactivate?, :new?, :show?, :update? do
5759
context "when user is a casa admin" do
58-
let(:record) { build_stubbed(:volunteer, casa_org: admin.casa_org) }
60+
let(:record) { build_stubbed(:volunteer, casa_org: casa_org) }
5961

6062
it "allows" do
6163
expect(subject).to permit(admin, record)
6264
end
6365
end
6466

6567
context "when user is a supervisor" do
66-
let(:record) { build_stubbed(:volunteer, casa_org: supervisor.casa_org) }
68+
let(:record) { build_stubbed(:volunteer, casa_org: casa_org) }
6769

6870
it "allows" do
6971
expect(subject).to permit(supervisor, record)

0 commit comments

Comments
 (0)