dacz-authuser 0.1.2

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