Skip to content

Commit

Permalink
Fix matched effort policy spec for factory bot rails
Browse files Browse the repository at this point in the history
The change introduced in factory bot rails 6.4.3 impacts this spec.

thoughtbot/factory_bot_rails@0040292#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R168

One we switch to Factory bot Rails > 6.4.3 we began to see Bullet
errors when running this spec.

It's no clear right now if the errors relate to the spec or the code,
but switching all the `build_stubbed` to `create` stops the issue, which
might suggest it is the spec.

Whilst there is a performance hit to using `create` this policy relies
on the `ActivityPolicy` which in turns loads objects from the
database, making stubbing pretty complicated.

For the moment, we will take the perfromance hit for working specs.
  • Loading branch information
mec committed Jan 3, 2024
1 parent 262eb10 commit 2047deb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions spec/policies/matched_effort_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
subject { described_class.new(user, matched_effort) }

let!(:report) { create(:report, :approved, organisation: user.organisation, fund: activity.associated_fund) }
let(:matched_effort) { build_stubbed(:matched_effort, activity: activity) }
let(:matched_effort) { create(:matched_effort, activity: activity) }

context "as a user that belongs to BEIS" do
let(:user) { build_stubbed(:beis_user) }
let(:user) { create(:beis_user) }

context "when the activity is a programme activity owned by the organisation" do
let(:activity) { build_stubbed(:programme_activity, organisation: user.organisation) }
let(:activity) { create(:programme_activity, organisation: user.organisation) }

it "permits all actions" do
is_expected.to permit_action(:create)
Expand All @@ -20,7 +20,7 @@
end

context "when the activity is a project activity" do
let(:activity) { build_stubbed(:project_activity) }
let(:activity) { create(:project_activity) }

it "forbids all actions" do
is_expected.to forbid_action(:create)
Expand All @@ -31,10 +31,10 @@
end

context "as a partner organisation user" do
let(:user) { build_stubbed(:partner_organisation_user) }
let(:user) { create(:partner_organisation_user) }

context "when the matched effort belongs to an activity owned by the user" do
let(:activity) { build_stubbed(:project_activity, organisation: user.organisation) }
let(:activity) { create(:project_activity, organisation: user.organisation) }

context "when there is an editable report for the organisation" do
before do
Expand All @@ -58,7 +58,7 @@
end

context "when the matched effort does not belong to an activity owned by the user" do
let(:activity) { build_stubbed(:project_activity) }
let(:activity) { create(:project_activity) }

context "when there is an editable report for the organisation" do
before do
Expand Down

0 comments on commit 2047deb

Please sign in to comment.