authorizy 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +92 -10
- data/lib/authorizy/base_cop.rb +3 -3
- data/lib/authorizy/config.rb +2 -2
- data/lib/authorizy/core.rb +34 -21
- data/lib/authorizy/expander.rb +15 -16
- data/lib/authorizy/extension.rb +20 -5
- data/lib/authorizy/rspec.rb +44 -0
- data/lib/authorizy/version.rb +1 -1
- data/spec/authorizy/base_cop/access_question_spec.rb +2 -1
- data/spec/authorizy/config/aliases_spec.rb +2 -2
- data/spec/authorizy/config/cop_spec.rb +2 -2
- data/spec/authorizy/config/current_user_spec.rb +4 -4
- data/spec/authorizy/config/dependencies_spec.rb +2 -2
- data/spec/authorizy/config/initialize_spec.rb +1 -1
- data/spec/authorizy/config/redirect_url_spec.rb +4 -4
- data/spec/authorizy/cop/controller_spec.rb +1 -2
- data/spec/authorizy/cop/model_spec.rb +7 -6
- data/spec/authorizy/cop/namespaced_controller_spec.rb +1 -2
- data/spec/authorizy/core/access_spec.rb +57 -83
- data/spec/authorizy/expander/expand_spec.rb +41 -46
- data/spec/authorizy/extension/authorizy_question_spec.rb +14 -10
- data/spec/authorizy/extension/authorizy_spec.rb +14 -2
- data/spec/common_helper.rb +2 -0
- data/spec/spec_helper.rb +3 -3
- data/spec/support/coverage.rb +5 -1
- data/spec/support/models/authorizy_cop.rb +5 -5
- data/spec/support/schema.rb +1 -1
- metadata +69 -26
@@ -12,32 +12,36 @@ RSpec.describe DummyController, '#authorizy?', type: :controller do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'when config returns current user' do
|
15
|
-
let!(:
|
16
|
-
let!(:
|
15
|
+
let!(:config) { Authorizy.config }
|
16
|
+
let!(:user) { User.new }
|
17
|
+
|
18
|
+
before { allow(Authorizy).to receive(:config).and_return(config) }
|
17
19
|
|
18
20
|
context 'when authorizy returns false' do
|
19
|
-
let!(:
|
21
|
+
let!(:core) { instance_double('Authorizy::Core', access?: false) }
|
22
|
+
let!(:parameters) { ActionController::Parameters.new(controller: 'controller', action: 'action') }
|
20
23
|
|
21
24
|
it 'returns false' do
|
22
25
|
allow(Authorizy::Core).to receive(:new)
|
23
|
-
.with(
|
24
|
-
.and_return(
|
26
|
+
.with(user, parameters, session, cop: config.cop)
|
27
|
+
.and_return(core)
|
25
28
|
|
26
|
-
config_mock(current_user:
|
29
|
+
config_mock(current_user: user) do
|
27
30
|
expect(controller.helpers.authorizy?('controller', 'action')).to be(false)
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
35
|
context 'when authorizy returns true' do
|
33
|
-
let!(:
|
36
|
+
let!(:core) { instance_double('Authorizy::Core', access?: true) }
|
37
|
+
let!(:parameters) { ActionController::Parameters.new(controller: 'controller', action: 'action') }
|
34
38
|
|
35
39
|
it 'returns true' do
|
36
40
|
allow(Authorizy::Core).to receive(:new)
|
37
|
-
.with(
|
38
|
-
.and_return(
|
41
|
+
.with(user, parameters, session, cop: config.cop)
|
42
|
+
.and_return(core)
|
39
43
|
|
40
|
-
config_mock(current_user:
|
44
|
+
config_mock(current_user: user) do
|
41
45
|
expect(controller.helpers.authorizy?('controller', 'action')).to be(true)
|
42
46
|
end
|
43
47
|
end
|
@@ -3,12 +3,20 @@
|
|
3
3
|
require 'support/controllers/dummy_controller'
|
4
4
|
|
5
5
|
RSpec.describe DummyController, '#authorizy', type: :controller do
|
6
|
+
let!(:config) { Authorizy.config }
|
6
7
|
let!(:parameters) { ActionController::Parameters.new(key: 'value', controller: 'dummy', action: 'action') }
|
8
|
+
let!(:user) { nil }
|
9
|
+
|
10
|
+
before { allow(Authorizy).to receive(:config).and_return(config) }
|
7
11
|
|
8
12
|
context 'when user has access' do
|
9
13
|
let!(:authorizy_core) { instance_double('Authorizy::Core', access?: true) }
|
10
14
|
|
11
|
-
before
|
15
|
+
before do
|
16
|
+
allow(Authorizy::Core).to receive(:new)
|
17
|
+
.with(user, parameters, session, cop: config.cop)
|
18
|
+
.and_return(authorizy_core)
|
19
|
+
end
|
12
20
|
|
13
21
|
context 'when is a xhr request' do
|
14
22
|
it 'receives the default values and do not denied the access' do
|
@@ -32,7 +40,11 @@ RSpec.describe DummyController, '#authorizy', type: :controller do
|
|
32
40
|
context 'when user has no access' do
|
33
41
|
let!(:authorizy_core) { instance_double('Authorizy::Core', access?: false) }
|
34
42
|
|
35
|
-
before
|
43
|
+
before do
|
44
|
+
allow(Authorizy::Core).to receive(:new)
|
45
|
+
.with(user, parameters, session, cop: config.cop)
|
46
|
+
.and_return(authorizy_core)
|
47
|
+
end
|
36
48
|
|
37
49
|
context 'when is a xhr request' do
|
38
50
|
it 'receives the default values and denied the access' do
|
data/spec/common_helper.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -12,9 +12,9 @@ def config_mock(aliases: nil, cop: nil, current_user: nil, dependencies: nil, re
|
|
12
12
|
Authorizy.configure do |config|
|
13
13
|
config.aliases = aliases if aliases
|
14
14
|
config.cop = cop if cop
|
15
|
-
config.current_user = ->
|
16
|
-
config.dependencies = dependencies
|
17
|
-
config.redirect_url = ->
|
15
|
+
config.current_user = ->(_context) { current_user } if current_user
|
16
|
+
config.dependencies = dependencies if dependencies
|
17
|
+
config.redirect_url = ->(_context) { redirect_url } if redirect_url
|
18
18
|
end
|
19
19
|
|
20
20
|
yield
|
data/spec/support/coverage.rb
CHANGED
@@ -9,6 +9,10 @@ if ENV['COVERAGE'] == 'true'
|
|
9
9
|
SimpleCov.minimum_coverage(ENV.fetch('MINIMUM_COVERAGE', 80).to_i)
|
10
10
|
|
11
11
|
SimpleCov.start('rails') do
|
12
|
-
add_filter
|
12
|
+
add_filter [
|
13
|
+
'/lib/generators',
|
14
|
+
'/vendor',
|
15
|
+
'/lib/authorizy/version.rb',
|
16
|
+
]
|
13
17
|
end
|
14
18
|
end
|
@@ -9,23 +9,23 @@ class AuthorizyCop < Authorizy::BaseCop
|
|
9
9
|
params[:access] == 'true'
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def fetch_action
|
13
13
|
action
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def fetch_controller
|
17
17
|
controller
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def fetch_current_user
|
21
21
|
current_user
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def fetch_params
|
25
25
|
params
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def fetch_session
|
29
29
|
session
|
30
30
|
end
|
31
31
|
end
|
data/spec/support/schema.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authorizy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Washington Botelho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: codecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pg
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,34 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-performance
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: rubocop-rspec
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,6 +154,7 @@ files:
|
|
112
154
|
- lib/authorizy/core.rb
|
113
155
|
- lib/authorizy/expander.rb
|
114
156
|
- lib/authorizy/extension.rb
|
157
|
+
- lib/authorizy/rspec.rb
|
115
158
|
- lib/authorizy/version.rb
|
116
159
|
- lib/generators/authorizy/install_generator.rb
|
117
160
|
- lib/generators/authorizy/templates/config/initializers/authorizy.rb
|
@@ -163,36 +206,36 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
206
|
- !ruby/object:Gem::Version
|
164
207
|
version: '0'
|
165
208
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
209
|
+
rubygems_version: 3.2.22
|
167
210
|
signing_key:
|
168
211
|
specification_version: 4
|
169
212
|
summary: A JSON based Authorization.
|
170
213
|
test_files:
|
171
|
-
- spec/
|
172
|
-
- spec/
|
173
|
-
- spec/
|
174
|
-
- spec/
|
175
|
-
- spec/support/locales/en.yml
|
176
|
-
- spec/support/i18n.rb
|
177
|
-
- spec/support/application.rb
|
178
|
-
- spec/support/models/authorizy_cop.rb
|
179
|
-
- spec/support/models/empty_cop.rb
|
180
|
-
- spec/support/models/user.rb
|
181
|
-
- spec/support/common.rb
|
182
|
-
- spec/support/coverage.rb
|
183
|
-
- spec/support/controllers/dummy_controller.rb
|
184
|
-
- spec/support/controllers/admin/dummy_controller.rb
|
185
|
-
- spec/authorizy/core/access_spec.rb
|
186
|
-
- spec/authorizy/extension/authorizy_spec.rb
|
187
|
-
- spec/authorizy/extension/authorizy_question_spec.rb
|
214
|
+
- spec/authorizy/base_cop/access_question_spec.rb
|
215
|
+
- spec/authorizy/config/aliases_spec.rb
|
216
|
+
- spec/authorizy/config/cop_spec.rb
|
217
|
+
- spec/authorizy/config/current_user_spec.rb
|
188
218
|
- spec/authorizy/config/dependencies_spec.rb
|
189
219
|
- spec/authorizy/config/initialize_spec.rb
|
190
220
|
- spec/authorizy/config/redirect_url_spec.rb
|
191
|
-
- spec/authorizy/config/current_user_spec.rb
|
192
|
-
- spec/authorizy/config/cop_spec.rb
|
193
|
-
- spec/authorizy/config/aliases_spec.rb
|
194
|
-
- spec/authorizy/expander/expand_spec.rb
|
195
|
-
- spec/authorizy/base_cop/access_question_spec.rb
|
196
|
-
- spec/authorizy/cop/namespaced_controller_spec.rb
|
197
221
|
- spec/authorizy/cop/controller_spec.rb
|
198
222
|
- spec/authorizy/cop/model_spec.rb
|
223
|
+
- spec/authorizy/cop/namespaced_controller_spec.rb
|
224
|
+
- spec/authorizy/core/access_spec.rb
|
225
|
+
- spec/authorizy/expander/expand_spec.rb
|
226
|
+
- spec/authorizy/extension/authorizy_question_spec.rb
|
227
|
+
- spec/authorizy/extension/authorizy_spec.rb
|
228
|
+
- spec/common_helper.rb
|
229
|
+
- spec/spec_helper.rb
|
230
|
+
- spec/support/application.rb
|
231
|
+
- spec/support/common.rb
|
232
|
+
- spec/support/controllers/admin/dummy_controller.rb
|
233
|
+
- spec/support/controllers/dummy_controller.rb
|
234
|
+
- spec/support/coverage.rb
|
235
|
+
- spec/support/i18n.rb
|
236
|
+
- spec/support/locales/en.yml
|
237
|
+
- spec/support/models/authorizy_cop.rb
|
238
|
+
- spec/support/models/empty_cop.rb
|
239
|
+
- spec/support/models/user.rb
|
240
|
+
- spec/support/routes.rb
|
241
|
+
- spec/support/schema.rb
|