openstax_utilities 4.2.0 → 4.2.1

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: 7336e5f9c9952756f9a981da7b79d5dece466022
4
- data.tar.gz: e6a8621a11547eae03d63fc0d94e05053cc86664
3
+ metadata.gz: 4772e799075a8e6e6fb5d6b670be36448369e87e
4
+ data.tar.gz: e7fd112367bbfec2cc3047963c71289a980deb78
5
5
  SHA512:
6
- metadata.gz: 7b17cb61f65fe32b021ce90b736ff163fedc34ffcb3173f9ba0af024d165a4b53ea586547df15cda7b3d787bcf2afc3cf5a2c39a69ce1bc546ddce1056c6a6cf
7
- data.tar.gz: a5a03f359924bc9de55fd70e3b433fd3ef84dbed7c94d1c7ff40e802b1c5cc65d452a6bf09d77198872d94f82f3e3da6ca65a773f1becd7d6b003a122605c16c
6
+ metadata.gz: 364297c1c70a6218b52ca4eac44e8917bbb97cea1981a55c54fa174488cf831b34fc2a418e5dae66c01e9ccacf9939d7e01042aefbbc80b6cb1116e3588569d2
7
+ data.tar.gz: af1ec77a057b82d86586e644fae8546bab74fcccc92f00810a35c692880ebd3e73c876e3f62d50f481b14cf049c207c166a2a503ab89418f23a8e6224f84d723
@@ -38,7 +38,7 @@ module OpenStax
38
38
  end
39
39
 
40
40
  resource_class = resource.is_a?(Class) ? resource : resource.class
41
- policy_class = instance.resource_policy_map[resource_class.to_s]
41
+ policy_class = instance.resource_policy_map[resource_class.to_s].try(:constantize)
42
42
 
43
43
  # If there is no policy registered, we by default deny access
44
44
  return false if policy_class.nil?
@@ -47,7 +47,7 @@ module OpenStax
47
47
  end
48
48
 
49
49
  def self.register(resource_class, policy_class)
50
- self.instance.resource_policy_map[resource_class.to_s] = policy_class
50
+ self.instance.resource_policy_map[resource_class.to_s] = policy_class.to_s
51
51
  end
52
52
 
53
53
  end
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Utilities
3
- VERSION = "4.2.0"
3
+ VERSION = "4.2.1"
4
4
  end
5
5
  end
@@ -0,0 +1,10 @@
1
+ class DummierAccessPolicy
2
+ cattr_accessor :last_action, :last_requestor, :last_resource
3
+
4
+ def self.action_allowed?(action, requestor, resource)
5
+ @@last_action = action
6
+ @@last_requestor = requestor
7
+ @@last_resource = resource
8
+ true
9
+ end
10
+ end
@@ -13,7 +13,7 @@ Rails.application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static asset server for tests with Cache-Control for performance.
16
- config.serve_static_assets = true
16
+ config.serve_static_files = true
17
17
  config.static_cache_control = 'public, max-age=3600'
18
18
 
19
19
  # Show full error reports and disable caching.
@@ -24,30 +24,31 @@ module OpenStax
24
24
 
25
25
  it 'delegates checks to policy classes based on resource class' do
26
26
  dummy_object = double('Dummy')
27
- dummy_policy = double('Dummy Policy', :action_allowed? => true)
28
27
 
29
28
  AccessPolicy.register(User, DummyAccessPolicy)
30
- AccessPolicy.register(dummy_object.class, dummy_policy)
29
+ AccessPolicy.register(dummy_object.class, DummierAccessPolicy)
31
30
 
32
31
  DummyAccessPolicy.last_action = nil
33
32
  DummyAccessPolicy.last_requestor = nil
34
33
  DummyAccessPolicy.last_resource = nil
35
34
 
36
- expect(AccessPolicy.action_allowed?(:read, user, dummy_object)).to(
37
- eq(true))
38
-
39
- expect{AccessPolicy.require_action_allowed!(:read, user, dummy_object)
40
- }.not_to raise_error
35
+ DummierAccessPolicy.last_action = nil
36
+ DummierAccessPolicy.last_requestor = nil
37
+ DummierAccessPolicy.last_resource = nil
41
38
 
42
- expect(DummyAccessPolicy.last_action).to be_nil
43
- expect(DummyAccessPolicy.last_requestor).to be_nil
44
- expect(DummyAccessPolicy.last_resource).to be_nil
39
+ expect(AccessPolicy.action_allowed?(:read, user, dummy_object)).to eq true
40
+ expect{
41
+ AccessPolicy.require_action_allowed!(:read, user, dummy_object)
42
+ }.not_to raise_error
45
43
 
46
- expect(AccessPolicy.action_allowed?(:create, user, User.new)).to(
47
- eq(true))
44
+ expect(DummierAccessPolicy.last_action).to eq(:read)
45
+ expect(DummierAccessPolicy.last_requestor).to eq(user)
46
+ expect(DummierAccessPolicy.last_resource).to eq(dummy_object)
48
47
 
49
- expect{AccessPolicy.require_action_allowed!(:create, user, User.new)
50
- }.not_to raise_error
48
+ expect(AccessPolicy.action_allowed?(:create, user, User.new)).to eq true
49
+ expect{
50
+ AccessPolicy.require_action_allowed!(:create, user, User.new)
51
+ }.not_to raise_error
51
52
 
52
53
  expect(DummyAccessPolicy.last_action).to eq(:create)
53
54
  expect(DummyAccessPolicy.last_requestor).to eq(user)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_utilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-16 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -160,6 +160,7 @@ files:
160
160
  - lib/openstax_utilities.rb
161
161
  - spec/dummy/README.md
162
162
  - spec/dummy/Rakefile
163
+ - spec/dummy/app/access_policies/dummier_access_policy.rb
163
164
  - spec/dummy/app/access_policies/dummy_access_policy.rb
164
165
  - spec/dummy/app/assets/javascripts/application.js
165
166
  - spec/dummy/app/assets/stylesheets/application.css
@@ -230,6 +231,7 @@ signing_key:
230
231
  specification_version: 4
231
232
  summary: Utilities for OpenStax web sites
232
233
  test_files:
234
+ - spec/dummy/app/access_policies/dummier_access_policy.rb
233
235
  - spec/dummy/app/access_policies/dummy_access_policy.rb
234
236
  - spec/dummy/app/assets/javascripts/application.js
235
237
  - spec/dummy/app/assets/stylesheets/application.css