clearance 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0e5c1ad076dc7b6d2437299cd7888a0112eb892
4
- data.tar.gz: fbe33eb3eca23b455dd535d7d6c7df5af9e85d53
3
+ metadata.gz: 8266915cf611dc113c30738eb37360376aaa7aa2
4
+ data.tar.gz: b36bbf255d84a2840b5e99c6379c8e844d4e8813
5
5
  SHA512:
6
- metadata.gz: 3c34b9bb7f111bc599149e006fbee5e3a98e6c7bbf00797469781585b9a846ae4900d1deed564795ef3da81f62dfe7a691f69f14b574c17091a2e158f2fa3956
7
- data.tar.gz: 66f14e544e08dbf94d16ca3066750abe3d444280ff2dae2dc6782e90790efc6ce066234bc2592bffb0e5c4c01f1c3578c69d9529afc75411eca24fe2f95291dc
6
+ metadata.gz: fcde94feb3534ea779e9dc7f221f7038afa78963a2858bf437537d6c8c780122fa76e302e549059d95466573db08d5b90e3b3710fa7241c16a879ee7ccef4e99
7
+ data.tar.gz: 676762b9c0c0cae39863aecedb3f88017c949a1687645f3782c56127ce32fa8afc783fd43dbaeee8cf7f9fa21ce61e24515f3d1fc18bc41e9655030820416184
@@ -4,13 +4,14 @@ language:
4
4
  rvm:
5
5
  - 1.9.3
6
6
  - 2.0.0
7
+ - 2.1.0
7
8
 
8
9
  before_install:
9
10
  - "sudo apt-get install ca-certificates"
10
11
  - "gem update --system"
11
12
 
12
13
  install:
13
- - "bundle install"
14
+ - "travis_retry bundle install"
14
15
 
15
16
  before_script:
16
17
  - "bundle exec rake db:migrate"
data/Appraisals CHANGED
@@ -1,7 +1,21 @@
1
- rails_versions = ['~> 3.2.15', '~> 4.0.0']
1
+ # These are the various versions of rails we want to test against.
2
+ # The non-rails gems (jbuilder, sdoc, etc) are dependencies introduced
3
+ # in the default rails gemfiles used in the clearance features.
4
+ appraise 'rails3.2' do
5
+ gem 'jbuilder', '~> 1.2'
6
+ gem 'rails', '~> 3.2.17'
7
+ gem 'sdoc'
8
+ end
9
+
10
+ appraise 'rails4.0' do
11
+ gem 'jbuilder', '~> 1.2'
12
+ gem 'rails', '~> 4.0.3'
13
+ gem 'sdoc'
14
+ end
2
15
 
3
- rails_versions.each do |rails_version|
4
- appraise "rails#{rails_version.slice(/\d+\.\d+/)}" do
5
- gem 'rails', rails_version
6
- end
16
+ appraise 'rails4.1' do
17
+ gem 'jbuilder', '~> 2.0'
18
+ gem 'rails', '~> 4.1.0.rc1'
19
+ gem 'sdoc'
20
+ gem 'spring'
7
21
  end
data/Gemfile CHANGED
@@ -10,9 +10,7 @@ gem 'capybara', '~> 2.0.3'
10
10
  gem 'cucumber-rails', '~> 1.3', require: false
11
11
  gem 'database_cleaner', '~> 1.0'
12
12
  gem 'factory_girl_rails', '~> 4.2'
13
- gem 'jbuilder', '~> 1.2'
14
13
  gem 'rspec-rails', '~> 2.13'
15
- gem 'sdoc'
16
14
  gem 'shoulda-matchers', '~> 2.4'
17
15
  gem 'sqlite3', '~> 1.3'
18
16
  gem 'timecop', '~> 0.6'
@@ -1,33 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clearance (1.1.0)
5
- bcrypt-ruby
4
+ clearance (1.2.0)
5
+ bcrypt
6
6
  email_validator (~> 1.4)
