reuser 2.0.0 → 3.0.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.
@@ -1,5 +1,5 @@
1
1
  module ReUser
2
- MAJOR = 2
2
+ MAJOR = 3
3
3
  MINOR = 0
4
4
  PATCH = 0
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
data/lib/reuser.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative "./reuser/role"
1
+ require "reuser/role"
2
2
 
3
3
  module ReUser
4
4
 
@@ -19,8 +19,12 @@ module ReUser
19
19
  end
20
20
  end
21
21
 
22
+ def permissions
23
+ self.class.role(self.role.to_sym).permissions
24
+ end
25
+
22
26
  def can? permission
23
- @role.can? permission
27
+ self.class.role(self.role.to_sym).can? permission
24
28
  end
25
29
 
26
30
  def cant? permission
@@ -28,10 +32,10 @@ module ReUser
28
32
  end
29
33
 
30
34
  def could? permission, block_args
31
- @role.could? permission, block_args
35
+ self.class.role(self.role.to_sym).could? permission, block_args
32
36
  end
33
37
 
34
38
  def couldnt? permission, block_args
35
- !(couldnt? permission, block_args)
39
+ !(could? permission, block_args)
36
40
  end
37
41
  end
@@ -1,4 +1,4 @@
1
- require_relative '../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Classes including ReUser" do
4
4
  let(:klass) do
@@ -1,10 +1,11 @@
1
- require_relative '../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Instances of a Class including ReUser" do
4
4
  let(:klass) do
5
5
  kls = Class.new
6
6
  kls.instance_eval do
7
7
  include ReUser
8
+ attr_accessor :role
8
9
 
9
10
  roles do
10
11
  role :admin do |admin|
@@ -20,15 +21,35 @@ describe "Instances of a Class including ReUser" do
20
21
 
21
22
  subject do
22
23
  instance = klass.new
23
- instance.instance_variable_set(:@role, klass.role(:admin))
24
+ instance.role = :admin
24
25
  instance
25
26
  end
26
27
 
27
- it "#can? and #could? are delegated to the ReUser::Role" do
28
- true
28
+ let(:admin_role) do
29
+ klass.role(:admin)
29
30
  end
30
31
 
31
- it "#cant? and #couldnt? are negations of #can? and #could?" do
32
- true
32
+ describe '#permissions' do
33
+ it 'returns the array of permissions on the subject\'s role' do
34
+ subject.permissions.should =~ [:read, :write]
35
+ end
36
+ end
37
+
38
+ specify "#can? is delegated to the ReUser::Role" do
39
+ admin_role.should_receive :can?
40
+ subject.can? :read
41
+ end
42
+
43
+ specify "#could? is delegated to the ReUser::Role" do
44
+ admin_role.should_receive :could?
45
+ subject.could? :write, 'Farsi'
46
+ end
47
+
48
+ specify "#cant? is #can? negated" do
49
+ subject.can?(:write).should == !(subject.cant? :write)
50
+ end
51
+
52
+ specify "#couldnt? is #could? negated" do
53
+ subject.could?(:write, 'Farsi').should == !(subject.couldnt? :write, 'Farsi')
33
54
  end
34
55
  end
@@ -1,4 +1,4 @@
1
- require_relative '../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe ReUser::Role do
4
4
  subject do
@@ -18,7 +18,7 @@ describe ReUser::Role do
18
18
 
19
19
  role = ReUser::Role.new :user, [:read, :write]
20
20
  role.name.should == :user
21
- role.permissions.should == [:read, :write]
21
+ role.permissions.should =~ [:read, :write]
22
22
  end
23
23
 
24
24
  context 'shares its name and permissions' do
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1 @@
1
- $: << '../'
2
- $: << './'
3
- require 'lib/reuser'
4
- autoload :ReUser, 'lib/reuser'
5
- require 'rspec/expectations'
1
+ require 'reuser'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reuser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-03 00:00:00.000000000 Z
12
+ date: 2012-06-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ReUse is an Internal DSL for Ruby to create roles and manage actions.
15
15
  email: isaac@isaacsanders.com
@@ -17,13 +17,13 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - lib/reuser.rb
21
20
  - lib/reuser/role.rb
22
21
  - lib/reuser/version.rb
23
- - spec/spec_helper.rb
22
+ - lib/reuser.rb
24
23
  - spec/reuser/class_spec.rb
25
- - spec/reuser/role_spec.rb
26
24
  - spec/reuser/instances_spec.rb
25
+ - spec/reuser/role_spec.rb
26
+ - spec/spec_helper.rb
27
27
  homepage: http://isaacbfsanders.com/reuser
28
28
  licenses: []
29
29
  post_install_message:
@@ -36,6 +36,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
36
  - - ! '>='
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
+ segments:
40
+ - 0
41
+ hash: -2919554755411533887
39
42
  required_rubygems_version: !ruby/object:Gem::Requirement
40
43
  none: false
41
44
  requirements:
@@ -44,12 +47,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
47
  version: '0'
45
48
  requirements: []
46
49
  rubyforge_project:
47
- rubygems_version: 1.8.15
50
+ rubygems_version: 1.8.24
48
51
  signing_key:
49
52
  specification_version: 3
50
53
  summary: An internal DSL for Ruby to make user role management simple.
51
54
  test_files:
52
- - spec/spec_helper.rb
53
55
  - spec/reuser/class_spec.rb
54
- - spec/reuser/role_spec.rb
55
56
  - spec/reuser/instances_spec.rb
57
+ - spec/reuser/role_spec.rb
58
+ - spec/spec_helper.rb