allowy 0.2.0 → 0.2.1

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.
data/README.md CHANGED
@@ -41,7 +41,7 @@ Or use `allowy` gem any other way you are not in Rails.
41
41
  # Usage
42
42
 
43
43
  I will be assuming a CMS-like system in the examples below.
44
- The `Page` class may be ActiveRecord, Mongoid or any other model of your choise. Doesn't matter.
44
+ The `Page` class may be ActiveRecord, Mongoid or any other model of your choice. Doesn't matter.
45
45
 
46
46
 
47
47
  ## Minimal setup
@@ -216,6 +216,11 @@ describe PagesController do
216
216
  it "will always allow no matter what" do
217
217
  post(:create).should be_success
218
218
  end
219
+
220
+ it "checks the authorisation" do
221
+ should_authorize_for(:create, page)
222
+ post(:create)
223
+ end
219
224
  end
220
225
 
221
226
  ```
@@ -27,13 +27,12 @@ module Allowy
27
27
  end
28
28
  end
29
29
 
30
- ::RSpec::Matchers.define :be_able_to do |*args|
31
- m = AbleToMatcher.new(*args)
32
- match {|a| m.matches?(a) }
33
- failure_message_for_should { m.failure_message }
34
- failure_message_for_should_not { m.negative_failure_message }
35
- description { m.description }
30
+ def be_able_to(*args)
31
+ AbleToMatcher.new(*args)
36
32
  end
37
-
38
33
  end
39
34
  end
35
+
36
+ module RSpec::Matchers
37
+ include Allowy::Matchers
38
+ end
@@ -3,11 +3,28 @@ require 'allowy/matchers'
3
3
  module Allowy
4
4
 
5
5
  module ControllerAuthorizationMacros
6
- def ignore_authorization!
7
- before(:each) do
8
- registry = double 'Registry'
9
- registry.stub(:can? => true, :cannot? => false, :authorize! => nil, access_control_for!: registry)
10
- @controller.stub(:current_allowy).and_return registry
6
+ extend ActiveSupport::Concern
7
+
8
+ def allowy
9
+ @controller.current_allowy
10
+ end
11
+
12
+
13
+ def should_authorize_for(*args)
14
+ allowy.should_receive(:authorize!).with(*args)
15
+ end
16
+
17
+ def should_not_authorize_for(*args)
18
+ allowy.should_not_receive(:authorize!).with(*args)
19
+ end
20
+
21
+ module ClassMethods
22
+ def ignore_authorization!
23
+ before(:each) do
24
+ registry = double 'Registry'
25
+ registry.stub(:can? => true, :cannot? => false, :authorize! => nil, access_control_for!: registry)
26
+ @controller.stub(:current_allowy).and_return registry
27
+ end
11
28
  end
12
29
  end
13
30
  end
@@ -15,6 +32,6 @@ module Allowy
15
32
  end
16
33
 
17
34
  RSpec.configure do |config|
18
- config.extend Allowy::ControllerAuthorizationMacros, :type => :controller
35
+ config.include Allowy::ControllerAuthorizationMacros, :type => :controller
19
36
  end
20
37
 
@@ -1,3 +1,3 @@
1
1
  module Allowy
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'allowy/rspec'
3
+
4
+ module Allowy
5
+ describe ControllerAuthorizationMacros do
6
+ include ControllerAuthorizationMacros
7
+ before { @controller = stub("FakeController") }
8
+
9
+ ignore_authorization!
10
+
11
+ it "aliases allowy as the current_allowy of the controller" do
12
+ allowy.should === @controller.current_allowy
13
+ end
14
+
15
+ describe "authorize_for matcher" do
16
+ it "works when authorised" do
17
+ should_authorize_for(:create, 123)
18
+ allowy.authorize!(:create, 123)
19
+ end
20
+ it "works when not authorised" do
21
+ should_not_authorize_for(:create, 123)
22
+ allowy.authorize!(:edit, 123)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allowy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-25 00:00:00.000000000 Z
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &70283147409820 !ruby/object:Gem::Requirement
16
+ requirement: &70204751889380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70283147409820
24
+ version_requirements: *70204751889380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70283147409320 !ruby/object:Gem::Requirement
27
+ requirement: &70204751888620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.2'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70283147409320
35
+ version_requirements: *70204751888620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70283147408900 !ruby/object:Gem::Requirement
38
+ requirement: &70204751887700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70283147408900
46
+ version_requirements: *70204751887700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &70283147408440 !ruby/object:Gem::Requirement
49
+ requirement: &70204751886120 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70283147408440
57
+ version_requirements: *70204751886120
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard
60
- requirement: &70283147408020 !ruby/object:Gem::Requirement
60
+ requirement: &70204751884900 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70283147408020
68
+ version_requirements: *70204751884900
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &70283147407600 !ruby/object:Gem::Requirement
71
+ requirement: &70204751883800 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70283147407600
79
+ version_requirements: *70204751883800
80
80
  description: Allowy provides CanCan-like way of checking permission but doesn't enforce
81
81
  a tight DSL giving you more control
82
82
  email:
@@ -103,6 +103,7 @@ files:
103
103
  - spec/access_control_spec.rb
104
104
  - spec/context_spec.rb
105
105
  - spec/registry_spec.rb
106
+ - spec/rspec_spec.rb
106
107
  - spec/spec_helper.rb
107
108
  homepage: ''
108
109
  licenses: []
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  version: '0'
125
126
  requirements: []
126
127
  rubyforge_project: allowy
127
- rubygems_version: 1.8.10
128
+ rubygems_version: 1.8.17
128
129
  signing_key:
129
130
  specification_version: 3
130
131
  summary: Authorization with simplicity and explicitness in mind
@@ -132,5 +133,5 @@ test_files:
132
133
  - spec/access_control_spec.rb
133
134
  - spec/context_spec.rb
134
135
  - spec/registry_spec.rb
136
+ - spec/rspec_spec.rb
135
137
  - spec/spec_helper.rb
136
- has_rdoc: