johnsbrn-has_permission 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 0
2
+ :patch: 1
3
3
  :major: 0
4
4
  :minor: 2
@@ -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)
@@ -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
@@ -21,6 +21,10 @@ class Model
21
21
  value
22
22
  end
23
23
 
24
+ def attributes
25
+ {:read_access => "test", :no_access => "test"}
26
+ end
27
+
24
28
  def some_method
25
29
  "no permission"
26
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: johnsbrn-has_permission
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Johnson