clearance 0.10.3.2 → 0.10.4

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.

Potentially problematic release.


This version of clearance might be problematic. Click here for more details.

@@ -0,0 +1,65 @@
1
+ ENV["RAILS_ENV"] ||= "test"
2
+
3
+ PROJECT_ROOT = File.expand_path("../..", __FILE__)
4
+ $LOAD_PATH << File.join(PROJECT_ROOT, "lib")
5
+
6
+ require 'rails/all'
7
+ Bundler.require
8
+
9
+ require 'diesel/testing'
10
+ require 'rails/test_help'
11
+ require 'rspec/rails'
12
+
13
+ require 'clearance'
14
+ require 'clearance/shoulda_macros'
15
+
16
+ Clearance.configure do |config|
17
+ end
18
+
19
+ class ApplicationController < ActionController::Base
20
+ include Clearance::Authentication
21
+ end
22
+
23
+ class User < ActiveRecord::Base
24
+ include Clearance::User
25
+ end
26
+
27
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
28
+
29
+ RSpec.configure do |config|
30
+ config.mock_with :mocha
31
+ config.use_transactional_fixtures = true
32
+ config.backtrace_clean_patterns << %r{gems/}
33
+ end
34
+
35
+ # class ActiveSupport::TestCase
36
+ # def self.should_set_cookie(name, value, should_expire_at)
37
+ # description = "set a '#{name}' cookie to '#{value}'"
38
+ # if should_expire_at
39
+ # description << " expiring at #{should_expire_at}"
40
+ # else
41
+ # description << " with no expiration date (session cookie)"
42
+ # end
43
+ # should description do
44
+ # assert_equal value, cookies[name]
45
+ # # the following statement may be redundant with the preceding one, but can't hurt
46
+ # assert_equal value, @response.cookies[name]
47
+ # # cookies and @response[cookies] don't give us the expire time, so we need to fish it out 'manually'
48
+ # set_cookie_headers = @response.headers['Set-Cookie']
49
+ # assert_not_nil set_cookie_headers, "@response.headers['Set-Cookie'] must not be nil"
50
+ # set_cookie_headers = [set_cookie_headers] if set_cookie_headers.respond_to?(:to_str)
51
+ # regex = /^#{name}=#{value}(;|$)/
52
+ # assert_contains set_cookie_headers, regex
53
+ # cookie = set_cookie_headers.find {|h| h =~ regex}
54
+ # regex = /; expires=(.*?)(;|$)/
55
+ # if should_expire_at
56
+ # assert_contains cookie, regex, "cookie does not contain an 'expires=' attribute"
57
+ # cookie =~ regex
58
+ # expires_at = Time.parse($1)
59
+ # assert_in_delta should_expire_at, expires_at, 100 # number of seconds we don't expect the test suite to exceed
60
+ # else
61
+ # assert_does_not_contain cookie, regex, "cookie contains an 'expires=' attribute but it shouldn't"
62
+ # end
63
+ # end
64
+ # end
65
+ # end
@@ -0,0 +1,18 @@
1
+ module AuthorizationHelpers
2
+ def sign_in_as(user)
3
+ @controller.current_user = user
4
+ return user
5
+ end
6
+
7
+ def sign_in
8
+ sign_in_as Factory(:email_confirmed_user)
9
+ end
10
+
11
+ def sign_out
12
+ @controller.current_user = nil
13
+ end
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.include AuthorizationHelpers
18
+ end
@@ -0,0 +1,21 @@
1
+ module ClearanceRedirectMatchers
2
+ def redirect_to_url_after_create
3
+ redirect_to(@controller.send(:url_after_create))
4
+ end
5
+
6
+ def redirect_to_url_after_update
7
+ redirect_to(@controller.send(:url_after_update))
8
+ end
9
+
10
+ def redirect_to_url_after_destroy
11
+ redirect_to(@controller.send(:url_after_destroy))
12
+ end
13
+
14
+ def redirect_to_url_already_confirmed
15
+ redirect_to(@controller.send(:url_already_confirmed))
16
+ end
17
+ end
18
+
19
+ RSpec.configure do |config|
20
+ config.include ClearanceRedirectMatchers
21
+ end
@@ -0,0 +1,72 @@
1
+ RSpec::Matchers.define :set_cookie do |name, value, expected_expires_at|
2
+ match do |subject|
3
+ @response = subject.response
4
+ @name = name
5
+ @value = value
6
+ @expected_expires_at = expected_expires_at
7
+
8
+ extract_cookies
9
+ find_expected_cookie
10
+ parse_expiration
11
+
12
+ ensure_cookie_set
13
+ ensure_value_correct
14
+ ensure_expiration_correct
15
+ end
16
+
17
+ def extract_cookies
18
+ @cookie_headers = @response.headers['Set-Cookie'] || []
19
+ @cookie_headers = [@cookie_headers] if @cookie_headers.respond_to?(:to_str)
20
+ end
21
+
22
+ def find_expected_cookie
23
+ @cookie = @cookie_headers.detect do |header|
24
+ header =~ /^#{@name}=[^;]*(;|$)/
25
+ end
26
+ end
27
+
28
+ def parse_expiration
29
+ if @cookie && result = @cookie.match(/; expires=(.*?)(;|$)/)
30
+ @expires_at = Time.parse(result[1])
31
+ end
32
+ end
33
+
34
+ def ensure_cookie_set
35
+ @cookie.should_not be_nil
36
+ end
37
+
38
+ def ensure_value_correct
39
+ @response.cookies[@name].should == @value
40
+ end
41
+
42
+ def ensure_expiration_correct
43
+ if @expected_expires_at
44
+ @expires_at.should_not be_nil
45
+ @expires_at.should be_within(100).of(@expected_expires_at)
46
+ else
47
+ @expires_at.should be_nil
48
+ end
49
+ end
50
+
51
+ failure_message do
52
+ "Expected #{expectation} got #{result}"
53
+ end
54
+
55
+ def expectation
56
+ base = "Expected a cookie named #{@name} with value #{@value.inspect} "
57
+ if @expected_expires_at
58
+ base << "expiring at #{@expected_expires_at.inspect}"
59
+ else
60
+ base << "with no expiration"
61
+ end
62
+ base
63
+ end
64
+
65
+ def result
66
+ if @cookie
67
+ "value #{@value.inspect} expiring #{@expires_at.inspect}"
68
+ else
69
+ "cookies #{@response.cookies.inspect}"
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -1,14 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clearance
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 10
9
- - 3
10
- - 2
11
- version: 0.10.3.2
8
+ - 4
9
+ version: 0.10.4
12
10
  platform: ruby
