objectbouncer 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,18 +95,22 @@ module ObjectBouncer
95
95
  end
96
96
 
97
97
  def protect_method!(method, force = false)
98
- renamed_method = "#{method}_without_objectbouncer".to_sym
99
98
  if method_defined?(method)
100
- return if method_defined?(renamed_method)
101
- return if !force && method_defined?(renamed_method)
102
- alias_method renamed_method, method
103
- define_method method do |*args, &block|
104
- if call_denied?(method, *args)
105
- raise ObjectBouncer::PermissionDenied.new
106
- else
107
- send(renamed_method, *args, &block)
99
+ renamed_method = "#{method}_without_objectbouncer".to_sym
100
+ new_method = "#{method}_with_objectbouncer".to_sym
101
+ unless method_defined?(new_method)
102
+ define_method new_method do |*args, &block|
103
+ if call_denied?(method, *args)
104
+ raise ObjectBouncer::PermissionDenied.new
105
+ else
106
+ send(renamed_method, *args, &block)
107
+ end
108
108
  end
109
109
  end
110
+ if instance_method(method) != instance_method(new_method)
111
+ alias_method renamed_method, method
112
+ alias_method method, new_method
113
+ end
110
114
  end
111
115
  end
112
116
 
@@ -12,9 +12,9 @@ class Book < ActiveRecord::Base
12
12
  deny :destroy
13
13
  end
14
14
 
15
- #def destroy
16
- # super
17
- #end
15
+ def destroy
16
+ super
17
+ end
18
18
  end
19
19
 
20
20
  class Author
@@ -66,8 +66,6 @@ class ActiveRecordTest < Test::Unit::TestCase
66
66
  @book = Book.create!(:name => "On Food & Cooking",
67
67
  :author => "Harold McGee",
68
68
  :price => 4900)
69
- @book_as_author = Book.as(@author).find(@book.id)
70
- @book_as_reader = Book.as(@author).find(@book.id)
71
69
  end
72
70
 
73
71
  should "prevent all users from destroying (even with an overridden method)" do
@@ -89,18 +89,6 @@ class ObjectBouncerTest < Test::Unit::TestCase
89
89
  end
90
90
  end
91
91
 
92
- should "be able to specify user on creation" do
93
- joe_public = JoePublic.new
94
- @president = President.as(joe_public).new
95
- assert_raise ObjectBouncer::PermissionDenied do
96
- @president.shake_hands
97
- end
98
-
99
- first_lady = MichelleObama.new
100
- @president = President.as(first_lady).new
101
- assert_equal "shaking hands", @president.shake_hands
102
- end
103
-
104
92
  end
105
93
 
106
94
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: objectbouncer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Glenn Gillen