thoughtbot-clearance 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.textile CHANGED
@@ -1,3 +1,11 @@
1
+ h2. 0.6.4 (05/12/2009)
2
+
3
+ * Moved issue tracking to Github from Lighthouse. (Dan Croak)
4
+ * [#7] asking higher-level questions of controllers in webrat steps, such as signed_in? instead of what's in the session. same for accessors. (Dan Croak)
5
+ * [#11] replacing sign_in_as & sign_out shoulda macros with a stubbing (requires no dependency) approach. this will avoid dealing with the internals of current_user, such as session & cookies. added sign_in macro which signs in an email confirmed user from clearance's factories. (Dan Croak)
6
+ * [#13] move private methods on sessions controller into Clearance::Authentication module (Dan Croak)
7
+ * [#9] audited flash keys. (Dan Croak)
8
+
1
9
  h2. 0.6.3 (04/23/2009)
2
10
 
3
11
  * Scoping ClearanceMailer properly within controllers so it works in production environments. (Nick Quaranto)
data/README.textile CHANGED
@@ -17,7 +17,7 @@ In config/environment.rb:
17
17
  config.gem "thoughtbot-clearance",
18
18
  :lib => 'clearance',
19
19
  :source => 'http://gems.github.com',
20
- :version => '0.6.2'
20
+ :version => '0.6.4'
21
21
 
22
22
  Vendor the gem:
23
23
 
@@ -32,6 +32,10 @@ A number of files will be created and instructions will be printed.
32
32
 
33
33
  You may already have some of these files. Don't worry. You'll be asked if you want to overwrite them.
34
34
 
35
+ Run the migration:
36
+
37
+ rake db:migrate
38
+
35
39
  h2. Environment
36
40
 
37
41
  Define a HOST constant in your environment files.
@@ -65,15 +69,15 @@ In config/environments/test.rb:
65
69
  :source => "http://gems.github.com",
66
70
  :version => '1.2.1'
67
71
 
68
- Install nokogiri but don't vendor it (due to its native extensions):
69
-
70
- sudo gem install nokogiri
71
-
72
72
  Vendor the gems:
73
73
 
74
74
  rake gems:install RAILS_ENV=test
75
75
  rake gems:unpack RAILS_ENV=test
76
76
 
77
+ Don't vendor nokogiri (due to its native extensions):
78
+
79
+ rm -rf vendor/gems/nokogiri-1.2.3
80
+
77
81
  Run the Cucumber generator (if you haven't already) and Clearance's feature generator:
78
82
 
79
83
  script/generate cucumber
@@ -87,7 +91,7 @@ All of the files generated should be new with the exception of the features/supp
87
91
  when /the sign up page/i
88
92
  new_user_path
89
93
  when /the sign in page/i
90
- new_session_path
94
+ new_session_path
91
95
  when /the password reset request page/i
92
96
  new_password_path
93
97
  ...
@@ -95,15 +99,15 @@ All of the files generated should be new with the exception of the features/supp
95
99
 
96
100
  h2. Authors
97
101
 
98
- Clearance was extracted out of "Hoptoad":http://hoptoadapp.com. We merged the authentication code from two of thoughtbot's client's Rails apps. The following people have made significant contributions, suggestions, and generally improved the library. Thank you!
102
+ Clearance was extracted out of "Hoptoad":http://hoptoadapp.com. We merged the authentication code from two of thoughtbot's client's Rails apps and have since used it each time we need authentication. The following people have improved the library. Thank you!
99
103
 
100
104
  Dan Croak, Mike Burns, Jason Morrison, Joe Ferris, Eugene Bolshakov, Nick Quaranto, Josh Nichols, Mike Breen, Marcel Görner, Bence Nagy, Ben Mabey, Eloy Duran, Tim Pope, Mihai Anca, Mark Cornick, & Shay Arnett.
101
105
 
102
106
  h2. Questions?
103
107
 
104
- * Ask the "mailing list":http://groups.google.com/group/thoughtbot-clearance
108
+ Ask the "mailing list":http://groups.google.com/group/thoughtbot-clearance
105
109
 
106
- h2. Bugs?
110
+ h2. Suggestions, Bugs, Refactoring?
107
111
 
108
- * Open up a "Lighthouse ticket":https://thoughtbot.lighthouseapp.com/projects/18503-clearance
112
+ Fork away and create a "Github Issue":http://github.com/thoughtbot/clearance/issues. Please don't send pull requests.
109
113
 
data/Rakefile CHANGED
@@ -3,17 +3,17 @@ require 'rake/testtask'
3
3
  require 'cucumber/rake/task'
4
4
 
5
5
  namespace :test do
6
- Rake::TestTask.new(:all => ['generator:cleanup',
7
- 'generator:generate']) do |task|
8
- task.libs << 'lib'
6
+ Rake::TestTask.new(:all => ["generator:cleanup",
7
+ "generator:generate"]) do |task|
8
+ task.libs << "lib"
9
9
  task.libs << "test"
10
- task.pattern = 'test/**/*_test.rb'
10
+ task.pattern = "test/**/*_test.rb"
11
11
  task.verbose = false
12
12
  end
13
13
 
14
14
  Cucumber::Rake::Task.new(:features) do |t|
15
- t.cucumber_opts = "--format progress"
16
- t.feature_pattern = 'test/rails_root/features/*.feature'
15
+ t.cucumber_opts = "--format progress"
16
+ t.feature_pattern = "test/rails_root/features/*.feature"
17
17
  end
18
18
  end
19
19
 
@@ -51,7 +51,7 @@ task :default => ['test:all', 'test:features']
51
51
 
52
52
  gem_spec = Gem::Specification.new do |gem_spec|
53
53
  gem_spec.name = "clearance"
54
- gem_spec.version = "0.6.3"
54
+ gem_spec.version = "0.6.4"
55
55
  gem_spec.summary = "Rails authentication with email & password."
56
56
  gem_spec.email = "support@thoughtbot.com"
57
57
  gem_spec.homepage = "http://github.com/thoughtbot/clearance"
@@ -43,5 +43,4 @@ class Clearance::ConfirmationsController < ApplicationController
43
43
  def url_after_create
44
44
  root_url
45
45
  end
46
-
47
46
  end
@@ -17,7 +17,7 @@ class Clearance::PasswordsController < ApplicationController
17
17
  "It contains instructions for changing your password."
18
18
  redirect_to url_after_create
19
19
  else
20
- flash.now[:notice] = "Unknown email"
20
+ flash.now[:failure] = "Unknown email"
21
21
  render :template => 'passwords/new'
22
22
  end
23
23
  end
@@ -30,10 +30,11 @@ class Clearance::PasswordsController < ApplicationController
30
30
  def update
31
31
  @user = ::User.find_by_id_and_token(params[:user_id], params[:token])
32
32
 
33
- if @user.update_password(params[:user][:password],
33
+ if @user.update_password(params[:user][:password],
34
34
  params[:user][:password_confirmation])
35
35
  @user.confirm_email! unless @user.email_confirmed?
36
36
  sign_user_in(@user)
37
+ flash[:success] = "Signed in."
37
38
  redirect_to url_after_update
38
39
  else
39
40
  render :template => 'passwords/edit'
@@ -61,5 +62,4 @@ class Clearance::PasswordsController < ApplicationController
61
62
  def url_after_update
62
63
  root_url
63
64
  end
64
-
65
65
  end
@@ -12,13 +12,13 @@ class Clearance::SessionsController < ApplicationController
12
12
  @user = ::User.authenticate(params[:session][:email],
13
13
  params[:session][:password])
14
14
  if @user.nil?
15
- flash.now[:notice] = "Bad email or password."
15
+ flash.now[:failure] = "Bad email or password."
16
16
  render :template => 'sessions/new', :status => :unauthorized
17
17
  else
18
18
  if @user.email_confirmed?
19
- remember(@user) if remember?
20
19
  sign_user_in(@user)
21
- flash[:notice] = "Signed in successfully."
20
+ remember(@user) if remember?
21
+ flash[:success] = "Signed in."
22
22
  redirect_back_or url_after_create
23
23
  else
24
24
  ::ClearanceMailer.deliver_confirmation(@user)
@@ -29,28 +29,12 @@ class Clearance::SessionsController < ApplicationController
29
29
 
30
30
  def destroy
31
31
  forget(current_user)
32
- reset_session
33
- flash[:notice] = "You have been signed out."
32
+ flash[:success] = "Signed out."
34
33
  redirect_to url_after_destroy
35
34
  end
36
35
 
37
36
  private
38
37
 
39
- def remember?
40
- params[:session] && params[:session][:remember_me] == "1"
41
- end
42
-
43
- def remember(user)
44
- user.remember_me!
45
- cookies[:remember_token] = { :value => user.token,
46
- :expires => user.token_expires_at }
47
- end
48
-
49
- def forget(user)
50
- user.forget_me! if user
51
- cookies.delete :remember_token
52
- end
53
-
54
38
  def url_after_create
55
39
  root_url
56
40
  end
@@ -58,5 +42,4 @@ class Clearance::SessionsController < ApplicationController
58
42
  def url_after_destroy
59
43
  new_session_url
60
44
  end
61
-
62
45
  end
@@ -26,5 +26,4 @@ class Clearance::UsersController < ApplicationController
26
26
  def url_after_create
27
27
  new_session_url
28
28
  end
29
-
30
29
  end
@@ -2,24 +2,24 @@ Feature: Password reset
2
2
  In order to sign in even if user forgot their password
3
3
  A user
4
4
  Should be able to reset it
5
-
5
+
6
6
  Scenario: User is not signed up
7
7
  Given no user exists with an email of "email@person.com"
8
8
  When I request password reset link to be sent to "email@person.com"
9
9
  Then I should see "Unknown email"
10
-
10
+
11
11
  Scenario: User is signed up and requests password reset
12
12
  Given I signed up with "email@person.com/password"
13
13
  When I request password reset link to be sent to "email@person.com"
14
14
  Then I should see "instructions for changing your password"
15
15
  And a password reset message should be sent to "email@person.com"
16
-
16
+
17
17
  Scenario: User is signed up updated his password and types wrong confirmation
18
18
  Given I signed up with "email@person.com/password"
19
19
  When I follow the password reset link sent to "email@person.com"
20
20
  And I update my password with "newpassword/wrongconfirmation"
21
21
  Then I should see error messages
22
- And I should not be signed in
22
+ And I should be signed out
23
23
 
24
24
  Scenario: User is signed up and updates his password
25
25
  Given I signed up with "email@person.com/password"
@@ -27,5 +27,7 @@ Feature: Password reset
27
27
  And I update my password with "newpassword/newpassword"
28
28
  Then I should be signed in
29
29
  When I sign out
30
+ Then I should be signed out
30
31
  And I sign in as "email@person.com/newpassword"
31
- Then I should be signed in
32
+ Then I should be signed in
33
+
@@ -8,34 +8,35 @@ Feature: Sign in
8
8
  When I go to the sign in page
9
9
  And I sign in as "email@person.com/password"
10
10
  Then I should see "Bad email or password"
11
- And I should not be signed in
11
+ And I should be signed out
12
12
 
13
13
  Scenario: User is not confirmed
14
14
  Given I signed up with "email@person.com/password"
15
15
  When I go to the sign in page
16
16
  And I sign in as "email@person.com/password"
17
17
  Then I should see "User has not confirmed email"
18
- And I should not be signed in
18
+ And I should be signed out
19
19
 
20
20
  Scenario: User enters wrong password
21
21
  Given I am signed up and confirmed as "email@person.com/password"
22
22
  When I go to the sign in page
23
23
  And I sign in as "email@person.com/wrongpassword"
24
24
  Then I should see "Bad email or password"
25
- And I should not be signed in
25
+ And I should be signed out
26
26
 
27
27
  Scenario: User signs in successfully
28
28
  Given I am signed up and confirmed as "email@person.com/password"
29
29
  When I go to the sign in page
30
30
  And I sign in as "email@person.com/password"
31
- Then I should see "Signed in successfully"
31
+ Then I should see "Signed in"
32
32
  And I should be signed in
33
33
 
34
34
  Scenario: User signs in and checks "remember me"
35
35
  Given I am signed up and confirmed as "email@person.com/password"
36
36
  When I go to the sign in page
37
37
  And I sign in with "remember me" as "email@person.com/password"
38
- Then I should see "Signed in successfully"
39
- And I should be signed in
38
+ Then I should see "Signed in"
39
+ And I should be signed in
40
40
  When I return next time
41
41
  Then I should be signed in
42
+
@@ -2,21 +2,22 @@ Feature: Sign out
2
2
  To protect my account from unauthorized access
3
3
  A signed in user
4
4
  Should be able to sign out
5
-
5
+
6
6
  Scenario: User signs out
7
7
  Given I am signed up and confirmed as "email@person.com/password"
8
8
  When I sign in as "email@person.com/password"
9
9
  Then I should be signed in
10
10
  And I sign out
11
- Then I should see "You have been signed out"
12
- And I should not be signed in
13
-
11
+ Then I should see "Signed out"
12
+ And I should be signed out
13
+
14
14
  Scenario: User who was remembered signs out
15
15
  Given I am signed up and confirmed as "email@person.com/password"
16
16
  When I sign in with "remember me" as "email@person.com/password"
17
17
  Then I should be signed in
18
18
  And I sign out
19
- Then I should see "You have been signed out"
20
- And I should not be signed in
19
+ Then I should see "Signed out"
20
+ And I should be signed out
21
21
  When I return next time
22
- Then I should not be signed in
22
+ Then I should be signed out
23
+
@@ -2,7 +2,7 @@ Feature: Sign up
2
2
  In order to get access to protected sections of the site
3
3
  A user
4
4
  Should be able to sign up
5
-
5
+
6
6
  Scenario: User signs up with invalid data
7
7
  When I go to the sign up page
8
8
  And I fill in "Email" with "invalidemail"
@@ -10,7 +10,7 @@ Feature: Sign up
10
10
  And I fill in "Confirm password" with ""
11
11
  And I press "Sign Up"
12
12
  Then I should see error messages
13
-
13
+
14
14
  Scenario: User signs up with valid data
15
15
  When I go to the sign up page
16
16
  And I fill in "Email" with "email@person.com"
@@ -19,12 +19,10 @@ Feature: Sign up
19
19
  And I press "Sign Up"
20
20
  Then I should see "instructions for confirming"
21
21
  And a confirmation message should be sent to "email@person.com"
22
-
22
+
23
23
  Scenario: User confirms his account
24
24
  Given I signed up with "email@person.com/password"
25
25
  When I follow the confirmation link sent to "email@person.com"
26
26
  Then I should see "Confirmed email and signed in"
27
- And I should be signed in
28
-
29
-
30
-
27
+ And I should be signed in
28
+
@@ -11,15 +11,15 @@ Given /^no user exists with an email of "(.*)"$/ do |email|
11
11
  end
12
12
 
13
13
  Given /^I signed up with "(.*)\/(.*)"$/ do |email, password|
14
- user = Factory :user,
15
- :email => email,
14
+ user = Factory :user,
15
+ :email => email,
16
16
  :password => password,
17
17
  :password_confirmation => password
18
18
  end
19
19
 
20
20
  Given /^I am signed up and confirmed as "(.*)\/(.*)"$/ do |email, password|
21
21
  user = Factory :email_confirmed_user,
22
- :email => email,
22
+ :email => email,
23
23
  :password => password,
24
24
  :password_confirmation => password
25
25
  end
@@ -27,15 +27,16 @@ end
27
27
  # Session
28
28
 
29
29
  Then /^I should be signed in$/ do
30
- assert_not_nil request.session[:user_id]
30
+ assert controller.signed_in?
31
31
  end
32
32
 
33
- Then /^I should not be signed in$/ do
34
- assert_nil request.session[:user_id]
33
+ Then /^I should be signed out$/ do
34
+ assert ! controller.signed_in?
35
35
  end
36
36
 
37
37
  When /^session is cleared$/ do
38
- request.session[:user_id] = nil
38
+ request.reset_session
39
+ controller.instance_variable_set(:@_current_user, nil)
39
40
  end
40
41
 
41
42
  # Emails
@@ -77,7 +78,6 @@ Then /^I should be forbidden$/ do
77
78
  assert_response :forbidden
78
79
  end
79
80
 
80
-
81
81
  # Actions
82
82
 
83
83
  When /^I sign in( with "remember me")? as "(.*)\/(.*)"$/ do |remember, email, password|
@@ -51,6 +51,22 @@ module Clearance
51
51
  end
52
52
  end
53
53
 
54
+ def remember?
55
+ params[:session] && params[:session][:remember_me] == "1"
56
+ end
57
+
58
+ def remember(user)
59
+ user.remember_me!
60
+ cookies[:remember_token] = { :value => user.token,
61
+ :expires => user.token_expires_at }
62
+ end
63
+
64
+ def forget(user)
65
+ user.forget_me! if user
66
+ cookies.delete :remember_token
67
+ reset_session
68
+ end
69
+
54
70
  def redirect_back_or(default)
55
71
  session[:return_to] ||= params[:return_to]
56
72
  if session[:return_to]
data/lib/clearance.rb CHANGED
@@ -6,10 +6,14 @@ require 'clearance/user'
6
6
 
7
7
  class ActionController::Routing::RouteSet
8
8
  def load_routes_with_clearance!
9
- clearance_routes = File.join(File.dirname(__FILE__), *%w[.. config clearance_routes.rb])
10
- add_configuration_file(clearance_routes) unless configuration_files.include? clearance_routes
9
+ lib_path = File.dirname(__FILE__)
10
+ clearance_routes = File.join(lib_path, *%w[.. config clearance_routes.rb])
11
+ unless configuration_files.include?(clearance_routes)
12
+ add_configuration_file(clearance_routes)
13
+ end
11
14
  load_routes_without_clearance!
12
15
  end
13
16
 
14
17
  alias_method_chain :load_routes!, :clearance
15
18
  end
19
+
@@ -14,6 +14,7 @@ module Clearance
14
14
  end
15
15
 
16
16
  def should_be_signed_in_and_email_confirmed_as(&block)
17
+ warn "[DEPRECATION] questionable usefulness"
17
18
  should_be_signed_in_as &block
18
19
 
19
20
  should "have confirmed email" do
@@ -31,10 +32,8 @@ module Clearance
31
32
  end
32
33
  end
33
34
 
34
- # Examples:
35
- # should_deny_access_on :get, :index, :flash => /not authorized/i
36
- # should_deny_access_on :get, :show, :id => '1'
37
35
  def should_deny_access_on(http_method, action, opts = {})
36
+ warn "[DEPRECATION] use a setup & should_deny_access(:flash => ?)"
38
37
  flash_message = opts.delete(:flash)
39
38
  context "on #{http_method} to #{action}" do
40
39
  setup do
@@ -68,6 +67,7 @@ module Clearance
68
67
  # CONTEXTS
69
68
 
70
69
  def signed_in_user_context(&blk)
70
+ warn "[DEPRECATION] creates a Mystery Guest, causes Obscure Test"
71
71
  context "A signed in user" do
72
72
  setup do
73
73
  @user = Factory(:user)
@@ -79,6 +79,7 @@ module Clearance
79
79
  end
80
80
 
81
81
  def public_context(&blk)
82
+ warn "[DEPRECATION] common case is no-op. call sign_out otherwise"
82
83
  context "The public" do
83
84
  setup { sign_out }
84
85
  merge_block(&blk)
@@ -88,6 +89,7 @@ module Clearance
88
89
  # CREATING USERS
89
90
 
90
91
  def should_create_user_successfully
92
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
91
93
  should_assign_to :user
92
94
  should_change 'User.count', :by => 1
93
95
 
@@ -132,6 +134,7 @@ module Clearance
132
134
  # VALIDATIONS
133
135
 
134
136
  def should_validate_confirmation_of(attribute, opts = {})
137
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
135
138
  raise ArgumentError if opts[:factory].nil?
136
139
 
137
140
  context "on save" do
@@ -141,6 +144,7 @@ module Clearance
141
144
  end
142
145
 
143
146
  def should_validate_confirmation_is_not_blank(factory, attribute, opts = {})
147
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
144
148
  should "validate #{attribute}_confirmation is not blank" do
145
149
  model = Factory.build(factory, blank_confirmation_options(attribute))
146
150
  model.save
@@ -150,6 +154,7 @@ module Clearance
150
154
  end
151
155
 
152
156
  def should_validate_confirmation_is_not_bad(factory, attribute, opts = {})
157
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
153
158
  should "validate #{attribute}_confirmation is different than #{attribute}" do
154
159
  model = Factory.build(factory, bad_confirmation_options(attribute))
155
160
  model.save
@@ -161,6 +166,7 @@ module Clearance
161
166
  # FORMS
162
167
 
163
168
  def should_display_a_password_update_form
169
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
164
170
  should "have a form for the user's token, password, and password confirm" do
165
171
  update_path = ERB::Util.h(
166
172
  user_password_path(@user, :token => @user.token)
@@ -175,6 +181,7 @@ module Clearance
175
181
  end
176
182
 
177
183
  def should_display_a_sign_up_form
184
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
178
185
  should "display a form to sign up" do
179
186
  assert_select "form[action=#{users_path}][method=post]",
180
187
  true, "There must be a form to sign up" do
@@ -191,6 +198,7 @@ module Clearance
191
198
  end
192
199
 
193
200
  def should_display_a_sign_in_form
201
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
194
202
  should 'display a "sign in" form' do
195
203
  assert_select "form[action=#{session_path}][method=post]",
196
204
  true, "There must be a form to sign in" do
@@ -211,30 +219,35 @@ end
211
219
  module Clearance
212
220
  module Shoulda
213
221
  module Helpers
214
- def sign_in_as(user = nil)
215
- unless user
216
- user = Factory(:user)
217
- user.confirm_email!
218
- end
219
- @request.session[:user_id] = user.id
222
+ def sign_in_as(user)
223
+ @controller.class_eval { attr_accessor :current_user }
224
+ @controller.current_user = user
220
225
  return user
221
226
  end
222
227
 
228
+ def sign_in
229
+ sign_in_as Factory(:email_confirmed_user)
230
+ end
231
+
223
232
  def sign_out
224
- @request.session[:user_id] = nil
233
+ @controller.class_eval { attr_accessor :current_user }
234
+ @controller.current_user = nil
225
235
  end
226
236
 
227
237
  def blank_confirmation_options(attribute)
238
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
228
239
  opts = { attribute => attribute.to_s }
229
240
  opts.merge("#{attribute}_confirmation".to_sym => "")
230
241
  end
231
242
 
232
243
  def bad_confirmation_options(attribute)
244
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
233
245
  opts = { attribute => attribute.to_s }
234
246
  opts.merge("#{attribute}_confirmation".to_sym => "not_#{attribute}")
235
247
  end
236
248
 
237
249
  def assert_confirmation_error(model, attribute, message = "confirmation error")
250
+ warn "[DEPRECATION] not meant to be public, no longer used internally"
238
251
  assert model.errors.on(attribute).include?("doesn't match confirmation"),
239
252
  message
240
253
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thoughtbot-clearance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Croak
@@ -24,7 +24,7 @@ autorequire:
24
24
  bindir: bin
25
25
  cert_chain: []
26
26
 
27
- date: 2009-04-22 21:00:00 -07:00
27
+ date: 2009-05-11 21:00:00 -07:00
28
28
  default_executable:
29
29
  dependencies: []
30
30