authorizy 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +25 -11
- data/lib/authorizy/config.rb +1 -1
- data/lib/authorizy/core.rb +6 -6
- data/lib/authorizy/expander.rb +7 -11
- data/lib/authorizy/extension.rb +9 -6
- data/lib/authorizy/rspec.rb +3 -3
- data/lib/authorizy/version.rb +1 -1
- metadata +8 -184
- data/spec/authorizy/base_cop/access_question_spec.rb +0 -10
- data/spec/authorizy/config/aliases_spec.rb +0 -13
- data/spec/authorizy/config/cop_spec.rb +0 -13
- data/spec/authorizy/config/current_user_spec.rb +0 -29
- data/spec/authorizy/config/denied_spec.rb +0 -51
- data/spec/authorizy/config/dependencies_spec.rb +0 -13
- data/spec/authorizy/config/field_spec.rb +0 -29
- data/spec/authorizy/config/initialize_spec.rb +0 -7
- data/spec/authorizy/config/redirect_url_spec.rb +0 -31
- data/spec/authorizy/cop/controller_spec.rb +0 -41
- data/spec/authorizy/cop/model_spec.rb +0 -16
- data/spec/authorizy/cop/namespaced_controller_spec.rb +0 -41
- data/spec/authorizy/core/access_spec.rb +0 -181
- data/spec/authorizy/expander/expand_spec.rb +0 -139
- data/spec/authorizy/extension/authorizy_question_spec.rb +0 -50
- data/spec/authorizy/extension/authorizy_spec.rb +0 -54
- data/spec/authorizy/rspec_spec.rb +0 -11
- data/spec/common_helper.rb +0 -13
- data/spec/spec_helper.rb +0 -29
- data/spec/support/application.rb +0 -8
- data/spec/support/common.rb +0 -13
- data/spec/support/controllers/admin/dummy_controller.rb +0 -13
- data/spec/support/controllers/dummy_controller.rb +0 -11
- data/spec/support/coverage.rb +0 -18
- data/spec/support/i18n.rb +0 -3
- data/spec/support/locales/en.yml +0 -3
- data/spec/support/models/authorizy_cop.rb +0 -31
- data/spec/support/models/empty_cop.rb +0 -4
- data/spec/support/models/user.rb +0 -4
- data/spec/support/routes.rb +0 -6
- data/spec/support/schema.rb +0 -22
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Authorizy::Config, '#redirect_url' do
|
4
|
-
let!(:config) { described_class.new }
|
5
|
-
|
6
|
-
context 'when uses default value' do
|
7
|
-
context 'when context responds to root_url' do
|
8
|
-
let!(:context) { OpenStruct.new(root_url: '/root') }
|
9
|
-
|
10
|
-
it 'is called' do
|
11
|
-
expect(config.redirect_url.call(context)).to eq('/root')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when context does not respond to root_url' do
|
16
|
-
let!(:context) { 'context' }
|
17
|
-
|
18
|
-
it 'returns just a slash' do
|
19
|
-
expect(config.redirect_url.call(context)).to eq('/')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when uses custom value' do
|
25
|
-
it 'executes what you want' do
|
26
|
-
config.redirect_url = ->(context) { context[:key] }
|
27
|
-
|
28
|
-
expect(config.redirect_url.call({ key: :value })).to eq(:value)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'support/models/authorizy_cop'
|
4
|
-
require 'support/models/empty_cop'
|
5
|
-
require 'support/controllers/dummy_controller'
|
6
|
-
|
7
|
-
RSpec.describe DummyController, '#authorizy', type: :controller do
|
8
|
-
let!(:user) { User.new }
|
9
|
-
|
10
|
-
context 'when cop responds to the controller name' do
|
11
|
-
context 'when method resturns false' do
|
12
|
-
it 'denies the access' do
|
13
|
-
config_mock(cop: AuthorizyCop, current_user: user) do
|
14
|
-
get :action, params: { access: false }
|
15
|
-
end
|
16
|
-
|
17
|
-
expect(response).to redirect_to('/')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when method resturns true' do
|
22
|
-
it 'denies the access' do
|
23
|
-
config_mock(cop: AuthorizyCop, current_user: user) do
|
24
|
-
get :action, params: { access: true }
|
25
|
-
end
|
26
|
-
|
27
|
-
expect(response.body).to eq('{"message":"authorized"}')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when cop does not respond to the controller name' do
|
33
|
-
it 'denies the access' do
|
34
|
-
config_mock(cop: EmptyCop, current_user: user) do
|
35
|
-
get :action
|
36
|
-
end
|
37
|
-
|
38
|
-
expect(response).to redirect_to('/')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'support/models/authorizy_cop'
|
4
|
-
|
5
|
-
RSpec.describe AuthorizyCop do
|
6
|
-
let!(:params) { { controller: 'controller', action: 'action' } }
|
7
|
-
let(:cop) { described_class.new('current_user', params, 'session') }
|
8
|
-
|
9
|
-
it 'adds private attributes readers' do
|
10
|
-
expect(cop.fetch_action).to eq('action')
|
11
|
-
expect(cop.fetch_controller).to eq('controller')
|
12
|
-
expect(cop.fetch_current_user).to eq('current_user')
|
13
|
-
expect(cop.fetch_params).to eq(controller: 'controller', action: 'action')
|
14
|
-
expect(cop.fetch_session).to eq('session')
|
15
|
-
end
|
16
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'support/models/authorizy_cop'
|
4
|
-
require 'support/models/empty_cop'
|
5
|
-
require 'support/controllers/admin/dummy_controller'
|
6
|
-
|
7
|
-
RSpec.describe Admin::DummyController, '#authorizy', type: :controller do
|
8
|
-
let!(:user) { User.new }
|
9
|
-
|
10
|
-
context 'when cop responds to the controller name' do
|
11
|
-
context 'when method resturns false' do
|
12
|
-
it 'denies the access' do
|
13
|
-
config_mock(cop: AuthorizyCop, current_user: user) do
|
14
|
-
get :action, params: { admin: false }
|
15
|
-
end
|
16
|
-
|
17
|
-
expect(response).to redirect_to('/')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when method resturns true' do
|
22
|
-
it 'denies the access' do
|
23
|
-
config_mock(cop: AuthorizyCop, current_user: user) do
|
24
|
-
get :action, params: { admin: true }
|
25
|
-
end
|
26
|
-
|
27
|
-
expect(response.body).to eq('{"message":"authorized"}')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when cop does not respond to the controller name' do
|
33
|
-
it 'denies the access' do
|
34
|
-
config_mock(cop: EmptyCop, current_user: user) do
|
35
|
-
get :action
|
36
|
-
end
|
37
|
-
|
38
|
-
expect(response).to redirect_to('/')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,181 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Authorizy::Core, '#access?' do
|
4
|
-
context 'when cop#access? returns true' do
|
5
|
-
let!(:cop) { OpenStruct.new(access?: true) }
|
6
|
-
let!(:current_user) { User.new }
|
7
|
-
let!(:params) { { action: 'any', controller: 'any' } }
|
8
|
-
let!(:session) { {} }
|
9
|
-
|
10
|
-
it 'is authorized based in the cop response' do
|
11
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(true)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when permissions is in the current user' do
|
16
|
-
let!(:cop) { OpenStruct.new(access?: false) }
|
17
|
-
let!(:current_user) { User.new(authorizy: { permissions: [%w[controller create]] }) }
|
18
|
-
let!(:params) { { controller: 'controller', action: 'create' } }
|
19
|
-
let!(:session) { {} }
|
20
|
-
|
21
|
-
it 'is authorized based on the user permissions' do
|
22
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(true)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when session has no permission nor the user' do
|
27
|
-
let!(:cop) { OpenStruct.new(access?: false) }
|
28
|
-
let!(:current_user) { User.new }
|
29
|
-
let!(:params) { { controller: 'match', action: 'create' } }
|
30
|
-
let!(:session) { {} }
|
31
|
-
|
32
|
-
it 'does not authorize' do
|
33
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(false)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when cop does not respond to controller' do
|
38
|
-
let!(:cop) { instance_double('Authorizy::BaseCop', access?: false) }
|
39
|
-
let!(:current_user) { User.new }
|
40
|
-
let!(:params) { { action: 'create', controller: 'missing' } }
|
41
|
-
let!(:session) { {} }
|
42
|
-
|
43
|
-
it 'does not authorize via cop' do
|
44
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(false)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when cop responds to controller' do
|
49
|
-
let!(:current_user) { User.new }
|
50
|
-
let!(:params) { { controller: 'admin/controller', action: 'create' } }
|
51
|
-
let!(:session) { {} }
|
52
|
-
|
53
|
-
context 'when cop does not release the access' do
|
54
|
-
let!(:cop) do
|
55
|
-
Class.new(Authorizy::BaseCop) do
|
56
|
-
def access?
|
57
|
-
false
|
58
|
-
end
|
59
|
-
|
60
|
-
def admin__controller
|
61
|
-
false
|
62
|
-
end
|
63
|
-
end.new(current_user, params, session)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'is not authorized by cop' do
|
67
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(false)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'when cop releases the access' do
|
72
|
-
let!(:cop) do
|
73
|
-
Class.new(Authorizy::BaseCop) do
|
74
|
-
def access?
|
75
|
-
false
|
76
|
-
end
|
77
|
-
|
78
|
-
def admin__controller
|
79
|
-
true
|
80
|
-
end
|
81
|
-
end.new(current_user, params, session)
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'is authorized by the cop' do
|
85
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(true)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'when cop return nil' do
|
90
|
-
let!(:cop) do
|
91
|
-
Class.new(Authorizy::BaseCop) do
|
92
|
-
def access?
|
93
|
-
false
|
94
|
-
end
|
95
|
-
|
96
|
-
def admin__controller
|
97
|
-
nil
|
98
|
-
end
|
99
|
-
end.new(current_user, params, session)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'is converted to false' do
|
103
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(false)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'when cop return empty' do
|
108
|
-
let!(:cop) do
|
109
|
-
Class.new(Authorizy::BaseCop) do
|
110
|
-
def access?
|
111
|
-
false
|
112
|
-
end
|
113
|
-
|
114
|
-
def admin__controller
|
115
|
-
''
|
116
|
-
end
|
117
|
-
end.new(current_user, params, session)
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'is converted to false' do
|
121
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(false)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'when cop return nothing' do
|
126
|
-
let!(:cop) do
|
127
|
-
Class.new(Authorizy::BaseCop) do
|
128
|
-
def access?
|
129
|
-
false
|
130
|
-
end
|
131
|
-
|
132
|
-
def admin__controller; end
|
133
|
-
end.new(current_user, params, session)
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'is converted to false' do
|
137
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(false)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context 'when cop return true as string' do
|
142
|
-
let!(:cop) do
|
143
|
-
Class.new(Authorizy::BaseCop) do
|
144
|
-
def access?
|
145
|
-
false
|
146
|
-
end
|
147
|
-
|
148
|
-
def admin__controller
|
149
|
-
'true'
|
150
|
-
end
|
151
|
-
end.new(current_user, params, session)
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'is converted to false' do
|
155
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(false)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
context 'when user has the controller permission but not action' do
|
161
|
-
let!(:cop) { instance_double('Authorizy::BaseCop', access?: false) }
|
162
|
-
let!(:current_user) { User.new }
|
163
|
-
let!(:params) { { controller: 'controller', action: 'action' } }
|
164
|
-
let!(:session) { { permissions: [%w[controller miss]] } }
|
165
|
-
|
166
|
-
it 'is not authorized' do
|
167
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(false)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context 'when user has the action permission but not controller' do
|
172
|
-
let!(:cop) { instance_double('Authorizy::BaseCop', access?: false) }
|
173
|
-
let!(:current_user) { User.new }
|
174
|
-
let!(:params) { { controller: 'controller', action: 'action' } }
|
175
|
-
let!(:session) { { permissions: [%w[miss action]] } }
|
176
|
-
|
177
|
-
it 'is not authorized' do
|
178
|
-
expect(described_class.new(current_user, params, session, cop: cop).access?).to be(false)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
@@ -1,139 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Authorizy::Expander, '#expand' do
|
4
|
-
subject(:expander) { described_class.new }
|
5
|
-
|
6
|
-
context 'when permissions is blank' do
|
7
|
-
let(:permissions) { [] }
|
8
|
-
|
9
|
-
it 'returns an empty permissions' do
|
10
|
-
expect(expander.expand(permissions)).to eq []
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when permissions is given' do
|
15
|
-
context 'when data is symbol' do
|
16
|
-
let(:permissions) do
|
17
|
-
[
|
18
|
-
%i[controller create],
|
19
|
-
%i[controller update],
|
20
|
-
]
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'maps the default actions aliases' do
|
24
|
-
expect(expander.expand(permissions)).to match_array [
|
25
|
-
%w[controller create],
|
26
|
-
%w[controller edit],
|
27
|
-
%w[controller new],
|
28
|
-
%w[controller update],
|
29
|
-
]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when data is string' do
|
34
|
-
let(:permissions) do
|
35
|
-
[
|
36
|
-
%w[controller create],
|
37
|
-
%w[controller update],
|
38
|
-
]
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'maps the default actions aliases' do
|
42
|
-
expect(expander.expand(permissions)).to match_array [
|
43
|
-
%w[controller create],
|
44
|
-
%w[controller edit],
|
45
|
-
%w[controller new],
|
46
|
-
%w[controller update],
|
47
|
-
]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'when a dependencies is given' do
|
53
|
-
context 'when keys and values are strings' do
|
54
|
-
let(:dependencies) { { 'controller' => { 'action' => [%w[controller_2 action_2]] } } }
|
55
|
-
let!(:permissions) { [%w[controller action]] }
|
56
|
-
|
57
|
-
it 'addes the dependencies permissions' do
|
58
|
-
config_mock(dependencies: dependencies) do
|
59
|
-
expect(expander.expand(permissions)).to match_array [
|
60
|
-
%w[controller action],
|
61
|
-
%w[controller_2 action_2],
|
62
|
-
]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'when keys and values are symbol' do
|
68
|
-
let(:dependencies) { { controller: { action: [%i[controller_2 action_2]] } } }
|
69
|
-
let!(:permissions) { [%w[controller action]] }
|
70
|
-
|
71
|
-
it 'addes the dependencies permissions' do
|
72
|
-
config_mock(dependencies: dependencies) do
|
73
|
-
expect(expander.expand(permissions)).to match_array [
|
74
|
-
%w[controller action],
|
75
|
-
%w[controller_2 action_2],
|
76
|
-
]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when aliases is given' do
|
83
|
-
let!(:permissions) { [%w[controller action]] }
|
84
|
-
|
85
|
-
context 'when key and values are strings' do
|
86
|
-
let(:aliases) { { 'action' => 'action_2' } }
|
87
|
-
|
88
|
-
it 'maps the action with the current controller' do
|
89
|
-
config_mock(aliases: aliases) do
|
90
|
-
expect(expander.expand(permissions)).to match_array [
|
91
|
-
%w[controller action],
|
92
|
-
%w[controller action_2],
|
93
|
-
]
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'when key and values are symbols' do
|
99
|
-
let(:aliases) { { action: :action_2 } }
|
100
|
-
|
101
|
-
it 'maps the action with the current controller' do
|
102
|
-
config_mock(aliases: aliases) do
|
103
|
-
expect(expander.expand(permissions)).to match_array [
|
104
|
-
%w[controller action],
|
105
|
-
%w[controller action_2],
|
106
|
-
]
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'when key and values are array of strings' do
|
112
|
-
let(:aliases) { { action: %w[action_2 action_3] } }
|
113
|
-
|
114
|
-
it 'maps the actions with the current controller' do
|
115
|
-
config_mock(aliases: aliases) do
|
116
|
-
expect(expander.expand(permissions)).to match_array [
|
117
|
-
%w[controller action],
|
118
|
-
%w[controller action_2],
|
119
|
-
%w[controller action_3],
|
120
|
-
]
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'when key and values are array of symbols' do
|
126
|
-
let(:aliases) { { action: %i[action_2 action_3] } }
|
127
|
-
|
128
|
-
it 'maps the actions with the current controller' do
|
129
|
-
config_mock(aliases: aliases) do
|
130
|
-
expect(expander.expand(permissions)).to match_array [
|
131
|
-
%w[controller action],
|
132
|
-
%w[controller action_2],
|
133
|
-
%w[controller action_3],
|
134
|
-
]
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'support/controllers/dummy_controller'
|
4
|
-
|
5
|
-
RSpec.describe DummyController, '#authorizy?', type: :controller do
|
6
|
-
context 'when config returns no current user' do
|
7
|
-
it 'returns false' do
|
8
|
-
config_mock(current_user: nil) do
|
9
|
-
expect(controller.helpers.authorizy?('controller', 'action')).to be(false)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when config returns current user' do
|
15
|
-
let!(:config) { Authorizy.config }
|
16
|
-
let!(:user) { User.new }
|
17
|
-
|
18
|
-
before { allow(Authorizy).to receive(:config).and_return(config) }
|
19
|
-
|
20
|
-
context 'when authorizy returns false' do
|
21
|
-
let!(:core) { instance_double('Authorizy::Core', access?: false) }
|
22
|
-
let!(:parameters) { ActionController::Parameters.new(controller: 'controller', action: 'action') }
|
23
|
-
|
24
|
-
it 'returns false' do
|
25
|
-
allow(Authorizy::Core).to receive(:new)
|
26
|
-
.with(user, parameters, session, cop: config.cop)
|
27
|
-
.and_return(core)
|
28
|
-
|
29
|
-
config_mock(current_user: user) do
|
30
|
-
expect(controller.helpers.authorizy?('controller', 'action')).to be(false)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when authorizy returns true' do
|
36
|
-
let!(:core) { instance_double('Authorizy::Core', access?: true) }
|
37
|
-
let!(:parameters) { ActionController::Parameters.new(controller: 'controller', action: 'action') }
|
38
|
-
|
39
|
-
it 'returns true' do
|
40
|
-
allow(Authorizy::Core).to receive(:new)
|
41
|
-
.with(user, parameters, session, cop: config.cop)
|
42
|
-
.and_return(core)
|
43
|
-
|
44
|
-
config_mock(current_user: user) do
|
45
|
-
expect(controller.helpers.authorizy?('controller', 'action')).to be(true)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'support/controllers/dummy_controller'
|
4
|
-
|
5
|
-
RSpec.describe DummyController, '#authorizy', type: :controller do
|
6
|
-
let!(:parameters) { ActionController::Parameters.new(key: 'value', controller: 'dummy', action: 'action') }
|
7
|
-
let!(:user) { nil }
|
8
|
-
|
9
|
-
context 'when user has access' do
|
10
|
-
let!(:authorizy_core) { instance_double('Authorizy::Core', access?: true) }
|
11
|
-
|
12
|
-
before do
|
13
|
-
allow(Authorizy::Core).to receive(:new)
|
14
|
-
.with(user, parameters, session, cop: Authorizy.config.cop)
|
15
|
-
.and_return(authorizy_core)
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when is a xhr request' do
|
19
|
-
it 'receives the default values and do not denied the access' do
|
20
|
-
get :action, xhr: true, params: { key: 'value' }
|
21
|
-
|
22
|
-
expect(response.body).to eq('{"message":"authorized"}')
|
23
|
-
expect(response.status).to be(200)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when is a html request' do
|
28
|
-
it 'receives the default values and do not denied the access' do
|
29
|
-
get :action, params: { key: 'value' }
|
30
|
-
|
31
|
-
expect(response.body).to eq('{"message":"authorized"}')
|
32
|
-
expect(response.status).to be(200)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when user has no access' do
|
38
|
-
let!(:authorizy_core) { instance_double('Authorizy::Core', access?: false) }
|
39
|
-
|
40
|
-
before do
|
41
|
-
allow(Authorizy::Core).to receive(:new)
|
42
|
-
.with(user, parameters, session, cop: Authorizy.config.cop)
|
43
|
-
.and_return(authorizy_core)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'calls denied callback' do
|
47
|
-
allow(Authorizy.config.denied).to receive(:call)
|
48
|
-
|
49
|
-
get :action, xhr: true, params: { key: 'value' }
|
50
|
-
|
51
|
-
expect(Authorizy.config.denied).to have_received(:call).with(subject)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RSpec::Matchers, '#be_authorized' do
|
4
|
-
it 'pending' do
|
5
|
-
matcher = be_authorized('controller', 'action', params: { params: true }, session: { session: true })
|
6
|
-
|
7
|
-
expect(matcher.description).to eq %(
|
8
|
-
be authorized "controller", "action", and {:params=>{:params=>true}, :session=>{:session=>true}}
|
9
|
-
).squish
|
10
|
-
end
|
11
|
-
end
|
data/spec/common_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
ENV['RAILS_ENV'] ||= 'test'
|
4
|
-
|
5
|
-
require 'support/coverage'
|
6
|
-
|
7
|
-
require 'support/application'
|
8
|
-
require 'support/common'
|
9
|
-
require 'support/i18n'
|
10
|
-
require 'support/routes'
|
11
|
-
require 'support/schema'
|
12
|
-
require 'authorizy'
|
13
|
-
require 'pry-byebug'
|
data/spec/spec_helper.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
def config_mock(aliases: nil, cop: nil, current_user: nil, dependencies: nil, redirect_url: nil)
|
4
|
-
backup = {
|
5
|
-
aliases: Authorizy.config.aliases,
|
6
|
-
cop: Authorizy.config.cop,
|
7
|
-
current_user: Authorizy.config.current_user,
|
8
|
-
dependencies: Authorizy.config.dependencies,
|
9
|
-
redirect_url: Authorizy.config.redirect_url,
|
10
|
-
}
|
11
|
-
|
12
|
-
Authorizy.configure do |config|
|
13
|
-
config.aliases = aliases if aliases
|
14
|
-
config.cop = cop if cop
|
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
|
-
end
|
19
|
-
|
20
|
-
yield
|
21
|
-
ensure
|
22
|
-
Authorizy.configure do |config|
|
23
|
-
config.aliases = backup[:aliases]
|
24
|
-
config.cop = backup[:cop]
|
25
|
-
config.current_user = backup[:current_user]
|
26
|
-
config.dependencies = backup[:dependencies]
|
27
|
-
config.redirect_url = backup[:redirect_url]
|
28
|
-
end
|
29
|
-
end
|
data/spec/support/application.rb
DELETED
data/spec/support/common.rb
DELETED
data/spec/support/coverage.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if ENV['COVERAGE'] == 'true'
|
4
|
-
require 'simplecov'
|
5
|
-
require 'codecov'
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
8
|
-
|
9
|
-
SimpleCov.minimum_coverage(ENV.fetch('MINIMUM_COVERAGE', 80).to_i)
|
10
|
-
|
11
|
-
SimpleCov.start('rails') do
|
12
|
-
add_filter [
|
13
|
-
'/lib/generators',
|
14
|
-
'/vendor',
|
15
|
-
'/lib/authorizy/version.rb',
|
16
|
-
]
|
17
|
-
end
|
18
|
-
end
|
data/spec/support/i18n.rb
DELETED