thoughtbot-clearance 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/README.textile +8 -16
  2. data/Rakefile +12 -10
  3. data/TODO.textile +7 -4
  4. data/generators/clearance/templates/app/controllers/application.rb +1 -1
  5. data/generators/clearance/templates/app/controllers/confirmations_controller.rb +1 -1
  6. data/generators/clearance/templates/app/controllers/passwords_controller.rb +1 -1
  7. data/generators/clearance/templates/app/controllers/sessions_controller.rb +1 -1
  8. data/generators/clearance/templates/app/controllers/users_controller.rb +1 -1
  9. data/generators/clearance/templates/app/models/user.rb +1 -1
  10. data/generators/clearance/templates/app/models/user_mailer.rb +1 -1
  11. data/generators/clearance/templates/test/functional/confirmations_controller_test.rb +1 -1
  12. data/generators/clearance/templates/test/functional/passwords_controller_test.rb +1 -1
  13. data/generators/clearance/templates/test/functional/sessions_controller_test.rb +1 -1
  14. data/generators/clearance/templates/test/functional/users_controller_test.rb +1 -1
  15. data/generators/clearance/templates/test/unit/user_mailer_test.rb +1 -1
  16. data/generators/clearance/templates/test/unit/user_test.rb +1 -1
  17. data/lib/clearance.rb +6 -6
  18. data/lib/clearance/app/controllers/application_controller.rb +58 -54
  19. data/lib/clearance/app/controllers/confirmations_controller.rb +30 -26
  20. data/lib/clearance/app/controllers/passwords_controller.rb +48 -44
  21. data/lib/clearance/app/controllers/sessions_controller.rb +61 -56
  22. data/lib/clearance/app/controllers/users_controller.rb +32 -28
  23. data/lib/clearance/app/models/user.rb +58 -56
  24. data/lib/clearance/app/models/user_mailer.rb +21 -18
  25. data/lib/clearance/test/test_helper.rb +66 -64
  26. data/lib/clearance/version.rb +2 -2
  27. data/test/rails_root/app/controllers/application.rb +1 -1
  28. data/test/rails_root/app/controllers/confirmations_controller.rb +1 -1
  29. data/test/rails_root/app/controllers/passwords_controller.rb +1 -1
  30. data/test/rails_root/app/controllers/sessions_controller.rb +1 -1
  31. data/test/rails_root/app/controllers/users_controller.rb +1 -1
  32. data/test/rails_root/app/models/user.rb +1 -1
  33. data/test/rails_root/app/models/user_mailer.rb +1 -1
  34. data/test/rails_root/test/functional/confirmations_controller_test.rb +1 -1
  35. data/test/rails_root/test/functional/passwords_controller_test.rb +1 -1
  36. data/test/rails_root/test/functional/sessions_controller_test.rb +1 -1
  37. data/test/rails_root/test/functional/users_controller_test.rb +1 -1
  38. data/test/rails_root/test/test_helper.rb +1 -1
  39. data/test/rails_root/test/unit/user_mailer_test.rb +1 -1
  40. data/test/rails_root/test/unit/user_test.rb +1 -1
  41. metadata +34 -10
  42. data/lib/clearance/test/functionals/confirmations_controller_test.rb +0 -81
  43. data/lib/clearance/test/functionals/passwords_controller_test.rb +0 -188
  44. data/lib/clearance/test/functionals/sessions_controller_test.rb +0 -91
  45. data/lib/clearance/test/functionals/users_controller_test.rb +0 -60
  46. data/lib/clearance/test/units/user_mailer_test.rb +0 -34
  47. data/lib/clearance/test/units/user_test.rb +0 -203