13
11
  authors:
14
12
  - Dan Croak
@@ -33,7 +31,7 @@ autorequire:
33
31
  bindir: bin
34
32
  cert_chain: []
35
33
 
36
- date: 2011-03-06 00:00:00 -05:00
34
+ date: 2011-04-16 00:00:00 -04:00
37
35
  default_executable:
38
36
  dependencies:
39
37
  - !ruby/object:Gem::Dependency
@@ -44,7 +42,6 @@ dependencies:
44
42
  requirements:
45
43
  - - ~>
46
44
  - !ruby/object:Gem::Version
47
- hash: 7
48
45
  segments:
49
46
  - 3
50
47
  - 0
@@ -60,7 +57,6 @@ dependencies:
60
57
  requirements:
61
58
  - - ~>
62
59
  - !ruby/object:Gem::Version
63
- hash: 19
64
60
  segments:
65
61
  - 0
66
62
  - 1
@@ -76,7 +72,6 @@ dependencies:
76
72
  requirements:
77
73
  - - ~>
78
74
  - !ruby/object:Gem::Version
79
- hash: 27
80
75
  segments:
81
76
  - 1
82
77
  - 3
@@ -92,7 +87,6 @@ dependencies:
92
87
  requirements:
93
88
  - - ~>
94
89
  - !ruby/object:Gem::Version
95
- hash: 55
96
90
  segments:
97
91
  - 0
98
92
  - 10
@@ -112,6 +106,7 @@ extra_rdoc_files:
112
106
  files:
113
107
  - .bundle/config
114
108
  - .gitignore
109
+ - .rspec
115
110
  - CHANGELOG.md
