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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b36c10484673f64ecf6621a00b290bb481731ca1
4
- data.tar.gz: fd2a23e512ad678d7841128f9e7911cca174f0eb
3
+ metadata.gz: d79da2d88bfa6ddc89089705872fbf1ece5c42c2
4
+ data.tar.gz: f5e422a542e1eaed19c721c15a01ad1920c29938
5
5
  SHA512:
6
- metadata.gz: 31afa57919c1be57c63f8cbfea0b28bb035cd9e2f5df11ccfd0ae730c379d6360fd5638535ce7f047f57aa95f2c35be5ebdb44d6fb4b952f02324222d2203c43
7
- data.tar.gz: ea9b82a67c87ffeecae9163a3ed1a3868230d74301678e03dd5d92e09b67a668dc0eb50cfe5d64c146a251435d64f83f74ff4cd5ae2b9c28f637a5d8f0ddc0e4
6
+ metadata.gz: 6d478f0fc99a8dd5b72243fc0c18ba095fc38ecee3e5fdd58e38e4c7cbe4967a4064475da06c8c53b11ea0e0bd5e3432baf00909a81e4c206d29e89931100bcc
7
+ data.tar.gz: 486865b87a276387bfa4bdc5d823a14ada721291d4a79433d5a02e355aabb4b414f45583101696152f7964a8e2c0a69561a162fa49fc1b384c6ffd4617b06670
data/.travis.yml CHANGED
@@ -4,7 +4,7 @@ language:
4
4
  rvm:
5
5
  - 1.9.3
6
6
  - 2.0.0
7
- - 2.1.1
7
+ - 2.1.3
8
8
 
9
9
  install:
10
10
  - "travis_retry bundle install"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clearance (1.4.2)
4
+ clearance (1.4.3)
5
5
  bcrypt
6
6
  email_validator (~> 1.4)
7
7
  rails (>= 3.1)
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
- @request.env[:clearance].current_user
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
- @request.env[:clearance].signed_in?
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.env[:clearance].signed_out?
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
@@ -1,3 +1,3 @@
1
1
  module Clearance
2
- VERSION = '1.4.2'
2
+ VERSION = '1.4.3'
3
3
  end
@@ -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
- signed_in_constraint = Clearance::Constraints::SignedIn.new
7
- signed_in_constraint.matches?(request_with_remember_token(user.remember_token)).
8
- should be_true
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
- signed_in_constraint = Clearance::Constraints::SignedIn.new
13
- signed_in_constraint.matches?(request_without_remember_token).should be_false
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
- signed_in_constraint = Clearance::Constraints::SignedIn.new do |user|
20
- user.update_attribute :email, 'after@example.com'
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
- signed_in_constraint.matches?(request_with_remember_token(user.remember_token))
24
- user.reload.email.should == 'after@example.com'
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
- signed_in_constraint = Clearance::Constraints::SignedIn.new do |user|
31
- user.update_attribute :email, 'after@example.com'
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
- signed_in_constraint.matches?(request_without_remember_token)
35
- user.reload.email.should == 'before@example.com'
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
- signed_in_constraint = Clearance::Constraints::SignedIn.new { |user| true }
41
- signed_in_constraint.matches?(request_with_remember_token(user.remember_token)).
42
- should be_true
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
- signed_in_constraint = Clearance::Constraints::SignedIn.new { |user| false }
48
- signed_in_constraint.matches?(request_with_remember_token(user.remember_token)).
49
- should be_false
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
- signed_out_constraint = Clearance::Constraints::SignedOut.new
6
- signed_out_constraint.matches?(request_without_remember_token).should be_true
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
- signed_out_constraint = Clearance::Constraints::SignedOut.new
12
- signed_out_constraint.matches?(request_with_remember_token(user.remember_token)).
13
- should be_false
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.2
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-09-13 00:00:00.000000000 Z
28
+ date: 2014-10-03 00:00:00.000000000 Z
29
29
  dependencies:
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: bcrypt