Module: EvelpidonTestHelpers::ActiveModel::MassAssignment::Assertions

Included in:
ActiveSupport::TestCase
Defined in:
lib/evelpidon_test_helpers/active_model/mass_assignment.rb

Instance Method Summary collapse

Instance Method Details

#assert_attribute_protected(model, attribute, value = "foo") ⇒ Object

Asserts that the given attribute on the given model cannot be assigned through mass-assignment (like +update_attributes).

Parameters:

  • model (ActiveModel)

    A properly initialized instance of the class that we want to test.

  • attribute (Symbol)

    The attribute that is protected

  • value (Object) (defaults to: "foo")

    An optional value to use when trying to assign the attribute.



11
12
13
14
15
16
17
18
# File 'lib/evelpidon_test_helpers/active_model/mass_assignment.rb', line 11

def assert_attribute_protected(model, attribute, value = "foo")
  model.send("#{attribute}=", nil)
  model.attributes = {attribute => value}
  assert_nil model.send(attribute), "#{attribute} could be set through 'update_attributes' call"

  model.send("#{attribute}=", value)
  assert_equal value, model.send(attribute)
end