clearance 1.2.0 → 1.2.1
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/Gemfile.lock +2 -2
- data/NEWS.md +4 -0
- data/app/controllers/clearance/passwords_controller.rb +13 -13
- data/app/controllers/clearance/sessions_controller.rb +4 -4
- data/app/controllers/clearance/users_controller.rb +4 -4
- data/app/mailers/clearance_mailer.rb +4 -4
- data/db/migrate/20110111224543_create_clearance_users.rb +5 -5
- data/db/schema.rb +10 -10
- data/features/step_definitions/configuration_steps.rb +8 -8
- data/features/step_definitions/gem_file_steps.rb +1 -1
- data/lib/clearance/authorization.rb +2 -1
- data/lib/clearance/password_strategies/bcrypt.rb +1 -1
- data/lib/clearance/session.rb +5 -5
- data/lib/clearance/testing/app/controllers/application_controller.rb +1 -1
- data/lib/clearance/testing/application.rb +1 -1
- data/lib/clearance/testing/config/routes.rb +1 -1
- data/lib/clearance/user.rb +2 -2
- data/lib/clearance/version.rb +1 -1
- data/lib/generators/clearance/install/install_generator.rb +8 -8
- data/lib/generators/clearance/install/templates/db/migrate/create_users.rb +5 -5
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_in_spec.rb +2 -2
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_updates_password_spec.rb +3 -3
- data/lib/generators/clearance/specs/templates/support/features.rb +1 -1
- data/lib/generators/clearance/specs/templates/support/features/clearance_helpers.rb +6 -6
- data/spec/clearance/constraints/signed_in_spec.rb +2 -2
- data/spec/clearance/rack_session_spec.rb +1 -1
- data/spec/controllers/flashes_controller_spec.rb +1 -1
- data/spec/controllers/forgeries_controller_spec.rb +5 -5
- data/spec/controllers/passwords_controller_spec.rb +16 -16
- data/spec/controllers/sessions_controller_spec.rb +3 -3
- data/spec/controllers/users_controller_spec.rb +4 -4
- data/spec/models/bcrypt_migration_from_sha1_spec.rb +2 -2
- data/spec/models/bcrypt_spec.rb +4 -4
- data/spec/models/user_spec.rb +5 -5
- data/spec/support/request_with_remember_token.rb +1 -1
- 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: 971071b9ce630b8439d1abc19bdf0fea8c3e7ae8
|
4
|
+
data.tar.gz: 34239b2f526a2123cad5e76711b152f04939ffc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b0d18f3620ff38e93a0ca32a75e456c2d37cd59bc10f4496bb88647b0f6e6f6ef17231260d272ab79dd1a9101a9d1387aa53a119ddea6ae6abf5ba719ee4ffd
|
7
|
+
data.tar.gz: d61fd1590a4578a5970858e3220dcfbee98a942e603da2f456daaba107cf8ceff01149b31d778681095263b6aeb40c69550713a15c853879a032e4e38e488a62
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
clearance (1.2.
|
4
|
+
clearance (1.2.1)
|
5
5
|
bcrypt
|
6
6
|
email_validator (~> 1.4)
|
7
7
|
rails (>= 3.1)
|
@@ -42,7 +42,7 @@ GEM
|
|
42
42
|
cucumber (>= 1.1.1)
|
43
43
|
rspec-expectations (>= 2.7.0)
|
44
44
|
atomic (1.1.14)
|
45
|
-
bcrypt (3.1.
|
45
|
+
bcrypt (3.1.7)
|
46
46
|
bourne (1.5.0)
|
47
47
|
mocha (>= 0.13.2, < 0.15)
|
48
48
|
builder (3.1.4)
|
data/NEWS.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
Thank you to all the [contributors](https://github.com/thoughtbot/clearance/graphs/contributors)!
|
2
2
|
|
3
|
+
New for 1.2.1 (March 6, 2014):
|
4
|
+
* Query string is now included in the redirect URL when Clearance redirects to a
|
5
|
+
previously stored URL.
|
6
|
+
|
3
7
|
New for 1.2.0 (February 28, 2014):
|
4
8
|
* Support for Rails 4.1.0.rc1
|
5
9
|
* `clearance/testing` is now deprecated. Require `clearance/rspec` or
|
@@ -1,25 +1,25 @@
|
|
1
1
|
require 'active_support/deprecation'
|
2
2
|
|
3
3
|
class Clearance::PasswordsController < ApplicationController
|
4
|
-
skip_before_filter :authorize, :
|
5
|
-
before_filter :forbid_missing_token, :
|
6
|
-
before_filter :forbid_non_existent_user, :
|
4
|
+
skip_before_filter :authorize, only: [:create, :edit, :new, :update]
|
5
|
+
before_filter :forbid_missing_token, only: [:edit, :update]
|
6
|
+
before_filter :forbid_non_existent_user, only: [:edit, :update]
|
7
7
|
|
8
8
|
def create
|
9
9
|
if user = find_user_for_create
|
10
10
|
user.forgot_password!
|
11
11
|
deliver_email(user)
|
12
12
|
end
|
13
|
-
render :
|
13
|
+
render template: 'passwords/create'
|
14
14
|
end
|
15
15
|
|
16
16
|
def edit
|
17
17
|
@user = find_user_for_edit
|
18
|
-
render :
|
18
|
+
render template: 'passwords/edit'
|
19
19
|
end
|
20
20
|
|
21
21
|
def new
|
22
|
-
render :
|
22
|
+
render template: 'passwords/new'
|
23
23
|
end
|
24
24
|
|
25
25
|
def update
|
@@ -30,7 +30,7 @@ class Clearance::PasswordsController < ApplicationController
|
|
30
30
|
redirect_to url_after_update
|
31
31
|
else
|
32
32
|
flash_failure_after_update
|
33
|
-
render :
|
33
|
+
render template: 'passwords/edit'
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -71,27 +71,27 @@ class Clearance::PasswordsController < ApplicationController
|
|
71
71
|
|
72
72
|
def flash_failure_when_forbidden
|
73
73
|
flash.now[:notice] = translate(:forbidden,
|
74
|
-
:
|
75
|
-
:
|
74
|
+
scope: [:clearance, :controllers, :passwords],
|
75
|
+
default: t('flashes.failure_when_forbidden'))
|
76
76
|
end
|
77
77
|
|
78
78
|
def flash_failure_after_update
|
79
79
|
flash.now[:notice] = translate(:blank_password,
|
80
|
-
:
|
81
|
-
:
|
80
|
+
scope: [:clearance, :controllers, :passwords],
|
81
|
+
default: t('flashes.failure_after_update'))
|
82
82
|
end
|
83
83
|
|
84
84
|
def forbid_missing_token
|
85
85
|
if params[:token].to_s.blank?
|
86
86
|
flash_failure_when_forbidden
|
87
|
-
render :
|
87
|
+
render template: 'passwords/new'
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
def forbid_non_existent_user
|
92
92
|
unless find_user_by_id_and_confirmation_token
|
93
93
|
flash_failure_when_forbidden
|
94
|
-
render :
|
94
|
+
render template: 'passwords/new'
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Clearance::SessionsController < ApplicationController
|
2
|
-
skip_before_filter :authorize, :
|
3
|
-
protect_from_forgery :
|
2
|
+
skip_before_filter :authorize, only: [:create, :new, :destroy]
|
3
|
+
protect_from_forgery except: :create
|
4
4
|
|
5
5
|
def create
|
6
6
|
@user = authenticate(params)
|
@@ -10,7 +10,7 @@ class Clearance::SessionsController < ApplicationController
|
|
10
10
|
redirect_back_or url_after_create
|
11
11
|
else
|
12
12
|
flash.now.notice = status.failure_message
|
13
|
-
render :
|
13
|
+
render template: 'sessions/new', status: :unauthorized
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -21,7 +21,7 @@ class Clearance::SessionsController < ApplicationController
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def new
|
24
|
-
render :
|
24
|
+
render template: 'sessions/new'
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class Clearance::UsersController < ApplicationController
|
2
|
-
skip_before_filter :authorize, :
|
3
|
-
before_filter :avoid_sign_in, :
|
2
|
+
skip_before_filter :authorize, only: [:create, :new]
|
3
|
+
before_filter :avoid_sign_in, only: [:create, :new], if: :signed_in?
|
4
4
|
|
5
5
|
def new
|
6
6
|
@user = user_from_params
|
7
|
-
render :
|
7
|
+
render template: 'users/new'
|
8
8
|
end
|
9
9
|
|
10
10
|
def create
|
@@ -14,7 +14,7 @@ class Clearance::UsersController < ApplicationController
|
|
14
14
|
sign_in @user
|
15
15
|
redirect_back_or url_after_create
|
16
16
|
else
|
17
|
-
render :
|
17
|
+
render template: 'users/new'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class ClearanceMailer < ActionMailer::Base
|
2
2
|
def change_password(user)
|
3
3
|
@user = user
|
4
|
-
mail :
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
4
|
+
mail from: Clearance.configuration.mailer_sender, to: @user.email,
|
5
|
+
subject: I18n.t(:change_password,
|
6
|
+
scope: [:clearance, :models, :clearance_mailer],
|
7
|
+
default: 'Change your password')
|
8
8
|
end
|
9
9
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class CreateClearanceUsers < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :users do |t|
|
4
|
-
t.timestamps :
|
5
|
-
t.string :email, :
|
6
|
-
t.string :encrypted_password, :
|
7
|
-
t.string :confirmation_token, :
|
8
|
-
t.string :remember_token, :
|
4
|
+
t.timestamps null: false
|
5
|
+
t.string :email, null: false
|
6
|
+
t.string :encrypted_password, limit: 128, null: false
|
7
|
+
t.string :confirmation_token, limit: 128
|
8
|
+
t.string :remember_token, limit: 128, null: false
|
9
9
|
end
|
10
10
|
|
11
11
|
add_index :users, :email
|
data/db/schema.rb
CHANGED
@@ -11,18 +11,18 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:
|
14
|
+
ActiveRecord::Schema.define(version: 20110111224543) do
|
15
15
|
|
16
|
-
create_table "users", :
|
17
|
-
t.datetime "created_at", :
|
18
|
-
t.datetime "updated_at", :
|
19
|
-
t.string "email", :
|
20
|
-
t.string "encrypted_password", :
|
21
|
-
t.string "confirmation_token", :
|
22
|
-
t.string "remember_token", :
|
16
|
+
create_table "users", force: true do |t|
|
17
|
+
t.datetime "created_at", null: false
|
18
|
+
t.datetime "updated_at", null: false
|
19
|
+
t.string "email", null: false
|
20
|
+
t.string "encrypted_password", limit: 128, null: false
|
21
|
+
t.string "confirmation_token", limit: 128
|
22
|
+
t.string "remember_token", limit: 128, null: false
|
23
23
|
end
|
24
24
|
|
25
|
-
add_index "users", ["email"], :
|
26
|
-
add_index "users", ["remember_token"], :
|
25
|
+
add_index "users", ["email"], name: "index_users_on_email"
|
26
|
+
add_index "users", ["remember_token"], name: "index_users_on_remember_token"
|
27
27
|
|
28
28
|
end
|
@@ -31,7 +31,7 @@ When "I have a project with clearance" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
When /^I configure ActionMailer to use "([^"]+)" as a host$/ do |host|
|
34
|
-
mailer_config = "config.action_mailer.default_url_options = { :
|
34
|
+
mailer_config = "config.action_mailer.default_url_options = { host: '#{host}' }"
|
35
35
|
path = 'config/application.rb'
|
36
36
|
|
37
37
|
in_current_dir do
|
@@ -42,7 +42,7 @@ When /^I configure ActionMailer to use "([^"]+)" as a host$/ do |host|
|
|
42
42
|
end
|
43
43
|
|
44
44
|
When /^I configure a root route$/ do
|
45
|
-
route = "root :
|
45
|
+
route = "root to: 'home#show'"
|
46
46
|
path = 'config/routes.rb'
|
47
47
|
|
48
48
|
in_current_dir do
|
@@ -54,7 +54,7 @@ When /^I configure a root route$/ do
|
|
54
54
|
write_file('app/controllers/home_controller.rb', <<-CONTROLLER)
|
55
55
|
class HomeController < ApplicationController
|
56
56
|
def show
|
57
|
-
render :
|
57
|
+
render text: '', layout: 'application'
|
58
58
|
end
|
59
59
|
end
|
60
60
|
CONTROLLER
|
@@ -114,11 +114,11 @@ When /^I create a migration with clearance fields$/ do
|
|
114
114
|
class CreateUsers < ActiveRecord::Migration
|
115
115
|
def self.up
|
116
116
|
create_table :users do |t|
|
117
|
-
t.timestamps :
|
118
|
-
t.string :email, :
|
119
|
-
t.string :encrypted_password, :
|
120
|
-
t.string :confirmation_token, :
|
121
|
-
t.string :remember_token, :
|
117
|
+
t.timestamps null: false
|
118
|
+
t.string :email, null: false
|
119
|
+
t.string :encrypted_password, limit: 128, null: false
|
120
|
+
t.string :confirmation_token, limit: 128
|
121
|
+
t.string :remember_token, limit: 128, null: false
|
122
122
|
end
|
123
123
|
|
124
124
|
add_index :users, :email
|
@@ -3,7 +3,7 @@ When /^I add the "([^"]*)" gem$/ do |gem_name|
|
|
3
3
|
end
|
4
4
|
|
5
5
|
When /^I add the "([^"]*)" gem from this project$/ do |gem_name|
|
6
|
-
append_to_file('Gemfile', %{\ngem "#{gem_name}", :
|
6
|
+
append_to_file('Gemfile', %{\ngem "#{gem_name}", path: "../../.."\n})
|
7
7
|
end
|
8
8
|
|
9
9
|
When /^I remove the "([^"]*)" gem from this project$/ do |gem_name|
|
data/lib/clearance/session.rb
CHANGED
@@ -98,11 +98,11 @@ module Clearance
|
|
98
98
|
|
99
99
|
def cookie_value
|
100
100
|
value = {
|
101
|
-
:
|
102
|
-
:
|
103
|
-
:
|
104
|
-
:
|
105
|
-
:
|
101
|
+
expires: remember_token_expires,
|
102
|
+
httponly: Clearance.configuration.httponly,
|
103
|
+
path: Clearance.configuration.cookie_path,
|
104
|
+
secure: Clearance.configuration.secure_cookie,
|
105
|
+
value: remember_token
|
106
106
|
}
|
107
107
|
|
108
108
|
if Clearance.configuration.cookie_domain.present?
|
@@ -14,7 +14,7 @@ module Clearance
|
|
14
14
|
config.action_controller.allow_forgery_protection = false
|
15
15
|
config.action_controller.perform_caching = false
|
16
16
|
config.action_dispatch.show_exceptions = false
|
17
|
-
config.action_mailer.default_url_options = { :
|
17
|
+
config.action_mailer.default_url_options = { host: 'localhost' }
|
18
18
|
config.action_mailer.delivery_method = :test
|
19
19
|
config.active_support.deprecation = :stderr
|
20
20
|
config.assets.enabled = true
|
data/lib/clearance/user.rb
CHANGED
@@ -63,12 +63,12 @@ module Clearance
|
|
63
63
|
|
64
64
|
def forgot_password!
|
65
65
|
generate_confirmation_token
|
66
|
-
save :
|
66
|
+
save validate: false
|
67
67
|
end
|
68
68
|
|
69
69
|
def reset_remember_token!
|
70
70
|
generate_remember_token
|
71
|
-
save :
|
71
|
+
save validate: false
|
72
72
|
end
|
73
73
|
|
74
74
|
def update_password(new_password)
|
data/lib/clearance/version.rb
CHANGED
@@ -48,8 +48,8 @@ module Clearance
|
|
48
48
|
def create_add_columns_migration
|
49
49
|
if migration_needed?
|
50
50
|
config = {
|
51
|
-
:
|
52
|
-
:
|
51
|
+
new_columns: new_columns,
|
52
|
+
new_indexes: new_indexes
|
53
53
|
}
|
54
54
|
|
55
55
|
copy_migration('add_clearance_to_users.rb', config)
|
@@ -82,17 +82,17 @@ module Clearance
|
|
82
82
|
|
83
83
|
def new_columns
|
84
84
|
@new_columns ||= {
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
85
|
+
email: 't.string :email',
|
86
|
+
encrypted_password: 't.string :encrypted_password, limit: 128',
|
87
|
+
confirmation_token: 't.string :confirmation_token, limit: 128',
|
88
|
+
remember_token: 't.string :remember_token, limit: 128'
|
89
89
|
}.reject { |column| existing_users_columns.include?(column.to_s) }
|
90
90
|
end
|
91
91
|
|
92
92
|
def new_indexes
|
93
93
|
@new_indexes ||= {
|
94
|
-
:
|
95
|
-
:
|
94
|
+
index_users_on_email: 'add_index :users, :email',
|
95
|
+
index_users_on_remember_token: 'add_index :users, :remember_token'
|
96
96
|
}.reject { |index| existing_users_indexes.include?(index.to_s) }
|
97
97
|
end
|
98
98
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class CreateUsers < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :users do |t|
|
4
|
-
t.timestamps :
|
5
|
-
t.string :email, :
|
6
|
-
t.string :encrypted_password, :
|
7
|
-
t.string :confirmation_token, :
|
8
|
-
t.string :remember_token, :
|
4
|
+
t.timestamps null: false
|
5
|
+
t.string :email, null: false
|
6
|
+
t.string :encrypted_password, limit: 128, null: false
|
7
|
+
t.string :confirmation_token, limit: 128
|
8
|
+
t.string :remember_token, limit: 128, null: false
|
9
9
|
end
|
10
10
|
|
11
11
|
add_index :users, :email
|
@@ -33,12 +33,12 @@ feature 'Visitor signs in' do
|
|
33
33
|
private
|
34
34
|
|
35
35
|
def create_user(email, password)
|
36
|
-
create(:user, :
|
36
|
+
create(:user, email: email, password: password)
|
37
37
|
end
|
38
38
|
|
39
39
|
def page_should_display_sign_in_error
|
40
40
|
page.body.should include(
|
41
|
-
I18n.t('flashes.failure_after_create', :
|
41
|
+
I18n.t('flashes.failure_after_create', sign_up_path: sign_up_path)
|
42
42
|
)
|
43
43
|
end
|
44
44
|
end
|
data/lib/generators/clearance/specs/templates/features/clearance/visitor_updates_password_spec.rb
CHANGED
@@ -35,13 +35,13 @@ feature 'Visitor updates password' do
|
|
35
35
|
|
36
36
|
def visit_password_reset_page_for(user)
|
37
37
|
visit edit_user_password_path(
|
38
|
-
:
|
39
|
-
:
|
38
|
+
user_id: user,
|
39
|
+
token: user.confirmation_token
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
43
43
|
def change_password_to(password)
|
44
|
-
fill_in 'password_reset_password', :
|
44
|
+
fill_in 'password_reset_password', with: password
|
45
45
|
click_button I18n.t('helpers.submit.password_reset.submit')
|
46
46
|
end
|
47
47
|
end
|
@@ -2,21 +2,21 @@ module Features
|
|
2
2
|
module ClearanceHelpers
|
3
3
|
def sign_up_with(email, password)
|
4
4
|
visit sign_up_path
|
5
|
-
fill_in 'user_email', :
|
6
|
-
fill_in 'user_password', :
|
5
|
+
fill_in 'user_email', with: email
|
6
|
+
fill_in 'user_password', with: password
|
7
7
|
click_button I18n.t('helpers.submit.user.create')
|
8
8
|
end
|
9
9
|
|
10
10
|
def sign_in_with(email, password)
|
11
11
|
visit sign_in_path
|
12
|
-
fill_in 'session_email', :
|
13
|
-
fill_in 'session_password', :
|
12
|
+
fill_in 'session_email', with: email
|
13
|
+
fill_in 'session_password', with: password
|
14
14
|
click_button I18n.t('helpers.submit.session.submit')
|
15
15
|
end
|
16
16
|
|
17
17
|
def signed_in_user
|
18
18
|
password = 'password'
|
19
|
-
user = create(:user, :
|
19
|
+
user = create(:user, password: password)
|
20
20
|
sign_in_with user.email, password
|
21
21
|
user
|
22
22
|
end
|
@@ -42,7 +42,7 @@ module Features
|
|
42
42
|
|
43
43
|
def reset_password_for(email)
|
44
44
|
visit new_password_path
|
45
|
-
fill_in 'password_email', :
|
45
|
+
fill_in 'password_email', with: email
|
46
46
|
click_button I18n.t('helpers.submit.password.submit')
|
47
47
|
end
|
48
48
|
end
|
@@ -14,7 +14,7 @@ describe Clearance::Constraints::SignedIn do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'yields a signed-in user to a provided block' do
|
17
|
-
user = create(:user, :
|
17
|
+
user = create(:user, email: 'before@example.com')
|
18
18
|
|
19
19
|
signed_in_constraint = Clearance::Constraints::SignedIn.new do |user|
|
20
20
|
user.update_attribute :email, 'after@example.com'
|
@@ -25,7 +25,7 @@ describe Clearance::Constraints::SignedIn do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'does not yield a user if they are not signed in' do
|
28
|
-
user = create(:user, :
|
28
|
+
user = create(:user, email: 'before@example.com')
|
29
29
|
|
30
30
|
signed_in_constraint = Clearance::Constraints::SignedIn.new do |user|
|
31
31
|
user.update_attribute :email, 'after@example.com'
|
@@ -4,7 +4,7 @@ describe Clearance::RackSession do
|
|
4
4
|
it 'injects a clearance session into the environment' do
|
5
5
|
expected_session = 'the session'
|
6
6
|
expected_session.stubs :add_cookie_to_headers
|
7
|
-
Clearance::Session.stubs :
|
7
|
+
Clearance::Session.stubs new: expected_session
|
8
8
|
headers = { 'X-Roaring-Lobster' => 'Red' }
|
9
9
|
|
10
10
|
app = Rack::Builder.new do
|
@@ -10,7 +10,7 @@ class ForgeriesController < ActionController::Base
|
|
10
10
|
self.allow_forgery_protection = true
|
11
11
|
|
12
12
|
def create
|
13
|
-
redirect_to :
|
13
|
+
redirect_to action: 'index'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -19,7 +19,7 @@ describe ForgeriesController do
|
|
19
19
|
before do
|
20
20
|
Rails.application.routes.draw do
|
21
21
|
resources :forgeries
|
22
|
-
get '/sign_in' => 'clearance/sessions#new', :
|
22
|
+
get '/sign_in' => 'clearance/sessions#new', as: 'sign_in'
|
23
23
|
end
|
24
24
|
|
25
25
|
@user = create(:user)
|
@@ -33,12 +33,12 @@ describe ForgeriesController do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'succeeds with authentic token' do
|
36
|
-
post :create, :
|
37
|
-
subject.should redirect_to(:
|
36
|
+
post :create, authenticity_token: 'golden-ticket'
|
37
|
+
subject.should redirect_to(action: 'index')
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'fails with invalid token' do
|
41
|
-
post :create, :
|
41
|
+
post :create, authenticity_token: 'hax0r'
|
42
42
|
subject.should deny_access
|
43
43
|
end
|
44
44
|
|
@@ -7,7 +7,7 @@ describe Clearance::PasswordsController do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'on GET to #new' do
|
10
|
-
before { get :new, :
|
10
|
+
before { get :new, user_id: @user.to_param }
|
11
11
|
|
12
12
|
it { should respond_with(:success) }
|
13
13
|
it { should render_template(:new) }
|
@@ -17,7 +17,7 @@ describe Clearance::PasswordsController do
|
|
17
17
|
describe 'with correct email address' do
|
18
18
|
before do
|
19
19
|
ActionMailer::Base.deliveries.clear
|
20
|
-
post :create, :
|
20
|
+
post :create, password: { email: @user.email }
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should generate a token for the change your password email' do
|
@@ -35,7 +35,7 @@ describe Clearance::PasswordsController do
|
|
35
35
|
describe 'with correct email address capitalized differently' do
|
36
36
|
before do
|
37
37
|
ActionMailer::Base.deliveries.clear
|
38
|
-
post :create, :
|
38
|
+
post :create, password: { email: @user.email.upcase }
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should generate a token for the change your password email' do
|
@@ -57,7 +57,7 @@ describe Clearance::PasswordsController do
|
|
57
57
|
ActionMailer::Base.deliveries.clear
|
58
58
|
@user.reload.confirmation_token.should == @user.confirmation_token
|
59
59
|
|
60
|
-
post :create, :
|
60
|
+
post :create, password: { email: email }
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should not generate a token for the change your password email' do
|
@@ -81,8 +81,8 @@ describe Clearance::PasswordsController do
|
|
81
81
|
|
82
82
|
describe 'on GET to #edit with correct id and token' do
|
83
83
|
before do
|
84
|
-
get :edit, :
|
85
|
-
:
|
84
|
+
get :edit, user_id: @user.to_param,
|
85
|
+
token: @user.confirmation_token
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should find the user' do
|
@@ -95,7 +95,7 @@ describe Clearance::PasswordsController do
|
|
95
95
|
|
96
96
|
describe 'on GET to #edit with correct id but blank token' do
|
97
97
|
before do
|
98
|
-
get :edit, :
|
98
|
+
get :edit, user_id: @user.to_param, token: ''
|
99
99
|
end
|
100
100
|
|
101
101
|
it { should set_the_flash.to(/double check the URL/i).now }
|
@@ -104,7 +104,7 @@ describe Clearance::PasswordsController do
|
|
104
104
|
|
105
105
|
describe 'on GET to #edit with correct id but no token' do
|
106
106
|
before do
|
107
|
-
get :edit, :
|
107
|
+
get :edit, user_id: @user.to_param
|
108
108
|
end
|
109
109
|
|
110
110
|
it { should set_the_flash.to(/double check the URL/i).now }
|
@@ -116,8 +116,8 @@ describe Clearance::PasswordsController do
|
|
116
116
|
@new_password = 'new_password'
|
117
117
|
@old_encrypted_password = @user.encrypted_password
|
118
118
|
|
119
|
-
put :update, :
|
120
|
-
:
|
119
|
+
put :update, user_id: @user, token: @user.confirmation_token,
|
120
|
+
password_reset: { password: @new_password }
|
121
121
|
@user.reload
|
122
122
|
end
|
123
123
|
|
@@ -138,8 +138,8 @@ describe Clearance::PasswordsController do
|
|
138
138
|
|
139
139
|
describe 'on PUT to #update with blank password' do
|
140
140
|
before do
|
141
|
-
put :update, :
|
142
|
-
:
|
141
|
+
put :update, user_id: @user.to_param, token: @user.confirmation_token,
|
142
|
+
password_reset: { password: '' }
|
143
143
|
@user.reload
|
144
144
|
end
|
145
145
|
|
@@ -162,10 +162,10 @@ describe Clearance::PasswordsController do
|
|
162
162
|
|
163
163
|
describe 'on PUT to #update with an empty token after the user sets a password' do
|
164
164
|
before do
|
165
|
-
put :update, :
|
166
|
-
:
|
167
|
-
put :update, :
|
168
|
-
:
|
165
|
+
put :update, user_id: @user.to_param, token: @user.confirmation_token,
|
166
|
+
password_reset: { password: 'good password' }
|
167
|
+
put :update, user_id: @user.to_param, token: [nil],
|
168
|
+
password_reset: { password: 'new password' }
|
169
169
|
end
|
170
170
|
|
171
171
|
it { should set_the_flash.to(/double check the URL/i).now }
|
@@ -26,7 +26,7 @@ describe Clearance::SessionsController do
|
|
26
26
|
before do
|
27
27
|
@user = create(:user)
|
28
28
|
@user.update_attribute :remember_token, 'old-token'
|
29
|
-
post :create, :
|
29
|
+
post :create, session: { email: @user.email, password: @user.password }
|
30
30
|
end
|
31
31
|
|
32
32
|
it { should redirect_to_url_after_create }
|
@@ -43,9 +43,9 @@ describe Clearance::SessionsController do
|
|
43
43
|
describe 'on POST to #create with good credentials and a session return url' do
|
44
44
|
before do
|
45
45
|
@user = create(:user)
|
46
|
-
@return_url = '/url_in_the_session'
|
46
|
+
@return_url = '/url_in_the_session?foo=bar'
|
47
47
|
@request.session[:return_to] = @return_url
|
48
|
-
post :create, :
|
48
|
+
post :create, session: { email: @user.email, password: @user.password }
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'redirects to the return URL' do
|
@@ -15,7 +15,7 @@ describe Clearance::UsersController do
|
|
15
15
|
describe 'on GET to #new with email' do
|
16
16
|
before do
|
17
17
|
@email = 'a@example.com'
|
18
|
-
get :new, :
|
18
|
+
get :new, user: { email: @email }
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should set assigned user email' do
|
@@ -27,7 +27,7 @@ describe Clearance::UsersController do
|
|
27
27
|
before do
|
28
28
|
user_attributes = FactoryGirl.attributes_for(:user)
|
29
29
|
@old_user_count = User.count
|
30
|
-
post :create, :
|
30
|
+
post :create, user: user_attributes
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'assigns a user' do
|
@@ -47,7 +47,7 @@ describe Clearance::UsersController do
|
|
47
47
|
@old_user_count = User.count
|
48
48
|
@return_url = '/url_in_the_session'
|
49
49
|
@request.session[:return_to] = @return_url
|
50
|
-
post :create, :
|
50
|
+
post :create, user: user_attributes
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'assigns a user' do
|
@@ -77,7 +77,7 @@ describe Clearance::UsersController do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
describe 'POST to create' do
|
80
|
-
before { post :create, :
|
80
|
+
before { post :create, user: {} }
|
81
81
|
|
82
82
|
it 'redirects to the home page' do
|
83
83
|
should redirect_to(Clearance.configuration.redirect_url)
|
@@ -15,7 +15,7 @@ describe Clearance::PasswordStrategies::BCryptMigrationFromSHA1 do
|
|
15
15
|
before do
|
16
16
|
subject.salt = salt
|
17
17
|
subject.encrypted_password = Digest::SHA1.hexdigest("--#{salt}--#{password}--")
|
18
|
-
BCrypt::Password.stubs :
|
18
|
+
BCrypt::Password.stubs create: encrypted_password
|
19
19
|
subject.password = password
|
20
20
|
end
|
21
21
|
|
@@ -41,7 +41,7 @@ describe Clearance::PasswordStrategies::BCryptMigrationFromSHA1 do
|
|
41
41
|
before do
|
42
42
|
subject.salt = salt
|
43
43
|
subject.encrypted_password = sha1_hash
|
44
|
-
subject.stubs :
|
44
|
+
subject.stubs save: true
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'is authenticated' do
|
data/spec/models/bcrypt_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Clearance::PasswordStrategies::BCrypt do
|
|
10
10
|
let(:encrypted_password) { stub('encrypted password') }
|
11
11
|
|
12
12
|
before do
|
13
|
-
BCrypt::Password.stubs :
|
13
|
+
BCrypt::Password.stubs create: encrypted_password
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'encrypts the password into encrypted_password' do
|
@@ -20,13 +20,13 @@ describe Clearance::PasswordStrategies::BCrypt do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'encrypts with BCrypt using default cost in non test environments' do
|
23
|
-
Rails.stubs :
|
23
|
+
Rails.stubs env: ActiveSupport::StringInquirer.new("production")
|
24
24
|
|
25
25
|
subject.password = password
|
26
26
|
|
27
27
|
BCrypt::Password.should have_received(:create).with(
|
28
28
|
password,
|
29
|
-
:
|
29
|
+
cost: ::BCrypt::Engine::DEFAULT_COST
|
30
30
|
)
|
31
31
|
end
|
32
32
|
|
@@ -35,7 +35,7 @@ describe Clearance::PasswordStrategies::BCrypt do
|
|
35
35
|
|
36
36
|
BCrypt::Password.should have_received(:create).with(
|
37
37
|
password,
|
38
|
-
:
|
38
|
+
cost: ::BCrypt::Engine::MIN_COST
|
39
39
|
)
|
40
40
|
end
|
41
41
|
end
|
data/spec/models/user_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe User do
|
|
18
18
|
it { should_not allow_value('foo;@example.com').for(:email) }
|
19
19
|
|
20
20
|
it 'stores email in down case and removes whitespace' do
|
21
|
-
user = create(:user, :
|
21
|
+
user = create(:user, email: 'Jo hn.Do e @exa mp le.c om')
|
22
22
|
user.email.should == 'john.doe@example.com'
|
23
23
|
end
|
24
24
|
end
|
@@ -84,10 +84,10 @@ describe User do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'does not generate same remember token for users with same password at same time' do
|
87
|
-
Time.stubs :
|
87
|
+
Time.stubs now: Time.now
|
88
88
|
password = 'secret'
|
89
|
-
first_user = create(:user, :
|
90
|
-
second_user = create(:user, :
|
89
|
+
first_user = create(:user, password: password)
|
90
|
+
second_user = create(:user, password: password)
|
91
91
|
second_user.remember_token.should_not == first_user.remember_token
|
92
92
|
end
|
93
93
|
|
@@ -158,7 +158,7 @@ describe User do
|
|
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, :
|
161
|
+
build(:user, password: 'test').should be_valid
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
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.2.
|
4
|
+
version: 1.2.1
|
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-03-
|
28
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
29
29
|
dependencies:
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bcrypt
|