Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
Treat nil just as any other value, allowing to define NilClassAccess,…
Browse files Browse the repository at this point in the history
… see #4
  • Loading branch information
dnagir committed Feb 26, 2014
1 parent 79c8855 commit b1be9a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/allowy/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def access_control_for!(subject)
end

def access_control_for(subject)
return unless subject

# Try subject as decorated object
clazz = class_for "#{subject.class.source_class.name}Access" if subject.class.respond_to?(:source_class)

Expand Down
8 changes: 8 additions & 0 deletions spec/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ module Allowy
lambda { subject.access_control_for!(nil) }.should raise_error UndefinedAccessControl
end

it "should return NilClassAccess when subject is nil and NilClassAccess is defined" do
nil_class_access = Class.new do
include Allowy::AccessControl
end
stub_const("NilClassAccess", nil_class_access)
subject.access_control_for!(nil).should be_a nil_class_access
end

it "should return the same AC instance" do
first = subject.access_control_for!(Sample)
secnd = subject.access_control_for!(Sample)
Expand Down

0 comments on commit b1be9a0

Please sign in to comment.