fortress 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8807ceb07a787af9e28880231b85215cd11e10c4
4
- data.tar.gz: 916d0af542ab25823cac2db1df20d7810502f8ca
3
+ metadata.gz: 4b5730842ffb0c266be737f1beb08214fa812a2e
4
+ data.tar.gz: f89c8718b2bd3f83e387d20c0ddb407922fe32d9
5
5
  SHA512:
6
- metadata.gz: 11fb3fce13b31dd8f0db8236051b7386df0c9d9007812aba764a4d2d1a724ef747e726a81ef939d2164a1f39ad46c7b2ddd8fc5c8d2d30200e629998a5add6a3
7
- data.tar.gz: 38b701f41f66e26b1a7869fb7f08cfc54a2ce277c5bf3c328df2b0e189adceae8811364cdc9eb3607536a6e54b63d3c2f4eeced5014d33175be46973e1a54339
6
+ metadata.gz: 7021c45f9a31239645766b7ba2cf7962f2a15bdcf942d68177f6ebe4a7d72307ef660fd1e8b2d8d8b35f800660d449c430c0cc8b1c9c0f713f4e2b293c58b15d
7
+ data.tar.gz: 61adb02f34db781748d294976416157a2ea9840acf45d0ac1d18e2314e82c9bd41d2a4f75bb8ce0fb5f4e90e134265368ed279a6ca8b61c0eee56be6dd9f4694
@@ -0,0 +1,3 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/*'
@@ -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 params[:if][:method] == true
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
 
@@ -4,5 +4,5 @@
4
4
  # @author zedtux
5
5
  #
6
6
  module Fortress
7
- VERSION = '0.2.2'
7
+ VERSION = '0.2.3'
8
8
  end
@@ -26,6 +26,16 @@ class GuitarsController < TestController
26
26
  def update; end
27
27
 
28
28
  def destroy; end
29
+
30
+ private
31
+
32
+ def true
33
+ true
34
+ end
35
+
36
+ def false
37
+ false
38
+ end
29
39
  end
30
40
 
31
41
  #
@@ -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(:controller) { 'GuitarsController' }
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(controller)
11
- expect(Fortress::Mechanism.authorisations[controller])
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).to have_key(controller)
18
- expect(Fortress::Mechanism.authorisations[controller])
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(controller)
29
- expect(Fortress::Mechanism.authorisations[controller])
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
- before { GuitarsController.fortress_allow :destroy, if: true }
34
- it 'should append keys to the existing controller authorisation' do
35
- expect(Fortress::Mechanism.authorisations).to have_key(controller)
36
- expect(Fortress::Mechanism.authorisations[controller])
37
- .to eql(all: true, except: [:destroy],
38
- if: { method: true, actions: [:destroy] })
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
@@ -1,4 +1,4 @@
1
- require "codeclimate-test-reporter"
1
+ require 'codeclimate-test-reporter'
2
2
  CodeClimate::TestReporter.start
3
3
 
4
4
  require 'action_controller/railtie'
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.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-24 00:00:00.000000000 Z
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"