clearance 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of clearance might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile.lock +1 -1
- data/NEWS.md +3 -0
- data/lib/clearance/constraints/signed_in.rb +6 -2
- data/lib/clearance/constraints/signed_out.rb +12 -1
- data/lib/clearance/version.rb +1 -1
- data/spec/clearance/constraints/signed_in_spec.rb +26 -19
- data/spec/clearance/constraints/signed_out_spec.rb +12 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d79da2d88bfa6ddc89089705872fbf1ece5c42c2
|
4
|
+
data.tar.gz: f5e422a542e1eaed19c721c15a01ad1920c29938
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d478f0fc99a8dd5b72243fc0c18ba095fc38ecee3e5fdd58e38e4c7cbe4967a4064475da06c8c53b11ea0e0bd5e3432baf00909a81e4c206d29e89931100bcc
|
7
|
+
data.tar.gz: 486865b87a276387bfa4bdc5d823a14ada721291d4a79433d5a02e355aabb4b414f45583101696152f7964a8e2c0a69561a162fa49fc1b384c6ffd4617b06670
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/NEWS.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
Thank you to all the [contributors](https://github.com/thoughtbot/clearance/graphs/contributors)!
|
2
2
|
|
3
|
+
New for 1.4.3 (October 3, 2014)
|
4
|
+
* Routing constraints act appropriately when session data is missing.
|
5
|
+
|
3
6
|
New for 1.4.2 (September 13, 2014)
|
4
7
|
* Eliminate deprecation message when using DenyAccess matcher with RSpec 3.
|
5
8
|
|
@@ -12,8 +12,12 @@ module Clearance
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
+
def clearance_session
|
16
|
+
@request.env[:clearance]
|
17
|
+
end
|
18
|
+
|
15
19
|
def current_user
|
16
|
-
|
20
|
+
clearance_session.current_user
|
17
21
|
end
|
18
22
|
|
19
23
|
def current_user_fulfills_additional_requirements?
|
@@ -21,7 +25,7 @@ module Clearance
|
|
21
25
|
end
|
22
26
|
|
23
27
|
def signed_in?
|
24
|
-
|
28
|
+
clearance_session.present? && clearance_session.signed_in?
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -2,7 +2,18 @@ module Clearance
|
|
2
2
|
module Constraints
|
3
3
|
class SignedOut
|
4
4
|
def matches?(request)
|
5
|
-
request
|
5
|
+
@request = request
|
6
|
+
missing_session? || clearance_session.signed_out?
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def clearance_session
|
12
|
+
@request.env[:clearance]
|
13
|
+
end
|
14
|
+
|
15
|
+
def missing_session?
|
16
|
+
clearance_session.nil?
|
6
17
|
end
|
7
18
|
end
|
8
19
|
end
|
data/lib/clearance/version.rb
CHANGED
@@ -3,49 +3,56 @@ require 'spec_helper'
|
|
3
3
|
describe Clearance::Constraints::SignedIn do
|
4
4
|
it 'returns true when user is signed in' do
|
5
5
|
user = create(:user)
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
constraint = Clearance::Constraints::SignedIn.new
|
7
|
+
request = request_with_remember_token(user.remember_token)
|
8
|
+
expect(constraint.matches?(request)).to eq true
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'returns false when user is not signed in' do
|
12
|
-
|
13
|
-
|
12
|
+
constraint = Clearance::Constraints::SignedIn.new
|
13
|
+
request = request_without_remember_token
|
14
|
+
expect(constraint.matches?(request)).to eq false
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false when clearance session data is not present' do
|
18
|
+
constraint = Clearance::Constraints::SignedIn.new
|
19
|
+
request = Rack::Request.new({})
|
20
|
+
expect(constraint.matches?(request)).to eq false
|
14
21
|
end
|
15
22
|
|
16
23
|
it 'yields a signed-in user to a provided block' do
|
17
24
|
user = create(:user, email: 'before@example.com')
|
18
25
|
|
19
|
-
|
20
|
-
|
26
|
+
constraint = Clearance::Constraints::SignedIn.new do |signed_in_user|
|
27
|
+
signed_in_user.update_attribute :email, 'after@example.com'
|
21
28
|
end
|
22
29
|
|
23
|
-
|
24
|
-
user.reload.email.
|
30
|
+
constraint.matches?(request_with_remember_token(user.remember_token))
|
31
|
+
expect(user.reload.email).to eq 'after@example.com'
|
25
32
|
end
|
26
33
|
|
27
34
|
it 'does not yield a user if they are not signed in' do
|
28
35
|
user = create(:user, email: 'before@example.com')
|
29
36
|
|
30
|
-
|
31
|
-
|
37
|
+
constraint = Clearance::Constraints::SignedIn.new do |signed_in_user|
|
38
|
+
signed_in_user.update_attribute :email, 'after@example.com'
|
32
39
|
end
|
33
40
|
|
34
|
-
|
35
|
-
user.reload.email.
|
41
|
+
constraint.matches?(request_without_remember_token)
|
42
|
+
expect(user.reload.email).to eq 'before@example.com'
|
36
43
|
end
|
37
44
|
|
38
45
|
it 'matches if the user-provided block returns true' do
|
39
46
|
user = create(:user)
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
constraint = Clearance::Constraints::SignedIn.new { true }
|
48
|
+
request = request_with_remember_token(user.remember_token)
|
49
|
+
expect(constraint.matches?(request)).to eq true
|
43
50
|
end
|
44
51
|
|
45
52
|
it 'does not match if the user-provided block returns false' do
|
46
53
|
user = create(:user)
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
constraint = Clearance::Constraints::SignedIn.new { false }
|
55
|
+
request = request_with_remember_token(user.remember_token)
|
56
|
+
expect(constraint.matches?(request)).to eq false
|
50
57
|
end
|
51
58
|
end
|
@@ -2,14 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Clearance::Constraints::SignedOut do
|
4
4
|
it 'returns true when user is signed out' do
|
5
|
-
|
6
|
-
|
5
|
+
constraint = Clearance::Constraints::SignedOut.new
|
6
|
+
request = request_without_remember_token
|
7
|
+
expect(constraint.matches?(request)).to eq true
|
7
8
|
end
|
8
9
|
|
9
10
|
it 'returns false when user is not signed out' do
|
10
11
|
user = create(:user)
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
constraint = Clearance::Constraints::SignedOut.new
|
13
|
+
request = request_with_remember_token(user.remember_token)
|
14
|
+
expect(constraint.matches?(request)).to eq false
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns true when clearance info is missing from request' do
|
18
|
+
constraint = Clearance::Constraints::SignedOut.new
|
19
|
+
request = Rack::Request.new({})
|
20
|
+
expect(constraint.matches?(request)).to eq true
|
14
21
|
end
|
15
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clearance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Croak
|
@@ -25,7 +25,7 @@ authors:
|
|
25
25
|
autorequire:
|
26
26
|
bindir: bin
|
27
27
|
cert_chain: []
|
28
|
-
date: 2014-
|
28
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
29
29
|
dependencies:
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bcrypt
|