clearance 1.12.1 → 1.13.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.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -2
  3. data/Appraisals +3 -7
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +7 -5
  6. data/NEWS.md +15 -0
  7. data/README.md +15 -7
  8. data/app/controllers/clearance/passwords_controller.rb +18 -4
  9. data/app/controllers/clearance/sessions_controller.rb +17 -3
  10. data/app/controllers/clearance/users_controller.rb +10 -4
  11. data/gemfiles/rails40.gemfile +1 -1
  12. data/gemfiles/rails41.gemfile +1 -1
  13. data/gemfiles/rails42.gemfile +1 -1
  14. data/gemfiles/rails50.gemfile +4 -8
  15. data/lib/clearance/authentication.rb +1 -1
  16. data/lib/clearance/authorization.rb +3 -3
  17. data/lib/clearance/configuration.rb +9 -1
  18. data/lib/clearance/engine.rb +1 -4
  19. data/lib/clearance/testing/controller_helpers.rb +2 -2
  20. data/lib/clearance/testing/deny_access_matcher.rb +5 -1
  21. data/lib/clearance/token.rb +1 -1
  22. data/lib/clearance/version.rb +1 -1
  23. data/lib/generators/clearance/install/install_generator.rb +12 -2
  24. data/lib/generators/clearance/install/templates/db/migrate/add_clearance_to_users.rb +1 -1
  25. data/lib/generators/clearance/install/templates/db/migrate/create_users.rb +1 -1
  26. data/lib/generators/clearance/specs/templates/features/clearance/user_signs_out_spec.rb.tt +1 -1
  27. data/lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt +10 -1
  28. data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_in_spec.rb.tt +1 -1
  29. data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_up_spec.rb.tt +1 -1
  30. data/lib/generators/clearance/specs/templates/features/clearance/visitor_updates_password_spec.rb.tt +1 -1
  31. data/spec/app_templates/testapp/app/controllers/home_controller.rb +5 -1
  32. data/spec/clearance/testing/controller_helpers_spec.rb +5 -5
  33. data/spec/configuration_spec.rb +9 -0
  34. data/spec/controllers/apis_controller_spec.rb +6 -2
  35. data/spec/controllers/forgeries_controller_spec.rb +6 -1
  36. data/spec/controllers/permissions_controller_spec.rb +7 -3
  37. data/spec/controllers/sessions_controller_spec.rb +2 -2
  38. data/spec/dummy/app/controllers/application_controller.rb +5 -1
  39. data/spec/dummy/application.rb +4 -0
  40. data/spec/generators/clearance/install/install_generator_spec.rb +15 -3
  41. data/spec/spec_helper.rb +7 -0
  42. data/spec/support/http_method_shim.rb +23 -0
  43. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 625a226d7fafddee52dd57e85023dd92035f7093
4
- data.tar.gz: e28717fbeb6a97e8d6dde485ca67fb4d2f0aeabd
3
+ metadata.gz: 0472155cf20becdae95b0449996f13422cf8fd9f
4
+ data.tar.gz: 593e5208e89806394b03e9c0bac1c69f6836434b
5
5
  SHA512:
6
- metadata.gz: 2984d34843ad635be7463a123448bf002d46a40b34ac0a60c83d5e04da9b068be57aa3ddb4552bf468204fdf0390a23c2896995135efa2bbf692a95b7745917d
7
- data.tar.gz: 59b82d503fbe6b139b22992751a14ac2c62d5817df8ddddb319499ebd912a7dec7072ef818c675bf0b8a21c40250192774068f8429f37092109af1f6ec4d93b5
6
+ metadata.gz: c855e609161a0adc70754a033596de44ffc49ded096b0f1e61bb541c670e1d75e82f518e73f5a0ed53d00d25b4763e12d2f9b494a23802c3428154304665097d
7
+ data.tar.gz: b243f157204f0256c3405e62c8e24219c5101e7852c3818d21e057c0405c36d02aa59dbfe4a3d7f27260eb802b2d1f9d5ff306135fbce1f78d6dcefb39d52cbb
@@ -18,8 +18,6 @@ gemfile:
18
18
  - gemfiles/rails50.gemfile
19
19
 
20
20
  matrix:
21
- allow_failures:
22
- - gemfile: gemfiles/rails50.gemfile
23
21
  exclude:
24
22
  - rvm: 1.9.3
25
23
  gemfile: gemfiles/rails50.gemfile
data/Appraisals CHANGED
@@ -19,12 +19,8 @@ end
19
19
 
20
20
  if RUBY_VERSION >= "2.2.0"
21
21
  appraise "rails50" do
22
- gem "rails", "~> 5.0.0.beta1"
23
- gem "rspec-rails", github: "rspec/rspec-rails"
24
- gem "rspec-support", github: "rspec/rspec-support"
25
- gem "rspec-core", github: "rspec/rspec-core"
26
- gem "rspec-mocks", github: "rspec/rspec-mocks"
27
- gem "rspec-expectations", github: "rspec/rspec-expectations"
28
- gem "rspec", github: "rspec/rspec"
22
+ gem "rails", "~> 5.0.0.beta3"
23
+ gem "rails-controller-testing"
24
+ gem "rspec-rails", "~> 3.5.0.beta1"
29
25
  end
30
26
  end
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
  gem 'appraisal', '~> 1.0'
6
6
  gem 'ammeter'
7
7
  gem 'bundler', '~> 1.3'
8
- gem 'capybara', '>= 2.3'
8
+ gem 'capybara', '>= 2.6.2'
9
9
  gem 'database_cleaner', '~> 1.0'
10
10
  gem 'factory_girl_rails', '~> 4.2'
11
11
  gem 'rspec-rails', '~> 3.1'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clearance (1.12.1)
4
+ clearance (1.13.0)
5
5
  bcrypt
6
6
  email_validator (~> 1.4)
7
7
  rails (>= 3.1)
@@ -44,6 +44,7 @@ GEM
44
44
  minitest (~> 5.1)
45
45
  thread_safe (~> 0.3, >= 0.3.4)
46
46
  tzinfo (~> 1.1)
47
+ addressable (2.4.0)
47
48
  ammeter (1.1.3)
48
49
  activesupport (>= 3.0)
49
50
  railties (>= 3.0)
@@ -55,14 +56,15 @@ GEM
55
56
  arel (6.0.3)
56
57
  bcrypt (3.1.10)
57
58
  builder (3.2.2)
58
- capybara (2.5.0)
59
+ capybara (2.6.2)
60
+ addressable
59
61
  mime-types (>= 1.16)
60
62
  nokogiri (>= 1.3.3)
61
63
  rack (>= 1.0.0)
62
64
  rack-test (>= 0.5.4)
63
65
  xpath (~> 2.0)
64
66
  coderay (1.1.0)
65
- concurrent-ruby (1.0.0)
67
+ concurrent-ruby (1.0.1)
66
68
  database_cleaner (1.5.1)
67
69
  diff-lcs (1.2.5)
68
70
  email_validator (1.6.0)
@@ -142,7 +144,7 @@ GEM
142
144
  sprockets (3.5.2)
143
145
  concurrent-ruby (~> 1.0)
144
146
  rack (> 1, < 3)
145
- sprockets-rails (3.0.0)
147
+ sprockets-rails (3.0.4)
146
148
  actionpack (>= 4.0)
147
149
  activesupport (>= 4.0)
148
150
  sprockets (>= 3.0.0)
@@ -162,7 +164,7 @@ DEPENDENCIES
162
164
  ammeter
163
165
  appraisal (~> 1.0)
164
166
  bundler (~> 1.3)
165
- capybara (>= 2.3)
167
+ capybara (>= 2.6.2)
166
168
  clearance!
167
169
  database_cleaner (~> 1.0)
168
170
  factory_girl_rails (~> 4.2)
data/NEWS.md CHANGED
@@ -3,12 +3,27 @@
3
3
  The noteworthy changes for each Clearance version are included here. For a
4
4
  complete changelog, see the git history for each version via the version links.
5
5
 
