clearance 1.14.0 → 1.14.1
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/Gemfile.lock +3 -3
- data/NEWS.md +10 -0
- data/README.md +15 -15
- data/lib/clearance/controller.rb +1 -1
- data/lib/clearance/testing/deny_access_matcher.rb +1 -1
- data/lib/clearance/version.rb +1 -1
- data/lib/generators/clearance/install/install_generator.rb +1 -1
- data/spec/app_templates/app/models/rails5/user.rb +5 -0
- data/spec/configuration_spec.rb +44 -84
- data/spec/generators/clearance/install/install_generator_spec.rb +14 -0
- data/spec/support/generator_spec_helpers.rb +9 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 388172ea597e347bdc3de456ef71b97a3b2cedba
|
4
|
+
data.tar.gz: 35009502fecdd3eac14aff84850a3f32edb05594
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05b2d5f2d0c369a99a37f34962f7772a6f0a5af66aa29e8761b40e159fc8c21921cfb50893529eb7b6b92c4c2a9ee45fbe342fa23f64b4661181838c8651bff8
|
7
|
+
data.tar.gz: 72e86acac7f47f097775b42f443171812bcc1e274d9d8aa96e3fe439926bfb87fec00364a69a8618ac10c79e220c2c2dd6a085345a54aa022d381f8db4e9a35d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
clearance (1.14.
|
4
|
+
clearance (1.14.1)
|
5
5
|
bcrypt
|
6
6
|
email_validator (~> 1.4)
|
7
7
|
rails (>= 3.1)
|
@@ -56,7 +56,7 @@ GEM
|
|
56
56
|
arel (6.0.3)
|
57
57
|
bcrypt (3.1.11)
|
58
58
|
builder (3.2.2)
|
59
|
-
capybara (2.7.
|
59
|
+
capybara (2.7.1)
|
60
60
|
addressable
|
61
61
|
mime-types (>= 1.16)
|
62
62
|
nokogiri (>= 1.3.3)
|
@@ -64,7 +64,7 @@ GEM
|
|
64
64
|
rack-test (>= 0.5.4)
|
65
65
|
xpath (~> 2.0)
|
66
66
|
coderay (1.1.1)
|
67
|
-
concurrent-ruby (1.0.
|
67
|
+
concurrent-ruby (1.0.2)
|
68
68
|
database_cleaner (1.5.3)
|
69
69
|
diff-lcs (1.2.5)
|
70
70
|
email_validator (1.6.0)
|
data/NEWS.md
CHANGED
@@ -3,6 +3,16 @@
|
|
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.14.1] - May 12, 2016
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- Fixed insertion of `include Clearance::User` when running the install
|
10
|
+
generator in an app that already has a `User` model.
|
11
|
+
- Updated `deny_access` matcher to assert against configured redirect location
|
12
|
+
rather than hard coded `/`.
|
13
|
+
|
14
|
+
[1.14.1]: https://github.com/thoughtbot/clearance/compare/v1.14.0...v1.14.1
|
15
|
+
|
6
16
|
## [1.14.0] - April 29, 2016
|
7
17
|
|
8
18
|
### Added
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Clearance is a Rails engine tested against Rails `>= 3.2` and Ruby `>= 1.9.3`.
|
|
23
23
|
You can add it to your Gemfile with:
|
24
24
|
|
25
25
|
```sh
|
26
|
-
gem
|
26
|
+
gem "clearance"
|
27
27
|
```
|
28
28
|
|
29
29
|
Run the bundle command to install it.
|
@@ -49,15 +49,15 @@ Override any of these defaults in `config/initializers/clearance.rb`:
|
|
49
49
|
```ruby
|
50
50
|
Clearance.configure do |config|
|
51
51
|
config.allow_sign_up = true
|
52
|
-
config.cookie_domain =
|
52
|
+
config.cookie_domain = ".example.com"
|
53
53
|
config.cookie_expiration = lambda { |cookies| 1.year.from_now.utc }
|
54
|
-
config.cookie_name =
|
55
|
-
config.cookie_path =
|
54
|
+
config.cookie_name = "remember_token"
|
55
|
+
config.cookie_path = "/"
|
56
56
|
config.routes = true
|
57
57
|
config.httponly = false
|
58
|
-
config.mailer_sender =
|
58
|
+
config.mailer_sender = "reply@example.com"
|
59
59
|
config.password_strategy = Clearance::PasswordStrategies::BCrypt
|
60
|
-
config.redirect_url =
|
60
|
+
config.redirect_url = "/"
|
61
61
|
config.secure_cookie = false
|
62
62
|
config.sign_in_guards = []
|
63
63
|
config.user_model = User
|
@@ -86,15 +86,15 @@ at the routing layer:
|
|
86
86
|
```ruby
|
87
87
|
Blog::Application.routes.draw do
|
88
88
|
constraints Clearance::Constraints::SignedIn.new { |user| user.admin? } do
|
89
|
-
root to:
|
89
|
+
root to: "admin/dashboards#show", as: :admin_root
|
90
90
|
end
|
91
91
|
|
92
92
|
constraints Clearance::Constraints::SignedIn.new do
|
93
|
-
root to:
|
93
|
+
root to: "dashboards#show", as: :signed_in_root
|
94
94
|
end
|
95
95
|
|
96
96
|
constraints Clearance::Constraints::SignedOut.new do
|
97
|
-
root to:
|
97
|
+
root to: "marketing#index"
|
98
98
|
end
|
99
99
|
end
|
100
100
|
```
|
@@ -120,7 +120,7 @@ should change the `mailer_sender` default, used in the email's "from" header:
|
|
120
120
|
|
121
121
|
```ruby
|
122
122
|
Clearance.configure do |config|
|
123
|
-
config.mailer_sender =
|
123
|
+
config.mailer_sender = "reply@example.com"
|
124
124
|
end
|
125
125
|
```
|
126
126
|
|
@@ -223,9 +223,9 @@ to change the layout that Clearance uses when rendering its views, simply
|
|
223
223
|
specify the layout in an initializer.
|
224
224
|
|
225
225
|
```ruby
|
226
|
-
Clearance::PasswordsController.layout
|
227
|
-
Clearance::SessionsController.layout
|
228
|
-
Clearance::UsersController.layout
|
226
|
+
Clearance::PasswordsController.layout "my_passwords_layout"
|
227
|
+
Clearance::SessionsController.layout "my_sessions_layout"
|
228
|
+
Clearance::UsersController.layout "my_admin_layout"
|
229
229
|
```
|
230
230
|
|
231
231
|
### Translations
|
@@ -372,13 +372,13 @@ For `rspec`, add the following line to your `spec/rails_helper.rb` or
|
|
372
372
|
`spec/spec_helper` if `rails_helper` does not exist:
|
373
373
|
|
374
374
|
```ruby
|
375
|
-
require
|
375
|
+
require "clearance/rspec"
|
376
376
|
```
|
377
377
|
|
378
378
|
For `test-unit`, add this line to your `test/test_helper.rb`:
|
379
379
|
|
380
380
|
```ruby
|
381
|
-
require
|
381
|
+
require "clearance/test_unit"
|
382
382
|
```
|
383
383
|
|
384
384
|
This will make `Clearance::Controller` methods work in your controllers
|
data/lib/clearance/controller.rb
CHANGED
@@ -11,7 +11,7 @@ module Clearance
|
|
11
11
|
# The `clearance:install` generator automatically adds this mixin to
|
12
12
|
# `ApplicationController`, which is the recommended configuration.
|
13
13
|
#
|
14
|
-
# class ApplicationController <
|
14
|
+
# class ApplicationController < ActionController::Base
|
15
15
|
# include Clearance::Controller
|
16
16
|
# end
|
17
17
|
#
|
data/lib/clearance/version.rb
CHANGED
data/spec/configuration_spec.rb
CHANGED
@@ -1,143 +1,103 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Clearance::Configuration do
|
4
4
|
after { restore_default_config }
|
5
5
|
|
6
|
-
context
|
7
|
-
|
8
|
-
Clearance.configure do |config|
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'defaults to User' do
|
6
|
+
context "when no user_model_name is specified" do
|
7
|
+
it "defaults to User" do
|
13
8
|
expect(Clearance.configuration.user_model).to eq ::User
|
14
9
|
end
|
15
10
|
end
|
16
11
|
|
17
|
-
context
|
18
|
-
|
12
|
+
context "when a custom user_model_name is specified" do
|
13
|
+
it "is used instead of User" do
|
19
14
|
MyUser = Class.new
|
15
|
+
Clearance.configure { |config| config.user_model = MyUser }
|
20
16
|
|
21
|
-
Clearance.configure do |config|
|
22
|
-
config.user_model = MyUser
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'is used instead of User' do
|
27
17
|
expect(Clearance.configuration.user_model).to eq ::MyUser
|
28
18
|
end
|
29
19
|
end
|
30
20
|
|
31
|
-
context
|
32
|
-
|
33
|
-
Clearance.configure
|
34
|
-
config.secure_cookie = true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'returns true' do
|
21
|
+
context "when secure_cookie is set to true" do
|
22
|
+
it "returns true" do
|
23
|
+
Clearance.configure { |config| config.secure_cookie = true }
|
39
24
|
expect(Clearance.configuration.secure_cookie).to eq true
|
40
25
|
end
|
41
26
|
end
|
42
27
|
|
43
|
-
context
|
44
|
-
|
45
|
-
Clearance.configure do |config|
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'defaults to false' do
|
28
|
+
context "when secure_cookie is not specified" do
|
29
|
+
it "defaults to false" do
|
50
30
|
expect(Clearance.configuration.secure_cookie).to eq false
|
51
31
|
end
|
52
32
|
end
|
53
33
|
|
54
|
-
context
|
34
|
+
context "when no redirect URL specified" do
|
55
35
|
it 'returns "/" as redirect URL' do
|
56
|
-
expect(Clearance::Configuration.new.redirect_url).to eq
|
36
|
+
expect(Clearance::Configuration.new.redirect_url).to eq "/"
|
57
37
|
end
|
58
38
|
end
|
59
39
|
|
60
|
-
context
|
61
|
-
|
40
|
+
context "when redirect URL is specified" do
|
41
|
+
it "returns new redirect URL" do
|
42
|
+
new_redirect_url = "/admin"
|
43
|
+
Clearance.configure { |config| config.redirect_url = new_redirect_url }
|
62
44
|
|
63
|
-
before do
|
64
|
-
Clearance.configure do |config|
|
65
|
-
config.redirect_url = new_redirect_url
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'returns new redirect URL' do
|
70
45
|
expect(Clearance.configuration.redirect_url).to eq new_redirect_url
|
71
46
|
end
|
72
47
|
end
|
73
48
|
|
74
|
-
context
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
Clearance.configure do |config|
|
79
|
-
config.sign_in_guards = [DummyGuard]
|
80
|
-
end
|
81
|
-
end
|
49
|
+
context "when specifying sign in guards" do
|
50
|
+
it "returns the stack with added guards" do
|
51
|
+
DummyGuard = Class.new
|
52
|
+
Clearance.configure { |config| config.sign_in_guards = [DummyGuard] }
|
82
53
|
|
83
|
-
it 'returns the stack with added guards' do
|
84
54
|
expect(Clearance.configuration.sign_in_guards).to eq [DummyGuard]
|
85
55
|
end
|
86
56
|
end
|
87
57
|
|
88
|
-
context
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
Clearance.configure do |config|
|
93
|
-
config.cookie_domain = domain
|
94
|
-
end
|
95
|
-
end
|
58
|
+
context "when cookie domain is specified" do
|
59
|
+
it "returns configured value" do
|
60
|
+
domain = ".example.com"
|
61
|
+
Clearance.configure { |config| config.cookie_domain = domain }
|
96
62
|
|
97
|
-
it 'returns configured value' do
|
98
63
|
expect(Clearance.configuration.cookie_domain).to eq domain
|
99
64
|
end
|
100
65
|
end
|
101
66
|
|
102
|
-
context
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
Clearance.configure do |config|
|
107
|
-
config.cookie_path = path
|
108
|
-
end
|
109
|
-
end
|
67
|
+
context "when cookie path is specified" do
|
68
|
+
it "returns configured value" do
|
69
|
+
path = "/user"
|
70
|
+
Clearance.configure { |config| config.cookie_path = path }
|
110
71
|
|
111
|
-
it 'returns configured value' do
|
112
72
|
expect(Clearance.configuration.cookie_path).to eq path
|
113
73
|
end
|
114
74
|
end
|
115
75
|
|
116
|
-
describe
|
117
|
-
context
|
118
|
-
it
|
76
|
+
describe "#allow_sign_up?" do
|
77
|
+
context "when allow_sign_up is configured to false" do
|
78
|
+
it "returns false" do
|
119
79
|
Clearance.configure { |config| config.allow_sign_up = false }
|
120
80
|
expect(Clearance.configuration.allow_sign_up?).to eq false
|
121
81
|
end
|
122
82
|
end
|
123
83
|
|
124
|
-
context
|
125
|
-
it
|
84
|
+
context "when allow_sign_up has not been configured" do
|
85
|
+
it "returns true" do
|
126
86
|
expect(Clearance.configuration.allow_sign_up?).to eq true
|
127
87
|
end
|
128
88
|
end
|
129
89
|
end
|
130
90
|
|
131
|
-
describe
|
132
|
-
context
|
133
|
-
it
|
91
|
+
describe "#user_actions" do
|
92
|
+
context "when allow_sign_up is configured to false" do
|
93
|
+
it "returns empty array" do
|
134
94
|
Clearance.configure { |config| config.allow_sign_up = false }
|
135
95
|
expect(Clearance.configuration.user_actions).to eq []
|
136
96
|
end
|
137
97
|
end
|
138
98
|
|
139
|
-
context
|
140
|
-
it
|
99
|
+
context "when sign_up has not been configured" do
|
100
|
+
it "returns create" do
|
141
101
|
expect(Clearance.configuration.user_actions).to eq [:create]
|
142
102
|
end
|
143
103
|
end
|
@@ -152,8 +112,8 @@ describe Clearance::Configuration do
|
|
152
112
|
end
|
153
113
|
end
|
154
114
|
|
155
|
-
describe
|
156
|
-
it
|
115
|
+
describe "#user_id_parameter" do
|
116
|
+
it "returns the parameter key to use based on the user_model" do
|
157
117
|
CustomUser = Class.new(ActiveRecord::Base)
|
158
118
|
Clearance.configure { |config| config.user_model = CustomUser }
|
159
119
|
|
@@ -161,12 +121,12 @@ describe Clearance::Configuration do
|
|
161
121
|
end
|
162
122
|
end
|
163
123
|
|
164
|
-
describe
|
165
|
-
it
|
124
|
+
describe "#routes_enabled?" do
|
125
|
+
it "is true by default" do
|
166
126
|
expect(Clearance.configuration.routes_enabled?).to be true
|
167
127
|
end
|
168
128
|
|
169
|
-
it
|
129
|
+
it "is false when routes are set to false" do
|
170
130
|
Clearance.configure { |config| config.routes = false }
|
171
131
|
expect(Clearance.configuration.routes_enabled?).to be false
|
172
132
|
end
|
@@ -37,6 +37,7 @@ describe Clearance::Generators::InstallGenerator, :generator do
|
|
37
37
|
|
38
38
|
expect(user_class).to exist
|
39
39
|
expect(user_class).to have_correct_syntax
|
40
|
+
expect(user_class).to contain_models_inherit_from
|
40
41
|
expect(user_class).to contain("include Clearance::User")
|
41
42
|
end
|
42
43
|
end
|
@@ -51,6 +52,7 @@ describe Clearance::Generators::InstallGenerator, :generator do
|
|
51
52
|
|
52
53
|
expect(user_class).to exist
|
53
54
|
expect(user_class).to have_correct_syntax
|
55
|
+
expect(user_class).to contain_models_inherit_from
|
54
56
|
expect(user_class).to contain("include Clearance::User")
|
55
57
|
expect(user_class).to have_method("previously_existed?")
|
56
58
|
end
|
@@ -127,4 +129,16 @@ describe Clearance::Generators::InstallGenerator, :generator do
|
|
127
129
|
and_return(false)
|
128
130
|
end
|
129
131
|
end
|
132
|
+
|
133
|
+
def contain_models_inherit_from
|
134
|
+
contain "< #{models_inherit_from}\n"
|
135
|
+
end
|
136
|
+
|
137
|
+
def models_inherit_from
|
138
|
+
if Rails.version >= "5.0.0"
|
139
|
+
"ApplicationRecord"
|
140
|
+
else
|
141
|
+
"ActiveRecord::Base"
|
142
|
+
end
|
143
|
+
end
|
130
144
|
end
|
@@ -18,7 +18,7 @@ module GeneratorSpecHelpers
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def provide_existing_user_class
|
21
|
-
copy_to_generator_root("app/models", "user.rb")
|
21
|
+
copy_to_generator_root("app/models", versionize_template("user.rb"))
|
22
22
|
allow(File).to receive(:exist?).and_call_original
|
23
23
|
allow(File).to receive(:exist?).with("app/models/user.rb").and_return(true)
|
24
24
|
end
|
@@ -32,6 +32,14 @@ module GeneratorSpecHelpers
|
|
32
32
|
FileUtils.mkdir_p(destination)
|
33
33
|
FileUtils.cp(template_file, destination)
|
34
34
|
end
|
35
|
+
|
36
|
+
def versionize_template(template_file)
|
37
|
+
if Rails.version >= "5.0.0"
|
38
|
+
template_file = ["rails5", template_file].join("/")
|
39
|
+
end
|
40
|
+
|
41
|
+
template_file
|
42
|
+
end
|
35
43
|
end
|
36
44
|
|
37
45
|
RSpec.configure do |config|
|
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.14.
|
4
|
+
version: 1.14.1
|
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-
|
28
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
29
29
|
dependencies:
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bcrypt
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- lib/generators/clearance/views/views_generator.rb
|
170
170
|
- spec/acceptance/clearance_installation_spec.rb
|
171
171
|
- spec/app_templates/app/controllers/application_controller.rb
|
172
|
+
- spec/app_templates/app/models/rails5/user.rb
|
172
173
|
- spec/app_templates/app/models/user.rb
|
173
174
|
- spec/app_templates/config/initializers/clearance.rb
|
174
175
|
- spec/app_templates/config/routes.rb
|