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