Skip to content

Commit

Permalink
Update tests to include the warden scope in user
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines committed May 17, 2024
1 parent 6690278 commit d0b34ea
Showing 1 changed file with 49 additions and 9 deletions.
58 changes: 49 additions & 9 deletions spec/integrations/warden_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d0b34ea

Please sign in to comment.