accessible_for 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/lib/accessible_for.rb +1 -1
- data/lib/mass_assignment_backport.rb +4 -1
- data/test/mass_assignment_test.rb +10 -1
- metadata +1 -1
data/lib/accessible_for.rb
CHANGED
@@ -21,7 +21,10 @@ module MassAssignmentBackport
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def sanitize_for_mass_assignment values, role=:default
|
24
|
-
return
|
24
|
+
return nil if values.nil?
|
25
|
+
if !self.class._accessible_attributes || self.class._accessible_attributes[role].nil?
|
26
|
+
return values
|
27
|
+
end
|
25
28
|
{}.tap do |result|
|
26
29
|
values.each do |k, v|
|
27
30
|
if self.class._accessible_attributes[role].include?(k.to_sym)
|
@@ -6,7 +6,7 @@ class MassAssignmentTest < MiniTest::Unit::TestCase
|
|
6
6
|
attr_accessible :price, :as => :manager
|
7
7
|
|
8
8
|
def test_nil_params
|
9
|
-
|
9
|
+
assert_nil sanitize_for_mass_assignment(nil)
|
10
10
|
end
|
11
11
|
def test_accessible_default
|
12
12
|
default = sanitize_for_mass_assignment :topping => 'salsa', :price => 123, :extra => 'foo'
|
@@ -22,6 +22,15 @@ class MassAssignmentTest < MiniTest::Unit::TestCase
|
|
22
22
|
assert !manager.has_key?(:extra), "role does not get extra key"
|
23
23
|
end
|
24
24
|
|
25
|
+
class UnspecifiedTest
|
26
|
+
include MassAssignmentBackport
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_unspecified_passes_values
|
30
|
+
unspec = UnspecifiedTest.new
|
31
|
+
assert_equal({:foo => :bar, :baz => :wubbo }, unspec.sanitize_for_mass_assignment(:foo => :bar, :baz => :wubbo))
|
32
|
+
end
|
33
|
+
|
25
34
|
class SubTest
|
26
35
|
include MassAssignmentBackport
|
27
36
|
attr_accessible :toasted
|