arrthorizer 0.1.3 → 0.2.0
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/.gitignore +1 -0
- data/.travis.yml +4 -0
- data/{Gemfile → gemfiles/Gemfile.rails.3.2} +2 -2
- data/gemfiles/Gemfile.rails.4.0 +9 -0
- data/gemfiles/Gemfile.rails.4.1 +10 -0
- data/lib/arrthorizer/context.rb +4 -0
- data/lib/arrthorizer/rails/configuration.rb +2 -0
- data/lib/arrthorizer/rspec/shared_examples.rb +12 -0
- data/lib/arrthorizer/rspec.rb +7 -3
- data/lib/arrthorizer/version.rb +1 -1
- data/lib/generators/rspec/context_role/templates/role_spec.rb +14 -16
- data/spec/arrthorizer_exception/inner_spec.rb +1 -1
- data/spec/context/merge_spec.rb +2 -2
- data/spec/context_builder/build_spec.rb +1 -1
- data/spec/context_spec.rb +3 -3
- data/spec/integration/group/initialize_spec.rb +1 -1
- data/spec/integration/role_spec.rb +1 -1
- data/spec/integration/some_controller_spec.rb +6 -6
- data/spec/permission/grant_spec.rb +1 -1
- data/spec/privilege/get_spec.rb +11 -7
- data/spec/rails/controller_concern/arrthorizer_context_spec.rb +3 -1
- data/spec/rails/controller_concern/integration_spec.rb +9 -5
- data/spec/spec_helper.rb +4 -0
- metadata +8 -5
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/lib/arrthorizer/context.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
Arrthorizer::RSpec::SharedExamples do
|
2
|
+
shared_examples "not persisting state in the role object" do |options = {}|
|
3
|
+
specify "no state is maintained in the role object" do
|
4
|
+
the_role = options[:role] || role
|
5
|
+
the_context = options[:current_context] || current_context
|
6
|
+
|
7
|
+
the_role.applies_to_user?(user, Arrthorizer::Context(the_context))
|
8
|
+
|
9
|
+
expect(the_role.instance.instance_variables).to be_empty
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/arrthorizer/rspec.rb
CHANGED
@@ -2,14 +2,18 @@ require 'rspec/expectations'
|
|
2
2
|
|
3
3
|
module Arrthorizer
|
4
4
|
module RSpec
|
5
|
-
autoload :Matchers,
|
5
|
+
autoload :Matchers, 'arrthorizer/rspec/matchers'
|
6
|
+
autoload :SharedExamples, 'arrthorizer/rspec/shared_examples'
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
-
config.include Arrthorizer::RSpec::Matchers::Roles, {
|
9
|
+
role_spec = {
|
10
10
|
type: :role,
|
11
11
|
example_group: { file_path: %r(spec/roles) }
|
12
12
|
}
|
13
|
+
|
14
|
+
::RSpec.configure do |config|
|
15
|
+
config.include Arrthorizer::RSpec::Matchers::Roles, role_spec
|
16
|
+
config.include Arrthorizer::RSpec::SharedExamples, role_spec
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
data/lib/arrthorizer/version.rb
CHANGED
@@ -5,49 +5,47 @@ describe <%= class_name %> do
|
|
5
5
|
|
6
6
|
let(:user) { double(:user) }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
let(:current_context) { Arrthorizer::Context.new(context_hash) }
|
8
|
+
let(:current_context) { { } }
|
10
9
|
|
11
10
|
describe :applies_to_user? do
|
12
11
|
context "when some_condition" do
|
13
12
|
before :each do
|
14
|
-
# TODO: Add the required elements to the
|
13
|
+
# TODO: Add the required elements to the current_context
|
14
|
+
# to make the ContextRole apply to the user
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns true" do
|
18
18
|
pending
|
19
19
|
|
20
|
-
expect(role.
|
20
|
+
expect(role).to apply_to_user(user).with_context(current_context)
|
21
21
|
end
|
22
22
|
|
23
23
|
# This is an extremely important test - it safeguards against
|
24
24
|
# persisting data between requests.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
25
|
+
# if you want to rename the 'role' or 'current_context' variables,
|
26
|
+
# you can call this shared example with different options like so:
|
27
|
+
# it_behaves_like "not persisting state in the role object", role: some_role, current_context: some_context
|
28
|
+
it_behaves_like "not persisting state in the role object"
|
30
29
|
end
|
31
30
|
|
32
31
|
context "when some_other_condition" do
|
33
32
|
before :each do
|
34
|
-
# TODO: Add the required elements to the
|
33
|
+
# TODO: Add the required elements to the current_context
|
35
34
|
# to make the ContextRole *not* apply to the user
|
36
35
|
end
|
37
36
|
|
38
37
|
it "returns false" do
|
39
38
|
pending
|
40
39
|
|
41
|
-
expect(role.
|
40
|
+
expect(role).not_to apply_to_user(user).with_context(current_context)
|
42
41
|
end
|
43
42
|
|
44
43
|
# This is an extremely important test - it safeguards against
|
45
44
|
# persisting data between requests.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
45
|
+
# if you want to rename the 'role' or 'current_context' variables,
|
46
|
+
# you can call this shared example with different options like so:
|
47
|
+
# it_behaves_like "not persisting state in the role object", role: some_role, current_context: some_context
|
48
|
+
it_behaves_like "not persisting state in the role object"
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|
data/spec/context/merge_spec.rb
CHANGED
@@ -9,13 +9,13 @@ describe Arrthorizer::Context do
|
|
9
9
|
|
10
10
|
shared_examples_for "the return value of Arrthorizer::Context#merge" do
|
11
11
|
it "returns an Arrthorizer::Context" do
|
12
|
-
result.
|
12
|
+
expect(result).to be_an Arrthorizer::Context
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "the returned Arrthorizer::Context" do
|
16
16
|
it "contains the merged contents" do
|
17
17
|
merged_hash.each_pair do |key, value|
|
18
|
-
result.send(key).
|
18
|
+
expect(result.send(key)).to eql value
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/spec/context_spec.rb
CHANGED
@@ -26,14 +26,14 @@ describe Arrthorizer do
|
|
26
26
|
it "returns an Arrthorizer::Context" do
|
27
27
|
result = Arrthorizer::Context(arg)
|
28
28
|
|
29
|
-
result.
|
29
|
+
expect(result).to be_an Arrthorizer::Context
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "the returned Arrthorizer::Context" do
|
33
33
|
let(:result) { Arrthorizer::Context(arg) }
|
34
34
|
|
35
35
|
specify "it contains the same key-value pairs" do
|
36
|
-
result.send(key).
|
36
|
+
expect(result.send(key)).to eql(value)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -42,7 +42,7 @@ describe Arrthorizer do
|
|
42
42
|
let(:param) { Arrthorizer::Context.new }
|
43
43
|
|
44
44
|
specify "that context is returned unmodified" do
|
45
|
-
Arrthorizer::Context(param).
|
45
|
+
expect(Arrthorizer::Context(param)).to be(param)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -5,7 +5,7 @@ describe Arrthorizer::Role do
|
|
5
5
|
let(:context_role) { class TestRole < Arrthorizer::ContextRole; end; TestRole.instance }
|
6
6
|
|
7
7
|
specify "that role is stored" do
|
8
|
-
Arrthorizer::Role.get(context_role.to_key).
|
8
|
+
expect(Arrthorizer::Role.get(context_role.to_key)).to be context_role
|
9
9
|
end
|
10
10
|
|
11
11
|
after :each do
|
@@ -28,7 +28,7 @@ describe SomeController do
|
|
28
28
|
it "succeeds" do
|
29
29
|
get :some_action
|
30
30
|
|
31
|
-
response.
|
31
|
+
expect(response).to be_success
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -40,7 +40,7 @@ describe SomeController do
|
|
40
40
|
it "fails" do
|
41
41
|
get :some_action
|
42
42
|
|
43
|
-
response.
|
43
|
+
expect(response).to be_forbidden
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -57,7 +57,7 @@ describe SomeController do
|
|
57
57
|
it "fails" do
|
58
58
|
get :some_action
|
59
59
|
|
60
|
-
response.
|
60
|
+
expect(response).to be_forbidden
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -87,7 +87,7 @@ describe SomeController do
|
|
87
87
|
it "succeeds" do
|
88
88
|
get :some_action, some_param: allow_request
|
89
89
|
|
90
|
-
response.
|
90
|
+
expect(response).to be_success
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -97,7 +97,7 @@ describe SomeController do
|
|
97
97
|
it "succeeds" do
|
98
98
|
get :some_action, some_param: allow_request
|
99
99
|
|
100
|
-
response.
|
100
|
+
expect(response).to be_forbidden
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -114,7 +114,7 @@ describe SomeController do
|
|
114
114
|
it "still fails" do
|
115
115
|
get :some_action, some_param: allow_request
|
116
116
|
|
117
|
-
response.
|
117
|
+
expect(response).to be_forbidden
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
@@ -5,7 +5,7 @@ describe Arrthorizer::Permission do
|
|
5
5
|
let(:privilege) { Arrthorizer::Privilege.new(name: "privilege") }
|
6
6
|
let(:role) { Arrthorizer::Group.new("role") }
|
7
7
|
|
8
|
-
it "adds the role to the privilege
|
8
|
+
it "adds the role to the privilege" do
|
9
9
|
Arrthorizer::Permission.grant(privilege, to: role)
|
10
10
|
|
11
11
|
expect(privilege).to be_accessible_to(role)
|
data/spec/privilege/get_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Arrthorizer::Privilege do
|
4
4
|
describe :get do
|
5
|
-
context "when the privilege
|
5
|
+
context "when the privilege does not exist" do
|
6
6
|
it "raises a Privilege::NotFound error" do
|
7
7
|
expect {
|
8
8
|
Arrthorizer::Privilege.get("computer_says_no")
|
@@ -10,25 +10,29 @@ describe Arrthorizer::Privilege do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
context "when the privilege
|
13
|
+
context "when the privilege with the given name exists" do
|
14
14
|
let(:name) { "computer_says_hi" }
|
15
15
|
|
16
16
|
before do
|
17
17
|
@privilege = Arrthorizer::Privilege.new(name: name)
|
18
18
|
end
|
19
19
|
|
20
|
-
it "returns that privilege
|
21
|
-
Arrthorizer::Privilege.get(name)
|
20
|
+
it "returns that privilege" do
|
21
|
+
fetched_privilege = Arrthorizer::Privilege.get(name)
|
22
|
+
|
23
|
+
expect(fetched_privilege).to be @privilege
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
context "when the parameter is already a privilege
|
27
|
+
context "when the parameter is already a privilege" do
|
26
28
|
before do
|
27
29
|
@privilege = Arrthorizer::Privilege.new(name: "irrelevant")
|
28
30
|
end
|
29
31
|
|
30
|
-
specify "that privilege
|
31
|
-
Arrthorizer::Privilege.get(@privilege)
|
32
|
+
specify "that privilege is returned" do
|
33
|
+
fetched_privilege = Arrthorizer::Privilege.get(@privilege)
|
34
|
+
|
35
|
+
expect(fetched_privilege).to be @privilege
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -16,7 +16,9 @@ describe Arrthorizer::Rails::ControllerConcern do
|
|
16
16
|
|
17
17
|
describe :arrthorizer_context do
|
18
18
|
it "returns an Arrthorizer::Context" do
|
19
|
-
controller.send(:arrthorizer_context)
|
19
|
+
context = controller.send(:arrthorizer_context)
|
20
|
+
|
21
|
+
expect(context).to be_a Arrthorizer::Context
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -8,11 +8,11 @@ describe Arrthorizer::Rails do
|
|
8
8
|
|
9
9
|
describe "each controller class" do
|
10
10
|
it "responds to :prepare_context" do
|
11
|
-
controller_class.
|
11
|
+
expect(controller_class).to respond_to :to_prepare_context
|
12
12
|
end
|
13
13
|
|
14
14
|
it "responds to :arrthorizer_configuration" do
|
15
|
-
controller_class.
|
15
|
+
expect(controller_class).to respond_to :arrthorizer_configuration
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -22,7 +22,7 @@ describe Arrthorizer::Rails do
|
|
22
22
|
it "has a protected method called :arrthorizer_context" do
|
23
23
|
# this method is protected to prevent exposing it
|
24
24
|
# via default or wildcard routes
|
25
|
-
controller.protected_methods.
|
25
|
+
expect(controller.protected_methods).to include :arrthorizer_context
|
26
26
|
end
|
27
27
|
|
28
28
|
context "when it has a proper configuration for context building" do
|
@@ -45,7 +45,9 @@ describe Arrthorizer::Rails do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "uses the 'default' config to build an Arrthorizer context" do
|
48
|
-
controller.send(:arrthorizer_context)
|
48
|
+
context = controller.send(:arrthorizer_context)
|
49
|
+
|
50
|
+
expect(context).to eql Arrthorizer::Context(injected_params)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -68,7 +70,9 @@ describe Arrthorizer::Rails do
|
|
68
70
|
context_hash = injected_params.merge(action_specific_config)
|
69
71
|
expected_context = Arrthorizer::Context(context_hash)
|
70
72
|
|
71
|
-
controller.send(:arrthorizer_context)
|
73
|
+
context = controller.send(:arrthorizer_context)
|
74
|
+
|
75
|
+
expect(context).to eql expected_context
|
72
76
|
end
|
73
77
|
end
|
74
78
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arrthorizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -86,12 +86,14 @@ extra_rdoc_files: []
|
|
86
86
|
files:
|
87
87
|
- .gitignore
|
88
88
|
- .travis.yml
|
89
|
-
- Gemfile
|
90
89
|
- LICENSE.txt
|
91
90
|
- README.md
|
92
91
|
- Rakefile
|
93
92
|
- arrthorizer.gemspec
|
94
93
|
- config.ru
|
94
|
+
- gemfiles/Gemfile.rails.3.2
|
95
|
+
- gemfiles/Gemfile.rails.4.0
|
96
|
+
- gemfiles/Gemfile.rails.4.1
|
95
97
|
- lib/arrthorizer.rb
|
96
98
|
- lib/arrthorizer/arrthorizer_exception.rb
|
97
99
|
- lib/arrthorizer/context.rb
|
@@ -111,6 +113,7 @@ files:
|
|
111
113
|
- lib/arrthorizer/roles.rb
|
112
114
|
- lib/arrthorizer/rspec.rb
|
113
115
|
- lib/arrthorizer/rspec/matchers.rb
|
116
|
+
- lib/arrthorizer/rspec/shared_examples.rb
|
114
117
|
- lib/arrthorizer/version.rb
|
115
118
|
- lib/generators/arrthorizer/context_role/USAGE
|
116
119
|
- lib/generators/arrthorizer/context_role/context_role_generator.rb
|
@@ -197,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
200
|
version: '0'
|
198
201
|
segments:
|
199
202
|
- 0
|
200
|
-
hash: -
|
203
|
+
hash: -1100063686042318668
|
201
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
205
|
none: false
|
203
206
|
requirements:
|
@@ -206,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
209
|
version: '0'
|
207
210
|
segments:
|
208
211
|
- 0
|
209
|
-
hash: -
|
212
|
+
hash: -1100063686042318668
|
210
213
|
requirements: []
|
211
214
|
rubyforge_project:
|
212
215
|
rubygems_version: 1.8.24
|