@@ -1,91 +0,0 @@
1
- module Clearance
2
- module SessionsControllerTest
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- context "Given a user" do
7
- setup { @user = Factory :user }
8
-
9
- should_filter_params :password
10
-
11
- context "on GET to /sessions/new" do
12
- setup { get :new }
13
-
14
- should_respond_with :success
15
- should_render_template :new
16
- should_not_set_the_flash
17
- should_have_form :action => "session_path",
18
- :fields => { "session[email]" => :text,
19
- "session[password]" => :password,
20
- "session[remember_me]" => :checkbox }
21
- end
22
-
23
- context "a POST to #create with good credentials" do
24
- setup do
25
- post :create, :session => { :email => @user.email, :password => @user.password }
26
- end
27
-
28
- should_set_the_flash_to /success/i
29
- should_redirect_to '@controller.send(:url_after_create)'
30
- #should_return_from_session(:user_id, '@user.id')
31
- should "return the correct value from the session for key :user_id" do
32
- instantiate_variables_from_assigns do
33
- expected_value = @user.id
34
- assert_equal expected_value, session[:user_id], "Expected #{expected_value.inspect} but was #{session[:user_id]}"
35
- end
36
- end
37
- end
38
-
39
- context "a POST to #create with bad credentials" do
40
- setup do
41
- post :create, :session => { :email => @user.email, :password => "bad value" }
42
- end
43
-
44
- should_set_the_flash_to /bad/i
45
- should_render_template :new
46
- #should_return_from_session(:user_id, 'nil')
47
- should "return nil from the session for key :user_id" do
48
- instantiate_variables_from_assigns do
49
- assert_nil session[:user_id], "Expected nil but was #{session[:user_id]}"
50
- end
51
- end
52
- end
53
-
54
- # TODO: two tests for remember me - success and failure
55
- end
56
-
57
- public_context do
58
- context "logging out again" do
59
- setup { delete :destroy }
60
- should_redirect_to '@controller.send(:url_after_destroy)'
61
- end
62
- end
63
-
64
- logged_in_user_context do
65
- context "a DELETE to #destroy without a cookie" do
66
- setup { delete :destroy }
67
-
68
- should_set_the_flash_to(/logged out/i)
69
- should_redirect_to '@controller.send(:url_after_destroy)'
70
- end
71
-
72
- context 'a DELETE to #destroy with a cookie' do
73
- setup do
74
- cookies['auth_token'] = CGI::Cookie.new 'token', 'value'
75
- delete :destroy
76
- end
77
-
78
- should 'delete the cookie' do
79
- assert cookies['auth_token'].empty?
80
- end
81
-
82
- should 'delete the remember me token in users table' do
83
- assert_nil @user.reload.remember_token
84
- assert_nil @user.reload.remember_token_expires_at
85
- end
86
- end
87
- end
88
- end
89
- end
90
- end
91
- end
@@ -1,60 +0,0 @@
1
- module Clearance
2
- module UsersControllerTest
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- public_context do
7
-
8
- context "on GET to /users/new" do
9
- setup { get :new }
10
- should_respond_with :success
11
- should_render_template :new
12
- should_not_set_the_flash
13
- should_have_form :action => "users_path",
14
- :method => :post,
15
- :fields => { :email => :text,
16
- :password => :password,
17
- :password_confirmation => :password }
18
-
19
- context "with params" do
20
- setup do
21
- @email = 'a@example.com'
22
- get :new, :user => {:email => @email}
23
- end
24
-
25
- should_assign_to :user
26
- should "set the @user's params" do
27
- assert_equal @email, assigns(:user).email
28
- end
29
- end
30
- end
31
-
32
- context "on POST to /users" do
33
- setup do
34
- post :create, :user => {
35
- :email => Factory.next(:email),
36
- :password => 'skerit',
37
- :password_confirmation => 'skerit'
38
- }
39
- end
40
-
41
- should_set_the_flash_to /confirm/i
42
- should_redirect_to "@controller.send(:url_after_create)"
43
- should_assign_to :user
44
- should_change 'User.count', :by => 1
45
- end
46
-
47
- end
48
-
49
- logged_in_user_context do
50
-
51
- should_deny_access_on "get :new"
52
- should_deny_access_on "post :create, :user => {}"
53
- should_filter_params :password
54
-
55
- end
56
- end
57
- end
58
-
59
- end
60
- end
@@ -1,34 +0,0 @@
1
- module Clearance
2
- module UserMailerTest
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- context "A change password email" do
7
- setup do
8
- @user = Factory :user
9
- @email = UserMailer.create_change_password @user
10
- end
11
-
12
- should "set its from address to 'donotreply@example.com'" do
13
- assert_equal 'donotreply@example.com', @email.from[0]
14
- end
15
-
16
- should "contain a link to edit the user's password" do
17
- host = ActionMailer::Base.default_url_options[:host]
18
- regexp = %r{http://#{host}/users/#{@user.id}/password/edit\?email=#{@user.email.gsub("@", "%40")}&password=#{@user.crypted_password}}
19
- assert_match regexp, @email.body
20
- end
21
-
22
- should "be sent to the user" do
23
- assert_equal [@user.email], @email.to
24
- end
25
-
26
- should "have a subject of '[YOUR APP] Request to change your password'" do
27
- assert_equal "[YOUR APP] Request to change your password", @email.subject
28
- end
29
- end
30
- end
31
- end
32
-
33
- end
34
- end
@@ -1,203 +0,0 @@
1
- module Clearance
2
- module UserTest
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- should_require_attributes :email, :password
7
-
8
- should "require password validation on create" do
9
- user = Factory.build(:user, :password => 'blah', :password_confirmation => 'boogidy')
10
- assert !user.save
11
- assert_match(/confirmation/i, user.errors.on(:password))
12
- end
13
-
14
- should "create a crypted_password on save" do
15
- assert_not_nil Factory(:user, :crypted_password => nil).crypted_password
16
- end
17
-
18
- context 'updating a password' do
19
- setup do
20
- @user = Factory(:user)
21
- assert_not_nil @user.crypted_password
22
- @crypt = @user.crypted_password
23
- assert_not_nil @user.salt
24
- @salt = @user.salt
25
- @user.password = 'a_new_password'
26
- @user.password_confirmation = 'a_new_password'
27
- assert @user.save
28
- end
29
-
30
- should 'update a crypted_password' do
31
- @user.reload
32
- assert @user.crypted_password != @crypt
33
- end
34
- end
35
-
36
- context 'A user' do
37
- setup do
38
- @salt = 'salt'
39
- User.any_instance.stubs(:initialize_salt)
40
- @user = Factory :user, :salt => @salt
41
- @password = @user.password
42
- end
43
-
44
- should "require password validation on update" do
45
- @user.update_attributes(:password => "blah", :password_confirmation => "boogidy")
46
- assert !@user.save
47
- assert_match(/confirmation/i, @user.errors.on(:password))
48
- end
49
-
50
- should_require_unique_attributes :email
51
-
52
- context 'authenticating a user' do
53
- context 'with good credentials' do
54
- setup do
55
- @result = User.authenticate @user.email, @password
56
- end
57
-
58
- should 'return true' do
59
- assert @result
60
- end
61
- end
62
-
63
- context 'with bad credentials' do
64
- setup do
65
- @result = User.authenticate @user.email, 'horribly_wrong_password'
66
- end
67
-
68
- should 'return false' do
69
- assert !@result
70
- end
71
- end
72
- end
73
-
74
- context 'authenticated?' do
75
- context 'with good credentials' do
76
- setup do
77
- @result = @user.authenticated? @password
78
- end
79
-
80
- should 'return true' do
81
- assert @result
82
- end
83
- end
84
-
85
- context 'with bad credentials' do
86
- setup do
87
- @result = @user.authenticated? 'horribly_wrong_password'
88
- end
89
-
90
- should 'return false' do
91
- assert !@result
92
- end
93
- end
94
- end
95
-
96
- context 'encrypt' do
97
- setup do
98
- @crypted = @user.encrypt(@password)
99
- @expected = Digest::SHA1.hexdigest("--#{@salt}--#{@password}--")
100
- end
101
-
102
- should 'create a Hash using SHA1 encryption' do
103
- assert_equal @expected, @crypted
104
- assert_not_equal @password, @crypted
105
- end
106
- end
107
-
108
- context 'remember_me!' do
109
- setup do
110
- assert_nil @user.remember_token
111
- assert_nil @user.remember_token_expires_at
112
- @user.remember_me!
113
- end
114
-
115
- should 'set the remember token and expiration date' do
116
- assert_not_nil @user.remember_token
117
- assert_not_nil @user.remember_token_expires_at
118
- end
119
-
120
- should 'remember_token?' do
121
- assert @user.remember_token?
122
- end
123
-
124
- context 'forget_me!' do
125
- setup do
126
- @user.forget_me!
127
- end
128
-
129
- should 'unset the remember token and expiration date' do
130
- assert_nil @user.remember_token
131
- assert_nil @user.remember_token_expires_at
132
- end
133
-
134
- should 'not remember_token?' do
135
- assert ! @user.remember_token?
136
- end
137
- end
138
- end
139
-
140
- context 'remember_token?' do
141
- context 'when token expires in the future' do
142
- setup do
143
- @user.update_attribute :remember_token_expires_at, 2.weeks.from_now.utc
144
- end
145
-
146
- should 'be true' do
147
- assert @user.remember_token?
148
- end
149
- end
150
-
151
- context 'when token expired' do
152
- setup do
153
- @user.update_attribute :remember_token_expires_at, 2.weeks.ago.utc
154
- end
155
-
156
- should 'be false' do
157
- assert ! @user.remember_token?
158
- end
159
- end
160
- end
161
-
162
- context "User.authenticate with a valid email and password" do
163
- setup do
164
- @found_user = User.authenticate @user.email, @user.password
165
- end
166
-
167
- should "find that user" do
168
- assert_equal @user, @found_user
169
- end
170
- end
171
-
172
- context "When sent authenticate with an invalid email and password" do
173
- setup do
174
- @found_user = User.authenticate "not", "valid"
175
- end
176
-
177
- should "find nothing" do
178
- assert_nil @found_user
179
- end
180
- end
181
- end
182
-
183
- context "A user" do
184
- setup do
185
- @user = Factory :user
186
- end
187
-
188
- context 'when sent #confirm!' do
189
- setup do
190
- assert ! @user.confirmed?
191
- assert @user.confirm!
192
- @user.reload
193
- end
194
-
195
- should 'mark the User record as confirmed' do
196
- assert @user.confirmed?
197
- end
198
- end
199
- end
200
- end
201
- end
202
- end
203
- end