thoughtbot-clearance 0.2.9 → 0.3.0

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/TODO.textile CHANGED
@@ -1,15 +1,14 @@
1
1
  (highest priority first)
2
2
 
3
- # change url_after_creates to be a class method or use after_filter
4
3
  # activation code (like restful-auth) instead of salt?
5
4
  # remove dependency on root_url?
6
- # users#show doesn't exist, but confirmations create redirects there
7
5
  # should_have_form should be pulled into shoulda
8
6
  # generator should print out instructions to include modules existing files
9
7
  # check to make sure attr_accessible doesn't override and w/ attr_protected
10
8
  # move shoulda macros in test_helper to shoulda_macros folder
11
9
  # add shoulda and factory girl dependencies to gemspec
12
10
  # refactor Mailer default_url_options[:host] to something cleaner
11
+ # application controller uses protected, all other controllers use private
13
12
 
14
13
  ideas to steal from merb-auth:
15
14
 
@@ -23,7 +23,7 @@ module Clearance
23
23
  @user = User.find_by_id_and_salt(params[:user_id], params[:salt])
24
24
  @user.confirm!
25
25
  session[:user_id] = @user.id
26
- redirect_to user_path(@user)
26
+ redirect_to url_after_create
27
27
  end
28
28
  end
29
29
 
@@ -34,6 +34,10 @@ module Clearance
34
34
  render :nothing => true, :status => :not_found
35
35
  end
36
36
  end
37
+
38
+ def url_after_create
39
+ root_url
40
+ end
37
41
  end
38
42
 
39
43
  end
@@ -7,7 +7,9 @@ module Clearance
7
7
  base.class_eval do
8
8
  before_filter :existing_user?, :only => [:edit, :update]
9
9
  filter_parameter_logging :password, :password_confirmation
10
+
10
11
  include InstanceMethods
12
+
11
13
  private
12
14
  include PrivateInstanceMethods
13
15
  end
@@ -24,7 +26,7 @@ module Clearance
24
26
  render :action => :new
25
27
  else
26
28
  UserMailer.deliver_change_password user
27
- redirect_to new_session_url
29
+ redirect_to url_after_create
28
30
  end
29
31
  end
30
32
 
@@ -53,6 +55,10 @@ module Clearance
53
55
  render :nothing => true, :status => :not_found
54
56
  end
55
57
  end
58
+
59
+ def url_after_create
60
+ new_session_url
61
+ end
56
62
  end
57
63
 
58
64
  end
@@ -11,8 +11,8 @@ module Clearance
11
11
 
12
12
  include InstanceMethods
13
13
 
14
- protected
15
- include ProtectedInstanceMethods
14
+ private
15
+ include PrivateInstanceMethods
16
16
  end
17
17
  end
18
18
 
@@ -30,7 +30,7 @@ module Clearance
30
30
  end
31
31
  end
32
32
 
33
- module ProtectedInstanceMethods
33
+ module PrivateInstanceMethods
34
34
  def login_via_password(email, password, remember_me)
35
35
  user = user_model.authenticate(email, password)
36
36
  if login(user)
@@ -56,7 +56,7 @@ module Clearance
56
56
  assert_equal @user.id, session[:user_id]
57
57
  end
58
58
 
59
- should_redirect_to "user_path(@user)"
59
+ should_redirect_to "@controller.send(:url_after_create)"
60
60
  end
61
61
 
62
62
  context "without the User with the given id's salt" do
@@ -28,10 +28,10 @@ module Clearance
28
28
  end
29
29
 
30
30
  should 'send an email to the user to edit their password' do
31
- assert @email.subject =~ /request to change your password/i
31
+ assert @email.subject =~ /change your password/i
32
32
  end
33
33
 
34
- should_redirect_to "new_session_path"
34
+ should_redirect_to "@controller.send(:url_after_create)"
35
35
  end
36
36
 
37
37
  context 'with a non-existing email address' do
@@ -86,9 +86,7 @@ module Clearance
86
86
 
87
87
  context "with an existing user's id but not password" do
88
88
  setup do
89
- get(:edit,
90
- :user_id => @user.id,
91
- :password => '')
89
+ get :edit, :user_id => @user.id, :password => ''
92
90
  end
93
91
 
94
92
  should_respond_with :not_found
@@ -102,9 +100,7 @@ module Clearance
102
100
  context 'A PUT to #update' do
103
101
  context "with an existing user's id but not password" do
104
102
  setup do
105
- put(:update,
106
- :user_id => @user.id,
107
- :password => '')
103
+ put :update, :user_id => @user.id, :password => ''
108
104
  end
109
105
 
110
106
  should "not update the user's password" do
@@ -51,7 +51,7 @@ module Clearance
51
51
  end
52
52
 
53
53
  should_set_the_flash_to /success/i
54
- should_redirect_to '@controller.send(:url_after_create)'
54
+ should_redirect_to "@controller.send(:url_after_create)"
55
55
  should_return_from_session :user_id, "@user.id"
56
56
 
57
57
  should 'set the cookie' do
@@ -11,8 +11,8 @@ module Clearance
11
11
  @email = UserMailer.create_change_password @user
12
12
  end
13
13
 
14
- should "set its from address to 'donotreply@example.com'" do
15
- assert_equal 'donotreply@example.com', @email.from[0]
14
+ should "set its from address to DO_NOT_REPLY" do
15
+ assert_equal DO_NOT_REPLY, @email.from[0]
16
16
  end
17
17
 
18
18
  should "contain a link to edit the user's password" do
@@ -25,8 +25,33 @@ module Clearance
25
25
  assert_equal [@user.email], @email.to
26
26
  end
27
27
 
28
- should "have a subject of '[YOUR APP] Request to change your password'" do
29
- assert_equal "[YOUR APP] Request to change your password", @email.subject
28
+ should "have a subject of '[PROJECT_NAME] Change your password'" do
29
+ assert_equal @email.subject, "[#{PROJECT_NAME.humanize}] Change your password"
30
+ end
31
+ end
32
+
33
+ context "A confirmation email" do
34
+ setup do
35
+ @user = Factory :user
36
+ @email = UserMailer.create_confirmation @user
37
+ end
38
+
39
+ should 'set its recipient to the given user' do
40
+ assert_equal @user.email, @email.to[0]
41
+ end
42
+
43
+ should 'set its subject' do
44
+ assert_equal "[#{PROJECT_NAME.humanize}] Email confirmation", @email.subject
45
+ end
46
+
47
+ should 'set its from address to DO_NOT_REPLY' do
48
+ assert_equal DO_NOT_REPLY, @email.from[0]
49
+ end
50
+
51
+ should "contain a link to confirm the user's account" do
52
+ host = ActionMailer::Base.default_url_options[:host]
53
+ regexp = %r{http://#{host}/users/#{@user.id}/confirmation/new\?salt=#{@user.salt}}
54
+ assert_match regexp, @email.body
30
55
  end
31
56
  end
32
57
  end
@@ -1,7 +1,7 @@
1
- module Clearance
2
- module Version
3
- MAJOR = 0
4
- MINOR = 2
5
- PATCH = 9
6
- end
1
+ module Clearance
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 3
5
+ PATCH = 0
7
6
  end
7
+ end
@@ -13,5 +13,4 @@ Rails::Initializer.run do |config|
13
13
  config.gem 'thoughtbot-shoulda', :lib => 'shoulda', :source => 'http://gems.github.com'
14
14
  end
15
15
 
16
-
17
-
16
+ DO_NOT_REPLY = "donotreply@example.com"
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.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot, inc.