johnsbrn-has_permission 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 2
3
3
  :major: 0
4
4
  :minor: 2
@@ -36,6 +36,14 @@ module Permission
36
36
  object.update_attributes(attributes.reject{|key,value| !can_write?(key) })
37
37
  end
38
38
 
39
+ def attribute_names
40
+ object.attribute_names.reject{|key| !can_read?(key) }
41
+ end
42
+
43
+ def column_names
44
+ object.column_names.reject{|key| !can_read?(key) }
45
+ end
46
+
39
47
  def attributes
40
48
  object.attributes.reject{|key,value| !can_read?(key) }
41
49
  end
@@ -63,6 +63,14 @@ class HasPermissionTest < Test::Unit::TestCase
63
63
  assert_equal [:read_access], @model.with_permission(nil).attributes.keys
64
64
  end
65
65
 
66
+ should "only allow readable attributes for attribute_names" do
67
+ assert_equal [:read_access], @model.with_permission(nil).attribute_names
68
+ end
69
+
70
+ should "only allow readable attributes for column_names" do
71
+ assert_equal [:read_access], @model.with_permission(nil).column_names
72
+ end
73
+
66
74
  should "only allow writeable attribute for update attribute" do
67
75
  assert_raise PermissionException do
68
76
  @model.with_permission(nil).update_attribute(:no_access, "test")
@@ -21,6 +21,14 @@ class Model
21
21
  value
22
22
  end
23
23
 
24
+ def column_names
25
+ [:read_access, :no_access]
26
+ end
27
+
28
+ def attribute_names
29
+ [:read_access, :no_access]
30
+ end
31
+
24
32
  def attributes
25
33
  {:read_access => "test", :no_access => "test"}
26
34
  end
@@ -56,9 +64,9 @@ module Permission
56
64
  end
57
65
 
58
66
  def can_write?(attr_name)
59
- case attr_name
60
- when :write_access : true
61
- when :no_access : false
67
+ case attr_name.to_s
68
+ when "write_access" : true
69
+ when "no_access" : false
62
70
  else true
63
71
  end
64
72
  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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Johnson