thoughtbot-clearance 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +25 -1
- data/README.textile +18 -5
- data/Rakefile +9 -10
- data/TODO.textile +6 -0
- data/app/controllers/clearance/confirmations_controller.rb +47 -0
- data/app/controllers/clearance/passwords_controller.rb +65 -0
- data/app/controllers/clearance/sessions_controller.rb +62 -0
- data/app/controllers/clearance/users_controller.rb +30 -0
- data/app/models/clearance_mailer.rb +19 -0
- data/{generators/clearance/templates/app → app}/views/clearance_mailer/change_password.html.erb +0 -0
- data/{generators/clearance/templates/app → app}/views/clearance_mailer/confirmation.html.erb +0 -0
- data/{generators/clearance/templates/app → app}/views/passwords/edit.html.erb +0 -0
- data/{generators/clearance/templates/app → app}/views/passwords/new.html.erb +0 -0
- data/{generators/clearance/templates/app → app}/views/sessions/new.html.erb +0 -0
- data/{generators/clearance/templates/app → app}/views/users/_form.html.erb +0 -0
- data/{generators/clearance/templates/app → app}/views/users/new.html.erb +0 -0
- data/config/clearance_routes.rb +19 -0
- data/generators/clearance/clearance_generator.rb +16 -76
- data/generators/clearance/templates/README +6 -23
- data/generators/clearance/templates/{test/factories/clearance.rb → factories.rb} +2 -5
- data/generators/clearance/templates/{db/migrate/create_users_with_clearance_columns.rb → migrations/create_users.rb} +1 -1
- data/generators/clearance/templates/{db/migrate/update_users_with_clearance_columns.rb → migrations/update_users.rb} +7 -7
- data/generators/clearance/templates/user.rb +3 -0
- data/generators/clearance_features/templates/features/step_definitions/clearance_steps.rb +1 -1
- data/lib/clearance.rb +15 -15
- data/lib/clearance/authentication.rb +80 -0
- data/lib/clearance/{lib/extensions → extensions}/errors.rb +0 -0
- data/lib/clearance/{lib/extensions → extensions}/rescue.rb +0 -0
- data/lib/clearance/user.rb +114 -0
- data/shoulda_macros/clearance.rb +11 -4
- metadata +34 -63
- data/generators/clearance/templates/app/controllers/application.rb +0 -5
- data/generators/clearance/templates/app/controllers/confirmations_controller.rb +0 -3
- data/generators/clearance/templates/app/controllers/passwords_controller.rb +0 -3
- data/generators/clearance/templates/app/controllers/sessions_controller.rb +0 -3
- data/generators/clearance/templates/app/controllers/users_controller.rb +0 -3
- data/generators/clearance/templates/app/models/clearance_mailer.rb +0 -5
- data/generators/clearance/templates/app/models/user.rb +0 -3
- data/generators/clearance/templates/app/views/users/edit.html.erb +0 -6
- data/generators/clearance/templates/test/functional/confirmations_controller_test.rb +0 -5
- data/generators/clearance/templates/test/functional/passwords_controller_test.rb +0 -5
- data/generators/clearance/templates/test/functional/sessions_controller_test.rb +0 -5
- data/generators/clearance/templates/test/functional/users_controller_test.rb +0 -5
- data/generators/clearance/templates/test/unit/clearance_mailer_test.rb +0 -6
- data/generators/clearance/templates/test/unit/user_test.rb +0 -5
- data/lib/clearance/app/controllers/application_controller.rb +0 -84
- data/lib/clearance/app/controllers/confirmations_controller.rb +0 -63
- data/lib/clearance/app/controllers/passwords_controller.rb +0 -79
- data/lib/clearance/app/controllers/sessions_controller.rb +0 -74
- data/lib/clearance/app/controllers/users_controller.rb +0 -45
- data/lib/clearance/app/models/clearance_mailer.rb +0 -23
- data/lib/clearance/app/models/user.rb +0 -118
- data/lib/clearance/test/functional/confirmations_controller_test.rb +0 -72
- data/lib/clearance/test/functional/passwords_controller_test.rb +0 -180
- data/lib/clearance/test/functional/sessions_controller_test.rb +0 -187
- data/lib/clearance/test/functional/users_controller_test.rb +0 -60
- data/lib/clearance/test/unit/clearance_mailer_test.rb +0 -65
- data/lib/clearance/test/unit/user_test.rb +0 -236
@@ -1,60 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module Test
|
3
|
-
module Functional
|
4
|
-
module UsersControllerTest
|
5
|
-
|
6
|
-
def self.included(controller_test)
|
7
|
-
controller_test.class_eval do
|
8
|
-
|
9
|
-
should_filter_params :password
|
10
|
-
|
11
|
-
public_context do
|
12
|
-
context "When getting new User view" do
|
13
|
-
setup { get :new }
|
14
|
-
|
15
|
-
should_respond_with :success
|
16
|
-
should_render_template :new
|
17
|
-
should_not_set_the_flash
|
18
|
-
|
19
|
-
should_display_a_sign_up_form
|
20
|
-
end
|
21
|
-
|
22
|
-
context "Given email parameter when getting new User view" do
|
23
|
-
setup do
|
24
|
-
@email = "a@example.com"
|
25
|
-
get :new, :user => { :email => @email }
|
26
|
-
end
|
27
|
-
|
28
|
-
should "set assigned user's email" do
|
29
|
-
assert_equal @email, assigns(:user).email
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "Given valid attributes when creating a new user" do
|
34
|
-
setup do
|
35
|
-
user_attributes = Factory.attributes_for(:user)
|
36
|
-
post :create, :user => user_attributes
|
37
|
-
end
|
38
|
-
|
39
|
-
should_create_user_successfully
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
signed_in_user_context do
|
44
|
-
context "GET to new" do
|
45
|
-
setup { get :new }
|
46
|
-
should_redirect_to("the home page") { root_url }
|
47
|
-
end
|
48
|
-
|
49
|
-
context "POST to create" do
|
50
|
-
setup { post :create, :user => {} }
|
51
|
-
should_redirect_to("the home page") { root_url }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module Test
|
3
|
-
module Unit
|
4
|
-
module ClearanceMailerTest
|
5
|
-
|
6
|
-
def self.included(mailer_test)
|
7
|
-
mailer_test.class_eval do
|
8
|
-
|
9
|
-
context "A change password email" do
|
10
|
-
setup do
|
11
|
-
@user = Factory(:user)
|
12
|
-
@email = ClearanceMailer.create_change_password @user
|
13
|
-
end
|
14
|
-
|
15
|
-
should "set its from address to DO_NOT_REPLY" do
|
16
|
-
assert_equal DO_NOT_REPLY, @email.from[0]
|
17
|
-
end
|
18
|
-
|
19
|
-
should "contain a link to edit the user's password" do
|
20
|
-
host = ActionMailer::Base.default_url_options[:host]
|
21
|
-
regexp = %r{http://#{host}/users/#{@user.id}/password/edit\?token=#{@user.token}}
|
22
|
-
assert_match regexp, @email.body
|
23
|
-
end
|
24
|
-
|
25
|
-
should "be sent to the user" do
|
26
|
-
assert_equal [@user.email], @email.to
|
27
|
-
end
|
28
|
-
|
29
|
-
should "set its subject" do
|
30
|
-
assert_match /Change your password/, @email.subject
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "A confirmation email" do
|
35
|
-
setup do
|
36
|
-
@user = Factory(:user)
|
37
|
-
@email = ClearanceMailer.create_confirmation @user
|
38
|
-
end
|
39
|
-
|
40
|
-
should "set its recipient to the given user" do
|
41
|
-
assert_equal @user.email, @email.to[0]
|
42
|
-
end
|
43
|
-
|
44
|
-
should "set its subject" do
|
45
|
-
assert_match /Account confirmation/, @email.subject
|
46
|
-
end
|
47
|
-
|
48
|
-
should "set its from address to DO_NOT_REPLY" do
|
49
|
-
assert_equal DO_NOT_REPLY, @email.from[0]
|
50
|
-
end
|
51
|
-
|
52
|
-
should "contain a link to confirm the user's account" do
|
53
|
-
host = ActionMailer::Base.default_url_options[:host]
|
54
|
-
regexp = %r{http://#{host}/users/#{@user.id}/confirmation/new\?token=#{@user.token}}
|
55
|
-
assert_match regexp, @email.body
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,236 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module Test
|
3
|
-
module Unit
|
4
|
-
module UserTest
|
5
|
-
|
6
|
-
def self.included(unit_test)
|
7
|
-
unit_test.class_eval do
|
8
|
-
|
9
|
-
should_not_allow_mass_assignment_of :email_confirmed,
|
10
|
-
:salt, :encrypted_password,
|
11
|
-
:token, :token_expires_at
|
12
|
-
|
13
|
-
# signing up
|
14
|
-
|
15
|
-
context "When signing up" do
|
16
|
-
should_validate_presence_of :email, :password
|
17
|
-
should_allow_values_for :email, "foo@example.com"
|
18
|
-
should_not_allow_values_for :email, "foo"
|
19
|
-
should_not_allow_values_for :email, "example.com"
|
20
|
-
|
21
|
-
should "require password confirmation on create" do
|
22
|
-
user = Factory.build(:user, :password => 'blah',
|
23
|
-
:password_confirmation => 'boogidy')
|
24
|
-
assert ! user.save
|
25
|
-
assert user.errors.on(:password)
|
26
|
-
end
|
27
|
-
|
28
|
-
should "initialize salt" do
|
29
|
-
assert_not_nil Factory(:user).salt
|
30
|
-
end
|
31
|
-
|
32
|
-
should "initialize token without expiry date" do
|
33
|
-
assert_not_nil Factory(:user).token
|
34
|
-
assert_nil Factory(:user).token_expires_at
|
35
|
-
end
|
36
|
-
|
37
|
-
context "encrypt password" do
|
38
|
-
setup do
|
39
|
-
@salt = "salt"
|
40
|
-
@user = Factory.build(:user, :salt => @salt)
|
41
|
-
def @user.initialize_salt; end
|
42
|
-
@user.save!
|
43
|
-
@password = @user.password
|
44
|
-
|
45
|
-
@user.encrypt(@password)
|
46
|
-
@expected = Digest::SHA1.hexdigest("--#{@salt}--#{@password}--")
|
47
|
-
end
|
48
|
-
|
49
|
-
should "create an encrypted password using SHA1 encryption" do
|
50
|
-
assert_equal @expected, @user.encrypted_password
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
should "store email in exact case" do
|
55
|
-
user = Factory(:user, :email => "John.Doe@example.com")
|
56
|
-
assert_equal "John.Doe@example.com", user.email
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "When multiple users have signed up" do
|
61
|
-
setup { @user = Factory(:user) }
|
62
|
-
should_validate_uniqueness_of :email
|
63
|
-
end
|
64
|
-
|
65
|
-
# confirming email
|
66
|
-
|
67
|
-
context "A user without email confirmation" do
|
68
|
-
setup do
|
69
|
-
@user = Factory(:user)
|
70
|
-
assert ! @user.email_confirmed?
|
71
|
-
end
|
72
|
-
|
73
|
-
context "after #confirm_email!" do
|
74
|
-
setup do
|
75
|
-
assert @user.confirm_email!
|
76
|
-
@user.reload
|
77
|
-
end
|
78
|
-
|
79
|
-
should "have confirmed their email" do
|
80
|
-
assert @user.email_confirmed?
|
81
|
-
end
|
82
|
-
|
83
|
-
should "reset token" do
|
84
|
-
assert_nil @user.token
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# authenticating
|
90
|
-
|
91
|
-
context "A user" do
|
92
|
-
setup do
|
93
|
-
@user = Factory(:user)
|
94
|
-
@password = @user.password
|
95
|
-
end
|
96
|
-
|
97
|
-
should "authenticate with good credentials" do
|
98
|
-
assert User.authenticate(@user.email, @password)
|
99
|
-
assert @user.authenticated?(@password)
|
100
|
-
end
|
101
|
-
|
102
|
-
should "not authenticate with bad credentials" do
|
103
|
-
assert ! User.authenticate(@user.email, 'bad_password')
|
104
|
-
assert ! @user.authenticated?('bad_password')
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# remember me
|
109
|
-
|
110
|
-
context "When authenticating with remember_me!" do
|
111
|
-
setup do
|
112
|
-
@user = Factory(:email_confirmed_user)
|
113
|
-
@token = @user.token
|
114
|
-
assert_nil @user.token_expires_at
|
115
|
-
@user.remember_me!
|
116
|
-
end
|
117
|
-
|
118
|
-
should "set the remember token and expiration date" do
|
119
|
-
assert_not_equal @token, @user.token
|
120
|
-
assert_not_nil @user.token_expires_at
|
121
|
-
end
|
122
|
-
|
123
|
-
should "remember user when token expires in the future" do
|
124
|
-
@user.update_attribute :token_expires_at,
|
125
|
-
2.weeks.from_now.utc
|
126
|
-
assert @user.remember?
|
127
|
-
end
|
128
|
-
|
129
|
-
should "not remember user when token has already expired" do
|
130
|
-
@user.update_attribute :token_expires_at,
|
131
|
-
2.weeks.ago.utc
|
132
|
-
assert ! @user.remember?
|
133
|
-
end
|
134
|
-
|
135
|
-
should "not remember user when token expiry date is not set" do
|
136
|
-
@user.update_attribute :token_expires_at, nil
|
137
|
-
assert ! @user.remember?
|
138
|
-
end
|
139
|
-
|
140
|
-
# logging out
|
141
|
-
|
142
|
-
context "forget_me!" do
|
143
|
-
setup { @user.forget_me! }
|
144
|
-
|
145
|
-
should "unset the remember token and expiration date" do
|
146
|
-
assert_nil @user.token
|
147
|
-
assert_nil @user.token_expires_at
|
148
|
-
end
|
149
|
-
|
150
|
-
should "not remember user" do
|
151
|
-
assert ! @user.remember?
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
# updating password
|
157
|
-
|
158
|
-
context "An email confirmed user" do
|
159
|
-
setup do
|
160
|
-
@user = Factory(:email_confirmed_user)
|
161
|
-
@old_encrypted_password = @user.encrypted_password
|
162
|
-
end
|
163
|
-
|
164
|
-
context "who updates password with confirmation" do
|
165
|
-
setup do
|
166
|
-
@user.update_password("new_password", "new_password")
|
167
|
-
end
|
168
|
-
|
169
|
-
should "change encrypted password" do
|
170
|
-
assert_not_equal @user.encrypted_password,
|
171
|
-
@old_encrypted_password
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
# recovering forgotten password
|
177
|
-
|
178
|
-
context "An email confirmed user" do
|
179
|
-
setup do
|
180
|
-
@user = Factory(:email_confirmed_user)
|
181
|
-
@old_encrypted_password = @user.encrypted_password
|
182
|
-
@user.confirm_email!
|
183
|
-
end
|
184
|
-
|
185
|
-
context "who requests password reminder" do
|
186
|
-
setup do
|
187
|
-
assert_nil @user.token
|
188
|
-
@user.forgot_password!
|
189
|
-
end
|
190
|
-
|
191
|
-
should "generate token" do
|
192
|
-
assert_not_nil @user.token
|
193
|
-
end
|
194
|
-
|
195
|
-
context "and then updates password" do
|
196
|
-
context 'with confirmation' do
|
197
|
-
setup do
|
198
|
-
@user.update_password("new_password", "new_password")
|
199
|
-
end
|
200
|
-
|
201
|
-
should "change encrypted password" do
|
202
|
-
assert_not_equal @user.encrypted_password,
|
203
|
-
@old_encrypted_password
|
204
|
-
end
|
205
|
-
|
206
|
-
should "clear token" do
|
207
|
-
assert_nil @user.token
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
context 'without confirmation' do
|
212
|
-
setup do
|
213
|
-
@user.update_password("new_password", "")
|
214
|
-
end
|
215
|
-
|
216
|
-
should "not change encrypted password" do
|
217
|
-
assert_equal @user.encrypted_password,
|
218
|
-
@old_encrypted_password
|
219
|
-
end
|
220
|
-
|
221
|
-
should "not clear token" do
|
222
|
-
assert_not_nil @user.token
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|