jeffrafter-clearance 0.5.4

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