clearance 1.8.0 → 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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +24 -6
- data/.yardopts +6 -0
- data/Appraisals +12 -4
- data/CONTRIBUTING.md +4 -1
- data/Gemfile +2 -2
- data/Gemfile.lock +87 -85
- data/NEWS.md +672 -311
- data/README.md +185 -330
- data/app/controllers/clearance/passwords_controller.rb +25 -19
- data/app/controllers/clearance/sessions_controller.rb +17 -4
- data/app/controllers/clearance/users_controller.rb +10 -4
- data/app/mailers/clearance_mailer.rb +2 -3
- data/app/views/clearance_mailer/change_password.html.erb +6 -3
- data/app/views/clearance_mailer/change_password.text.erb +5 -0
- data/app/views/layouts/application.html.erb +2 -2
- data/app/views/passwords/create.html.erb +1 -1
- data/app/views/passwords/edit.html.erb +2 -2
- data/app/views/passwords/new.html.erb +2 -2
- data/app/views/sessions/_form.html.erb +2 -2
- data/app/views/sessions/new.html.erb +1 -1
- data/app/views/users/new.html.erb +2 -2
- data/bin/setup +6 -2
- data/config/locales/clearance.en.yml +6 -0
- data/db/migrate/20110111224543_create_clearance_users.rb +1 -1
- data/gemfiles/{rails3.2.gemfile → rails32.gemfile} +1 -1
- data/gemfiles/{rails4.0.gemfile → rails40.gemfile} +2 -2
- data/gemfiles/{rails4.1.gemfile → rails41.gemfile} +2 -2
- data/gemfiles/{rails4.2.gemfile → rails42.gemfile} +2 -2
- data/gemfiles/rails50.gemfile +19 -0
- data/lib/clearance/authentication.rb +52 -1
- data/lib/clearance/authorization.rb +47 -4
- data/lib/clearance/back_door.rb +1 -0
- data/lib/clearance/configuration.rb +127 -15
- data/lib/clearance/constraints/signed_in.rb +21 -0
- data/lib/clearance/constraints/signed_out.rb +12 -0
- data/lib/clearance/constraints.rb +12 -0
- data/lib/clearance/controller.rb +13 -0
- data/lib/clearance/default_sign_in_guard.rb +17 -0
- data/lib/clearance/engine.rb +24 -4
- data/lib/clearance/password_strategies/bcrypt.rb +9 -2
- data/lib/clearance/password_strategies/bcrypt_migration_from_sha1.rb +19 -0
- data/lib/clearance/password_strategies/blowfish.rb +17 -0
- data/lib/clearance/password_strategies/sha1.rb +17 -0
- data/lib/clearance/password_strategies.rb +13 -0
- data/lib/clearance/rack_session.rb +13 -0
- data/lib/clearance/rspec.rb +15 -4
- data/lib/clearance/session.rb +46 -1
- data/lib/clearance/session_status.rb +7 -0
- data/lib/clearance/sign_in_guard.rb +65 -0
- data/lib/clearance/test_unit.rb +3 -3
- data/lib/clearance/testing/controller_helpers.rb +44 -0
- data/lib/clearance/testing/deny_access_matcher.rb +35 -1
- data/lib/clearance/testing/helpers.rb +9 -25
- data/lib/clearance/testing/view_helpers.rb +32 -0
- data/lib/clearance/token.rb +7 -0
- data/lib/clearance/user.rb +159 -0
- data/lib/clearance/version.rb +1 -1
- data/lib/clearance.rb +2 -0
- data/lib/generators/clearance/install/install_generator.rb +13 -3
- data/lib/generators/clearance/install/templates/db/migrate/add_clearance_to_users.rb +3 -3
- data/lib/generators/clearance/install/templates/db/migrate/create_users.rb +2 -2
- data/lib/generators/clearance/routes/routes_generator.rb +23 -0
- data/lib/generators/clearance/routes/templates/routes.rb +7 -7
- data/lib/generators/clearance/specs/templates/features/clearance/user_signs_out_spec.rb.tt +1 -1
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt +12 -2
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_in_spec.rb.tt +1 -1
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_up_spec.rb.tt +1 -1
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_updates_password_spec.rb.tt +1 -1
- data/spec/acceptance/clearance_installation_spec.rb +4 -1
- data/spec/app_templates/config/initializers/clearance.rb +2 -0
- data/spec/app_templates/testapp/app/controllers/home_controller.rb +5 -1
- data/spec/app_templates/testapp/config/initializers/action_mailer.rb +1 -3
- data/spec/clearance/controller_spec.rb +11 -0
- data/spec/clearance/rack_session_spec.rb +5 -5
- data/spec/clearance/testing/{helpers_spec.rb → controller_helpers_spec.rb} +12 -12
- data/spec/clearance/testing/view_helpers_spec.rb +37 -0
- data/spec/configuration_spec.rb +24 -0
- data/spec/controllers/apis_controller_spec.rb +6 -2
- data/spec/controllers/forgeries_controller_spec.rb +6 -1
- data/spec/controllers/passwords_controller_spec.rb +1 -11
- data/spec/controllers/permissions_controller_spec.rb +13 -3
- data/spec/controllers/sessions_controller_spec.rb +4 -4
- data/spec/dummy/app/controllers/application_controller.rb +5 -1
- data/spec/dummy/application.rb +4 -0
- data/spec/generators/clearance/install/install_generator_spec.rb +15 -3
- data/spec/generators/clearance/routes/routes_generator_spec.rb +5 -1
- data/spec/generators/clearance/views/views_generator_spec.rb +11 -10
- data/spec/helpers/helper_helpers_spec.rb +10 -0
- data/spec/mailers/clearance_mailer_spec.rb +13 -19
- data/spec/password_strategies/bcrypt_migration_from_sha1_spec.rb +6 -0
- data/spec/password_strategies/blowfish_spec.rb +6 -0
- data/spec/password_strategies/sha1_spec.rb +6 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/support/generator_spec_helpers.rb +4 -0
- data/spec/support/http_method_shim.rb +23 -0
- data/spec/user_spec.rb +9 -0
- data/spec/views/view_helpers_spec.rb +10 -0
- metadata +19 -8
data/lib/clearance.rb
CHANGED
@@ -10,6 +10,8 @@ require 'clearance/password_strategies'
|
|
10
10
|
require 'clearance/constraints'
|
11
11
|
|
12
12
|
module Clearance
|
13
|
+
# @deprecated Use `Gem::Specification` API if you need to access Clearance's
|
14
|
+
# Gem root.
|
13
15
|
def self.root
|
14
16
|
warn "#{Kernel.caller.first}: [DEPRECATION] `Clearance.root` is " +
|
15
17
|
"deprecated and will be removed in the next major release. If you need " +
|
@@ -23,7 +23,7 @@ module Clearance
|
|
23
23
|
if File.exist? "app/models/user.rb"
|
24
24
|
inject_into_file(
|
25
25
|
"app/models/user.rb",
|
26
|
-
"include Clearance::User\n\n",
|
26
|
+
" include Clearance::User\n\n",
|
27
27
|
after: "class User < ActiveRecord::Base\n"
|
28
28
|
)
|
29
29
|
else
|
@@ -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.
|
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,6 +1,6 @@
|
|
1
|
-
class AddClearanceToUsers < ActiveRecord::Migration
|
1
|
+
class AddClearanceToUsers < ActiveRecord::Migration<%= migration_version %>
|
2
2
|
def self.up
|
3
|
-
change_table :users
|
3
|
+
change_table :users do |t|
|
4
4
|
<% config[:new_columns].values.each do |column| -%>
|
5
5
|
<%= column %>
|
6
6
|
<% end -%>
|
@@ -24,7 +24,7 @@ class AddClearanceToUsers < ActiveRecord::Migration
|
|
24
24
|
def self.down
|
25
25
|
change_table :users do |t|
|
26
26
|
<% if config[:new_columns].any? -%>
|
27
|
-
t.remove <%= new_columns.keys.map { |column| ":#{column}" }.join(",") %>
|
27
|
+
t.remove <%= new_columns.keys.map { |column| ":#{column}" }.join(", ") %>
|
28
28
|
<% end -%>
|
29
29
|
end
|
30
30
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
class CreateUsers < ActiveRecord::Migration
|
1
|
+
class CreateUsers < ActiveRecord::Migration<%= migration_version %>
|
2
2
|
def change
|
3
|
-
create_table :users
|
3
|
+
create_table :users do |t|
|
4
4
|
t.timestamps null: false
|
5
5
|
t.string :email, null: false
|
6
6
|
t.string :encrypted_password, limit: 128, null: false
|
@@ -9,6 +9,14 @@ module Clearance
|
|
9
9
|
route(clearance_routes)
|
10
10
|
end
|
11
11
|
|
12
|
+
def disable_clearance_internal_routes
|
13
|
+
inject_into_file(
|
14
|
+
"config/initializers/clearance.rb",
|
15
|
+
" config.routes = false\n",
|
16
|
+
after: "Clearance.configure do |config|\n",
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
12
20
|
private
|
13
21
|
|
14
22
|
def clearance_routes
|
@@ -18,6 +26,21 @@ module Clearance
|
|
18
26
|
def routes_file_path
|
19
27
|
File.expand_path(find_in_source_paths('routes.rb'))
|
20
28
|
end
|
29
|
+
|
30
|
+
def route(routing_code)
|
31
|
+
log :route, "all clearance routes"
|
32
|
+
sentinel = /\.routes\.draw do\s*\n/m
|
33
|
+
|
34
|
+
in_root do
|
35
|
+
inject_into_file(
|
36
|
+
"config/routes.rb",
|
37
|
+
routing_code,
|
38
|
+
after: sentinel,
|
39
|
+
verbose: false,
|
40
|
+
force: true,
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
21
44
|
end
|
22
45
|
end
|
23
46
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
resources :passwords, controller:
|
2
|
-
resource :session, controller:
|
1
|
+
resources :passwords, controller: "clearance/passwords", only: [:create, :new]
|
2
|
+
resource :session, controller: "clearance/sessions", only: [:create]
|
3
3
|
|
4
|
-
resources :users, controller:
|
4
|
+
resources :users, controller: "clearance/users", only: [:create] do
|
5
5
|
resource :password,
|
6
|
-
controller:
|
6
|
+
controller: "clearance/passwords",
|
7
7
|
only: [:create, :edit, :update]
|
8
8
|
end
|
9
9
|
|
10
|
-
get
|
11
|
-
delete
|
12
|
-
get
|
10
|
+
get "/sign_in" => "clearance/sessions#new", as: "sign_in"
|
11
|
+
delete "/sign_out" => "clearance/sessions#destroy", as: "sign_out"
|
12
|
+
get "/sign_up" => "clearance/users#new", as: "sign_up"
|
data/lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt
CHANGED
@@ -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
|
@@ -47,7 +56,8 @@ feature "Visitor resets password" do
|
|
47
56
|
message = ActionMailer::Base.deliveries.any? do |email|
|
48
57
|
email.to == [recipient] &&
|
49
58
|
email.subject =~ /#{subject}/i &&
|
50
|
-
email.body =~ /#{body}/
|
59
|
+
email.html_part.body =~ /#{body}/ &&
|
60
|
+
email.text_part.body =~ /#{body}/
|
51
61
|
end
|
52
62
|
|
53
63
|
expect(message).to be
|
data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_in_spec.rb.tt
CHANGED
@@ -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"
|
data/lib/generators/clearance/specs/templates/features/clearance/visitor_updates_password_spec.rb.tt
CHANGED
@@ -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"
|
@@ -10,6 +10,7 @@ describe "Clearance Installation" do
|
|
10
10
|
|
11
11
|
it "can successfully run specs" do
|
12
12
|
app_name = "testapp"
|
13
|
+
|
13
14
|
generate_test_app(app_name)
|
14
15
|
|
15
16
|
Dir.chdir(app_name) do
|
@@ -28,7 +29,8 @@ describe "Clearance Installation" do
|
|
28
29
|
--skip-git \
|
29
30
|
--skip-javascript \
|
30
31
|
--skip-sprockets \
|
31
|
-
--skip-keeps
|
32
|
+
--skip-keeps \
|
33
|
+
--no-rc"
|
32
34
|
|
33
35
|
FileUtils.rm_f("public/index.html")
|
34
36
|
FileUtils.rm_f("app/views/layouts/application.html.erb")
|
@@ -70,6 +72,7 @@ describe "Clearance Installation" do
|
|
70
72
|
end
|
71
73
|
|
72
74
|
return_value = system("#{command} #{silencer}")
|
75
|
+
|
73
76
|
expect(return_value).to eq true
|
74
77
|
end
|
75
78
|
end
|
@@ -2,21 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Clearance::RackSession do
|
4
4
|
it 'injects a clearance session into the environment' do
|
5
|
-
expected_session = 'the session'
|
6
|
-
allow(expected_session).to receive(:add_cookie_to_headers)
|
7
|
-
allow(Clearance::Session).to receive(:new).and_return(expected_session)
|
8
5
|
headers = { 'X-Roaring-Lobster' => 'Red' }
|
9
|
-
|
10
6
|
app = Rack::Builder.new do
|
11
7
|
use Clearance::RackSession
|
12
8
|
run lambda { |env| Rack::Response.new(env[:clearance], 200, headers).finish }
|
13
9
|
end
|
14
10
|
|
15
11
|
env = Rack::MockRequest.env_for('/')
|
12
|
+
expected_session = "the session"
|
13
|
+
allow(expected_session).to receive(:add_cookie_to_headers)
|
14
|
+
allow(Clearance::Session).to receive(:new).
|
15
|
+
with(env).
|
16
|
+
and_return(expected_session)
|
16
17
|
|
17
18
|
response = Rack::MockResponse.new(*app.call(env))
|
18
19
|
|
19
|
-
expect(Clearance::Session).to have_received(:new).with(env)
|
20
20
|
expect(response.body).to eq expected_session
|
21
21
|
expect(expected_session).to have_received(:add_cookie_to_headers).
|
22
22
|
with(hash_including(headers))
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Clearance::Testing::
|
3
|
+
describe Clearance::Testing::ControllerHelpers do
|
4
4
|
class TestClass
|
5
|
-
include Clearance::Testing::
|
5
|
+
include Clearance::Testing::ControllerHelpers
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
|
16
|
-
describe
|
17
|
-
it
|
16
|
+
describe "#sign_in" do
|
17
|
+
it "creates an instance of the clearance user model with FactoryGirl" do
|
18
18
|
MyUserModel = Class.new
|
19
19
|
allow(FactoryGirl).to receive(:create)
|
20
20
|
allow(Clearance.configuration).to receive(:user_model).
|
@@ -26,8 +26,8 @@ describe Clearance::Testing::Helpers do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
30
|
-
it
|
29
|
+
describe "#sign_in_as" do
|
30
|
+
it "returns the user if signed in successfully" do
|
31
31
|
user = build(:user)
|
32
32
|
|
33
33
|
returned_user = TestClass.new.sign_in_as user
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Clearance::Testing::ViewHelpers do
|
4
|
+
describe "#sign_in" do
|
5
|
+
it "sets the signed in user to a new user object" do
|
6
|
+
user_model = Class.new
|
7
|
+
allow(Clearance.configuration).to receive(:user_model).
|
8
|
+
and_return(user_model)
|
9
|
+
|
10
|
+
view = test_view_class.new
|
11
|
+
view.sign_in
|
12
|
+
|
13
|
+
expect(view.current_user).to be_an_instance_of(user_model)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#sign_in_as" do
|
18
|
+
it "sets the signed in user to the object provided" do
|
19
|
+
user = double("User")
|
20
|
+
|
21
|
+
view = test_view_class.new
|
22
|
+
view.sign_in_as(user)
|
23
|
+
|
24
|
+
expect(view.current_user).to eq user
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_view_class
|
29
|
+
Class.new do
|
30
|
+
include Clearance::Testing::ViewHelpers
|
31
|
+
|
32
|
+
def view
|
33
|
+
@view ||= extend Clearance::Testing::ViewHelpers::CurrentUser
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -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)
|
@@ -162,4 +171,19 @@ describe Clearance::Configuration do
|
|
162
171
|
expect(Clearance.configuration.routes_enabled?).to be false
|
163
172
|
end
|
164
173
|
end
|
174
|
+
|
175
|
+
describe "#reload_user_model" do
|
176
|
+
it "returns the user model class if one has already been configured" do
|
177
|
+
ConfiguredUser = Class.new
|
178
|
+
Clearance.configure { |config| config.user_model = ConfiguredUser }
|
179
|
+
|
180
|
+
expect(Clearance.configuration.reload_user_model).to eq ConfiguredUser
|
181
|
+
end
|
182
|
+
|
183
|
+
it "returns nil if the user_model has not been configured" do
|
184
|
+
Clearance.configuration = Clearance::Configuration.new
|
185
|
+
|
186
|
+
expect(Clearance.configuration.reload_user_model).to be_nil
|
187
|
+
end
|
188
|
+
end
|
165
189
|
end
|
@@ -3,10 +3,14 @@ require 'spec_helper'
|
|
3
3
|
class ApisController < ActionController::Base
|
4
4
|
include Clearance::Controller
|
5
5
|
|
6
|
-
|
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
|
-
|
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
|
-
|
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
|
@@ -101,16 +101,6 @@ describe Clearance::PasswordsController do
|
|
101
101
|
expect(user.reload.encrypted_password).not_to eq old_encrypted_password
|
102
102
|
end
|
103
103
|
|
104
|
-
it "sets the remember token and clears the confirmation token" do
|
105
|
-
user = create(:user, :with_forgotten_password)
|
106
|
-
|
107
|
-
put :update, update_parameters(user, new_password: "my_new_password")
|
108
|
-
|
109
|
-
user.reload
|
110
|
-
expect(user.remember_token).not_to be_nil
|
111
|
-
expect(user.confirmation_token).to be_nil
|
112
|
-
end
|
113
|
-
|
114
104
|
it "signs the user in and redirects" do
|
115
105
|
user = create(:user, :with_forgotten_password)
|
116
106
|
|
@@ -121,7 +111,7 @@ describe Clearance::PasswordsController do
|
|
121
111
|
end
|
122
112
|
end
|
123
113
|
|
124
|
-
context "
|
114
|
+
context "password update fails" do
|
125
115
|
it "does not update the password" do
|
126
116
|
user = create(:user, :with_forgotten_password)
|
127
117
|
old_encrypted_password = user.encrypted_password
|
@@ -3,14 +3,18 @@ require 'spec_helper'
|
|
3
3
|
class PermissionsController < ActionController::Base
|
4
4
|
include Clearance::Controller
|
5
5
|
|
6
|
-
|
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
|
-
|
13
|
+
head :ok
|
10
14
|
end
|
11
15
|
|
12
16
|
def show
|
13
|
-
|
17
|
+
head :ok
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
@@ -54,6 +58,12 @@ describe PermissionsController do
|
|
54
58
|
|
55
59
|
expect(subject).to deny_access(redirect: sign_in_url)
|
56
60
|
end
|
61
|
+
|
62
|
+
it "denies access to show and display a flash message" do
|
63
|
+
get :show
|
64
|
+
|
65
|
+
expect(flash[:notice]).to match(/^Please sign in to continue/)
|
66
|
+
end
|
57
67
|
end
|
58
68
|
|
59
69
|
context 'when remember_token is blank' do
|
@@ -9,7 +9,7 @@ describe Clearance::SessionsController do
|
|
9
9
|
|
10
10
|
it { should respond_with(:success) }
|
11
11
|
it { should render_template(:new) }
|
12
|
-
it { should_not
|
12
|
+
it { should_not set_flash }
|
13
13
|
end
|
14
14
|
|
15
15
|
context "when a user is signed in" do
|
@@ -19,7 +19,7 @@ describe Clearance::SessionsController do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it { should redirect_to(Clearance.configuration.redirect_url) }
|
22
|
-
it { should_not
|
22
|
+
it { should_not set_flash }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -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(
|
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(
|
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
|
-
|
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
|
data/spec/dummy/application.rb
CHANGED
@@ -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
|
-
|
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
|
@@ -4,14 +4,18 @@ require "generators/clearance/routes/routes_generator"
|
|
4
4
|
describe Clearance::Generators::RoutesGenerator, :generator do
|
5
5
|
it "adds clearance routes to host application routes" do
|
6
6
|
provide_existing_routes_file
|
7
|
+
provide_existing_initializer
|
7
8
|
|
8
9
|
routes = file("config/routes.rb")
|
10
|
+
initializer = file("config/initializers/clearance.rb")
|
9
11
|
|
10
12
|
run_generator
|
11
13
|
|
14
|
+
expect(initializer).to have_correct_syntax
|
15
|
+
expect(initializer).to contain("config.routes = false")
|
12
16
|
expect(routes).to have_correct_syntax
|
13
17
|
expect(routes).to contain(
|
14
|
-
|
18
|
+
'get "/sign_in" => "clearance/sessions#new", as: "sign_in"'
|
15
19
|
)
|
16
20
|
end
|
17
21
|
end
|
@@ -6,18 +6,19 @@ describe Clearance::Generators::ViewsGenerator, :generator do
|
|
6
6
|
run_generator
|
7
7
|
|
8
8
|
views = %w(
|
9
|
-
clearance_mailer/change_password
|
10
|
-
|
11
|
-
|
12
|
-
passwords/
|
13
|
-
passwords/
|
14
|
-
|
15
|
-
sessions/
|
16
|
-
|
17
|
-
users/
|
9
|
+
clearance_mailer/change_password.html.erb
|
10
|
+
clearance_mailer/change_password.text.erb
|
11
|
+
layouts/application.html.erb
|
12
|
+
passwords/create.html.erb
|
13
|
+
passwords/edit.html.erb
|
14
|
+
passwords/new.html.erb
|
15
|
+
sessions/_form.html.erb
|
16
|
+
sessions/new.html.erb
|
17
|
+
users/_form.html.erb
|
18
|
+
users/new.html.erb
|
18
19
|
)
|
19
20
|
|
20
|
-
view_files = views.map { |view| file("app/views/#{view}
|
21
|
+
view_files = views.map { |view| file("app/views/#{view}") }
|
21
22
|
|
22
23
|
view_files.each do |each|
|
23
24
|
expect(each).to exist
|