Skip to content

Commit 83bee50

Browse files
committed
Prep for having multiple cache states
This is basically a whitespace only change. It simply nests the existing specs inside the appropriate cache related context. This is in preparation for needing to flush out all the existing cache states. We want to make sure we also don't break the existing functionality during this.
1 parent 75deaf2 commit 83bee50

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

spec/kracken/controllers/token_authenticatable_spec.rb

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,55 @@ def authenticate_or_request_with_http_token(realm = nil)
1414

1515
RSpec.describe Controllers::TokenAuthenticatable do
1616
describe "authenticating via a token" do
17-
before do
18-
allow(Authenticator).to receive(:user_with_token)
19-
end
17+
context "on a cache miss with a valid token" do
18+
before do
19+
allow(Authenticator).to receive(:user_with_token)
20+
end
2021

21-
it "munges the request headers to support parameterized tokens" do
22-
controller = TokenAuthController.new
23-
controller.request.env = {
24-
'HTTP_AUTHORIZATION' => 'Token token="header token"'
25-
}
26-
controller.params = { token: "param token" }
22+
it "munges the request headers to support parameterized tokens" do
23+
controller = TokenAuthController.new
24+
controller.request.env = {
25+
'HTTP_AUTHORIZATION' => 'Token token="header token"'
26+
}
27+
controller.params = { token: "param token" }
2728

28-
expect {
29-
controller.authenticate_user_with_token!
30-
}.to change {
31-
controller.request.env
32-
}.from(
33-
'HTTP_AUTHORIZATION' => 'Token token="header token"'
34-
).to(
35-
'HTTP_AUTHORIZATION' => 'Token token="param token"'
36-
)
37-
end
29+
expect {
30+
controller.authenticate_user_with_token!
31+
}.to change {
32+
controller.request.env
33+
}.from(
34+
'HTTP_AUTHORIZATION' => 'Token token="header token"'
35+
).to(
36+
'HTTP_AUTHORIZATION' => 'Token token="param token"'
37+
)
38+
end
3839

39-
it "leaves the request header unchange when with no parameterized token" do
40-
controller = TokenAuthController.new
41-
controller.request.env = {
42-
'HTTP_AUTHORIZATION' => 'Token token="any token"'
43-
}
40+
it "leaves the request header unchange when with no parameterized token" do
41+
controller = TokenAuthController.new
42+
controller.request.env = {
43+
'HTTP_AUTHORIZATION' => 'Token token="any token"'
44+
}
4445

45-
expect {
46-
controller.authenticate_user_with_token!
47-
}.not_to change { controller.request.env }.from(
48-
'HTTP_AUTHORIZATION' => 'Token token="any token"'
49-
)
50-
end
46+
expect {
47+
controller.authenticate_user_with_token!
48+
}.not_to change { controller.request.env }.from(
49+
'HTTP_AUTHORIZATION' => 'Token token="any token"'
50+
)
51+
end
5152

52-
it "authenticates the current user via the token" do
53-
a_user = instance_double(User)
54-
allow(Authenticator).to receive(:user_with_token).with("any token")
55-
.and_return(a_user)
56-
controller = TokenAuthController.new
57-
controller.request.env = {
58-
'HTTP_AUTHORIZATION' => 'Token token="any token"'
59-
}
53+
it "authenticates the current user via the token" do
54+
a_user = instance_double(User)
55+
allow(Authenticator).to receive(:user_with_token).with("any token")
56+
.and_return(a_user)
57+
controller = TokenAuthController.new
58+
controller.request.env = {
59+
'HTTP_AUTHORIZATION' => 'Token token="any token"'
60+
}
6061

61-
expect {
62-
controller.authenticate_user_with_token!
63-
}.to change { controller.current_user }.from(nil).to(a_user)
62+
expect {
63+
controller.authenticate_user_with_token!
64+
}.to change { controller.current_user }.from(nil).to(a_user)
65+
end
6466
end
6567
end
6668
end

0 commit comments

Comments
 (0)