fortress 0.2.2 → 0.2.3
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/.rubocop.yml +3 -0
- data/lib/fortress/controller_interface.rb +2 -2
- data/lib/fortress/version.rb +1 -1
- data/spec/fixtures/controllers.rb +10 -0
- data/spec/fortress/authorisations_appending_spec.rb +42 -15
- data/spec/fortress/controller_interface_spec.rb +2 -2
- data/spec/fortress/controller_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -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: 4b5730842ffb0c266be737f1beb08214fa812a2e
|
4
|
+
data.tar.gz: f89c8718b2bd3f83e387d20c0ddb407922fe32d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7021c45f9a31239645766b7ba2cf7962f2a15bdcf942d68177f6ebe4a7d72307ef660fd1e8b2d8d8b35f800660d449c430c0cc8b1c9c0f713f4e2b293c58b15d
|
7
|
+
data.tar.gz: 61adb02f34db781748d294976416157a2ea9840acf45d0ac1d18e2314e82c9bd41d2a4f75bb8ce0fb5f4e90e134265368ed279a6ca8b61c0eee56be6dd9f4694
|
data/.rubocop.yml
ADDED
@@ -32,7 +32,7 @@ module Fortress
|
|
32
32
|
return false if action_forbidden?(name.to_sym)
|
33
33
|
|
34
34
|
if conditionnal_method_with_action?(name.to_sym)
|
35
|
-
return
|
35
|
+
return call_allow_method == true
|
36
36
|
end
|
37
37
|
|
38
38
|
return true if action_allowed_from_only?(name.to_sym)
|
@@ -55,7 +55,7 @@ module Fortress
|
|
55
55
|
|
56
56
|
def conditionally_allowed?(action_name)
|
57
57
|
return unless allow_method?
|
58
|
-
return unless needs_to_check_action?(action_name)
|
58
|
+
return unless needs_to_check_action?(action_name.to_sym)
|
59
59
|
call_allow_method
|
60
60
|
end
|
61
61
|
|
data/lib/fortress/version.rb
CHANGED
@@ -2,22 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Authorisations appending (YourCursus/fortress#7)' do
|
4
4
|
describe GuitarsController, type: :controller do
|
5
|
-
let(:
|
5
|
+
let(:controller_name) { 'GuitarsController' }
|
6
6
|
before { Fortress::Mechanism.initialize_authorisations }
|
7
7
|
context 'when calling the first time `fortress_allow` method' do
|
8
8
|
before { GuitarsController.fortress_allow [:index, :show] }
|
9
9
|
it 'should create a new authorisation for the controller' do
|
10
|
-
expect(Fortress::Mechanism.authorisations).to have_key(
|
11
|
-
expect(Fortress::Mechanism.authorisations[
|
10
|
+
expect(Fortress::Mechanism.authorisations).to have_key(controller_name)
|
11
|
+
expect(Fortress::Mechanism.authorisations[controller_name])
|
12
12
|
.to eql(only: [:index, :show])
|
13
13
|
end
|
14
14
|
context 'when calling a second time `fortress_allow` method' do
|
15
|
-
before { GuitarsController.fortress_allow :create, if: true }
|
15
|
+
before { GuitarsController.fortress_allow :create, if: :true }
|
16
16
|
it 'should append keys to the existing controller authorisation' do
|
17
|
-
expect(Fortress::Mechanism.authorisations)
|
18
|
-
|
17
|
+
expect(Fortress::Mechanism.authorisations)
|
18
|
+
.to have_key(controller_name)
|
19
|
+
expect(Fortress::Mechanism.authorisations[controller_name])
|
19
20
|
.to eql(only: [:index, :show],
|
20
|
-
if: { method: true, actions: [:create] })
|
21
|
+
if: { method: :true, actions: [:create] })
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -25,17 +26,43 @@ describe 'Authorisations appending (YourCursus/fortress#7)' do
|
|
25
26
|
context 'when calling the first time `fortress_allow` method' do
|
26
27
|
before { GuitarsController.fortress_allow :all, except: :destroy }
|
27
28
|
it 'should create a new authorisation for the controller' do
|
28
|
-
expect(Fortress::Mechanism.authorisations).to have_key(
|
29
|
-
expect(Fortress::Mechanism.authorisations[
|
29
|
+
expect(Fortress::Mechanism.authorisations).to have_key(controller_name)
|
30
|
+
expect(Fortress::Mechanism.authorisations[controller_name])
|
30
31
|
.to eql(all: true, except: [:destroy])
|
31
32
|
end
|
32
33
|
context 'when calling a second time `fortress_allow` method' do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
context 'using the `:if` option with a method returning true' do
|
35
|
+
before { GuitarsController.fortress_allow :destroy, if: :true }
|
36
|
+
it 'should append keys to the existing controller authorisation' do
|
37
|
+
expect(Fortress::Mechanism.authorisations)
|
38
|
+
.to have_key(controller_name)
|
39
|
+
expect(Fortress::Mechanism.authorisations[controller_name])
|
40
|
+
.to eql(all: true, except: [:destroy],
|
41
|
+
if: { method: :true, actions: [:destroy] })
|
42
|
+
end
|
43
|
+
it 'should allow the controller action' do
|
44
|
+
post :destroy, id: 1
|
45
|
+
|
46
|
+
expect(response).to_not redirect_to(root_url)
|
47
|
+
expect(flash[:error]).to be_nil
|
48
|
+
expect(response).to have_http_status(:ok)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'using the `:if` option with a method returning false' do
|
52
|
+
before { GuitarsController.fortress_allow :destroy, if: :false }
|
53
|
+
it 'should append keys to the existing controller authorisation' do
|
54
|
+
expect(Fortress::Mechanism.authorisations)
|
55
|
+
.to have_key(controller_name)
|
56
|
+
expect(Fortress::Mechanism.authorisations[controller_name])
|
57
|
+
.to eql(all: true, except: [:destroy],
|
58
|
+
if: { method: :false, actions: [:destroy] })
|
59
|
+
end
|
60
|
+
it 'should prevent the controller action' do
|
61
|
+
post :destroy, id: 1
|
62
|
+
|
63
|
+
expect(response).to redirect_to(root_url)
|
64
|
+
expect(flash[:error]).to be_present
|
65
|
+
end
|
39
66
|
end
|
40
67
|
end
|
41
68
|
end
|
@@ -95,7 +95,7 @@ describe Fortress::ControllerInterface do
|
|
95
95
|
context 'the `:method` return false' do
|
96
96
|
before do
|
97
97
|
Fortress::Mechanism.authorisations['GuitarsController'] = {
|
98
|
-
if: { actions: [:index], method: false }
|
98
|
+
if: { actions: [:index], method: :false }
|
99
99
|
}
|
100
100
|
end
|
101
101
|
subject { Fortress::ControllerInterface.new(@controller) }
|
@@ -106,7 +106,7 @@ describe Fortress::ControllerInterface do
|
|
106
106
|
context 'the `:method` return true' do
|
107
107
|
before do
|
108
108
|
Fortress::Mechanism.authorisations['GuitarsController'] = {
|
109
|
-
if: { actions: [:index], method: true }
|
109
|
+
if: { actions: [:index], method: :true }
|
110
110
|
}
|
111
111
|
end
|
112
112
|
subject { Fortress::ControllerInterface.new(@controller) }
|
@@ -382,7 +382,7 @@ describe GuitarsController, type: :controller do
|
|
382
382
|
context 'allowing the index action with a condition returning true' do
|
383
383
|
before do
|
384
384
|
Fortress::Mechanism.initialize_authorisations
|
385
|
-
GuitarsController.fortress_allow :index, if: true
|
385
|
+
GuitarsController.fortress_allow :index, if: :true
|
386
386
|
end
|
387
387
|
describe 'GET index' do
|
388
388
|
it 'should return a 200 HTTP code' do
|
@@ -454,7 +454,7 @@ describe GuitarsController, type: :controller do
|
|
454
454
|
context 'allowing the index action with a condition returning false' do
|
455
455
|
before do
|
456
456
|
Fortress::Mechanism.initialize_authorisations
|
457
|
-
GuitarsController.fortress_allow :index, if: false
|
457
|
+
GuitarsController.fortress_allow :index, if: :false
|
458
458
|
end
|
459
459
|
describe 'GET index' do
|
460
460
|
it 'should redirect to the root_url and set a flash error message' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fortress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Hain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -120,6 +120,7 @@ extra_rdoc_files: []
|
|
120
120
|
files:
|
121
121
|
- ".gitignore"
|
122
122
|
- ".rspec"
|
123
|
+
- ".rubocop.yml"
|
123
124
|
- ".ruby-gemset"
|
124
125
|
- ".ruby-version"
|
125
126
|
- ".travis.yml"
|