Allow FeatureToggleConstraint to run w/o warden

Routing specs and controller specs don't set warden on the request
environment. While we could try to re-implement Warden/Devise logic
here, it's much easier to not rely on the environment to be set.

While I'm usually opposed to changing production code to make testing
easier, it does avoid a lot of complication in this case. And maybe it
would be handy in other circumstances to have a more defensive approach
to checking the logged in user.
This commit is contained in:
Maikel Linke
2022-10-27 15:07:04 +11:00
parent 6aefc23c35
commit 36c44a5487
2 changed files with 1 additions and 5 deletions

View File

@@ -12,6 +12,6 @@ class FeatureToggleConstraint
end
def current_user(request)
request.env['warden'].user
request.env['warden']&.user
end
end

View File

@@ -3,10 +3,6 @@
require "spec_helper"
describe "routing for Stripe return URLS", type: :routing do
before do
allow_any_instance_of(FeatureToggleConstraint).to receive(:current_user) { build(:user) }
end
context "checkout return URLs" do
it "routes /checkout to checkout#edit" do
expect(get: "checkout").