Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for missing declaration and nil params

  • Loading branch information...
commit 8d246881f7d7c5133ed57df9718848deef560585 1 parent ec20b69
@zenhob authored
Showing with 14 additions and 2 deletions.
  1. +4 −1 lib/mass_assignment_backport.rb
  2. +10 −1 test/mass_assignment_test.rb
View
5 lib/mass_assignment_backport.rb
@@ -21,7 +21,10 @@ def accessible_attributes role=:default
end
def sanitize_for_mass_assignment values, role=:default
- return {} if values.nil?
+ return nil if values.nil?
+ if !self.class._accessible_attributes || self.class._accessible_attributes[role].nil?
+ return values
+ end
{}.tap do |result|
values.each do |k, v|
if self.class._accessible_attributes[role].include?(k.to_sym)
View
11 test/mass_assignment_test.rb
@@ -6,7 +6,7 @@ class MassAssignmentTest < MiniTest::Unit::TestCase
attr_accessible :price, :as => :manager
def test_nil_params
- assert_empty sanitize_for_mass_assignment(nil)
+ assert_nil sanitize_for_mass_assignment(nil)
end
def test_accessible_default
default = sanitize_for_mass_assignment :topping => 'salsa', :price => 123, :extra => 'foo'
@@ -22,6 +22,15 @@ def test_accessible_role
assert !manager.has_key?(:extra), "role does not get extra key"
end
+ class UnspecifiedTest
+ include MassAssignmentBackport
+ end
+
+ def test_unspecified_passes_values
+ unspec = UnspecifiedTest.new
+ assert_equal({:foo => :bar, :baz => :wubbo }, unspec.sanitize_for_mass_assignment(:foo => :bar, :baz => :wubbo))
+ end
+
class SubTest
include MassAssignmentBackport
attr_accessible :toasted
Please sign in to comment.
Something went wrong with that request. Please try again.