thoughtbot-clearance 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -35,7 +35,7 @@ task :default => 'test:all'
35
35
 
36
36
  gem_spec = Gem::Specification.new do |gem_spec|
37
37
  gem_spec.name = "clearance"
38
- gem_spec.version = "0.4.2"
38
+ gem_spec.version = "0.4.3"
39
39
  gem_spec.summary = "Rails authentication for developers who write tests."
40
40
  gem_spec.email = "support@thoughtbot.com"
41
41
  gem_spec.homepage = "http://github.com/thoughtbot/clearance"
@@ -34,7 +34,7 @@ module Clearance
34
34
 
35
35
  def user_from_cookie
36
36
  if cookies[:remember_token]
37
- user = User.find_by_remember_token(cookies[:remember_token])
37
+ user = User.find_by_token(cookies[:remember_token])
38
38
  user && user.remember? ? user : nil
39
39
  end
40
40
  end
@@ -6,6 +6,7 @@ module Clearance
6
6
  def self.included(controller)
7
7
  controller.class_eval do
8
8
 
9
+ before_filter :email_confirmed_user?, :only => :new
9
10
  before_filter :existing_user?, :only => :new
10
11
  filter_parameter_logging :token
11
12
 
@@ -22,6 +23,15 @@ module Clearance
22
23
 
23
24
  private
24
25
 
26
+ def email_confirmed_user?
27
+ @user = User.find_by_id(params[:user_id])
28
+ if @user.nil?
29
+ render :nothing => true, :status => :not_found
30
+ elsif @user.email_confirmed?
31
+ redirect_to new_session_url
32
+ end
33
+ end
34
+
25
35
  def existing_user?
26
36
  @user = User.find_by_id_and_token(params[:user_id], params[:token])
27
37
  if @user.nil?
@@ -22,7 +22,8 @@ module Clearance
22
22
  flash[:notice] = "Signed in successfully"
23
23
  redirect_back_or url_after_create
24
24
  else
25
- deny_access("User has not confirmed email.")
25
+ ClearanceMailer.deliver_confirmation(@user)
26
+ deny_access("User has not confirmed email. Confirmation email will be resent.")
26
27
  end
27
28
  end
28
29
  end
@@ -5,12 +5,12 @@ module Clearance
5
5
 
6
6
  def self.included(controller_test)
7
7
  controller_test.class_eval do
8
-
8
+
9
9
  should_filter_params :token
10
-
10
+
11
11
  context "Given a user whose email has not been confirmed" do
12
12
  setup { @user = Factory(:registered_user) }
13
-
13
+
14
14
  context "on GET to #new with correct id and token" do
15
15
  setup do
16
16
  get :new, :user_id => @user.to_param, :token => @user.token
@@ -21,7 +21,32 @@ module Clearance
21
21
  should_be_signed_in_and_email_confirmed_as { @user }
22
22
  should_redirect_to_url_after_create
23
23
  end
24
-
24
+
25
+ context "on GET to #new with incorrect token" do
26
+ setup do
27
+ token = ""
28
+ assert_not_equal token, @user.token
29
+
30
+ get :new, :user_id => @user.to_param, :token => token
31
+ end
32
+
33
+ should_respond_with :not_found
34
+ should_render_nothing
35
+ end
36
+ end
37
+
38
+ context "Given a user whose email has been confirmed" do
39
+ setup { @user = Factory(:email_confirmed_user) }
40
+
41
+ context "on GET to #new with correct id and token" do
42
+ setup do
43
+ get :new, :user_id => @user.to_param, :token => @user.token
44
+ end
45
+
46
+ should_not_be_signed_in
47
+ should_redirect_to 'new_session_url'
48
+ end
49
+
25
50
  context "on GET to #new with incorrect token" do
26
51
  setup do
27
52
  token = ""
@@ -30,11 +55,23 @@ module Clearance
30
55
  get :new, :user_id => @user.to_param, :token => token
31
56
  end
32
57
 
58
+ should_not_be_signed_in
59
+ should_redirect_to 'new_session_url'
60
+ end
61
+ end
62
+
63
+ context "Given no user records" do
64
+ setup { assert_equal 0, User.count }
65
+ context "on GET to #new with nonexistent id and token" do
66
+ setup do
67
+ get :new, :user_id => '123', :token => '123'
68
+ end
69
+
33
70
  should_respond_with :not_found
34
71
  should_render_nothing
35
72
  end
36
73
  end
37
-
74
+
38
75
  end
39
76
  end
40
77
 
@@ -29,7 +29,13 @@ module Clearance
29
29
  :password => @user.password }
30
30
  end
31
31
 
32
- should_deny_access(:flash => /confirm/i)
32
+ should_deny_access(:flash => /User has not confirmed email. Confirmation email will be resent./i)
33
+
34
+ should "send the confirmation email" do
35
+ assert_not_nil email = ActionMailer::Base.deliveries[0]
36
+ assert_match /account confirmation/i, email.subject
37
+ end
38
+
33
39
  end
34
40
  end
35
41
 
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.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot, inc.
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2009-01-27 21:00:00 -08:00
18
+ date: 2009-01-29 21:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21