6
+ ## [1.13.0] - March 4, 2016
7
+
8
+ ### Added
9
+ - Clearance now supports Rails 5.0.0.beta3 and newer.
10
+
11
+ ### Fixed
12
+ - Clearance will now infer the parameter name to use when accessing user
13
+ parameters in a request. This previously used `:user`, which was incorrect for
14
+ customized user models.
15
+ - Generated feature specs no longer rely on RSpec monkey patches.
16
+
17
+ [1.13.0]: https://github.com/thoughtbot/clearance/compare/v1.12.1...v1.13.0
18
+
6
19
  ## [1.12.1] - January 7, 2016
7
20
 
8
21
  ### Fixed
9
22
  - Fixed the `create_users` migration generated by `rails generate
10
23
  clearance:install` under Rails 3.x.
11
24
 
25
+ [1.12.1]: https://github.com/thoughtbot/clearance/compare/v1.12.0...v1.12.1
26
+
12
27
  ## [1.12.0] - November 17, 2015
13
28
 
14
29
  ### Added
data/README.md CHANGED
@@ -16,22 +16,30 @@ monitored by contributors.
16
16
  [GitHub Issues]: https://github.com/thoughtbot/clearance/issues
17
17
  [Stack Overflow]: http://stackoverflow.com/questions/tagged/clearance
18
18
 
19
- ## Install
19
+ ## Getting Started
20
20
 
21
21
  Clearance is a Rails engine tested against Rails `>= 3.2` and Ruby `>= 1.9.3`.
22
- To get started, add Clearance to your `Gemfile`, `bundle install`, and run the
23
- `install generator`:
22
+
23
+ You can add it to your Gemfile with:
24
+
25
+ ```sh
26
+ gem 'clearance'
27
+ ```
28
+
29
+ Run the bundle command to install it.
30
+
31
+ After you install Clearance, you need to run the generator:
24
32
 
25
33
  ```sh
26
34
  $ rails generate clearance:install
27
35
  ```
28
36
 
29
- The generator:
37
+ The Clearance install generator:
30
38
 
31
39
  * Inserts `Clearance::User` into your `User` model
32
40
  * Inserts `Clearance::Controller` into your `ApplicationController`
33
- * Creates an initializer to allow further configuration.
34
- * Creates a migration that either creates a users table or adds any necessary
41
+ * Creates an initializer file to allow further configuration.
42
+ * Creates a migration file that either create a users table or adds any necessary
35
43
  columns to the existing table.
36
44
 
37
45
  ## Configure
@@ -343,7 +351,7 @@ $ rails generate clearance:specs
343
351
 
344
352
  ### Controller Test Helpers
345
353
 
346
- To test controller actions that are protected by `before_filter :require_login`,
354
+ To test controller actions that are protected by `before_action :require_login`,
347
355
  require Clearance's test helpers in your test suite.
348
356
 
349
357
  For `rspec`, add the following line to your `spec/rails_helper.rb` or
@@ -1,9 +1,23 @@
1
1
  require 'active_support/deprecation'
2
2
 
3
3
  class Clearance::PasswordsController < Clearance::BaseController
4
- skip_before_filter :require_login, only: [:create, :edit, :new, :update]
5
- skip_before_filter :authorize, only: [:create, :edit, :new, :update]
6
- before_filter :ensure_existing_user, only: [:edit, :update]
4
+ if respond_to?(:before_action)
5
+ skip_before_action :require_login,
6
+ only: [:create, :edit, :new, :update],
7
+ raise: false
8
+ skip_before_action :authorize,
9
+ only: [:create, :edit, :new, :update],
10
+ raise: false
11
+ before_action :ensure_existing_user, only: [:edit, :update]
12
+ else
13
+ skip_before_filter :require_login,
14
+ only: [:create, :edit, :new, :update],
15
+ raise: false
16
+ skip_before_filter :authorize,
17
+ only: [:create, :edit, :new, :update],
18
+ raise: false
19
+ before_filter :ensure_existing_user, only: [:edit, :update]
20
+ end
7
21
 
8
22
  def create
9
23
  if user = find_user_for_create
@@ -39,7 +53,7 @@ class Clearance::PasswordsController < Clearance::BaseController
39
53
  def deliver_email(user)
40
54
  mail = ::ClearanceMailer.change_password(user)
41
55
 
42
- if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.2.0")
56
+ if mail.respond_to?(:deliver_later)
43
57
  mail.deliver_later
44
58
  else
45
59
  mail.deliver
