Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Filled out missing specs for authority_controlled (100% coverage).

Fixed the handling of authority_area for models that inherit their authorities from a related model.
  • Loading branch information...
commit eef4f846ec2731f4bc919da9d14a6d8cee4819db 1 parent 1168123
@grantneufeld authored
View
15 lib/authority_controlled.rb
@@ -60,14 +60,19 @@ def is_authority_restricted?
def self.authority_area
'#{option_area}'
end"
- elsif inherits_from.present?
+ else
+ # just fall back on the authority_area method inherited from ActiveRecord (defined below)
+ end
+ if inherits_from.present?
class_eval "
- def self.authority_area
- self.#{inherits_from}.authority_area
+ def authority_area
+ if self.#{inherits_from}
+ self.#{inherits_from}.authority_area
+ else
+ self.class.authority_area
+ end
end
"
- else
- # just fall back on the authority_area method inherited from ActiveRecord (defined below)
end
class_eval do
View
7 spec/models/authority_controlled_spec.rb
@@ -229,5 +229,12 @@ class TestAuthorityControlledCustomArea < ActiveRecord::Base
end
it "should not allow unauthorized users to access restricted items" do
end
+ it "should allow area-authorized users access when no item to inherit from" do
+ user = Factory.create(:user)
+ user.set_authority_on_area(INHERITED_AUTHORITY_CLASS.authority_area, :can_edit)
+ item = INHERITED_AUTHORITY_CLASS.create!(:sitepath => '/spec/authority/inherited/no_item', :redirect => '/')
+ item.has_authority_for_user_to?(user, :can_edit).should be_true
+ item.has_authority_for_user_to?(user, :can_delete).should be_false
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.