access_policy_rails 0.0.1 → 0.0.2

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: 90e7d6b18bd059963e82d1cbc2486150a71a5a3c
4
- data.tar.gz: 0a532c786ab1a225dab5ef6d8cb074083619aa5b
3
+ metadata.gz: 87547ac0de14fb1192be856e09b806c8e4ca0b99
4
+ data.tar.gz: dfb335dce94875c436775a02f90ec8fc15fd4c6d
5
5
  SHA512:
6
- metadata.gz: b4bbbde1e2ef3549b244a87206d706dd0b87daa64aed228e709241bb7e086e262a73116f314620f4ea8fbdae4e5c7bc54b6def6ed579c11bab8c20c5abbef51b
7
- data.tar.gz: a1ae44e5234d0ebeab0d19c99bd585cd7ba6b7e4e52415d9178f1a2f7d4458654f52e8e994c86e1defabcef14da9439e13d2545b80119e2588e14f9e156f5e82
6
+ metadata.gz: e5e671362763aa7ac22e8f282f2239cf95ce584b5cb0fdb8c3eb9811eac15059c2f610168cfb01e4e43869f6089e446bb6deb63498ae4b3ddbb7b0a29c6b9fd5
7
+ data.tar.gz: a1345b03dfb575e2fb48f11c7da48d513166d621ca262b296f841cd991a678b74352efe8999eea10d298a180fa20e1632839c056d6226804543d7311f4b9546a
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AccessPolicyRails [![Code Climate](https://codeclimate.com/github/slowjack2k/access_policy_rails.png)](https://codeclimate.com/github/slowjack2k/access_policy_rails) [![Build Status](https://travis-ci.org/slowjack2k/access_policy_rails.png?branch=master)](https://travis-ci.org/slowjack2k/access_policy_rails) [![Coverage Status](https://coveralls.io/repos/slowjack2k/access_policy_rails/badge.png?branch=master)](https://coveralls.io/r/slowjack2k/access_policy_rails?branch=master) [![Gem Version](https://badge.fury.io/rb/access_policy_rails.png)](http://badge.fury.io/rb/access_policy_rails)
2
2
 
3
- Rails extension for AccessPolicy. Stores the policy_check_user (default current_user)
3
+ Rails extension for [AccessPolicy](https://github.com/slowjack2k/access_policy). Stores the policy_check_user (default current_user)
4
4
  in a RequestLocalStorage. So it is not needed to pass the user around.
5
5
 
6
6
  Further more some macros are provided to query permissions and protect actions.
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
  ```ruby
25
25
 
26
26
  class DummyController < ActionController::Base
27
- attr_accessor :current_user
27
+ # ... typical controller stuff
28
28
 
29
29
  # instead of
30
30
  #
@@ -12,8 +12,10 @@ module AccessPolicyRails
12
12
  hide_action :policy_check_user
13
13
  hide_action :authorize
14
14
  hide_action :policy_for
15
+ hide_action :policy
15
16
 
16
17
  helper_method :policy_for
18
+ helper_method :policy
17
19
 
18
20
  end
19
21
 
@@ -26,8 +28,12 @@ module AccessPolicyRails
26
28
  end
27
29
 
28
30
  def policy_for(object_to_guard=self)
31
+ PolicyWrapper.new(policy(object_to_guard))
32
+ end
33
+
34
+ def policy(object_to_guard=self)
29
35
  _guard.send(:switched_user_or_role, policy_check_user) do
30
- PolicyWrapper.new(_guard.policy_for(object_to_guard))
36
+ _guard.policy_for(object_to_guard)
31
37
  end
32
38
  end
33
39
 
@@ -1,3 +1,3 @@
1
1
  module AccessPolicyRails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,42 @@
1
+ require 'acceptance_spec_helper'
2
+
3
+ feature 'Expose helper', %q{
4
+ In order to change views dependent on permissions
5
+ as a developer
6
+ I want to be able to query permissions in views
7
+ }, type: :helper do
8
+
9
+ given(:service_object){
10
+ Class.new() do
11
+ include AccessPolicy
12
+
13
+ def self.policy_class
14
+ Struct.new(:current_user, :service_object) do
15
+ def create?
16
+ !!(current_user && current_user.create_allowed?)
17
+ end
18
+
19
+ def show?
20
+ !!(current_user && current_user.show_allowed?)
21
+ end
22
+ end
23
+ end
24
+
25
+ end.new
26
+ }
27
+
28
+ given(:a_user){
29
+ double('user', create_allowed?: false, show_allowed?: true)
30
+ }
31
+
32
+ scenario 'action is allowed' do
33
+ allow(controller).to receive(:current_user).and_return a_user
34
+ expect(helper.policy_for(service_object).allow?(:show)).to be_truthy
35
+ end
36
+
37
+ scenario 'action is forbidden' do
38
+ allow(controller).to receive(:current_user).and_return a_user
39
+ expect(helper.policy_for(service_object).allow?(:create)).to be_falsy
40
+ end
41
+
42
+ end
@@ -20,7 +20,7 @@ end
20
20
  def self.feature(*args, &block)
21
21
  options = if args.last.is_a?(Hash) then args.pop else {} end
22
22
  options[:capybara_feature] = true
23
- options[:type] = :feature
23
+ options[:type] ||= :feature
24
24
  options[:caller] ||= caller
25
25
  args.push(options)
26
26
 
@@ -13,7 +13,7 @@ class BaseControllerDummy
13
13
  end
14
14
 
15
15
  def self.policy_class
16
- Struct.new(:current_user, :controller) do
16
+ @policy_class ||= Struct.new(:current_user, :controller) do
17
17
  def create?
18
18
  current_user && current_user.create_allowed?
19
19
  end
@@ -85,5 +85,11 @@ module AccessPolicyRails
85
85
  expect(subject.new(user).policy_for).to be_kind_of PolicyWrapper
86
86
  end
87
87
  end
88
+
89
+ describe '#policy' do
90
+ it 'returns a policy' do
91
+ expect(subject.new(user).policy).to be_kind_of subject.policy_class
92
+ end
93
+ end
88
94
  end
89
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: access_policy_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter Späth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-12 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: access_policy
@@ -296,6 +296,7 @@ files:
296
296
  - spec/acceptance/dummy/public/favicon.ico
297
297
  - spec/acceptance/enables_permission_query_spec.rb
298
298
  - spec/acceptance/enforce_authorize_outside_of_action_spec.rb
299
+ - spec/acceptance/expose_as_helper_spec.rb
299
300
  - spec/acceptance/protect_controller_actions_spec.rb
300
301
  - spec/acceptance/support/dummy_controller.rb
301
302
  - spec/acceptance/support/dummy_controller_policy.rb
@@ -373,6 +374,7 @@ test_files:
373
374
  - spec/acceptance/dummy/public/favicon.ico
374
375
  - spec/acceptance/enables_permission_query_spec.rb
375
376
  - spec/acceptance/enforce_authorize_outside_of_action_spec.rb
377
+ - spec/acceptance/expose_as_helper_spec.rb
376
378
  - spec/acceptance/protect_controller_actions_spec.rb
377
379
  - spec/acceptance/support/dummy_controller.rb
378
380
  - spec/acceptance/support/dummy_controller_policy.rb