116
111
  - Gemfile
117
112
  - Gemfile.lock
@@ -160,13 +155,16 @@ files:
160
155
  - lib/generators/clearance/install/templates/db/migrate/upgrade_clearance_to_diesel.rb
161
156
  - lib/generators/clearance/install/templates/user.rb
162
157
  - lib/generators/clearance/views/views_generator.rb
163
- - test/controllers/passwords_controller_test.rb
164
- - test/controllers/sessions_controller_test.rb
165
- - test/controllers/users_controller_test.rb
166
- - test/factories.rb
167
- - test/models/clearance_mailer_test.rb
168
- - test/models/user_test.rb
169
- - test/test_helper.rb
158
+ - spec/controllers/passwords_controller_spec.rb
159
+ - spec/controllers/sessions_controller_spec.rb
160
+ - spec/controllers/users_controller_spec.rb
161
+ - spec/factories.rb
162
+ - spec/models/clearance_mailer_spec.rb
163
+ - spec/models/user_spec.rb
164
+ - spec/spec_helper.rb
165
+ - spec/support/authorization.rb
166
+ - spec/support/clearance_redirects.rb
167
+ - spec/support/cookies.rb
170
168
  has_rdoc: true
171
169
  homepage: http://github.com/thoughtbot/clearance
172
170
  licenses: []
@@ -181,7 +179,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
179
  requirements:
182
180
  - - ">="
183
181
  - !ruby/object:Gem::Version
184
- hash: 3
185
182
  segments:
186
183
  - 0
187
184
  version: "0"
@@ -190,14 +187,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
187
  requirements:
191
188
  - - ">="
192
189
  - !ruby/object:Gem::Version
193
- hash: 3
194
190
  segments:
195
191
  - 0
196
192
  version: "0"
197
193
  requirements: []
198
194
 
199
195
  rubyforge_project:
200
- rubygems_version: 1.4.2
196
+ rubygems_version: 1.3.7
201
197
  signing_key:
202
198
  specification_version: 3
203
199
  summary: Rails authentication with email & password.
@@ -212,10 +208,3 @@ test_files:
212
208
  - features/step_definitions/web_steps.rb
213
209
  - features/support/env.rb
214
210
  - features/support/paths.rb
