permissive 0.2.5.alpha → 0.2.6.alpha

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5.alpha
1
+ 0.2.6.alpha
@@ -81,7 +81,7 @@ module Permissive
81
81
  end
82
82
 
83
83
  def bits_for(scope, permissions)
84
- on = PermissionDefinition.normalize_scope(proxy_owner.class, scope)
84
+ on = Permissive::PermissionDefinition.normalize_scope(proxy_owner.class, scope)
85
85
  permissions.flatten.map do |permission|
86
86
  proxy_owner.class.permissions[on].try(:permissions).try(:[], permission.to_s.underscore.gsub('/', '_').to_sym) || raise(Permissive::InvalidPermissionError.new("#{proxy_owner.class.name} does not have a#{'n' if permission.to_s[0, 1].downcase =~ /[aeiou]/} #{permission} permission#{" on #{on}" if on}"))
87
87
  end
@@ -12,7 +12,8 @@ module Permissive
12
12
  {:conditions => {:scoped_object_id => scoped_object.id, :scoped_object_type => scoped_object.class.to_s}}
13
13
  when Class
14
14
  {:conditions => {:scoped_object_id => nil, :scoped_object_type => scoped_object.name}}
15
- when Symbol
15
+ when String, Symbol
16
+ scope =
16
17
  {:conditions => {:scoped_object_id => nil, :scoped_object_type => scoped_object.to_s.classify}}
17
18
  else
18
19
  {:conditions => {:scoped_object_id => nil, :scoped_object_type => nil}}
@@ -32,6 +32,8 @@ module Permissive
32
32
  def normalize_scope(model, scope)
33
33
  return :global if scope.to_s == 'global'
34
34
  scope = case scope
35
+ when ActiveRecord::Base
36
+ scope.class.name.to_s.tableize
35
37
  when Class
36
38
  scope.name.tableize
37
39
  when String, Symbol
@@ -86,12 +88,10 @@ module Permissive
86
88
  def role=(role_name)
87
89
  if role_name
88
90
  self.permissions = self.class.permissions[:global].roles[role_name.to_s.downcase.to_sym]
89
- if respond_to?(:write_attribute)
90
- write_attribute(:role, role_name.to_s.downcase.strip)
91
- end
92
91
  else
93
92
  self.permissions = []
94
93
  end
94
+ write_attribute(:role, role_name.to_s.downcase.strip)
95
95
  end
96
96
  end
97
97
  else
@@ -0,0 +1,31 @@
1
+ require File.join File.dirname(__FILE__), 'spec_helper'
2
+ load File.join File.dirname(__FILE__), 'spec_models.rb'
3
+
4
+ describe Permissive::PermissionDefinition do
5
+ describe "normalize_scope" do
6
+ it "should normalize an ActiveRecord::Base instance" do
7
+ user = Permissive::User.create!
8
+ Permissive::PermissionDefinition.normalize_scope(user.class, user).should == :permissive_users
9
+ end
10
+
11
+ it "should normalize a symbol" do
12
+ user = Permissive::User.create!
13
+ Permissive::PermissionDefinition.normalize_scope(user.class, :foobar).should == :foobars
14
+ end
15
+
16
+ it "should normalize a string" do
17
+ user = Permissive::User.create!
18
+ Permissive::PermissionDefinition.normalize_scope(user.class, 'baz').should == :bazs
19
+ end
20
+
21
+ it "should normalize a class" do
22
+ user = Permissive::User.create!
23
+ Permissive::PermissionDefinition.normalize_scope(user.class, Permissive::Organization).should == :permissive_organizations
24
+ end
25
+
26
+ it "should interpolate a class's name" do
27
+ user = Permissive::User.create!
28
+ Permissive::PermissionDefinition.normalize_scope(user.class, :organizations).should == :permissive_organizations
29
+ end
30
+ end
31
+ end
@@ -82,5 +82,13 @@ describe Permissive, "roles" do
82
82
  user.is_hungry_person?.should be_true
83
83
  user.is_sleepy_person?.should be_false
84
84
  end
85
+
86
+ it "should allow setting the role to 'nil'" do
87
+ user = UserWithRole.create!(:role => 'hungry_person')
88
+ user.can_eat?.should be_true
89
+ user.update_attributes(:role => nil)
90
+ user.can_eat?.should be_false
91
+ end
92
+
85
93
  end
86
94
  end
@@ -29,7 +29,9 @@ describe Permissive, "scoped permissions" do
29
29
 
30
30
  it "should not respond to generic permissions on scoped permissions" do
31
31
  @user.can!(:manage_games, :on => @organization)
32
- @user.can?(:manage_games).should be_false
32
+ lambda {
33
+ @user.can?(:manage_games).should be_false
34
+ }.should raise_error(Permissive::InvalidPermissionError)
33
35
  @user.can?(:manage_games, :on => @organization).should be_true
34
36
  end
35
37
 
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
8
+ - 6
9
9
  - alpha
10
- version: 0.2.5.alpha
10
+ version: 0.2.6.alpha
11
11
  platform: ruby
12
12
  authors:
13
13
  - Flip Sasser
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-20 00:00:00 -04:00
18
+ date: 2010-04-21 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -52,6 +52,7 @@ files:
52
52
  - spec/defining_permissions_spec.rb
53
53
  - spec/has_permissions_spec.rb
54
54
  - spec/metaprogramming_spec.rb
55
+ - spec/permission_definition_spec.rb
55
56
  - spec/rcov.opts
56
57
  - spec/roles_spec.rb
57
58
  - spec/scoping_permissions_spec.rb
@@ -95,6 +96,7 @@ test_files:
95
96
  - spec/defining_permissions_spec.rb
96
97
  - spec/has_permissions_spec.rb
97
98
  - spec/metaprogramming_spec.rb
99
+ - spec/permission_definition_spec.rb
98
100
  - spec/roles_spec.rb
99
101
  - spec/scoping_permissions_spec.rb
100
102
  - spec/spec_helper.rb