7
7
  rails (>= 3.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionmailer (4.0.0)
13
- actionpack (= 4.0.0)
14
- mail (~> 2.5.3)
15
- actionpack (4.0.0)
16
- activesupport (= 4.0.0)
12
+ actionmailer (4.0.2)
13
+ actionpack (= 4.0.2)
14
+ mail (~> 2.5.4)
15
+ actionpack (4.0.2)
16
+ activesupport (= 4.0.2)
17
17
  builder (~> 3.1.0)
18
18
  erubis (~> 2.7.0)
19
19
  rack (~> 1.5.2)
20
20
  rack-test (~> 0.6.2)
21
- activemodel (4.0.0)
22
- activesupport (= 4.0.0)
21
+ activemodel (4.0.2)
22
+ activesupport (= 4.0.2)
23
23
  builder (~> 3.1.0)
24
- activerecord (4.0.0)
25
- activemodel (= 4.0.0)
24
+ activerecord (4.0.2)
25
+ activemodel (= 4.0.2)
26
26
  activerecord-deprecated_finders (~> 1.0.2)
27
- activesupport (= 4.0.0)
27
+ activesupport (= 4.0.2)
28
28
  arel (~> 4.0.0)
29
29
  activerecord-deprecated_finders (1.0.3)
30
- activesupport (4.0.0)
30
+ activesupport (4.0.2)
31
31
  i18n (~> 0.6, >= 0.6.4)
32
32
  minitest (~> 4.2)
33
33
  multi_json (~> 1.3)
@@ -37,12 +37,12 @@ GEM
37
37
  bundler
38
38
  rake
39
39
  arel (4.0.1)
40
- aruba (0.5.3)
40
+ aruba (0.5.4)
41
41
  childprocess (>= 0.3.6)
42
42
  cucumber (>= 1.1.1)
43
43
  rspec-expectations (>= 2.7.0)
44
44
  atomic (1.1.14)
45
- bcrypt-ruby (3.1.2)
45
+ bcrypt (3.1.6)
46
46
  bourne (1.5.0)
47
47
  mocha (>= 0.13.2, < 0.15)
48
48
  builder (3.1.4)
@@ -53,93 +53,86 @@ GEM
53
53
  rack-test (>= 0.5.4)
54
54
  selenium-webdriver (~> 2.0)
55
55
  xpath (~> 1.0.0)
56
- childprocess (0.3.9)
56
+ childprocess (0.4.0)
57
57
  ffi (~> 1.0, >= 1.0.11)
58
- cucumber (1.3.5)
58
+ cucumber (1.3.10)
59
59
  builder (>= 2.1.2)
60
60
  diff-lcs (>= 1.1.3)
61
- gherkin (~> 2.12.0)
62
- multi_json (~> 1.7.5)
61
+ gherkin (~> 2.12)
62
+ multi_json (>= 1.7.5, < 2.0)
63
63
  multi_test (>= 0.0.2)
64
- cucumber-rails (1.3.0)
64
+ cucumber-rails (1.4.0)
65
65
  capybara (>= 1.1.2)
66
- cucumber (>= 1.1.8)
66
+ cucumber (>= 1.2.0)
67
67
  nokogiri (>= 1.5.0)
68
- database_cleaner (1.0.1)
69
- diff-lcs (1.2.4)
68
+ rails (>= 3.0.0)
69
+ database_cleaner (1.2.0)
70
+ diff-lcs (1.2.5)
70
71
  email_validator (1.4.0)
71
72
  activemodel
72
73
  erubis (2.7.0)
73
- factory_girl (4.2.0)
74
+ factory_girl (4.3.0)
74
75
  activesupport (>= 3.0.0)
75
- factory_girl_rails (4.2.1)
76
- factory_girl (~> 4.2.0)
76
+ factory_girl_rails (4.3.0)
77
+ factory_girl (~> 4.3.0)
77
78
  railties (>= 3.0.0)
78
- ffi (1.9.0)
79
- gherkin (2.12.0)
79
+ ffi (1.9.3)
80
+ gherkin (2.12.2)
80
81
  multi_json (~> 1.3)
81
82
  hike (1.2.3)
82
- i18n (0.6.5)
83
- jbuilder (1.5.0)
84
- activesupport (>= 3.0.0)
85
- multi_json (>= 1.2.0)
86
- json (1.8.0)
83
+ i18n (0.6.9)
87
84
  mail (2.5.4)
88
85
  mime-types (~> 1.16)
89
86
  treetop (~> 1.4.8)
90
- metaclass (0.0.1)
91
- mime-types (1.23)
92
- mini_portile (0.5.1)
87
+ metaclass (0.0.2)
88
+ mime-types (1.25.1)
89
+ mini_portile (0.5.2)
93
90
  minitest (4.7.5)
94
91
  mocha (0.14.0)
95
92
  metaclass (~> 0.0.1)
96
- multi_json (1.7.9)
97
- multi_test (0.0.2)
98
- nokogiri (1.6.0)
93
+ multi_json (1.8.4)
94
+ multi_test (0.0.3)
95
+ nokogiri (1.6.1)
99
96
  mini_portile (~> 0.5.0)
100
- polyglot (0.3.3)
97
+ polyglot (0.3.4)
101
98
  rack (1.5.2)
102
99
  rack-test (0.6.2)
103
100
  rack (>= 1.0)
104
- rails (4.0.0)
105
- actionmailer (= 4.0.0)
106
- actionpack (= 4.0.0)
107
- activerecord (= 4.0.0)
108
- activesupport (= 4.0.0)
101
+ rails (4.0.2)
102
+ actionmailer (= 4.0.2)
103
+ actionpack (= 4.0.2)
104
+ activerecord (= 4.0.2)
105
+ activesupport (= 4.0.2)
109
106
  bundler (>= 1.3.0, < 2.0)
110
- railties (= 4.0.0)
107
+ railties (= 4.0.2)
111
108
  sprockets-rails (~> 2.0.0)
112
- railties (4.0.0)
113
- actionpack (= 4.0.0)
114
- activesupport (= 4.0.0)
109
+ railties (4.0.2)
110
+ actionpack (= 4.0.2)
111
+ activesupport (= 4.0.2)
115
112
  rake (>= 0.8.7)
116
113
  thor (>= 0.18.1, < 2.0)
117
- rake (10.1.0)
118
- rdoc (3.12.2)
119
- json (~> 1.4)
120
- rspec-core (2.14.4)
121
- rspec-expectations (2.14.0)
114
+ rake (10.1.1)
115
+ rspec-core (2.14.7)
116
+ rspec-expectations (2.14.4)
122
117
  diff-lcs (>= 1.1.3, < 2.0)
123
- rspec-mocks (2.14.2)
124
- rspec-rails (2.14.0)
118
+ rspec-mocks (2.14.4)
119
+ rspec-rails (2.14.1)
125
120
  actionpack (>= 3.0)
121
+ activemodel (>= 3.0)
126
122
  activesupport (>= 3.0)
127
123
  railties (>= 3.0)
128
124
  rspec-core (~> 2.14.0)
129
125
  rspec-expectations (~> 2.14.0)
130
126
  rspec-mocks (~> 2.14.0)
131
- rubyzip (0.9.9)
132
- sdoc (0.3.20)
133
- json (>= 1.1.3)
134
- rdoc (~> 3.10)
135
- selenium-webdriver (2.33.0)
127
+ rubyzip (1.1.0)
128
+ selenium-webdriver (2.39.0)
136
129
  childprocess (>= 0.2.5)
137
130
  multi_json (~> 1.0)
138
- rubyzip
131
+ rubyzip (~> 1.0)
139
132
  websocket (~> 1.0.4)
140
- shoulda-matchers (2.4.0)
133
+ shoulda-matchers (2.5.0)
141
134
  activesupport (>= 3.0.0)
142
- sprockets (2.10.0)
135
+ sprockets (2.10.1)
143
136
  hike (~> 1.2)
144
137
  multi_json (~> 1.0)
145
138
  rack (~> 1.0)
@@ -148,12 +141,12 @@ GEM
148
141
  actionpack (>= 3.0)
149
142
  activesupport (>= 3.0)
150
143
  sprockets (~> 2.8)
151
- sqlite3 (1.3.7)
144
+ sqlite3 (1.3.8)
152
145
  thor (0.18.1)
153
146
  thread_safe (0.1.3)
154
147
  atomic
155
148
  tilt (1.4.1)
156
- timecop (0.6.2.2)
149
+ timecop (0.7.1)
157
150
  treetop (1.4.15)
158
151
  polyglot
159
152
  polyglot (>= 0.3.1)
@@ -175,9 +168,7 @@ DEPENDENCIES
175
168
  cucumber-rails (~> 1.3)
176
169
  database_cleaner (~> 1.0)
177
170
  factory_girl_rails (~> 4.2)
178
- jbuilder (~> 1.2)
179
171
  rspec-rails (~> 2.13)
180
- sdoc
181
172
  shoulda-matchers (~> 2.4)
182
173
  sqlite3 (~> 1.3)
183
174
  timecop (~> 0.6)
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2009-2013 thoughtbot, inc.
3
+ Copyright (c) 2009-2014 thoughtbot, inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/NEWS.md CHANGED
@@ -1,5 +1,16 @@
1
1
  Thank you to all the [contributors](https://github.com/thoughtbot/clearance/graphs/contributors)!
2
2
 
3
+ New for 1.2.0 (February 28, 2014):
4
+ * Support for Rails 4.1.0.rc1
5
+ * `clearance/testing` is now deprecated. Require `clearance/rspec` or
6
+ `clearance/test_unit` as appropriate.
7
+ * Sign in failure message is now customized exclusively via I18n.
8
+ `SessionsController#flash_failure_after_create` is no longer called. To
9
+ customize the message, change the
10
+ `clearance.controllers.sessions.bad_email_or_password` or
11
+ `flashes.failure_after_create` key.
12
+ * Sign in can now be disabled with `config.allow_sign_in = false`
13
+
3
14
  New for 1.1.0 (November 21, 2013):
4
15
 
5
16
  * Validate email with `EmailValidator` [strict mode][strict].
data/README.md CHANGED
@@ -29,7 +29,7 @@ gem 'clearance'
29
29
 
30
30
  Bundle:
31
31
 
32
- bundle --binstubs
32
+ bundle install
33
33
 
34
34
  Make sure the development database exists. Then, run the generator:
35
35
 
@@ -57,6 +57,7 @@ Override any of these defaults in `config/initializers/clearance.rb`:
57
57
 
58
58
  ```ruby
59
59
  Clearance.configure do |config|
60
+ config.allow_sign_up = true
60
61
  config.cookie_domain = '.example.com'
61
62
  config.cookie_expiration = lambda { |cookies| 1.year.from_now.utc }
62
63
  config.cookie_path = '/'
@@ -116,15 +117,15 @@ Or, you can authorize users in `config/routes.rb`:
116
117
  ```ruby
117
118
  Blog::Application.routes.draw do
118
119
  constraints Clearance::Constraints::SignedIn.new { |user| user.admin? } do
119
- root to: 'admin'
120
+ root to: 'admin/dashboards#show', as: :admin_root
120
121
  end
121
122
 
122
123
  constraints Clearance::Constraints::SignedIn.new do
123
- root to: 'dashboard'
124
+ root to: 'dashboards#show', as: :signed_in_root
124
125
  end
125
126
 
126
127
  constraints Clearance::Constraints::SignedOut.new do
127
- root to: 'marketing'
128
+ root to: 'marketing#index'
128
129
  end
129
130
  end
130
131
  ```
@@ -198,7 +199,6 @@ Or, override private methods:
198
199
  passwords#forbid_non_existent_user
199
200
  passwords#url_after_create
200
201
  passwords#url_after_update
201
- sessions#flash_failure_after_create
202
202
  sessions#url_after_create
203
203
  sessions#url_after_destroy
204
204
  users#flash_failure_after_create
@@ -444,11 +444,18 @@ Testing authorized controller actions
444
444
  -------------------------------------
445
445
 
446
446
  To test controller actions that are protected by `before_filter :authorize`,
447
- include Clearance's test helpers and matchers in `spec/support/clearance.rb` or
448
- `test/test_helper.rb`:
447
+ require Clearance's test helpers and matchers in your test suite.
448
+
449
+ For `rspec`, add this line to your `spec/spec_helper.rb`:
450
+
451
+ ```ruby
452
+ require 'clearance/rspec'
453
+ ```
454
+
455
+ For `test-unit`, add this line to your `test/test_helper.rb`:
449
456
 
450
457
  ```ruby
451
- require 'clearance/testing'
458
+ require 'clearance/test_unit'
452
459
  ```
453
460
 
454
461
  This will make `Clearance::Controller` methods work in your controllers
@@ -522,12 +529,13 @@ Credits
522
529
  ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
523
530
 
524
531
  Clearance is maintained by [thoughtbot, inc](http://thoughtbot.com/community)
525
- and [contributors](/thoughtbot/clearance/graphs/contributors) like you. Thank you!
532
+ and [contributors](https://github.com/thoughtbot/clearance/contributors) like
533
+ you. Thank you!
526
534
 
527
535
  License
528
536
  -------
529
537
 
530
- Clearance is copyright © 2009-2013 thoughtbot. It is free software, and may be
538
+ Clearance is copyright © 2009-2014 thoughtbot. It is free software, and may be
531
539
  redistributed under the terms specified in the `LICENSE` file.
532
540
 
533
541
  The names and logos for thoughtbot are trademarks of thoughtbot, inc.
@@ -50,8 +50,10 @@ class Clearance::PasswordsController < ApplicationController
50
50
  end
51
51
 
52
52
  def find_user_by_id_and_confirmation_token
53
+ user_param = Clearance.configuration.user_id_parameter
54
+
53
55
  Clearance.configuration.user_model.
54
- find_by_id_and_confirmation_token params[:user_id], params[:token].to_s
56
+ find_by_id_and_confirmation_token params[user_param], params[:token].to_s
55
57
  end
56
58
 
57
59
  def find_user_for_create
@@ -26,12 +26,6 @@ class Clearance::SessionsController < ApplicationController
26
26
 
27
27
  private
28
28
 
29
- def flash_failure_after_create
30
- flash.now[:notice] = translate(:bad_email_or_password,
31
- :scope => [:clearance, :controllers, :sessions],
32
- :default => t('flashes.failure_after_create', :sign_up_path => sign_up_path).html_safe)
33
- end
34
-
35
29
  def url_after_create
36
30
  Clearance.configuration.redirect_url
37
31
  end
@@ -14,7 +14,9 @@
14
14
  </div>
15
15
 
16
16
  <div class='other-links'>
17
- <%= link_to t('.sign_up'), sign_up_path %>
17
+ <% if Clearance.configuration.allow_sign_up? %>
18
+ <%= link_to t('.sign_up'), sign_up_path %>
19
+ <% end %>
18
20
  <%= link_to t('.forgot_password'), new_password_path %>
19
21
  </div>
20
22
  <% end %>
@@ -3,7 +3,7 @@ require 'clearance/version'
3
3
  require 'date'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.add_dependency 'bcrypt-ruby'
6
+ s.add_dependency 'bcrypt'
7
7
  s.add_dependency 'email_validator', '~> 1.4'
8
8
  s.add_dependency 'rails', '>= 3.1'
9
9
  s.authors = [
@@ -1,75 +1,53 @@
1
+ ---
1
2
  en:
2
3
  clearance_mailer:
3
4
  change_password:
4
- opening:
5
- 'Someone, hopefully you, requested we send you a link to change your
6
- password:'
7
- closing:
8
- "If you didn't request this, ignore this email. Your password has not
9
- been changed."
5
+ closing: If you didn't request this, ignore this email. Your password
6
+ has not been changed.
7
+ opening: 'Someone, hopefully you, requested we send you a link to change
8
+ your password:'
10
9
  flashes:
11
- failure_when_forbidden:
12
- 'Please double check the URL or try submitting the form again.'
13
- failure_after_update:
14
- "Password can't be blank."
15
- failure_after_create:
16
- 'Bad email or password. Are you trying to register a new account?
17
- <a href="%{sign_up_path}">Sign up</a>.'
10
+ failure_after_create: Bad email or password.
11
+ failure_after_update: Password can't be blank.
12
+ failure_when_forbidden: Please double check the URL or try submitting
13
+ the form again.
18
14
  helpers:
15
+ label:
16
+ password:
17
+ email: Email address
18
+ password_reset:
19
+ password: Choose password
19
20
  submit:
20
21
  password:
21
- submit:
22
- 'Reset password'
22
+ submit: Reset password
23
23
  password_reset:
24
- submit:
25
- 'Save this password'
24
+ submit: Save this password
26
25
  session:
27
- submit:
28
- 'Sign in'
26
+ submit: Sign in
29
27
  user:
30
- create:
31
- 'Sign up'
32
- label:
33
- password:
34
- email:
35
- 'Email address'
36
- password_reset:
37
- password:
38
- 'Choose password'
28
+ create: Sign up
39
29
  layouts:
40
30
  application:
41
- sign_in:
42
- 'Sign in'
43
- sign_out:
44
- 'Sign out'
31
+ sign_in: Sign in
32
+ sign_out: Sign out
45
33
  passwords:
46
34
  create:
47
- description:
48
- 'You will receive an email within the next few minutes.
49
- It contains instructions for changing your password.'
35
+ description: You will receive an email within the next few minutes. It
36
+ contains instructions for changing your password.
50
37
  edit:
51
- description:
52
- 'Your password has been reset. Choose a new password below.'
53
- title:
54
- 'Change your password'
38
+ description: Your password has been reset. Choose a new password below.
39
+ title: Change your password
55
40
  new:
56
- description:
57
- 'To be emailed a link to reset your password, please enter your email
58
- address.'
59
- title:
60
- 'Reset your password'
41
+ description: To be emailed a link to reset your password, please enter
42
+ your email address.
43
+ title: Reset your password
61
44
  sessions:
62
45
  form:
63
- forgot_password:
64
- 'Forgot password?'
65
- sign_up:
66
- 'Sign up'
46
+ forgot_password: Forgot password?
47
+ sign_up: Sign up
67
48
  new:
68
- title:
69
- 'Sign in'
49
+ title: Sign in
70
50
  users:
71
51
  new:
72
- title:
73
- 'Sign up'
74
- sign_in:
75
- 'Sign in'
52
+ sign_in: Sign in
53
+ title: Sign up
@@ -1,21 +1,24 @@
1
1
  Rails.application.routes.draw do
2
2
  resources :passwords,
3
- :controller => 'clearance/passwords',
4
- :only => [:create, :new]
3
+ controller: 'clearance/passwords',
4
+ only: [:create, :new]
5
5
 
6
6
  resource :session,
7
- :controller => 'clearance/sessions',
8
- :only => [:create]
7
+ controller: 'clearance/sessions',
8
+ only: [:create]
9
9
 
10
10
  resources :users,
11
- :controller => 'clearance/users',
12
- :only => [:create] do
11
+ controller: 'clearance/users',
12
+ only: Clearance.configuration.user_actions do
13
13
  resource :password,
14
- :controller => 'clearance/passwords',
15
- :only => [:create, :edit, :update]
14
+ controller: 'clearance/passwords',
15
+ only: [:create, :edit, :update]
16
16
  end
17
17
 
18
- get '/sign_in' => 'clearance/sessions#new', :as => 'sign_in'
19
- delete '/sign_out' => 'clearance/sessions#destroy', :as => 'sign_out'
20
- get '/sign_up' => 'clearance/users#new', :as => 'sign_up'
18
+ get '/sign_in' => 'clearance/sessions#new', as: 'sign_in'
19
+ delete '/sign_out' => 'clearance/sessions#destroy', as: 'sign_out'
20
+
21
+ if Clearance.configuration.allow_sign_up?
22
+ get '/sign_up' => 'clearance/users#new', as: 'sign_up'
23
+ end
21
24
  end
@@ -13,4 +13,4 @@ Feature: integrate with test-unit
13
13
  And I successfully run `bundle exec rails generate controller posts index`
14
14
  And I configure test-unit
15
15
  And I successfully run `bundle exec rake`
16
- Then the output should match /1 tests.+1 assertions/
16
+ Then the output should match /1 (tests|runs).+1 assertions/
@@ -68,7 +68,7 @@ When /^I configure test-unit$/ do
68
68
  steps %Q{
69
69
  When I append to "test/test_helper.rb" with:
70
70
  """
71
- require 'clearance/testing'
71
+ require 'clearance/test_unit'
72
72
  """
73
73
  And I overwrite "test/#{controller_test_dir}/posts_controller_test.rb" with:
74
74
  """
@@ -25,8 +25,8 @@ module Clearance
25
25
  end
26
26
 
27
27
  def current_user=(user)
28
- warn 'DEPRECATION WARNING: Assigning the current_user this way has been' +
29
- ' deprecated. You should instead use the sign_in method.'
28
+ warn "#{Kernel.caller.first}: [DEPRECATION] " +
29
+ 'Assigning the current_user has been deprecated. Use the sign_in method instead.'
30
30
  clearance_session.sign_in user
31
31
  end
32
32
 
@@ -1,5 +1,7 @@
1
1
  module Clearance
2
2
  class Configuration
3
+ attr_writer :allow_sign_up
4
+
3
5
  attr_accessor \
4
6
  :cookie_domain,
5
7
  :cookie_expiration,
@@ -13,6 +15,7 @@ module Clearance
13
15
  :user_model
14
16
 
15
17
  def initialize
18
+ @allow_sign_up = true
16
19
  @cookie_expiration = ->(cookies) { 1.year.from_now.utc }
17
20
  @cookie_path = '/'
18
21
  @httponly = false
@@ -25,14 +28,33 @@ module Clearance
25
28
  def user_model
26
29
  @user_model || ::User
27
30
  end
31
+
32
+ def allow_sign_up?
33
+ @allow_sign_up
34
+ end
35
+
36
+ def user_actions
37
+ if allow_sign_up?
38
+ [:create]
39
+ else
40
+ []
41
+ end
42
+ end
43
+
44
+ def user_id_parameter
45
+ "#{user_model.model_name.singular}_id".to_sym
46
+ end
47
+ end
48
+
49
+ def self.configuration
50
+ @configuration ||= Configuration.new
28
51
  end
29
52
 
30
- class << self
31
- attr_accessor :configuration
53
+ def self.configuration=(config)
54
+ @configuration = config
32
55
  end
33
56
 
34
57
  def self.configure
35
- self.configuration ||= Configuration.new
36
58
  yield configuration
37
59
  end
38
60
  end
@@ -9,11 +9,11 @@ module Clearance
9
9
  end
10
10
 
11
11
  def default_failure_message
12
- I18n.t("flashes.failure_after_create", :sign_up_path => sign_up_path)
13
- end
14
-
15
- def sign_up_path
16
- Rails.application.routes.url_helpers.sign_up_path
12
+ I18n.t(
13
+ :bad_email_or_password,
14
+ scope: [:clearance, :controllers, :sessions],
15
+ default: I18n.t('flashes.failure_after_create').html_safe
16
+ )
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,8 @@
1
+ require 'rspec/rails'
2
+ require 'clearance/testing/deny_access_matcher'
3
+ require 'clearance/testing/helpers'
4
+
5
+ RSpec.configure do |config|
6
+ config.include Clearance::Testing::Matchers, type: :controller
7
+ config.include Clearance::Testing::Helpers, type: :controller
8
+ end
@@ -66,10 +66,10 @@ module Clearance
66
66
  if expires_configuration.arity == 1
67
67
  expires_configuration.call(cookies)
68
68
  else
69
- warn 'DEPRECATION WARNING: Clearance.configuration.cookie_expiration' +
70
- 'lambda with no parameters has been deprecated and will be removed' +
71
- ' from a future release. The lambda should accept the collection' +
72
- ' of previously set cookies.'
69
+ warn "#{Kernel.caller.first}: [DEPRECATION] " +
70
+ 'Clearance.configuration.cookie_expiration lambda with no parameters ' +
71
+ 'has been deprecated and will be removed from a future release. The ' +
72
+ 'lambda should accept the collection of previously set cookies.'
73
73
  expires_configuration.call
74
74
  end
75
75
  end
@@ -19,10 +19,9 @@ module Clearance
19
19
  stack.call
20
20
  end
21
21
 
22
-
23
22
  private
24
- attr_reader :stack, :session
25
23
 
24
+ attr_reader :stack, :session
26
25
 
27
26
  def signed_in?
28
27
  session.signed_in?
@@ -31,6 +30,5 @@ module Clearance
31
30
  def current_user
32
31
  session.current_user
33
32
  end
34
-
35
33
  end
36
34
  end
@@ -0,0 +1,8 @@
1
+ require 'clearance/testing/deny_access_matcher'
2
+ require 'clearance/testing/helpers'
3
+
4
+ ActionController::TestCase.extend Clearance::Testing::Matchers
5
+
6
+ class ActionController::TestCase
7
+ include Clearance::Testing::Helpers
8
+ end
@@ -1,18 +1,11 @@
1
- require 'clearance/testing/assertion_error'
2
- require 'clearance/testing/deny_access_matcher'
3
- require 'clearance/testing/helpers'
4
-
5
- if defined?(ActionController::TestCase)
6
- ActionController::TestCase.extend Clearance::Testing::Matchers
7
-
8
- class ActionController::TestCase
9
- include Clearance::Testing::Helpers
10
- end
1
+ if defined?(RSpec)
2
+ require 'clearance/rspec'
3
+ elsif defined?(ActionController::TestCase)
4
+ require 'clearance/test_unit'
11
5
  end
12
6
 
13
- if defined?(RSpec) && RSpec.respond_to?(:configure)
14
- RSpec.configure do |config|
15
- config.include Clearance::Testing::Matchers
16
- config.include Clearance::Testing::Helpers, :type => :controller
17
- end
18
- end
7
+ warn(
8
+ "#{Kernel.caller.first} [DEPRECATION] Requiring `clearance/testing` in " +
9
+ '`spec/spec_helper.rb` (or in `test/test_helper.rb`) is deprecated. ' +
10
+ 'Require `clearance/rspec` or `clearance/test_unit` instead.'
11
+ )
@@ -8,6 +8,8 @@ module Clearance
8
8
  Rails::VERSION::MAJOR == 4
9
9
  end
10
10
 
11
+ I18n.enforce_available_locales = true
12
+
11
13
  class Application < Rails::Application
12
14
  config.action_controller.allow_forgery_protection = false
13
15
  config.action_controller.perform_caching = false
@@ -1,3 +1,5 @@
1
+ require 'clearance/testing/assertion_error'
2
+
1
3
  module Clearance
2
4
  module Testing
3
5
  module Matchers
@@ -7,11 +7,19 @@ module Clearance
7
7
  end
8
8
 
9
9
  def sign_in
10
- sign_in_as FactoryGirl.create(:user)
10
+ unless defined?(FactoryGirl)
11
+ raise(
12
+ RuntimeError,
13
+ "Clearance's `sign_in` helper requires factory_girl"
14
+ )
15
+ end
16
+
17
+ factory = Clearance.configuration.user_model.to_s.underscore.to_sym
18
+ sign_in_as FactoryGirl.create(factory)
11
19
  end
12
20
 
13
21
  def sign_in_as(user)
14
- @controller.current_user = user
22
+ @controller.sign_in user
15
23
  end
16
24
 
17
25
  def sign_out
@@ -1,3 +1,3 @@
1
1
  module Clearance
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -35,7 +35,7 @@ module Clearance
35
35
  if users_table_exists?
36
36
  create_add_columns_migration
37
37
  else
38
- create_migration 'create_users.rb'
38
+ copy_migration 'create_users.rb'
39
39
  end
40
40
  end
41
41
 
@@ -52,11 +52,11 @@ module Clearance
52
52
  :new_indexes => new_indexes
53
53
  }
54
54
 
55
- create_migration('add_clearance_to_users.rb', config)
55
+ copy_migration('add_clearance_to_users.rb', config)
56
56
  end
57
57
  end
58
58
 
59
- def create_migration(migration_name, config = {})
59
+ def copy_migration(migration_name, config = {})
60
60
  unless migration_exists?(migration_name)
61
61
  migration_template(
62
62
  "db/migrate/#{migration_name}",
@@ -1 +1 @@
1
- require 'clearance/testing'
1
+ require 'clearance/rspec'
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Clearance::DefaultSignInGuard do
4
+ context 'session is signed in' do
5
+ it 'returns success' do
6
+ session = stub('Session', signed_in?: true)
7
+ guard = Clearance::DefaultSignInGuard.new(session)
8
+
9
+ expect(guard.call).to be_a Clearance::SuccessStatus
10
+ end
11
+ end
12
+
13
+ context 'session is not signed in' do
14
+ it 'returns failure' do
15
+ session = stub('Session', signed_in?: false)
16
+ guard = Clearance::DefaultSignInGuard.new(session)
17
+
18
+ response = guard.call
19
+
20
+ expect(response).to be_a Clearance::FailureStatus
21
+ expect(response.failure_message).to eq default_failure_message
22
+ end
23
+ end
24
+
25
+ def default_failure_message
26
+ I18n.t('flashes.failure_after_create').html_safe
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Clearance::Testing::Helpers do
4
+ class TestClass
5
+ include Clearance::Testing::Helpers
6
+
7
+ def initialize
8
+ @controller = Controller.new
9
+ end
10
+
11
+ class Controller
12
+ def sign_in(user); end
13
+ end
14
+ end
15
+
16
+ describe '#sign_in' do
17
+ it 'creates an instance of the clearance user model with FactoryGirl' do
18
+ MyUserModel = Class.new
19
+ FactoryGirl.stubs(:create)
20
+ Clearance.configuration.stubs(user_model: MyUserModel)
21
+
22
+ TestClass.new.sign_in
23
+
24
+ expect(FactoryGirl).to have_received(:create).with(:my_user_model)
25
+ end
26
+ end
27
+ end
@@ -112,4 +112,43 @@ describe Clearance::Configuration do
112
112
  expect(Clearance.configuration.cookie_path).to eq path
113
113
  end
114
114
  end
115
+
116
+ describe '#sign_up?' do
117
+ context 'when allow_sign_up is configured to false' do
118
+ it 'returns false' do
119
+ Clearance.configure { |config| config.allow_sign_up = false }
120
+ Clearance.configuration.allow_sign_up?.should be_false
121
+ end
122
+ end
123
+
124
+ context 'when allow_sign_up has not been configured' do
125
+ it 'returns true' do
126
+ Clearance.configuration.allow_sign_up?.should be_true
127
+ end
128
+ end
129
+ end
130
+
131
+ describe '#user_actions' do
132
+ context 'when allow_sign_up is configured to false' do
133
+ it 'returns empty array' do
134
+ Clearance.configure { |config| config.allow_sign_up = false }
135
+ Clearance.configuration.user_actions.should eq []
136
+ end
137
+ end
138
+
139
+ context 'when sign_up has not been configured' do
140
+ it 'returns create' do
141
+ Clearance.configuration.user_actions.should eq [:create]
142
+ end
143
+ end
144
+ end
145
+
146
+ describe '#user_id_parameter' do
147
+ it 'returns the parameter key to use based on the user_model' do
148
+ CustomUser = Class.new(ActiveRecord::Base)
149
+ Clearance.configure { |config| config.user_model = CustomUser }
150
+
151
+ Clearance.configuration.user_id_parameter.should eq :custom_user_id
152
+ end
153
+ end
115
154
  end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'routes for Clearance' do
4
+ context 'signup disabled' do
5
+ before(:all) do
6
+ Clearance.configure do |config|
7
+ config.allow_sign_up = false
8
+ end
9
+
10
+ Rails.application.reload_routes!
11
+ end
12
+
13
+ after :all do
14
+ Clearance.configuration = Clearance::Configuration.new
15
+ Rails.application.reload_routes!
16
+ end
17
+
18
+ it 'does not route sign_up' do
19
+ expect(get: 'sign_up').not_to be_routable
20
+ end
21
+
22
+ it 'does not route to users#create' do
23
+ expect(post: 'users').not_to be_routable
24
+ end
25
+
26
+ it 'does not route to users#new' do
27
+ expect(get: 'users/new').not_to be_routable
28
+ end
29
+ end
30
+
31
+ context 'signup enabled' do
32
+ it 'does route sign_up' do
33
+ expect(get: 'sign_up').to be_routable
34
+ end
35
+
36
+ it 'does route to users#create' do
37
+ expect(post: 'users').to be_routable
38
+ end
39
+ end
40
+ end
@@ -13,7 +13,7 @@ require 'rspec/rails'
13
13
  require 'bourne'
14
14
  require 'factory_girl_rails'
15
15
  require 'shoulda-matchers'
16
- require 'clearance/testing'
16
+ require 'clearance/rspec'
17
17
  require 'timecop'
18
18
 
19
19
  Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clearance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Croak
@@ -25,48 +25,48 @@ authors:
25
25
  autorequire:
26
26
  bindir: bin
27
27
  cert_chain: []
28
- date: 2013-11-21 00:00:00.000000000 Z
28
+ date: 2014-03-03 00:00:00.000000000 Z
29
29
  dependencies:
30
30
  - !ruby/object:Gem::Dependency
31
- name: bcrypt-ruby
31
+ name: bcrypt
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - '>='
34
+ - - ">="
35
35
  - !ruby/object:Gem::Version
36
36
  version: '0'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - '>='
41
+ - - ">="
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: email_validator
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - ~>
48
+ - - "~>"
49
49
  - !ruby/object:Gem::Version
50
50
  version: '1.4'
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - ~>
55
+ - - "~>"
56
56
  - !ruby/object:Gem::Version
57
57
  version: '1.4'
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rails
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - '>='
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
64
  version: '3.1'
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - '>='
69
+ - - ">="
70
70
  - !ruby/object:Gem::Version
71
71
  version: '3.1'
72
72
  description: Rails authentication & authorization with email & password.
@@ -77,9 +77,9 @@ extra_rdoc_files:
77
77
  - LICENSE
78
78
  - README.md
79
79
  files:
80
- - .gitignore
81
- - .rspec
82
- - .travis.yml
80
+ - ".gitignore"
81
+ - ".rspec"
82
+ - ".travis.yml"
83
83
  - Appraisals
84
84
  - CONTRIBUTING.md
85
85
  - Gemfile
@@ -131,9 +131,11 @@ files:
131
131
  - lib/clearance/password_strategies/blowfish.rb
132
132
  - lib/clearance/password_strategies/sha1.rb
133
133
  - lib/clearance/rack_session.rb
134
+ - lib/clearance/rspec.rb
134
135
  - lib/clearance/session.rb
135
136
  - lib/clearance/session_status.rb
136
137
  - lib/clearance/sign_in_guard.rb
138
+ - lib/clearance/test_unit.rb
137
139
  - lib/clearance/testing.rb
138
140
  - lib/clearance/testing/app/controllers/application_controller.rb
139
141
  - lib/clearance/testing/application.rb
@@ -168,9 +170,11 @@ files:
168
170
  - spec/clearance/back_door_spec.rb
169
171
  - spec/clearance/constraints/signed_in_spec.rb
170
172
  - spec/clearance/constraints/signed_out_spec.rb
173
+ - spec/clearance/default_sign_in_guard_spec.rb
171
174
  - spec/clearance/rack_session_spec.rb
172
175
  - spec/clearance/session_spec.rb
173
176
  - spec/clearance/sign_in_guard_spec.rb
177
+ - spec/clearance/testing/helpers_spec.rb
174
178
  - spec/configuration_spec.rb
175
179
  - spec/controllers/apis_controller_spec.rb
176
180
  - spec/controllers/flashes_controller_spec.rb
@@ -187,6 +191,7 @@ files:
187
191
  - spec/models/password_strategies_spec.rb
188
192
  - spec/models/sha1_spec.rb
189
193
  - spec/models/user_spec.rb
194
+ - spec/routing/clearance_routes_spec.rb
190
195
  - spec/spec_helper.rb
191
196
  - spec/support/clearance.rb
192
197
  - spec/support/cookies.rb
@@ -198,22 +203,22 @@ licenses:
198
203
  metadata: {}
199
204
  post_install_message:
200
205
  rdoc_options:
201
- - --charset=UTF-8
206
+ - "--charset=UTF-8"
202
207
  require_paths:
203
208
  - lib
204
209
  required_ruby_version: !ruby/object:Gem::Requirement
205
210
  requirements:
206
- - - '>='
211
+ - - ">="
207
212
  - !ruby/object:Gem::Version
208
213
  version: 1.9.2
209
214
  required_rubygems_version: !ruby/object:Gem::Requirement
210
215
  requirements:
211
- - - '>='
216
+ - - ">="
212
217
  - !ruby/object:Gem::Version
213
218
  version: '0'
214
219
  requirements: []
215
220
  rubyforge_project:
216
- rubygems_version: 2.0.5
221
+ rubygems_version: 2.2.0
217
222
  signing_key:
218
223
  specification_version: 4
219
224
  summary: Rails authentication & authorization with email & password.
@@ -228,9 +233,11 @@ test_files:
228
233
  - spec/clearance/back_door_spec.rb
229
234
  - spec/clearance/constraints/signed_in_spec.rb
230
235
  - spec/clearance/constraints/signed_out_spec.rb
236
+ - spec/clearance/default_sign_in_guard_spec.rb
231
237
  - spec/clearance/rack_session_spec.rb
232
238
  - spec/clearance/session_spec.rb
233
239
  - spec/clearance/sign_in_guard_spec.rb
240
+ - spec/clearance/testing/helpers_spec.rb
234
241
  - spec/configuration_spec.rb
235
242
  - spec/controllers/apis_controller_spec.rb
236
243
  - spec/controllers/flashes_controller_spec.rb
@@ -247,6 +254,7 @@ test_files:
247
254
  - spec/models/password_strategies_spec.rb
248
255
  - spec/models/sha1_spec.rb
249
256
  - spec/models/user_spec.rb
257
+ - spec/routing/clearance_routes_spec.rb
250
258
  - spec/spec_helper.rb
251
259
  - spec/support/clearance.rb
252
260
  - spec/support/cookies.rb