clearance 0.8.2
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.
- data/CHANGELOG.textile +194 -0
- data/LICENSE +21 -0
- data/README.textile +123 -0
- data/Rakefile +103 -0
- data/TODO.textile +6 -0
- data/app/controllers/clearance/confirmations_controller.rb +75 -0
- data/app/controllers/clearance/passwords_controller.rb +84 -0
- data/app/controllers/clearance/sessions_controller.rb +66 -0
- data/app/controllers/clearance/users_controller.rb +35 -0
- data/app/models/clearance_mailer.rb +23 -0
- data/app/views/clearance_mailer/change_password.html.erb +9 -0
- data/app/views/clearance_mailer/confirmation.html.erb +5 -0
- data/app/views/passwords/edit.html.erb +23 -0
- data/app/views/passwords/new.html.erb +15 -0
- data/app/views/sessions/new.html.erb +24 -0
- data/app/views/users/_form.html.erb +13 -0
- data/app/views/users/new.html.erb +6 -0
- data/config/clearance_routes.rb +30 -0
- data/generators/clearance/USAGE +1 -0
- data/generators/clearance/clearance_generator.rb +41 -0
- data/generators/clearance/lib/insert_commands.rb +33 -0
- data/generators/clearance/lib/rake_commands.rb +22 -0
- data/generators/clearance/templates/README +22 -0
- data/generators/clearance/templates/factories.rb +13 -0
- data/generators/clearance/templates/migrations/create_users.rb +21 -0
- data/generators/clearance/templates/migrations/update_users.rb +41 -0
- data/generators/clearance/templates/user.rb +3 -0
- data/generators/clearance_features/USAGE +1 -0
- data/generators/clearance_features/clearance_features_generator.rb +20 -0
- data/generators/clearance_features/templates/features/password_reset.feature +33 -0
- data/generators/clearance_features/templates/features/sign_in.feature +35 -0
- data/generators/clearance_features/templates/features/sign_out.feature +15 -0
- data/generators/clearance_features/templates/features/sign_up.feature +45 -0
- data/generators/clearance_features/templates/features/step_definitions/clearance_steps.rb +116 -0
- data/generators/clearance_features/templates/features/step_definitions/factory_girl_steps.rb +5 -0
- data/generators/clearance_features/templates/features/support/paths.rb +22 -0
- data/generators/clearance_views/USAGE +0 -0
- data/generators/clearance_views/clearance_views_generator.rb +27 -0
- data/generators/clearance_views/templates/formtastic/passwords/edit.html.erb +21 -0
- data/generators/clearance_views/templates/formtastic/passwords/new.html.erb +15 -0
- data/generators/clearance_views/templates/formtastic/sessions/new.html.erb +21 -0
- data/generators/clearance_views/templates/formtastic/users/_inputs.html.erb +6 -0
- data/generators/clearance_views/templates/formtastic/users/new.html.erb +10 -0
- data/lib/clearance.rb +6 -0
- data/lib/clearance/authentication.rb +125 -0
- data/lib/clearance/extensions/errors.rb +6 -0
- data/lib/clearance/extensions/rescue.rb +3 -0
- data/lib/clearance/extensions/routes.rb +14 -0
- data/lib/clearance/user.rb +199 -0
- data/rails/init.rb +1 -0
- data/shoulda_macros/clearance.rb +266 -0
- metadata +120 -0
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'clearance'
|
@@ -0,0 +1,266 @@
|
|
1
|
+
module Clearance
|
2
|
+
module Shoulda
|
3
|
+
|
4
|
+
# STATE OF AUTHENTICATION
|
5
|
+
|
6
|
+
def should_be_signed_in_as(&block)
|
7
|
+
warn "[DEPRECATION] should_be_signed_in_as cannot be used in functional tests anymore now that it depends on cookies, which are unavailable until the next request."
|
8
|
+
should "be signed in as #{block.bind(self).call}" do
|
9
|
+
user = block.bind(self).call
|
10
|
+
assert_not_nil user,
|
11
|
+
"please pass a User. try: should_be_signed_in_as { @user }"
|
12
|
+
assert_equal user, @controller.send(:current_user),
|
13
|
+
"#{user.inspect} is not the current_user, " <<
|
14
|
+
"which is #{@controller.send(:current_user).inspect}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def should_be_signed_in_and_email_confirmed_as(&block)
|
19
|
+
warn "[DEPRECATION] should_be_signed_in_and_email_confirmed_as: questionable usefulness"
|
20
|
+
should_be_signed_in_as &block
|
21
|
+
|
22
|
+
should "have confirmed email" do
|
23
|
+
user = block.bind(self).call
|
24
|
+
|
25
|
+
assert_not_nil user
|
26
|
+
assert_equal user, assigns(:user)
|
27
|
+
assert assigns(:user).email_confirmed?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def should_not_be_signed_in
|
32
|
+
warn "[DEPRECATION] should_not_be_signed_in is no longer a valid test since we now store a remember_token in cookies, not user_id in session"
|
33
|
+
should "not be signed in" do
|
34
|
+
assert_nil session[:user_id]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def should_deny_access_on(http_method, action, opts = {})
|
39
|
+
warn "[DEPRECATION] should_deny_access_on: use a setup & should_deny_access(:flash => ?)"
|
40
|
+
flash_message = opts.delete(:flash)
|
41
|
+
context "on #{http_method} to #{action}" do
|
42
|
+
setup do
|
43
|
+
send(http_method, action, opts)
|
44
|
+
end
|
45
|
+
|
46
|
+
should_deny_access(:flash => flash_message)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def should_deny_access(opts = {})
|
51
|
+
if opts[:flash]
|
52
|
+
should_set_the_flash_to opts[:flash]
|
53
|
+
else
|
54
|
+
should_not_set_the_flash
|
55
|
+
end
|
56
|
+
|
57
|
+
should_redirect_to('new_session_url') { new_session_url }
|
58
|
+
end
|
59
|
+
|
60
|
+
# HTTP FLUENCY
|
61
|
+
|
62
|
+
def should_forbid(description, &block)
|
63
|
+
should "forbid #{description}" do
|
64
|
+
assert_raises ActionController::Forbidden do
|
65
|
+
instance_eval(&block)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# CONTEXTS
|
71
|
+
|
72
|
+
def signed_in_user_context(&blk)
|
73
|
+
warn "[DEPRECATION] signed_in_user_context: creates a Mystery Guest, causes Obscure Test"
|
74
|
+
context "A signed in user" do
|
75
|
+
setup do
|
76
|
+
@user = Factory(:user)
|
77
|
+
@user.confirm_email!
|
78
|
+
sign_in_as @user
|
79
|
+
end
|
80
|
+
merge_block(&blk)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def public_context(&blk)
|
85
|
+
warn "[DEPRECATION] public_context: common case is no-op. call sign_out otherwise"
|
86
|
+
context "The public" do
|
87
|
+
setup { sign_out }
|
88
|
+
merge_block(&blk)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# CREATING USERS
|
93
|
+
|
94
|
+
def should_create_user_successfully
|
95
|
+
warn "[DEPRECATION] should_create_user_successfully: not meant to be public, no longer used internally"
|
96
|
+
should_assign_to :user
|
97
|
+
should_change 'User.count', :by => 1
|
98
|
+
|
99
|
+
should "send the confirmation email" do
|
100
|
+
assert_sent_email do |email|
|
101
|
+
email.subject =~ /account confirmation/i
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
should_set_the_flash_to /confirm/i
|
106
|
+
should_redirect_to_url_after_create
|
107
|
+
end
|
108
|
+
|
109
|
+
# RENDERING
|
110
|
+
|
111
|
+
def should_render_nothing
|
112
|
+
should "render nothing" do
|
113
|
+
assert @response.body.blank?
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# REDIRECTS
|
118
|
+
|
119
|
+
def should_redirect_to_url_after_create
|
120
|
+
should_redirect_to("the post-create url") do
|
121
|
+
@controller.send(:url_after_create)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def should_redirect_to_url_after_update
|
126
|
+
should_redirect_to("the post-update url") do
|
127
|
+
@controller.send(:url_after_update)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def should_redirect_to_url_after_destroy
|
132
|
+
should_redirect_to("the post-destroy url") do
|
133
|
+
@controller.send(:url_after_destroy)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def should_redirect_to_url_already_confirmed
|
138
|
+
should_redirect_to("the already confirmed url") do
|
139
|
+
@controller.send(:url_already_confirmed)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# VALIDATIONS
|
144
|
+
|
145
|
+
def should_validate_confirmation_of(attribute, opts = {})
|
146
|
+
warn "[DEPRECATION] should_validate_confirmation_of: not meant to be public, no longer used internally"
|
147
|
+
raise ArgumentError if opts[:factory].nil?
|
148
|
+
|
149
|
+
context "on save" do
|
150
|
+
should_validate_confirmation_is_not_blank opts[:factory], attribute
|
151
|
+
should_validate_confirmation_is_not_bad opts[:factory], attribute
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def should_validate_confirmation_is_not_blank(factory, attribute, opts = {})
|
156
|
+
warn "[DEPRECATION] should_validate_confirmation_is_not_blank: not meant to be public, no longer used internally"
|
157
|
+
should "validate #{attribute}_confirmation is not blank" do
|
158
|
+
model = Factory.build(factory, blank_confirmation_options(attribute))
|
159
|
+
model.save
|
160
|
+
assert_confirmation_error(model, attribute,
|
161
|
+
"#{attribute}_confirmation cannot be blank")
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def should_validate_confirmation_is_not_bad(factory, attribute, opts = {})
|
166
|
+
warn "[DEPRECATION] should_validate_confirmation_is_not_bad: not meant to be public, no longer used internally"
|
167
|
+
should "validate #{attribute}_confirmation is different than #{attribute}" do
|
168
|
+
model = Factory.build(factory, bad_confirmation_options(attribute))
|
169
|
+
model.save
|
170
|
+
assert_confirmation_error(model, attribute,
|
171
|
+
"#{attribute}_confirmation cannot be different than #{attribute}")
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# FORMS
|
176
|
+
|
177
|
+
def should_display_a_password_update_form
|
178
|
+
warn "[DEPRECATION] should_display_a_password_update_form: not meant to be public, no longer used internally"
|
179
|
+
should "have a form for the user's token, password, and password confirm" do
|
180
|
+
update_path = ERB::Util.h(
|
181
|
+
user_password_path(@user, :token => @user.confirmation_token)
|
182
|
+
)
|
183
|
+
|
184
|
+
assert_select 'form[action=?]', update_path do
|
185
|
+
assert_select 'input[name=_method][value=?]', 'put'
|
186
|
+
assert_select 'input[name=?]', 'user[password]'
|
187
|
+
assert_select 'input[name=?]', 'user[password_confirmation]'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def should_display_a_sign_up_form
|
193
|
+
warn "[DEPRECATION] should_display_a_sign_up_form: not meant to be public, no longer used internally"
|
194
|
+
should "display a form to sign up" do
|
195
|
+
assert_select "form[action=#{users_path}][method=post]",
|
196
|
+
true, "There must be a form to sign up" do
|
197
|
+
assert_select "input[type=text][name=?]",
|
198
|
+
"user[email]", true, "There must be an email field"
|
199
|
+
assert_select "input[type=password][name=?]",
|
200
|
+
"user[password]", true, "There must be a password field"
|
201
|
+
assert_select "input[type=password][name=?]",
|
202
|
+
"user[password_confirmation]", true, "There must be a password confirmation field"
|
203
|
+
assert_select "input[type=submit]", true,
|
204
|
+
"There must be a submit button"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def should_display_a_sign_in_form
|
210
|
+
warn "[DEPRECATION] should_display_a_sign_in_form: not meant to be public, no longer used internally"
|
211
|
+
should 'display a "sign in" form' do
|
212
|
+
assert_select "form[action=#{session_path}][method=post]",
|
213
|
+
true, "There must be a form to sign in" do
|
214
|
+
assert_select "input[type=text][name=?]",
|
215
|
+
"session[email]", true, "There must be an email field"
|
216
|
+
assert_select "input[type=password][name=?]",
|
217
|
+
"session[password]", true, "There must be a password field"
|
218
|
+
assert_select "input[type=submit]", true,
|
219
|
+
"There must be a submit button"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
module Clearance
|
227
|
+
module Shoulda
|
228
|
+
module Helpers
|
229
|
+
def sign_in_as(user)
|
230
|
+
@controller.current_user = user
|
231
|
+
return user
|
232
|
+
end
|
233
|
+
|
234
|
+
def sign_in
|
235
|
+
sign_in_as Factory(:email_confirmed_user)
|
236
|
+
end
|
237
|
+
|
238
|
+
def sign_out
|
239
|
+
@controller.current_user = nil
|
240
|
+
end
|
241
|
+
|
242
|
+
def blank_confirmation_options(attribute)
|
243
|
+
warn "[DEPRECATION] blank_confirmation_options: not meant to be public, no longer used internally"
|
244
|
+
opts = { attribute => attribute.to_s }
|
245
|
+
opts.merge("#{attribute}_confirmation".to_sym => "")
|
246
|
+
end
|
247
|
+
|
248
|
+
def bad_confirmation_options(attribute)
|
249
|
+
warn "[DEPRECATION] bad_confirmation_options: not meant to be public, no longer used internally"
|
250
|
+
opts = { attribute => attribute.to_s }
|
251
|
+
opts.merge("#{attribute}_confirmation".to_sym => "not_#{attribute}")
|
252
|
+
end
|
253
|
+
|
254
|
+
def assert_confirmation_error(model, attribute, message = "confirmation error")
|
255
|
+
warn "[DEPRECATION] assert_confirmation_error: not meant to be public, no longer used internally"
|
256
|
+
assert model.errors.on(attribute).include?("doesn't match confirmation"),
|
257
|
+
message
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
class Test::Unit::TestCase
|
264
|
+
include Clearance::Shoulda::Helpers
|
265
|
+
end
|
266
|
+
Test::Unit::TestCase.extend(Clearance::Shoulda)
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clearance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Croak
|
8
|
+
- Mike Burns
|
9
|
+
- Jason Morrison
|
10
|
+
- Joe Ferris
|
11
|
+
- Eugene Bolshakov
|
12
|
+
- Nick Quaranto
|
13
|
+
- Josh Nichols
|
14
|
+
- Mike Breen
|
15
|
+
- "Marcel G\xC3\xB6rner"
|
16
|
+
- Bence Nagy
|
17
|
+
- Ben Mabey
|
18
|
+
- Eloy Duran
|
19
|
+
- Tim Pope
|
20
|
+
- Mihai Anca
|
21
|
+
- Mark Cornick
|
22
|
+
- Shay Arnett
|
23
|
+
autorequire:
|
24
|
+
bindir: bin
|
25
|
+
cert_chain: []
|
26
|
+
|
27
|
+
date: 2009-09-01 00:00:00 -04:00
|
28
|
+
default_executable:
|
29
|
+
dependencies: []
|
30
|
+
|
31
|
+
description: Rails authentication with email & password.
|
32
|
+
email: support@thoughtbot.com
|
33
|
+
executables: []
|
34
|
+
|
35
|
+
extensions: []
|
36
|
+
|
37
|
+
extra_rdoc_files: []
|
38
|
+
|
39
|
+
files:
|
40
|
+
- CHANGELOG.textile
|
41
|
+
- LICENSE
|
42
|
+
- Rakefile
|
43
|
+
- README.textile
|
44
|
+
- TODO.textile
|
45
|
+
- app/controllers/clearance/confirmations_controller.rb
|
46
|
+
- app/controllers/clearance/passwords_controller.rb
|
47
|
+
- app/controllers/clearance/sessions_controller.rb
|
48
|
+
- app/controllers/clearance/users_controller.rb
|
49
|
+
- app/models/clearance_mailer.rb
|
50
|
+
- app/views/clearance_mailer/change_password.html.erb
|
51
|
+
- app/views/clearance_mailer/confirmation.html.erb
|
52
|
+
- app/views/passwords/edit.html.erb
|
53
|
+
- app/views/passwords/new.html.erb
|
54
|
+
- app/views/sessions/new.html.erb
|
55
|
+
- app/views/users/_form.html.erb
|
56
|
+
- app/views/users/new.html.erb
|
57
|
+
- config/clearance_routes.rb
|
58
|
+
- generators/clearance/clearance_generator.rb
|
59
|
+
- generators/clearance/lib/insert_commands.rb
|
60
|
+
- generators/clearance/lib/rake_commands.rb
|
61
|
+
- generators/clearance/templates/factories.rb
|
62
|
+
- generators/clearance/templates/migrations/create_users.rb
|
63
|
+
- generators/clearance/templates/migrations/update_users.rb
|
64
|
+
- generators/clearance/templates/README
|
65
|
+
- generators/clearance/templates/user.rb
|
66
|
+
- generators/clearance/USAGE
|
67
|
+
- generators/clearance_features/clearance_features_generator.rb
|
68
|
+
- generators/clearance_features/templates/features/password_reset.feature
|
69
|
+
- generators/clearance_features/templates/features/sign_in.feature
|
70
|
+
- generators/clearance_features/templates/features/sign_out.feature
|
71
|
+
- generators/clearance_features/templates/features/sign_up.feature
|
72
|
+
- generators/clearance_features/templates/features/step_definitions/clearance_steps.rb
|
73
|
+
- generators/clearance_features/templates/features/step_definitions/factory_girl_steps.rb
|
74
|
+
- generators/clearance_features/templates/features/support/paths.rb
|
75
|
+
- generators/clearance_features/USAGE
|
76
|
+
- generators/clearance_views/clearance_views_generator.rb
|
77
|
+
- generators/clearance_views/templates/formtastic/passwords/edit.html.erb
|
78
|
+
- generators/clearance_views/templates/formtastic/passwords/new.html.erb
|
79
|
+
- generators/clearance_views/templates/formtastic/sessions/new.html.erb
|
80
|
+
- generators/clearance_views/templates/formtastic/users/_inputs.html.erb
|
81
|
+
- generators/clearance_views/templates/formtastic/users/new.html.erb
|
82
|
+
- generators/clearance_views/USAGE
|
83
|
+
- lib/clearance/authentication.rb
|
84
|
+
- lib/clearance/extensions/errors.rb
|
85
|
+
- lib/clearance/extensions/rescue.rb
|
86
|
+
- lib/clearance/extensions/routes.rb
|
87
|
+
- lib/clearance/user.rb
|
88
|
+
- lib/clearance.rb
|
89
|
+
- shoulda_macros/clearance.rb
|
90
|
+
- rails/init.rb
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://github.com/thoughtbot/clearance
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: "0"
|
105
|
+
version:
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: "0"
|
111
|
+
version:
|
112
|
+
requirements: []
|
113
|
+
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.3.5
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Rails authentication with email & password.
|
119
|
+
test_files: []
|
120
|
+
|