Browse files

Support 'source_class' and drapper for providing custom access class,…

… fix spec
  • Loading branch information...
1 parent e3f9b5a commit 2fc79f502b40118d9cce0ac25735f4f7444f64ff @dnagir committed Mar 1, 2013
Showing with 5 additions and 11 deletions.
  1. +3 −5 lib/allowy/registry.rb
  2. +2 −6 spec/registry_spec.rb
View
8 lib/allowy/registry.rb
@@ -14,10 +14,8 @@ def access_control_for!(subject)
def access_control_for(subject)
return unless subject
- clazz = if defined?(Draper::Decorator) && subject.class <= Draper::Decorator
- # Try subject as decorated object
- class_for "#{subject.class.source_class.name}Access"
- end
+ # Try subject as decorated object
+ clazz = class_for "#{subject.class.source_class.name}Access" if subject.class.respond_to?(:source_class)
# Try subject as an object
clazz = class_for "#{subject.class.name}Access" unless clazz
@@ -31,7 +29,7 @@ def access_control_for(subject)
end
def class_for(name)
- name.constantize rescue nil #TODO: Handle just the NameError
+ name.safe_constantize
end
end
View
8 spec/registry_spec.rb
@@ -31,17 +31,13 @@ module Allowy
first.should === secnd
end
- it "should support objects decorated with Draper" do
- stub_const('Draper::Decorator', Class.new)
-
- decorator_class = Class.new(Draper::Decorator) do
+ it "should support objects that provide source_class method (such as Draper)" do
+ decorator_class = Class.new do
def self.source_class
Sample
end
end
-
decorated_object = decorator_class.new
-
subject.access_control_for!(decorated_object).should be_a SampleAccess
end

0 comments on commit 2fc79f5

Please sign in to comment.