215
- - test/controllers/passwords_controller_test.rb
216
- - test/controllers/sessions_controller_test.rb
217
- - test/controllers/users_controller_test.rb
218
- - test/factories.rb
219
- - test/models/clearance_mailer_test.rb
220
- - test/models/user_test.rb
221
- - test/test_helper.rb
@@ -1,198 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PasswordsControllerTest < ActionController::TestCase
4
-
5
- tests Clearance::PasswordsController
6
-
7
- should route(:get, '/users/1/password/edit').
8
- to(:controller => 'clearance/passwords', :action => 'edit', :user_id => '1')
9
-
10
- context "a signed up user" do
11
- setup do
12
- @user = Factory(:user)
13
- end
14
-
15
- context "on GET to #new" do
16
- setup { get :new, :user_id => @user.to_param }
17
-
18
- should respond_with(:success)
19
- should render_template(:new)
20
- end
21
-
22
- context "on POST to #create" do
23
- context "with correct email address" do
24
- setup do
25
- ActionMailer::Base.deliveries.clear
26
- post :create, :password => { :email => @user.email }
27
- end
28
-
29
- should "generate a token for the change your password email" do
30
- assert_not_nil @user.reload.confirmation_token
31
- end
32
-
33
- should have_sent_email.with_subject(/change your password/i)
34
-
35
- should set_the_flash.to(/password/i)
36
- should_redirect_to_url_after_create
37
- end
38
-
39
- context "with incorrect email address" do
40
- setup do
41
- email = "user1@example.com"
42
- assert ! ::User.exists?(['email = ?', email])
43
- ActionMailer::Base.deliveries.clear
44
- assert_equal @user.confirmation_token,
45
- @user.reload.confirmation_token
46
-
47
- post :create, :password => { :email => email }
48
- end
49
-
50
- should "not generate a token for the change your password email" do
51
- assert_equal @user.confirmation_token,
52
- @user.reload.confirmation_token
53
- end
54
-
55
- should "not send a password reminder email" do
56
- assert ActionMailer::Base.deliveries.empty?
57
- end
58
-
59
- should "set the failure flash to Unknown email" do
60
- assert_match /unknown email/i, flash.now[:failure]
61
- end
62
-
63
- should render_template(:new)
64
- end
65
- end
66
- end
67
-
68
- context "a signed up user and forgotten password" do
69
- setup do
70
- @user = Factory(:user)
71
- @user.forgot_password!
72
- end
73
-
74
- context "on GET to #edit with correct id and token" do
75
- setup do
76
- get :edit, :user_id => @user.to_param,
77
- :token => @user.confirmation_token
78
- end
79
-
80
- should "find the user" do
81
- assert_equal @user, assigns(:user)
82
- end
83
-
84
- should respond_with(:success)
85
- should render_template(:edit)
86
- end
87
-
88
- # here to see deprecation warning
89
- should_forbid "on GET to #edit with correct id but blank token" do
90
- get :edit, :user_id => @user.to_param, :token => ""
91
- end
92
-
93
- context "on GET to #edit with correct id but blank token" do
94
- setup do
95
- get :edit, :user_id => @user.to_param, :token => ""
96
- end
97
-
98
- should set_the_flash.to(/double check the URL/i)
99
- should render_template(:new)
100
- end
101
-
102
- should_forbid "on GET to #edit with correct id but no token" do
103
- get :edit, :user_id => @user.to_param
104
- end
105
-
106
- context "on GET to #edit with correct id but no token" do
107
- setup do
108
- get :edit, :user_id => @user.to_param
109
- end
110
-
111
- should set_the_flash.to(/double check the URL/i)
112
- should render_template(:new)
113
- end
114
-
115
- context "on PUT to #update with matching password and password confirmation" do
116
- setup do
117
- new_password = "new_password"
118
- @encrypted_new_password = @user.send(:encrypt, new_password)
119
- assert_not_equal @encrypted_new_password, @user.encrypted_password
120
-
121
- put(:update,
122
- :user_id => @user,
123
- :token => @user.confirmation_token,
124
- :user => {
125
- :password => new_password,
126
- :password_confirmation => new_password
127
- })
128
- @user.reload
129
- end
130
-
131
- should "update password" do
132
- assert_equal @encrypted_new_password,
133
- @user.encrypted_password
134
- end
135
-
136
- should "clear confirmation token" do
137
- assert_nil @user.confirmation_token
138
- end
139
-
140
- should "set remember token" do
141
- assert_not_nil @user.remember_token
142
- end
143
-
144
- should set_the_flash.to(/signed in/i)
145
- should_redirect_to_url_after_update
146
- end
147
-
148
- context "on PUT to #update with password but blank password confirmation" do
149
- setup do
150
- new_password = "new_password"
151
- @encrypted_new_password = @user.send(:encrypt, new_password)
152
-
153
- put(:update,
154
- :user_id => @user.to_param,
155
- :token => @user.confirmation_token,
156
- :user => {
157
- :password => new_password,
158
- :password_confirmation => ''
159
- })
160
- @user.reload
161
- end
162
-
163
- should "not update password" do
164
- assert_not_equal @encrypted_new_password,
165
- @user.encrypted_password
166
- end
167
-
168
- should "not clear token" do
169
- assert_not_nil @user.confirmation_token
170
- end
171
-
172
- should "not be signed in" do
173
- assert_nil cookies[:remember_token]
174
- end
175
-
176
- should_not set_the_flash
177
- should respond_with(:success)
178
- should render_template(:edit)
179
- end
180
-
181
- should_forbid "on PUT to #update with id but no token" do
182
- put :update, :user_id => @user.to_param, :token => ""
183
- end
184
- end
185
-
186
- context "given two users and user one signs in" do
187
- setup do
188
- @user_one = Factory(:user)
189
- @user_two = Factory(:user)
190
- sign_in_as @user_one
191
- end
192
-
193
- should_forbid "when user one tries to change user two's password on GET with no token" do
194
- get :edit, :user_id => @user_two.to_param
195
- end
196
- end
197
-
198
- end