@@ -1,7 +1,21 @@
1
1
  class Clearance::SessionsController < Clearance::BaseController
2
- before_filter :redirect_signed_in_users, only: [:new]
3
- skip_before_filter :require_login, only: [:create, :new, :destroy]
4
- skip_before_filter :authorize, only: [:create, :new, :destroy]
2
+ if respond_to?(:before_action)
3
+ before_action :redirect_signed_in_users, only: [:new]
4
+ skip_before_action :require_login,
5
+ only: [:create, :new, :destroy],
6
+ raise: false
7
+ skip_before_action :authorize,
8
+ only: [:create, :new, :destroy],
9
+ raise: false
10
+ else
11
+ before_filter :redirect_signed_in_users, only: [:new]
12
+ skip_before_filter :require_login,
13
+ only: [:create, :new, :destroy],
14
+ raise: false
15
+ skip_before_filter :authorize,
16
+ only: [:create, :new, :destroy],
17
+ raise: false
18
+ end
5
19
 
6
20
  def create
7
21
  @user = authenticate(params)
@@ -1,7 +1,13 @@
1
1
  class Clearance::UsersController < Clearance::BaseController
2
- before_filter :redirect_signed_in_users, only: [:create, :new]
3
- skip_before_filter :require_login, only: [:create, :new]
4
- skip_before_filter :authorize, only: [:create, :new]
2
+ if respond_to?(:before_action)
3
+ before_action :redirect_signed_in_users, only: [:create, :new]
4
+ skip_before_action :require_login, only: [:create, :new], raise: false
5
+ skip_before_action :authorize, only: [:create, :new], raise: false
6
+ else
7
+ before_filter :redirect_signed_in_users, only: [:create, :new]
8
+ skip_before_filter :require_login, only: [:create, :new], raise: false
9
+ skip_before_filter :authorize, only: [:create, :new], raise: false
10
+ end
5
11
 
6
12
  def new
7
13
  @user = user_from_params
@@ -50,6 +56,6 @@ class Clearance::UsersController < Clearance::BaseController
50
56
  end
51
57
 
52
58
  def user_params
53
- params[:user] || Hash.new
59
+ params[Clearance.configuration.user_parameter] || Hash.new
54
60
  end
55
61
  end
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  gem "appraisal", "~> 1.0"
6
6
  gem "ammeter"
7
7
  gem "bundler", "~> 1.3"
8
- gem "capybara", ">= 2.3"
8
+ gem "capybara", ">= 2.6.2"
9
9
  gem "database_cleaner", "~> 1.0"
10
10
  gem "factory_girl_rails", "~> 4.2"
11
11
  gem "rspec-rails", "~> 3.1"
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  gem "appraisal", "~> 1.0"
6
6
  gem "ammeter"
7
7
  gem "bundler", "~> 1.3"
8
- gem "capybara", ">= 2.3"
8
+ gem "capybara", ">= 2.6.2"
9
9
  gem "database_cleaner", "~> 1.0"
10
10
  gem "factory_girl_rails", "~> 4.2"
11
11
  gem "rspec-rails", "~> 3.1"
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  gem "appraisal", "~> 1.0"
6
6
  gem "ammeter"
7
7
  gem "bundler", "~> 1.3"
8
- gem "capybara", ">= 2.3"
8
+ gem "capybara", ">= 2.6.2"
9
9
  gem "database_cleaner", "~> 1.0"
10
10
  gem "factory_girl_rails", "~> 4.2"
11
11
  gem "rspec-rails", "~> 3.1"
@@ -5,19 +5,15 @@ source "https://rubygems.org"
5
5
  gem "appraisal", "~> 1.0"
6
6
  gem "ammeter"
7
7
  gem "bundler", "~> 1.3"
8
- gem "capybara", ">= 2.3"
8
+ gem "capybara", ">= 2.6.2"
9
9
  gem "database_cleaner", "~> 1.0"
10
10
  gem "factory_girl_rails", "~> 4.2"
11
- gem "rspec-rails", :github => "rspec/rspec-rails"
11
+ gem "rspec-rails", "~> 3.5.0.beta1"
12
12
  gem "shoulda-matchers", "~> 2.8"
13
13
  gem "sqlite3", "~> 1.3"
