arrthorizer 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ Gemfile
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/.travis.yml CHANGED
@@ -4,3 +4,7 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1.0
7
+ gemfile:
8
+ - gemfiles/Gemfile.rails.3.2
9
+ - gemfiles/Gemfile.rails.4.0
10
+ - gemfiles/Gemfile.rails.4.1
@@ -2,9 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 3.2.16'
4
4
 
5
- # Specify your gem's dependencies in arrthorizer.gemspec
6
- gemspec
5
+ gemspec path: '../'
7
6
 
8
7
  group :test do
9
8
  gem 'rake'
10
9
  end
10
+
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.0.0'
4
+
5
+ gemspec path: '../'
6
+
7
+ group :test do
8
+ gem 'rake'
9
+ end
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.1.0.beta1'
4
+
5
+ gemspec path: '../'
6
+
7
+ group :test do
8
+ gem 'rake'
9
+ end
10
+
@@ -61,6 +61,10 @@ module Arrthorizer
61
61
  marshal_dump
62
62
  end
63
63
 
64
+ def eql?(other)
65
+ self == other
66
+ end
67
+
64
68
  def ==(other)
65
69
  to_hash == other.to_hash
66
70
  end
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module Arrthorizer
2
4
  module Rails
3
5
  class Configuration
@@ -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
@@ -2,14 +2,18 @@ require 'rspec/expectations'
2
2
 
3
3
  module Arrthorizer
4
4
  module RSpec
5
- autoload :Matchers, 'arrthorizer/rspec/matchers'
5
+ autoload :Matchers, 'arrthorizer/rspec/matchers'
6
+ autoload :SharedExamples, 'arrthorizer/rspec/shared_examples'
6
7
  end
7
8
 
8
- ::RSpec.configure do |config|
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
 
@@ -1,3 +1,3 @@
1
1
  module Arrthorizer
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -5,49 +5,47 @@ describe <%= class_name %> do
5
5
 
6
6
  let(:user) { double(:user) }
7
7
 
8
- let(:context_hash) { { } }
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 context_hash to make the ContextRole apply to the user
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.applies_to_user?(user, current_context)).to be_true
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
- specify "no state is maintained in the role object" do
26
- role.applies_to_user?(user, current_context)
27
-
28
- role.instance.instance_variables.should be_empty
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 context_hash
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.applies_to_user?(user, current_context)).to be_false
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
- specify "no state is maintained in the role object" do
47
- role.applies_to_user?(user, current_context)
48
-
49
- role.instance.instance_variables.should be_empty
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
@@ -12,7 +12,7 @@ describe Arrthorizer::ArrthorizerException do
12
12
  begin
13
13
  raise Arrthorizer::ArrthorizerException
14
14
  rescue Exception => e
15
- e.inner.should be inner_exception
15
+ expect(e.inner).to be inner_exception
16
16
  end
17
17
  end
18
18
  end
@@ -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.should be_an Arrthorizer::Context
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).should == value
18
+ expect(result.send(key)).to eql value
19
19
  end
20
20
  end
21
21
  end
@@ -5,7 +5,7 @@ describe Arrthorizer::ContextBuilder do
5
5
 
6
6
  describe :build do
7
7
  it "returns an Arrthorizer::Context" do
8
- builder.build.should be_an Arrthorizer::Context
8
+ expect(builder.build).to be_an Arrthorizer::Context
9
9
  end
10
10
  end
11
11
  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.should be_an Arrthorizer::Context
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).should == value
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).should be(param)
45
+ expect(Arrthorizer::Context(param)).to be(param)
46
46
  end
47
47
  end
48
48
  end
@@ -5,7 +5,7 @@ describe Arrthorizer::Group do
5
5
  it "registers the new instance with Role" do
6
6
  role = Arrthorizer::Group.new("some new group")
7
7
 
8
- Arrthorizer::Role.get(role).should == role
8
+ expect(Arrthorizer::Role.get(role)).to eql role
9
9
  end
10
10
  end
11
11
  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).should be context_role
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.should be_success
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.should be_forbidden
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.should be_forbidden
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.should be_success
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.should be_forbidden
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.should be_forbidden
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 set" do
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)
@@ -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 set does not exist" do
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 set with the given name exists" do
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 set" do
21
- Arrthorizer::Privilege.get(name).should be @privilege
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 set" do
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 set is returned" do
31
- Arrthorizer::Privilege.get(@privilege).should be @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).should be_a 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.should respond_to :to_prepare_context
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.should respond_to :arrthorizer_configuration
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.should include :arrthorizer_context
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).should == Arrthorizer::Context(injected_params)
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).should == expected_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
@@ -18,4 +18,8 @@ end
18
18
 
19
19
  RSpec.configure do |config|
20
20
  config.use_transactional_fixtures = true
21
+
22
+ config.expect_with :rspec do |c|
23
+ c.syntax = :expect
24
+ end
21
25
  end
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.1.3
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-03-18 00:00:00.000000000 Z
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: -4378932366296225598
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: -4378932366296225598
212
+ hash: -1100063686042318668
210
213
  requirements: []
211
214
  rubyforge_project:
212
215
  rubygems_version: 1.8.24