clearance 1.4.3 → 1.5.0

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.

@@ -32,13 +32,13 @@ describe PermissionsController do
32
32
  it 'allows access to new' do
33
33
  get :new
34
34
 
35
- subject.should_not deny_access
35
+ expect(subject).not_to deny_access
36
36
  end
37
37
 
38
38
  it 'allows access to show' do
39
39
  get :show
40
40
 
41
- subject.should_not deny_access
41
+ expect(subject).not_to deny_access
42
42
  end
43
43
  end
44
44
 
@@ -46,13 +46,13 @@ describe PermissionsController do
46
46
  it 'allows access to new' do
47
47
  get :new
48
48
 
49
- subject.should_not deny_access
49
+ expect(subject).not_to deny_access
50
50
  end
51
51
 
52
52
  it 'denies access to show' do
53
53
  get :show
54
54
 
55
- subject.should deny_access(redirect: sign_in_url)
55
+ expect(subject).to deny_access(redirect: sign_in_url)
56
56
  end
57
57
  end
58
58
 
@@ -64,7 +64,7 @@ describe PermissionsController do
64
64
 
65
65
  get :show
66
66
 
67
- subject.should deny_access
67
+ expect(subject).to deny_access
68
68
  end
69
69
  end
70
70
  end
@@ -34,11 +34,11 @@ describe Clearance::SessionsController do
34
34
  it { should redirect_to_url_after_create }
35
35
 
36
36
  it 'sets the user in the clearance session' do
37
- controller.current_user.should == @user
37
+ expect(controller.current_user).to eq @user
38
38
  end
39
39
 
40
40
  it 'should not change the remember token' do
41
- @user.reload.remember_token.should == 'old-token'
41
+ expect(@user.reload.remember_token).to eq 'old-token'
42
42
  end
43
43
  end
44
44
 
@@ -75,11 +75,11 @@ describe Clearance::SessionsController do
75
75
  it { should redirect_to_url_after_destroy }
76
76
 
77
77
  it 'should reset the remember token' do
78
- @user.reload.remember_token.should_not == 'old-token'
78
+ expect(@user.reload.remember_token).not_to eq 'old-token'
79
79
  end
80
80
 
81
81
  it 'should unset the current user' do
82
- @controller.current_user.should be_nil
82
+ expect(@controller.current_user).to be_nil
83
83
  end
84
84
  end
85
85
  end
@@ -9,9 +9,9 @@ describe Clearance::UsersController do
9
9
  describe 'on GET to #new' do
10
10
  before { get :new }
11
11
 
12
- it { should respond_with(:success) }
13
- it { should render_template(:new) }
14
- it { should_not set_the_flash }
12
+ it { is_expected.to respond_with(:success) }
13
+ it { is_expected.to render_template(:new) }
14
+ it { is_expected.not_to set_the_flash }
15
15
  end
16
16
 
17
17
  describe 'on GET to #new with email' do
@@ -21,7 +21,7 @@ describe Clearance::UsersController do
21
21
  end
22
22
 
23
23
  it 'should set assigned user email' do
24
- assigns(:user).email.should == @email
24
+ expect(assigns(:user).email).to eq @email
25
25
  end
26
26
  end
27
27
 
@@ -33,11 +33,11 @@ describe Clearance::UsersController do
33
33
  end
34
34
 
35
35
  it 'assigns a user' do
36
- assigns(:user).should be
36
+ expect(assigns(:user)).to be_present
37
37
  end
38
38
 
39
39
  it 'should create a new user' do
40
- User.count.should == @old_user_count + 1
40
+ expect(User.count).to eq @old_user_count + 1
41
41
  end
42
42
 
43
43
  it { should redirect_to_url_after_create }
@@ -53,11 +53,11 @@ describe Clearance::UsersController do
53
53
  end
54
54
 
55
55
  it 'assigns a user' do
56
- assigns(:user).should be
56
+ expect(assigns(:user)).to be_present
57
57
  end
58
58
 
59
59
  it 'should create a new user' do
60
- User.count.should == @old_user_count + 1
60
+ expect(User.count).to eq @old_user_count + 1
61
61
  end
62
62
 
63
63
  it { should redirect_to(@return_url) }
@@ -8,28 +8,28 @@ describe ClearanceMailer do
8
8
  end
9
9
 
10
10
  it 'is from DO_NOT_REPLY' do
11
- Clearance.configuration.mailer_sender.should =~ /#{@email.from[0]}/i
11
+ expect(Clearance.configuration.mailer_sender).to match(/#{@email.from[0]}/i)
12
12
  end
13
13
 
14
14
  it 'is sent to user' do
15
- @email.to.first.should =~ /#{@user.email}/i
15
+ expect(@email.to.first).to match(/#{@user.email}/i)
16
16
  end
17
17
 
18
18
  it 'contains a link to edit the password' do
19
19
  host = ActionMailer::Base.default_url_options[:host]
20
20
  regexp = %r{http://#{host}/users/#{@user.id}/password/edit\?token=#{@user.confirmation_token}}
21
- @email.body.to_s.should =~ regexp
21
+ expect(@email.body.to_s).to match(regexp)
22
22
  end
23
23
 
24
24
  it 'sets its subject' do
25
- @email.subject.should =~ /Change your password/
25
+ expect(@email.subject).to match(/Change your password/)
26
26
  end
27
27
 
28
28
  it 'contains opening text in the body' do
29
- @email.body.should =~ /a link to change your password/
29
+ expect(@email.body).to match(/a link to change your password/)
30
30
  end
31
31
 
32
32
  it 'contains closing text in the body' do
33
- @email.body.should =~ /Your password has not been changed/
33
+ expect(@email.body).to match(/Your password has not been changed/)
34
34
  end
35
35
  end
@@ -14,21 +14,23 @@ describe Clearance::PasswordStrategies::BCryptMigrationFromSHA1 do
14
14
 
15
15
  before do
16
16
  subject.salt = salt
17
- subject.encrypted_password = Digest::SHA1.hexdigest("--#{salt}--#{password}--")
17
+ digestable = "--#{salt}--#{password}--"
18
+ subject.encrypted_password = Digest::SHA1.hexdigest(digestable)
18
19
  BCrypt::Password.stubs create: encrypted_password
19
20
  subject.password = password
20
21
  end
21
22
 
22
23
  it 'encrypts the password into a BCrypt-encrypted encrypted_password' do
23
- subject.encrypted_password.should == encrypted_password
24
+ expect(subject.encrypted_password).to eq encrypted_password
24
25
  end
25
26
 
26
27
  it 'encrypts with BCrypt' do
27
- BCrypt::Password.should have_received(:create).with(password, anything)
28
+ have_received_password = have_received(:create).with(password, anything)
29
+ expect(BCrypt::Password).to have_received_password
28
30
  end
29
31
 
30
32
  it 'sets the pasword on the subject' do
31
- subject.password.should be_present
33
+ expect(subject.password).to be_present
32
34
  end
33
35
  end
34
36
 
@@ -45,23 +47,21 @@ describe Clearance::PasswordStrategies::BCryptMigrationFromSHA1 do
45
47
  end
46
48
 
47
49
  it 'is authenticated' do
48
- subject.should be_authenticated(password)
50
+ expect(subject).to be_authenticated(password)
49
51
  end
50
52
 
51
53
  it 'changes the hash into a BCrypt-encrypted one' do
52
54
  subject.authenticated? password
53
- subject.encrypted_password.should_not == sha1_hash
55
+ expect(subject.encrypted_password).not_to eq sha1_hash
54
56
  end
55
57
 
56
58
  it 'does not raise a BCrypt error for invalid passwords' do
57
- expect {
58
- subject.authenticated? 'bad' + password
59
- }.not_to raise_error
59
+ expect { subject.authenticated? 'bad' + password }.not_to raise_error
60
60
  end
61
61
 
62
62
  it 'saves the subject to database' do
63
63
  subject.authenticated? password
64
- subject.should have_received(:save)
64
+ expect(subject).to have_received(:save)
65
65
  end
66
66
  end
67
67
 
@@ -73,12 +73,12 @@ describe Clearance::PasswordStrategies::BCryptMigrationFromSHA1 do
73
73
  end
74
74
 
75
75
  it 'is authenticated' do
76
- subject.should be_authenticated(password)
76
+ expect(subject).to be_authenticated(password)
77
77
  end
78
78
 
79
79
  it 'does not change the hash' do
80
80
  subject.authenticated? password
81
- subject.encrypted_password.to_s.should == bcrypt_hash.to_s
81
+ expect(subject.encrypted_password.to_s).to eq bcrypt_hash.to_s
82
82
  end
83
83
  end
84
84
  end
@@ -16,7 +16,7 @@ describe Clearance::PasswordStrategies::BCrypt do
16
16
  it 'encrypts the password into encrypted_password' do
17
17
  subject.password = password
18
18
 
19
- subject.encrypted_password.should == encrypted_password
19
+ expect(subject.encrypted_password).to eq encrypted_password
20
20
  end
21
21
 
22
22
  it 'encrypts with BCrypt using default cost in non test environments' do
@@ -24,7 +24,7 @@ describe Clearance::PasswordStrategies::BCrypt do
24
24
 
25
25
  subject.password = password
26
26
 
27
- BCrypt::Password.should have_received(:create).with(
27
+ expect(BCrypt::Password).to have_received(:create).with(
28
28
  password,
29
29
  cost: ::BCrypt::Engine::DEFAULT_COST
30
30
  )
@@ -33,7 +33,7 @@ describe Clearance::PasswordStrategies::BCrypt do
33
33
  it 'encrypts with BCrypt using minimum cost in test environment' do
34
34
  subject.password = password
35
35
 
36
- BCrypt::Password.should have_received(:create).with(
36
+ expect(BCrypt::Password).to have_received(:create).with(
37
37
  password,
38
38
  cost: ::BCrypt::Engine::MIN_COST
39
39
  )
@@ -50,7 +50,7 @@ describe Clearance::PasswordStrategies::BCrypt do
50
50
  let(:password) { 'password' }
51
51
 
52
52
  it 'is authenticated with BCrypt' do
53
- subject.should be_authenticated(password)
53
+ expect(subject).to be_authenticated(password)
54
54
  end
55
55
  end
56
56
 
@@ -58,7 +58,7 @@ describe Clearance::PasswordStrategies::BCrypt do
58
58
  let(:password) { nil }
59
59
 
60
60
  it 'is not authenticated' do
61
- subject.should_not be_authenticated(password)
61
+ expect(subject).not_to be_authenticated(password)
62
62
  end
63
63
  end
64
64
  end
@@ -16,14 +16,14 @@ describe Clearance::PasswordStrategies::Blowfish do
16
16
  end
17
17
 
18
18
  it 'does not initialize the salt' do
19
- subject.salt.should == salt
19
+ expect(subject.salt).to eq salt
20
20
  end
21
21
 
22
22
  it 'encrypts the password using Blowfish and the existing salt' do
23
23
  cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').encrypt
24
24
  cipher.key = Digest::SHA256.digest(salt)
25
25
  expected = cipher.update("--#{salt}--#{password}--") << cipher.final
26
- subject.encrypted_password.should == expected
26
+ expect(subject.encrypted_password).to eq expected
27
27
  end
28
28
  end
29
29
 
@@ -34,7 +34,7 @@ describe Clearance::PasswordStrategies::Blowfish do
34
34
  end
35
35
 
36
36
  it 'should initialize the salt' do
37
- subject.salt.should_not be_nil
37
+ expect(subject.salt).not_to be_nil
38
38
  end
39
39
  end
40
40
  end
@@ -25,7 +25,7 @@ describe Clearance::User do
25
25
  before { Clearance.configuration.password_strategy = mock_password_strategy }
26
26
 
27
27
  it 'includes the value it is set to' do
28
- subject.should be_kind_of(mock_password_strategy)
28
+ expect(subject).to be_kind_of(mock_password_strategy)
29
29
  end
30
30
  end
31
31
 
@@ -33,7 +33,7 @@ describe Clearance::User do
33
33
  before { Clearance.configuration.password_strategy = nil }
34
34
 
35
35
  it 'includes Clearance::PasswordStrategies::BCrypt' do
36
- subject.should be_kind_of(Clearance::PasswordStrategies::BCrypt)
36
+ expect(subject).to be_kind_of(Clearance::PasswordStrategies::BCrypt)
37
37
  end
38
38
  end
39
39
  end
@@ -16,12 +16,12 @@ describe Clearance::PasswordStrategies::SHA1 do
16
16
  end
17
17
 
18
18
  it 'does not initialize the salt' do
19
- subject.salt.should == salt
19
+ expect(subject.salt).to eq salt
20
20
  end
21
21
 
22
22
  it 'encrypts the password using SHA1 and the existing salt' do
23
23
  expected = Digest::SHA1.hexdigest("--#{salt}--#{password}--")
24
- subject.encrypted_password.should == expected
24
+ expect(subject.encrypted_password).to eq expected
25
25
  end
26
26
  end
27
27
 
@@ -32,11 +32,11 @@ describe Clearance::PasswordStrategies::SHA1 do
32
32
  end
33
33
 
34
34
  it "initializes the salt" do
35
- subject.salt.should_not be_nil
35
+ expect(subject.salt).not_to be_nil
36
36
  end
37
37
 
38
38
  it "doesn't encrpt the password" do
39
- subject.encrypted_password.should be_nil
39
+ expect(subject.encrypted_password).to be_nil
40
40
  end
41
41
  end
42
42
  end
@@ -5,27 +5,27 @@ describe User do
5
5
  it { should have_db_index(:remember_token) }
6
6
 
7
7
  describe 'when signing up' do
8
- it { should validate_presence_of(:email) }
9
- it { should validate_presence_of(:password) }
10
- it { should allow_value('foo@example.co.uk').for(:email) }
11
- it { should allow_value('foo@example.com').for(:email) }
12
- it { should allow_value('foo+bar@example.com').for(:email) }
13
- it { should_not allow_value('foo@').for(:email) }
14
- it { should_not allow_value('foo@example..com').for(:email) }
15
- it { should_not allow_value('foo@.example.com').for(:email) }
16
- it { should_not allow_value('foo').for(:email) }
17
- it { should_not allow_value('example.com').for(:email) }
18
- it { should_not allow_value('foo;@example.com').for(:email) }
8
+ it { is_expected.to validate_presence_of(:email) }
9
+ it { is_expected.to validate_presence_of(:password) }
10
+ it { is_expected.to allow_value('foo@example.co.uk').for(:email) }
11
+ it { is_expected.to allow_value('foo@example.com').for(:email) }
12
+ it { is_expected.to allow_value('foo+bar@example.com').for(:email) }
13
+ it { is_expected.not_to allow_value('foo@').for(:email) }
14
+ it { is_expected.not_to allow_value('foo@example..com').for(:email) }
15
+ it { is_expected.not_to allow_value('foo@.example.com').for(:email) }
16
+ it { is_expected.not_to allow_value('foo').for(:email) }
17
+ it { is_expected.not_to allow_value('example.com').for(:email) }
18
+ it { is_expected.not_to allow_value('foo;@example.com').for(:email) }
19
19
 
20
20
  it 'stores email in down case and removes whitespace' do
21
21
  user = create(:user, email: 'Jo hn.Do e @exa mp le.c om')
22
- user.email.should == 'john.doe@example.com'
22
+ expect(user.email).to eq 'john.doe@example.com'
23
23
  end
24
24
  end
25
25
 
26
26
  describe 'when multiple users have signed up' do
27
27
  before { create(:user) }
28
- it { should validate_uniqueness_of(:email) }
28
+ it { is_expected.to validate_uniqueness_of(:email) }
29
29
  end
30
30
 
31
31
  describe 'a user' do
@@ -35,22 +35,22 @@ describe User do
35
35
  end
36
36
 
37
37
  it 'is authenticated with correct email and password' do
38
- User.authenticate(@user.email, @password).should eq(@user)
39
- @user.should be_authenticated(@password)
38
+ expect(User.authenticate(@user.email, @password)).to eq(@user)
39
+ expect(@user).to be_authenticated(@password)
40
40
  end
41
41
 
42
42
  it 'is authenticated with correct uppercased email and correct password' do
43
- User.authenticate(@user.email.upcase, @password).should eq(@user)
44
- @user.should be_authenticated(@password)
43
+ expect(User.authenticate(@user.email.upcase, @password)).to eq(@user)
44
+ expect(@user).to be_authenticated(@password)
45
45
  end
46
46
 
47
47
  it 'is not authenticated with incorrect credentials' do
48
- User.authenticate(@user.email, 'bad_password').should be_nil
49
- @user.should_not be_authenticated('bad password')
48
+ expect(User.authenticate(@user.email, 'bad_password')).to be_nil
49
+ expect(@user).not_to be_authenticated('bad password')
50
50
  end
51
51
 
52
52
  it 'is retrieved via a case-insensitive search' do
53
- User.find_by_normalized_email(@user.email.upcase).should eq(@user)
53
+ expect(User.find_by_normalized_email(@user.email.upcase)).to eq(@user)
54
54
  end
55
55
  end
56
56
 
@@ -62,7 +62,7 @@ describe User do
62
62
  end
63
63
 
64
64
  it 'changes the remember token' do
65
- @user.remember_token.should_not == 'old-token'
65
+ expect(@user.remember_token).not_to eq 'old-token'
66
66
  end
67
67
  end
68
68
 
@@ -78,7 +78,7 @@ describe User do
78
78
  end
79
79
 
80
80
  it 'changes encrypted password' do
81
- @user.encrypted_password.should_not == @old_encrypted_password
81
+ expect(@user.encrypted_password).not_to eq @old_encrypted_password
82
82
  end
83
83
  end
84
84
  end
@@ -88,7 +88,7 @@ describe User do
88
88
  password = 'secret'
89
89
  first_user = create(:user, password: password)
90
90
  second_user = create(:user, password: password)
91
- second_user.remember_token.should_not == first_user.remember_token
91
+ expect(second_user.remember_token).not_to eq first_user.remember_token
92
92
  end
93
93
 
94
94
  describe 'a user' do
@@ -99,12 +99,12 @@ describe User do
99
99
 
100
100
  describe 'who requests password reminder' do
101
101
  before do
102
- @user.confirmation_token.should be_nil
102
+ expect(@user.confirmation_token).to be_nil
103
103
  @user.forgot_password!
104
104
  end
105
105
 
106
106
  it 'generates confirmation token' do
107
- @user.confirmation_token.should_not be_nil
107
+ expect(@user.confirmation_token).not_to be_nil
108
108
  end
109
109
 
110
110
  describe 'and then updates password' do
@@ -114,11 +114,11 @@ describe User do
114
114
  end
115
115
 
116
116
  it 'changes encrypted password' do
117
- @user.encrypted_password.should_not == @old_encrypted_password
117
+ expect(@user.encrypted_password).not_to eq @old_encrypted_password
118
118
  end
119
119
 
120
120
  it 'clears confirmation token' do
121
- @user.confirmation_token.should be_nil
121
+ expect(@user.confirmation_token).to be_nil
122
122
  end
123
123
  end
124
124
 
@@ -128,11 +128,11 @@ describe User do
128
128
  end
129
129
 
130
130
  it 'does not change encrypted password' do
131
- @user.encrypted_password.to_s.should == @old_encrypted_password
131
+ expect(@user.encrypted_password.to_s).to eq @old_encrypted_password
132
132
  end
133
133
 
134
134
  it 'does not clear confirmation token' do
135
- @user.confirmation_token.should_not be_nil
135
+ expect(@user.confirmation_token).to_not be_nil
136
136
  end
137
137
  end
138
138
  end
@@ -152,13 +152,13 @@ describe User do
152
152
 
153
153
  subject { @user }
154
154
 
155
- it { should allow_value(nil).for(:email) }
156
- it { should allow_value('').for(:email) }
155
+ it { is_expected.to allow_value(nil).for(:email) }
156
+ it { is_expected.to allow_value('').for(:email) }
157
157
  end
158
158
 
159
159
  describe 'user factory' do
160
160
  it 'should create a valid user with just an overridden password' do
161
- build(:user, password: 'test').should be_valid
161
+ expect(build(:user, password: 'test')).to be_valid
162
162
  end
163
163
  end
164
164
 
@@ -166,7 +166,7 @@ describe User do
166
166
  let(:email) { 'Jo hn.Do e @exa mp le.c om' }
167
167
 
168
168
  it 'downcases the address and strips spaces' do
169
- User.normalize_email(email).should eq 'john.doe@example.com'
169
+ expect(User.normalize_email(email)).to eq 'john.doe@example.com'
170
170
  end
171
171
  end
172
172
 
@@ -175,22 +175,22 @@ describe User do
175
175
  before { subject.send(:password=, password) }
176
176
 
177
177
  it 'sets password to the plain-text password' do
178
- subject.password.should == password
178
+ expect(subject.password).to eq password
179
179
  end
180
180
 
181
181
  it 'also sets encrypted_password' do
182
- subject.encrypted_password.should_not be_nil
182
+ expect(subject.encrypted_password).to_not be_nil
183
183
  end
184
184
  end
185
185
  end
186
186
 
187
187
  describe UserWithOptionalPassword do
188
- it { should allow_value(nil).for(:password) }
189
- it { should allow_value('').for(:password) }
188
+ it { is_expected.to allow_value(nil).for(:password) }
189
+ it { is_expected.to allow_value('').for(:password) }
190
190
 
191
191
  it 'cannot authenticate with blank password' do
192
192
  user = create(:user_with_optional_password)
193
193
 
194
- UserWithOptionalPassword.authenticate(user.email, '').should be_nil
194
+ expect(UserWithOptionalPassword.authenticate(user.email, '')).to be_nil
195
195
  end
196
196
  end