diff --git a/spec/integrations/warden_user_spec.rb b/spec/integrations/warden_user_spec.rb index 03b0b5fd..cfa3eeb9 100644 --- a/spec/integrations/warden_user_spec.rb +++ b/spec/integrations/warden_user_spec.rb @@ -6,31 +6,71 @@ user = double allow(user).to receive_messages( - :email => "TEST_EMAIL", - :name => "TEST_NAME", - :created_at => "TEST_NOW" + email: "TEST_EMAIL", + name: "TEST_NAME", + created_at: "TEST_NOW", ) warden = double allow(warden).to receive(:user).with({ - :scope => "user", - :run_callbacks => false + scope: "user", + run_callbacks: false, }).and_return(user) report = double("Bugsnag::Report") + expect(report).to receive(:request_data).exactly(3).times.and_return({ + rack_env: { + "warden" => warden, + "rack.session" => { + "warden.user.user.key" => "TEST_USER", + } + } + }) + + expect(report).to receive(:user=).with({ + email: "TEST_EMAIL", + name: "TEST_NAME", + created_at: "TEST_NOW", + warden_scope: "user", + }) + + expect(callback).to receive(:call).with(report) + + middleware = Bugsnag::Middleware::WardenUser.new(callback) + middleware.call(report) + end + + it "sets the scope to the 'best scope'" do + callback = double + + user = double + allow(user).to receive_messages( + email: "TEST_EMAIL", + name: "TEST_NAME", + created_at: "TEST_NOW", + ) + + warden = double + allow(warden).to receive(:user).with({ + scope: "admin", + run_callbacks: false, + }).and_return(user) + + report = double("Bugsnag::Report") expect(report).to receive(:request_data).exactly(3).times.and_return({ :rack_env => { "warden" => warden, "rack.session" => { - "warden.user.user.key" => "TEST_USER" + "warden.user.admin.key" => "TEST_USER" } } }) expect(report).to receive(:user=).with({ - :email => "TEST_EMAIL", - :name => "TEST_NAME", - :created_at => "TEST_NOW" + email: "TEST_EMAIL", + name: "TEST_NAME", + created_at: "TEST_NOW", + warden_scope: "admin", }) expect(callback).to receive(:call).with(report)