14
14
  gem "timecop", "~> 0.6"
15
15
  gem "pry", :require => false
16
- gem "rails", "~> 5.0.0.beta1"
17
- gem "rspec-support", :github => "rspec/rspec-support"
18
- gem "rspec-core", :github => "rspec/rspec-core"
19
- gem "rspec-mocks", :github => "rspec/rspec-mocks"
20
- gem "rspec-expectations", :github => "rspec/rspec-expectations"
21
- gem "rspec", :github => "rspec/rspec"
16
+ gem "rails", "~> 5.0.0.beta3"
17
+ gem "rails-controller-testing"
22
18
 
23
19
  gemspec :path => "../"
@@ -4,7 +4,7 @@ module Clearance
4
4
 
5
5
  included do
6
6
  helper_method :current_user, :signed_in?, :signed_out?
7
- hide_action(
7
+ private(
8
8
  :authenticate,
9
9
  :current_user,
10
10
  :current_user=,
@@ -3,7 +3,7 @@ module Clearance
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- hide_action :authorize, :deny_access, :require_login
6
+ private :authorize, :deny_access, :require_login
7
7
  end
8
8
 
9
9
  # Use as a `before_action` to require a user be signed in to proceed.
@@ -25,9 +25,9 @@ module Clearance
25
25
 
26
26
  # @deprecated use {#require_login}
27
27
  def authorize
28
- warn "[DEPRECATION] Clearance's `authorize` before_filter is " +
28
+ warn "[DEPRECATION] Clearance's `authorize` before_action is " +
29
29
  "deprecated. Use `require_login` instead. Be sure to update any " +
30
- "instances of `skip_before_filter :authorize` or " +
30
+ "instances of `skip_before_action :authorize` or " +
31
31
  "`skip_before_action :authorize` as well"
32
32
  require_login
33
33
  end
@@ -121,12 +121,20 @@ module Clearance
121
121
  end
122
122
  end
123
123
 
124
+ # The name of user parameter for the configured user model.
125
+ # This is derived from the `model_name` of the `user_model` setting.
126
+ # In the default configuration, this is `user`.
127
+ # @return [Symbol]
128
+ def user_parameter
129
+ user_model.model_name.singular.to_sym
130
+ end
131
+
124
132
  # The name of foreign key parameter for the configured user model.
125
133
  # This is derived from the `model_name` of the `user_model` setting.
126
134
  # In the default configuration, this is `user_id`.
127
135
  # @return [Symbol]
128
136
  def user_id_parameter
129
- "#{user_model.model_name.singular}_id".to_sym
137
+ "#{user_parameter}_id".to_sym
130
138
  end
131
139
 
132
140
  # @return [Boolean] are Clearance's built-in routes enabled?
@@ -23,10 +23,7 @@ module Clearance
23
23
  app.config.filter_parameters += [:password, :token]
24
24
  end
25
25
 
26
- config.app_middleware.insert_after(
27
- ActionDispatch::ParamsParser,
28
- Clearance::RackSession
29
- )
26
+ config.app_middleware.use(Clearance::RackSession)
30
27
 
31
28
  config.to_prepare do
32
29
  Clearance.configuration.reload_user_model
@@ -29,7 +29,7 @@ module Clearance
29
29
  #
30
30
  # @return user
31
31
  def sign_in_as(user)
32
- @controller.sign_in user
32
+ @request.env[:clearance].sign_in(user)
33
33
  user
34
34
  end
35
35
 
@@ -37,7 +37,7 @@ module Clearance
37
37
  #
38
38
  # @return [void]
39
39
  def sign_out
40
- @controller.sign_out
40
+ @request.env[:clearance].sign_out
41
41
  end
42
42
  end
43
43
  end
@@ -67,13 +67,17 @@ module Clearance
67
67
  private
68
68
 
69
69
  def denied_access_url
70
- if @controller.signed_in?
70
+ if clearance_session.signed_in?
71
71
  '/'
72
72
  else
73
73
  @controller.sign_in_url
74
74
  end
75
75
  end
76
76
 
77
+ def clearance_session
78
+ @controller.request.env[:clearance]
79
+ end
80
+
77
81
  def flash_notice
78
82
  @controller.flash[:notice]
79
83
  end
@@ -1,5 +1,5 @@
1
1
  module Clearance
2
- # Random token used for password reset tokens and password reset tokens.
2
+ # Random token used for password reset and remember tokens.
3
3
  # Clearance tokens are also public API and are inteded to be used anywhere you
4
4
  # need a random token to correspond to a given user (e.g. you added an email
5
5
  # confirmation token).
@@ -1,3 +1,3 @@
1
1
  module Clearance
2
- VERSION = "1.12.1"
2
+ VERSION = "1.13.0".freeze
3
3
  end
@@ -61,7 +61,7 @@ module Clearance
61
61
  migration_template(
62
62
  "db/migrate/#{migration_name}",
63
63
  "db/migrate/#{migration_name}",
64
- config
64
+ config.merge(migration_version: migration_version),
65
65
  )
66
66
  end
67
67
  end
@@ -101,7 +101,11 @@ module Clearance
101
101
  end
102
102
 
103
103
  def users_table_exists?
104
- ActiveRecord::Base.connection.table_exists?(:users)
104
+ if ActiveRecord::Base.connection.respond_to?(:data_source_exists?)
105
+ ActiveRecord::Base.connection.data_source_exists?(:users)
106
+ else
107
+ ActiveRecord::Base.connection.table_exists?(:users)
108
+ end
105
109
  end
106
110
 
107
111
  def existing_users_columns
@@ -116,6 +120,12 @@ module Clearance
116
120
  def self.next_migration_number(dir)
117
121
  ActiveRecord::Generators::Base.next_migration_number(dir)
118
122
  end
123
+
124
+ def migration_version
125
+ if Rails.version >= "5.0.0"
126
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
127
+ end
128
+ end
119
129
  end
120
130
  end
121
131
  end
@@ -1,4 +1,4 @@
1
- class AddClearanceToUsers < ActiveRecord::Migration
1
+ class AddClearanceToUsers < ActiveRecord::Migration<%= migration_version %>
2
2
  def self.up
3
3
  change_table :users do |t|
4
4
  <% config[:new_columns].values.each do |column| -%>
@@ -1,4 +1,4 @@
1
- class CreateUsers < ActiveRecord::Migration
1
+ class CreateUsers < ActiveRecord::Migration<%= migration_version %>
2
2
  def change
3
3
  create_table :users do |t|
4
4
  t.timestamps null: false
@@ -1,7 +1,7 @@
1
1
  require "<%= @helper_file %>"
2
2
  require "support/features/clearance_helpers"
3
3
 
4
- feature "User signs out" do
4
+ RSpec.feature "User signs out" do
5
5
  scenario "signs out" do
6
6
  sign_in
7
7
  sign_out
@@ -1,8 +1,17 @@
1
1
  require "<%= @helper_file %>"
2
2
  require "support/features/clearance_helpers"
3
3
 
4
- feature "Visitor resets password" do
4
+ RSpec.feature "Visitor resets password" do
5
5
  before { ActionMailer::Base.deliveries.clear }
6
+ <% if defined?(ActiveJob) -%>
7
+
8
+ around do |example|
9
+ original_adapter = ActiveJob::Base.queue_adapter
10
+ ActiveJob::Base.queue_adapter = :inline
11
+ example.run
12
+ ActiveJob::Base.queue_adapter = original_adapter
13
+ end
14
+ <% end -%>
6
15
 
7
16
  scenario "by navigating to the page" do
8
17
  visit sign_in_path
@@ -1,7 +1,7 @@
1
1
  require "<%= @helper_file %>"
2
2
  require "support/features/clearance_helpers"
3
3
 
4
- feature "Visitor signs in" do
4
+ RSpec.feature "Visitor signs in" do
5
5
  scenario "with valid email and password" do
6
6
  create_user "user@example.com", "password"
7
7
  sign_in_with "user@example.com", "password"
@@ -1,7 +1,7 @@
1
1
  require "<%= @helper_file %>"
2
2
  require "support/features/clearance_helpers"
3
3
 
4
- feature "Visitor signs up" do
4
+ RSpec.feature "Visitor signs up" do
5
5
  scenario "by navigating to the page" do
6
6
  visit sign_in_path
7
7
 
@@ -1,7 +1,7 @@
1
1
  require "<%= @helper_file %>"
2
2
  require "support/features/clearance_helpers"
3
3
 
4
- feature "Visitor updates password" do
4
+ RSpec.feature "Visitor updates password" do
5
5
  scenario "with valid password" do
6
6
  user = user_with_reset_password
7
7
  update_password user, "newpassword"
@@ -1,5 +1,9 @@
1
1
  class HomeController < ApplicationController
2
2
  def show
3
- render text: "", layout: "application"
3
+ if Rails::VERSION::MAJOR >= 5
4
+ render html: "", layout: "application"
5
+ else
6
+ render text: "", layout: "application"
7
+ end
4
8
  end
5
9
  end
@@ -5,11 +5,11 @@ describe Clearance::Testing::ControllerHelpers do
5
5
  include Clearance::Testing::ControllerHelpers
6
6
 
7
7
  def initialize
8
- @controller = Controller.new
9
- end
10
-
11
- class Controller
12
- def sign_in(user); end
8
+ @request = Class.new do
9
+ def env
10
+ { clearance: Clearance::Session.new({}) }
11
+ end
12
+ end.new
13
13
  end
14
14
  end
15
15
 
@@ -143,6 +143,15 @@ describe Clearance::Configuration do
143
143
  end
144
144
  end
145
145
 
146
+ describe "#user_parameter" do
147
+ it "returns the parameter key to use based on the user_model" do
148
+ Account = Class.new(ActiveRecord::Base)
149
+ Clearance.configure { |config| config.user_model = Account }
150
+
151
+ expect(Clearance.configuration.user_parameter).to eq :account
152
+ end
153
+ end
154
+
146
155
  describe '#user_id_parameter' do
147
156
  it 'returns the parameter key to use based on the user_model' do
148
157
  CustomUser = Class.new(ActiveRecord::Base)
@@ -3,10 +3,14 @@ require 'spec_helper'
3
3
  class ApisController < ActionController::Base
4
4
  include Clearance::Controller
5
5
 
6
- before_filter :require_login
6
+ if respond_to?(:before_action)
7
+ before_action :require_login
8
+ else
9
+ before_filter :require_login
10
+ end
7
11
 
8
12
  def show
9
- render text: 'response'
13
+ head :ok
10
14
  end
11
15
  end
12
16
 
@@ -4,7 +4,12 @@ class ForgeriesController < ActionController::Base
4
4
  include Clearance::Controller
5
5
 
6
6
  protect_from_forgery
7
- before_filter :require_login
7
+
8
+ if respond_to?(:before_action)
9
+ before_action :require_login
10
+ else
11
+ before_filter :require_login
12
+ end
8
13
 
9
14
  # This is off in test by default, but we need it for this test
10
15
  self.allow_forgery_protection = true
@@ -3,14 +3,18 @@ require 'spec_helper'
3
3
  class PermissionsController < ActionController::Base
4
4
  include Clearance::Controller
5
5
 
6
- before_filter :require_login, only: :show
6
+ if respond_to?(:before_action)
7
+ before_action :require_login, only: :show
8
+ else
9
+ before_filter :require_login, only: :show
10
+ end
7
11
 
8
12
  def new
9
- render text: 'New page'
13
+ head :ok
10
14
  end
11
15
 
12
16
  def show
13
- render text: 'Show page'
17
+ head :ok
14
18
  end
15
19
  end
16
20
 
@@ -45,7 +45,7 @@ describe Clearance::SessionsController do
45
45
  it { should redirect_to_url_after_create }
46
46
 
47
47
  it "sets the user in the clearance session" do
48
- expect(controller.current_user).to eq @user
48
+ expect(request.env[:clearance].current_user).to eq @user
49
49
  end
50
50
 
51
51
  it "should not change the remember token" do
@@ -92,7 +92,7 @@ describe Clearance::SessionsController do
92
92
  end
93
93
 
94
94
  it "should unset the current user" do
95
- expect(@controller.current_user).to be_nil
95
+ expect(request.env[:clearance].current_user).to be_nil
96
96
  end
97
97
  end
98
98
  end
@@ -2,6 +2,10 @@ class ApplicationController < ActionController::Base
2
2
  include Clearance::Controller
3
3
 
4
4
  def show
5
- render text: '', layout: 'application'
5
+ if Rails::VERSION::MAJOR >= 5
6
+ render html: "", layout: "application"
7
+ else
8
+ render text: "", layout: "application"
9
+ end
6
10
  end
7
11
  end
@@ -37,6 +37,10 @@ module Dummy
37
37
  config.paths.add "config/routes", with: "#{APP_ROOT}/config/routes.rb"
38
38
  end
39
39
 
40
+ if config.respond_to?(:active_job)
41
+ config.active_job.queue_adapter = :inline
42
+ end
43
+
40
44
  def require_environment!
41
45
  initialize!
42
46
  end
@@ -61,9 +61,7 @@ describe Clearance::Generators::InstallGenerator, :generator do
61
61
  context "users table does not exist" do
62
62
  it "creates a migration to create the users table" do
63
63
  provide_existing_application_controller
64
- allow(ActiveRecord::Base.connection).to receive(:table_exists?).
65
- with(:users).
66
- and_return(false)
64
+ table_does_not_exist(:users)
67
65
 
68
66
  run_generator
69
67
  migration = migration_file("db/migrate/create_users.rb")
@@ -115,4 +113,18 @@ describe Clearance::Generators::InstallGenerator, :generator do
115
113
  end
116
114
  end
117
115
  end
116
+
117
+ def table_does_not_exist(name)
118
+ connection = ActiveRecord::Base.connection
119
+
120
+ if connection.respond_to?(:data_source_exists?)
121
+ allow(connection).to receive(:data_source_exists?).
122
+ with(name).
123
+ and_return(false)
124
+ else
125
+ allow(connection).to receive(:table_exists?).
126
+ with(name).
127
+ and_return(false)
128
+ end
129
+ end
118
130
  end
@@ -26,6 +26,13 @@ RSpec.configure do |config|
26
26
  config.mock_with :rspec do |mocks|
27
27
  mocks.syntax = :expect
28
28
  end
29
+
30
+ if Rails::VERSION::MAJOR >= 5
31
+ require 'rails-controller-testing'
32
+ config.include Rails::Controller::Testing::TestProcess
33
+ config.include Rails::Controller::Testing::TemplateAssertions
34
+ config.include Rails::Controller::Testing::Integration
35
+ end
29
36
  end
30
37
 
31
38
  def restore_default_config
@@ -0,0 +1,23 @@
1
+ # Rails 5 deprecates calling HTTP action methods with positional arguments
2
+ # in favor of keyword arguments. However, the keyword argument form is only
3
+ # supported in Rails 5+. Since we support back to 3.1, we need some sort of shim
4
+ # to avoid super noisy deprecations when running tests.
5
+ module HTTPMethodShim
6
+ def get(path, params=nil, headers=nil)
7
+ super(path, params: params, headers: headers)
8
+ end
9
+
10
+ def put(path, params=nil, headers=nil)
11
+ super(path, params: params, headers: headers)
12
+ end
13
+
14
+ def post(path, params=nil, headers=nil)
15
+ super(path, params: params, headers: headers)
16
+ end
17
+ end
18
+
19
+ if Rails::VERSION::MAJOR >= 5
20
+ RSpec.configure do |config|
21
+ config.include HTTPMethodShim, type: :controller
22
+ end
23
+ end
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.12.1
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Croak
@@ -25,7 +25,7 @@ authors:
25
25
  autorequire:
26
26
  bindir: bin
27
27
  cert_chain: []
28
- date: 2016-01-08 00:00:00.000000000 Z
28
+ date: 2016-03-05 00:00:00.000000000 Z
29
29
  dependencies:
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: bcrypt
@@ -219,6 +219,7 @@ files:
219
219
  - spec/support/fake_model_with_password_strategy.rb
220
220
  - spec/support/fake_model_without_password_strategy.rb
221
221
  - spec/support/generator_spec_helpers.rb
222
+ - spec/support/http_method_shim.rb
222
223
  - spec/support/request_with_remember_token.rb
223
224
  - spec/user_spec.rb
224
225
  - spec/views/view_helpers_spec.rb