johnsbrn-has_permission 0.2.0 → 0.2.1
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.yml +1 -1
- data/lib/permission/base.rb +4 -0
- data/test/has_permission_test.rb +4 -0
- data/test/test_helper.rb +4 -0
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/permission/base.rb
CHANGED
@@ -36,6 +36,10 @@ module Permission
|
|
36
36
|
object.update_attributes(attributes.reject{|key,value| !can_write?(key) })
|
37
37
|
end
|
38
38
|
|
39
|
+
def attributes
|
40
|
+
object.attributes.reject{|key,value| !can_read?(key) }
|
41
|
+
end
|
42
|
+
|
39
43
|
def read_attribute(attr_name)
|
40
44
|
if can_read?(attr_name)
|
41
45
|
object.read_attribute(attr_name)
|
data/test/has_permission_test.rb
CHANGED
@@ -58,6 +58,10 @@ class HasPermissionTest < Test::Unit::TestCase
|
|
58
58
|
@model.expects(:update_attributes).with(:write_access => "test")
|
59
59
|
@model.with_permission(nil).update_attributes(:no_access => "test", :write_access => "test")
|
60
60
|
end
|
61
|
+
|
62
|
+
should "only allow readable attributes for attributes" do
|
63
|
+
assert_equal [:read_access], @model.with_permission(nil).attributes.keys
|
64
|
+
end
|
61
65
|
|
62
66
|
should "only allow writeable attribute for update attribute" do
|
63
67
|
assert_raise PermissionException do
|
data/test/test_helper.rb
CHANGED