thoughtbot-clearance 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/clearance/test/functional/confirmations_controller_test.rb +85 -0
- data/lib/clearance/test/functional/passwords_controller_test.rb +192 -0
- data/lib/clearance/test/functional/sessions_controller_test.rb +96 -0
- data/lib/clearance/test/functional/users_controller_test.rb +64 -0
- data/lib/clearance/test/unit/user_mailer_test.rb +38 -0
- data/lib/clearance/test/unit/user_test.rb +208 -0
- data/lib/clearance/version.rb +2 -2
- metadata +18 -42
@@ -0,0 +1,85 @@
|
|
1
|
+
module Clearance
|
2
|
+
module Test
|
3
|
+
module Functional
|
4
|
+
module ConfirmationsControllerTest
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
|
9
|
+
context 'A GET to #new' do
|
10
|
+
context "with the User with the given id's salt" do
|
11
|
+
setup do
|
12
|
+
@user = Factory :user
|
13
|
+
get :new, :user_id => @user.id, :salt => @user.salt
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'find the User record with the given id and salt' do
|
17
|
+
assert_equal @user, assigns(:user)
|
18
|
+
end
|
19
|
+
|
20
|
+
should_respond_with :success
|
21
|
+
should_render_template :new
|
22
|
+
end
|
23
|
+
|
24
|
+
context "without the User with the given id's salt" do
|
25
|
+
setup do
|
26
|
+
user = Factory :user
|
27
|
+
salt = ''
|
28
|
+
assert_not_equal salt, user.salt
|
29
|
+
|
30
|
+
get :new, :user_id => user.id, :salt => ''
|
31
|
+
end
|
32
|
+
|
33
|
+
should_respond_with :not_found
|
34
|
+
|
35
|
+
should 'render nothing' do
|
36
|
+
assert @response.body.blank?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'A POST to #create' do
|
42
|
+
context "with the User with the given id's salt" do
|
43
|
+
setup do
|
44
|
+
@user = Factory :user
|
45
|
+
assert ! @user.confirmed?
|
46
|
+
|
47
|
+
post :create, :user_id => @user, :salt => @user.salt
|
48
|
+
@user.reload
|
49
|
+
end
|
50
|
+
|
51
|
+
should 'confirm the User record with the given id' do
|
52
|
+
assert @user.confirmed?
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'log the User in' do
|
56
|
+
assert_equal @user.id, session[:user_id]
|
57
|
+
end
|
58
|
+
|
59
|
+
should_redirect_to "user_path(@user)"
|
60
|
+
end
|
61
|
+
|
62
|
+
context "without the User with the given id's salt" do
|
63
|
+
setup do
|
64
|
+
user = Factory :user
|
65
|
+
salt = ''
|
66
|
+
assert_not_equal salt, user.salt
|
67
|
+
|
68
|
+
post :create, :user_id => user.id, :salt => salt
|
69
|
+
end
|
70
|
+
|
71
|
+
should_respond_with :not_found
|
72
|
+
|
73
|
+
should 'render nothing' do
|
74
|
+
assert @response.body.blank?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
module Clearance
|
2
|
+
module Test
|
3
|
+
module Functional
|
4
|
+
module PasswordsControllerTest
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
|
9
|
+
should_route :get, '/users/1/password/edit', :action => 'edit', :user_id => '1'
|
10
|
+
|
11
|
+
context 'with a user' do
|
12
|
+
setup { @user = Factory :user }
|
13
|
+
|
14
|
+
context 'A GET to #new' do
|
15
|
+
setup { get :new, :user_id => @user_id }
|
16
|
+
|
17
|
+
should_respond_with :success
|
18
|
+
should_render_template 'new'
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'A POST to #create' do
|
22
|
+
context "with an existing user's email address" do
|
23
|
+
setup do
|
24
|
+
ActionMailer::Base.deliveries.clear
|
25
|
+
|
26
|
+
post :create, :password => { :email => @user.email }
|
27
|
+
@email = ActionMailer::Base.deliveries[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
should 'send an email to the user to edit their password' do
|
31
|
+
assert @email.subject =~ /request to change your password/i
|
32
|
+
end
|
33
|
+
|
34
|
+
should_redirect_to "new_session_path"
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with a non-existing email address' do
|
38
|
+
setup do
|
39
|
+
email = 'user1@example.com'
|
40
|
+
assert ! User.exists?(['email = ?', email])
|
41
|
+
ActionMailer::Base.deliveries.clear
|
42
|
+
|
43
|
+
post :create, :password => { :email => email }
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'not send a password reminder email' do
|
47
|
+
assert ActionMailer::Base.deliveries.empty?
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'set a :warning flash' do
|
51
|
+
assert_not_nil flash.now[:warning]
|
52
|
+
end
|
53
|
+
|
54
|
+
should_render_template "new"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'A GET to #edit' do
|
59
|
+
context "with an existing user's id and password" do
|
60
|
+
setup do
|
61
|
+
get :edit,
|
62
|
+
:user_id => @user.id,
|
63
|
+
:password => @user.crypted_password,
|
64
|
+
:email => @user.email
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'find the user with the given id and password' do
|
68
|
+
assert_equal @user, assigns(:user)
|
69
|
+
end
|
70
|
+
|
71
|
+
should_respond_with :success
|
72
|
+
should_render_template "edit"
|
73
|
+
|
74
|
+
should "have a form for the user's email, password, and password confirm" do
|
75
|
+
update_path = ERB::Util.h(user_password_path(@user,
|
76
|
+
:password => @user.crypted_password,
|
77
|
+
:email => @user.email))
|
78
|
+
|
79
|
+
assert_select 'form[action=?]', update_path do
|
80
|
+
assert_select 'input[name=_method][value=?]', 'put'
|
81
|
+
assert_select 'input[name=?]', 'user[password]'
|
82
|
+
assert_select 'input[name=?]', 'user[password_confirmation]'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "with an existing user's id but not password" do
|
88
|
+
setup do
|
89
|
+
get(:edit,
|
90
|
+
:user_id => @user.id,
|
91
|
+
:password => '')
|
92
|
+
end
|
93
|
+
|
94
|
+
should_respond_with :not_found
|
95
|
+
|
96
|
+
should 'render an empty response' do
|
97
|
+
assert @response.body.blank?
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'A PUT to #update' do
|
103
|
+
context "with an existing user's id but not password" do
|
104
|
+
setup do
|
105
|
+
put(:update,
|
106
|
+
:user_id => @user.id,
|
107
|
+
:password => '')
|
108
|
+
end
|
109
|
+
|
110
|
+
should "not update the user's password" do
|
111
|
+
assert_not_equal @encrypted_new_password, @user.crypted_password
|
112
|
+
end
|
113
|
+
|
114
|
+
should 'not log the user in' do
|
115
|
+
assert_nil session[:user_id]
|
116
|
+
end
|
117
|
+
|
118
|
+
should_respond_with :not_found
|
119
|
+
|
120
|
+
should 'render an empty response' do
|
121
|
+
assert @response.body.blank?
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'with a matching password and password confirmation' do
|
126
|
+
setup do
|
127
|
+
new_password = 'new_password'
|
128
|
+
encryption_format = "--#{@user.salt}--#{new_password}--"
|
129
|
+
@encrypted_new_password = Digest::SHA1.hexdigest encryption_format
|
130
|
+
assert_not_equal @encrypted_new_password, @user.crypted_password
|
131
|
+
|
132
|
+
put(:update,
|
133
|
+
:user_id => @user,
|
134
|
+
:email => @user.email,
|
135
|
+
:password => @user.crypted_password,
|
136
|
+
:user => {
|
137
|
+
:password => new_password,
|
138
|
+
:password_confirmation => new_password
|
139
|
+
})
|
140
|
+
@user.reload
|
141
|
+
end
|
142
|
+
|
143
|
+
should "update the user's password" do
|
144
|
+
assert_equal @encrypted_new_password, @user.crypted_password
|
145
|
+
end
|
146
|
+
|
147
|
+
should 'log the user in' do
|
148
|
+
assert_equal session[:user_id], @user.id
|
149
|
+
end
|
150
|
+
|
151
|
+
should_redirect_to "user_path(@user)"
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with password but blank password confirmation' do
|
155
|
+
setup do
|
156
|
+
new_password = 'new_password'
|
157
|
+
encryption_format = "--#{@user.salt}--#{new_password}--"
|
158
|
+
@encrypted_new_password = Digest::SHA1.hexdigest encryption_format
|
159
|
+
|
160
|
+
put(:update,
|
161
|
+
:user_id => @user.id,
|
162
|
+
:password => @user.crypted_password,
|
163
|
+
:user => {
|
164
|
+
:password => new_password,
|
165
|
+
:password_confirmation => ''
|
166
|
+
})
|
167
|
+
@user.reload
|
168
|
+
end
|
169
|
+
|
170
|
+
should "not update the user's password" do
|
171
|
+
assert_not_equal @encrypted_new_password, @user.crypted_password
|
172
|
+
end
|
173
|
+
|
174
|
+
should 'not log the user in' do
|
175
|
+
assert_nil session[:user_id]
|
176
|
+
end
|
177
|
+
|
178
|
+
should_respond_with :not_found
|
179
|
+
|
180
|
+
should 'render an empty response' do
|
181
|
+
assert @response.body.blank?
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Clearance
|
2
|
+
module Test
|
3
|
+
module Functional
|
4
|
+
module SessionsControllerTest
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
context "Given a user" do
|
9
|
+
setup { @user = Factory :user }
|
10
|
+
|
11
|
+
should_filter_params :password
|
12
|
+
|
13
|
+
context "on GET to /sessions/new" do
|
14
|
+
setup { get :new }
|
15
|
+
|
16
|
+
should_respond_with :success
|
17
|
+
should_render_template :new
|
18
|
+
should_not_set_the_flash
|
19
|
+
should_have_form :action => "session_path",
|
20
|
+
:fields => { "session[email]" => :text,
|
21
|
+
"session[password]" => :password,
|
22
|
+
"session[remember_me]" => :checkbox }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "a POST to #create with good credentials" do
|
26
|
+
setup do
|
27
|
+
post :create, :session => { :email => @user.email, :password => @user.password }
|
28
|
+
end
|
29
|
+
|
30
|
+
should_set_the_flash_to /success/i
|
31
|
+
should_redirect_to '@controller.send(:url_after_create)'
|
32
|
+
#should_return_from_session(:user_id, '@user.id')
|
33
|
+
should "return the correct value from the session for key :user_id" do
|
34
|
+
instantiate_variables_from_assigns do
|
35
|
+
expected_value = @user.id
|
36
|
+
assert_equal expected_value, session[:user_id], "Expected #{expected_value.inspect} but was #{session[:user_id]}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "a POST to #create with bad credentials" do
|
42
|
+
setup do
|
43
|
+
post :create, :session => { :email => @user.email, :password => "bad value" }
|
44
|
+
end
|
45
|
+
|
46
|
+
should_set_the_flash_to /bad/i
|
47
|
+
should_render_template :new
|
48
|
+
#should_return_from_session(:user_id, 'nil')
|
49
|
+
should "return nil from the session for key :user_id" do
|
50
|
+
instantiate_variables_from_assigns do
|
51
|
+
assert_nil session[:user_id], "Expected nil but was #{session[:user_id]}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# TODO: two tests for remember me - success and failure
|
57
|
+
end
|
58
|
+
|
59
|
+
public_context do
|
60
|
+
context "logging out again" do
|
61
|
+
setup { delete :destroy }
|
62
|
+
should_redirect_to '@controller.send(:url_after_destroy)'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
logged_in_user_context do
|
67
|
+
context "a DELETE to #destroy without a cookie" do
|
68
|
+
setup { delete :destroy }
|
69
|
+
|
70
|
+
should_set_the_flash_to(/logged out/i)
|
71
|
+
should_redirect_to '@controller.send(:url_after_destroy)'
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'a DELETE to #destroy with a cookie' do
|
75
|
+
setup do
|
76
|
+
cookies['auth_token'] = CGI::Cookie.new 'token', 'value'
|
77
|
+
delete :destroy
|
78
|
+
end
|
79
|
+
|
80
|
+
should 'delete the cookie' do
|
81
|
+
assert cookies['auth_token'].empty?
|
82
|
+
end
|
83
|
+
|
84
|
+
should 'delete the remember me token in users table' do
|
85
|
+
assert_nil @user.reload.remember_token
|
86
|
+
assert_nil @user.reload.remember_token_expires_at
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Clearance
|
2
|
+
module Test
|
3
|
+
module Functional
|
4
|
+
module UsersControllerTest
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
public_context do
|
9
|
+
|
10
|
+
context "on GET to /users/new" do
|
11
|
+
setup { get :new }
|
12
|
+
should_respond_with :success
|
13
|
+
should_render_template :new
|
14
|
+
should_not_set_the_flash
|
15
|
+
should_have_form :action => "users_path",
|
16
|
+
:method => :post,
|
17
|
+
:fields => { :email => :text,
|
18
|
+
:password => :password,
|
19
|
+
:password_confirmation => :password }
|
20
|
+
|
21
|
+
context "with params" do
|
22
|
+
setup do
|
23
|
+
@email = 'a@example.com'
|
24
|
+
get :new, :user => {:email => @email}
|
25
|
+
end
|
26
|
+
|
27
|
+
should_assign_to :user
|
28
|
+
should "set the @user's params" do
|
29
|
+
assert_equal @email, assigns(:user).email
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "on POST to /users" do
|
35
|
+
setup do
|
36
|
+
post :create, :user => {
|
37
|
+
:email => Factory.next(:email),
|
38
|
+
:password => 'skerit',
|
39
|
+
:password_confirmation => 'skerit'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
should_set_the_flash_to /confirm/i
|
44
|
+
should_redirect_to "@controller.send(:url_after_create)"
|
45
|
+
should_assign_to :user
|
46
|
+
should_change 'User.count', :by => 1
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
logged_in_user_context do
|
52
|
+
|
53
|
+
should_deny_access_on "get :new"
|
54
|
+
should_deny_access_on "post :create, :user => {}"
|
55
|
+
should_filter_params :password
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Clearance
|
2
|
+
module Test
|
3
|
+
module Unit
|
4
|
+
module UserMailerTest
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
context "A change password email" do
|
9
|
+
setup do
|
10
|
+
@user = Factory :user
|
11
|
+
@email = UserMailer.create_change_password @user
|
12
|
+
end
|
13
|
+
|
14
|
+
should "set its from address to 'donotreply@example.com'" do
|
15
|
+
assert_equal 'donotreply@example.com', @email.from[0]
|
16
|
+
end
|
17
|
+
|
18
|
+
should "contain a link to edit the user's password" do
|
19
|
+
host = ActionMailer::Base.default_url_options[:host]
|
20
|
+
regexp = %r{http://#{host}/users/#{@user.id}/password/edit\?email=#{@user.email.gsub("@", "%40")}&password=#{@user.crypted_password}}
|
21
|
+
assert_match regexp, @email.body
|
22
|
+
end
|
23
|
+
|
24
|
+
should "be sent to the user" do
|
25
|
+
assert_equal [@user.email], @email.to
|
26
|
+
end
|
27
|
+
|
28
|
+
should "have a subject of '[YOUR APP] Request to change your password'" do
|
29
|
+
assert_equal "[YOUR APP] Request to change your password", @email.subject
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
module Clearance
|
2
|
+
module Test
|
3
|
+
module Unit
|
4
|
+
module UserTest
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
should_require_attributes :email, :password
|
9
|
+
|
10
|
+
should "require password validation on create" do
|
11
|
+
user = Factory.build(:user, :password => 'blah', :password_confirmation => 'boogidy')
|
12
|
+
assert !user.save
|
13
|
+
assert_match(/confirmation/i, user.errors.on(:password))
|
14
|
+
end
|
15
|
+
|
16
|
+
should "create a crypted_password on save" do
|
17
|
+
assert_not_nil Factory(:user, :crypted_password => nil).crypted_password
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'updating a password' do
|
21
|
+
setup do
|
22
|
+
@user = Factory(:user)
|
23
|
+
assert_not_nil @user.crypted_password
|
24
|
+
@crypt = @user.crypted_password
|
25
|
+
assert_not_nil @user.salt
|
26
|
+
@salt = @user.salt
|
27
|
+
@user.password = 'a_new_password'
|
28
|
+
@user.password_confirmation = 'a_new_password'
|
29
|
+
assert @user.save
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'update a crypted_password' do
|
33
|
+
@user.reload
|
34
|
+
assert @user.crypted_password != @crypt
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'A user' do
|
39
|
+
setup do
|
40
|
+
@salt = 'salt'
|
41
|
+
User.any_instance.stubs(:initialize_salt)
|
42
|
+
@user = Factory :user, :salt => @salt
|
43
|
+
@password = @user.password
|
44
|
+
end
|
45
|
+
|
46
|
+
should "require password validation on update" do
|
47
|
+
@user.update_attributes(:password => "blah", :password_confirmation => "boogidy")
|
48
|
+
assert !@user.save
|
49
|
+
assert_match(/confirmation/i, @user.errors.on(:password))
|
50
|
+
end
|
51
|
+
|
52
|
+
should_require_unique_attributes :email
|
53
|
+
|
54
|
+
context 'authenticating a user' do
|
55
|
+
context 'with good credentials' do
|
56
|
+
setup do
|
57
|
+
@result = User.authenticate @user.email, @password
|
58
|
+
end
|
59
|
+
|
60
|
+
should 'return true' do
|
61
|
+
assert @result
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'with bad credentials' do
|
66
|
+
setup do
|
67
|
+
@result = User.authenticate @user.email, 'horribly_wrong_password'
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'return false' do
|
71
|
+
assert !@result
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'authenticated?' do
|
77
|
+
context 'with good credentials' do
|
78
|
+
setup do
|
79
|
+
@result = @user.authenticated? @password
|
80
|
+
end
|
81
|
+
|
82
|
+
should 'return true' do
|
83
|
+
assert @result
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with bad credentials' do
|
88
|
+
setup do
|
89
|
+
@result = @user.authenticated? 'horribly_wrong_password'
|
90
|
+
end
|
91
|
+
|
92
|
+
should 'return false' do
|
93
|
+
assert !@result
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'encrypt' do
|
99
|
+
setup do
|
100
|
+
@crypted = @user.encrypt(@password)
|
101
|
+
@expected = Digest::SHA1.hexdigest("--#{@salt}--#{@password}--")
|
102
|
+
end
|
103
|
+
|
104
|
+
should 'create a Hash using SHA1 encryption' do
|
105
|
+
assert_equal @expected, @crypted
|
106
|
+
assert_not_equal @password, @crypted
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'remember_me!' do
|
111
|
+
setup do
|
112
|
+
assert_nil @user.remember_token
|
113
|
+
assert_nil @user.remember_token_expires_at
|
114
|
+
@user.remember_me!
|
115
|
+
end
|
116
|
+
|
117
|
+
should 'set the remember token and expiration date' do
|
118
|
+
assert_not_nil @user.remember_token
|
119
|
+
assert_not_nil @user.remember_token_expires_at
|
120
|
+
end
|
121
|
+
|
122
|
+
should 'remember_token?' do
|
123
|
+
assert @user.remember_token?
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'forget_me!' do
|
127
|
+
setup do
|
128
|
+
@user.forget_me!
|
129
|
+
end
|
130
|
+
|
131
|
+
should 'unset the remember token and expiration date' do
|
132
|
+
assert_nil @user.remember_token
|
133
|
+
assert_nil @user.remember_token_expires_at
|
134
|
+
end
|
135
|
+
|
136
|
+
should 'not remember_token?' do
|
137
|
+
assert ! @user.remember_token?
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'remember_token?' do
|
143
|
+
context 'when token expires in the future' do
|
144
|
+
setup do
|
145
|
+
@user.update_attribute :remember_token_expires_at, 2.weeks.from_now.utc
|
146
|
+
end
|
147
|
+
|
148
|
+
should 'be true' do
|
149
|
+
assert @user.remember_token?
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when token expired' do
|
154
|
+
setup do
|
155
|
+
@user.update_attribute :remember_token_expires_at, 2.weeks.ago.utc
|
156
|
+
end
|
157
|
+
|
158
|
+
should 'be false' do
|
159
|
+
assert ! @user.remember_token?
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "User.authenticate with a valid email and password" do
|
165
|
+
setup do
|
166
|
+
@found_user = User.authenticate @user.email, @user.password
|
167
|
+
end
|
168
|
+
|
169
|
+
should "find that user" do
|
170
|
+
assert_equal @user, @found_user
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "When sent authenticate with an invalid email and password" do
|
175
|
+
setup do
|
176
|
+
@found_user = User.authenticate "not", "valid"
|
177
|
+
end
|
178
|
+
|
179
|
+
should "find nothing" do
|
180
|
+
assert_nil @found_user
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "A user" do
|
186
|
+
setup do
|
187
|
+
@user = Factory :user
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'when sent #confirm!' do
|
191
|
+
setup do
|
192
|
+
assert ! @user.confirmed?
|
193
|
+
assert @user.confirm!
|
194
|
+
@user.reload
|
195
|
+
end
|
196
|
+
|
197
|
+
should 'mark the User record as confirmed' do
|
198
|
+
assert @user.confirmed?
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
data/lib/clearance/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thoughtbot-clearance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoughtbot, inc.
|
@@ -81,15 +81,15 @@ files:
|
|
81
81
|
- lib/clearance/app/models/user.rb
|
82
82
|
- lib/clearance/app/models/user_mailer.rb
|
83
83
|
- lib/clearance/test
|
84
|
-
- lib/clearance/test/
|
85
|
-
- lib/clearance/test/
|
86
|
-
- lib/clearance/test/
|
87
|
-
- lib/clearance/test/
|
88
|
-
- lib/clearance/test/
|
84
|
+
- lib/clearance/test/functional
|
85
|
+
- lib/clearance/test/functional/confirmations_controller_test.rb
|
86
|
+
- lib/clearance/test/functional/passwords_controller_test.rb
|
87
|
+
- lib/clearance/test/functional/sessions_controller_test.rb
|
88
|
+
- lib/clearance/test/functional/users_controller_test.rb
|
89
89
|
- lib/clearance/test/test_helper.rb
|
90
|
-
- lib/clearance/test/
|
91
|
-
- lib/clearance/test/
|
92
|
-
- lib/clearance/test/
|
90
|
+
- lib/clearance/test/unit
|
91
|
+
- lib/clearance/test/unit/user_mailer_test.rb
|
92
|
+
- lib/clearance/test/unit/user_test.rb
|
93
93
|
- lib/clearance/version.rb
|
94
94
|
- lib/clearance.rb
|
95
95
|
- test/rails_root
|
@@ -142,8 +142,10 @@ files:
|
|
142
142
|
- test/rails_root/config/routes.rb
|
143
143
|
- test/rails_root/db
|
144
144
|
- test/rails_root/db/bootstrap
|
145
|
+
- test/rails_root/db/development.sqlite3
|
145
146
|
- test/rails_root/db/migrate
|
146
147
|
- test/rails_root/db/migrate/001_create_users.rb
|
148
|
+
- test/rails_root/db/schema.rb
|
147
149
|
- test/rails_root/db/test.sqlite3
|
148
150
|
- test/rails_root/doc
|
149
151
|
- test/rails_root/doc/README_FOR_APP
|
@@ -198,6 +200,8 @@ files:
|
|
198
200
|
- test/rails_root/script/server
|
199
201
|
- test/rails_root/test
|
200
202
|
- test/rails_root/test/factories.rb
|
203
|
+
- test/rails_root/test/fixtures
|
204
|
+
- test/rails_root/test/fixtures/mailer
|
201
205
|
- test/rails_root/test/functional
|
202
206
|
- test/rails_root/test/functional/confirmations_controller_test.rb
|
203
207
|
- test/rails_root/test/functional/passwords_controller_test.rb
|
@@ -211,6 +215,11 @@ files:
|
|
211
215
|
- test/rails_root/test/unit
|
212
216
|
- test/rails_root/test/unit/user_mailer_test.rb
|
213
217
|
- test/rails_root/test/unit/user_test.rb
|
218
|
+
- test/rails_root/tmp
|
219
|
+
- test/rails_root/tmp/cache
|
220
|
+
- test/rails_root/tmp/pids
|
221
|
+
- test/rails_root/tmp/sessions
|
222
|
+
- test/rails_root/tmp/sockets
|
214
223
|
- test/rails_root/vendor
|
215
224
|
- test/rails_root/vendor/gems
|
216
225
|
- test/rails_root/vendor/gems/mocha-0.9.1
|
@@ -532,39 +541,6 @@ files:
|
|
532
541
|
- test/rails_root/vendor/plugins/factory_girl_on_rails/rails_generators/factory/templates/unit_test.rb
|
533
542
|
- test/rails_root/vendor/plugins/factory_girl_on_rails/rails_generators/factory/USAGE
|
534
543
|
- test/rails_root/vendor/plugins/factory_girl_on_rails/README
|
535
|
-
- test/rails_root/vendor/plugins/shoulda
|
536
|
-
- test/rails_root/vendor/plugins/shoulda/bin
|
537
|
-
- test/rails_root/vendor/plugins/shoulda/lib
|
538
|
-
- test/rails_root/vendor/plugins/shoulda/lib/shoulda
|
539
|
-
- test/rails_root/vendor/plugins/shoulda/lib/shoulda/action_mailer
|
540
|
-
- test/rails_root/vendor/plugins/shoulda/lib/shoulda/active_record
|
541
|
-
- test/rails_root/vendor/plugins/shoulda/lib/shoulda/controller
|
542
|
-
- test/rails_root/vendor/plugins/shoulda/lib/shoulda/controller/formats
|
543
|
-
- test/rails_root/vendor/plugins/shoulda/tasks
|
544
|
-
- test/rails_root/vendor/plugins/shoulda/test
|
545
|
-
- test/rails_root/vendor/plugins/shoulda/test/fixtures
|
546
|
-
- test/rails_root/vendor/plugins/shoulda/test/functional
|
547
|
-
- test/rails_root/vendor/plugins/shoulda/test/other
|
548
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root
|
549
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/app
|
550
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/app/controllers
|
551
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/app/helpers
|
552
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/app/models
|
553
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/app/views
|
554
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/app/views/layouts
|
555
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/app/views/posts
|
556
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/app/views/users
|
557
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/config
|
558
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/config/environments
|
559
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/config/initializers
|
560
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/db
|
561
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/db/migrate
|
562
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/log
|
563
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/public
|
564
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/script
|
565
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/vendor
|
566
|
-
- test/rails_root/vendor/plugins/shoulda/test/rails_root/vendor/plugins
|
567
|
-
- test/rails_root/vendor/plugins/shoulda/test/unit
|
568
544
|
has_rdoc: false
|
569
545
|
homepage: http://github.com/thoughtbot/clearance
|
570
546
|
post_install_message:
|