Fixed Base#update_attribute to be indifferent to whether a string or symbol is used to describe the name
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@341 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
d1abe806c5
commit
393e98a859
@ -1,5 +1,7 @@
|
|||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Fixed Base#update_attribute to be indifferent to whether a string or symbol is used to describe the name
|
||||||
|
|
||||||
* Added Base#toggle(attribute) and Base#toggle!(attribute) that makes it easier to flip a switch or flag.
|
* Added Base#toggle(attribute) and Base#toggle!(attribute) that makes it easier to flip a switch or flag.
|
||||||
|
|
||||||
Before: topic.update_attribute(:approved, !approved?)
|
Before: topic.update_attribute(:approved, !approved?)
|
||||||
|
@ -828,7 +828,7 @@ def clone
|
|||||||
# Note: This method is overwritten by the Validation module that'll make sure that updates made with this method
|
# Note: This method is overwritten by the Validation module that'll make sure that updates made with this method
|
||||||
# doesn't get subjected to validation checks. Hence, attributes can be updated even if the full object isn't valid.
|
# doesn't get subjected to validation checks. Hence, attributes can be updated even if the full object isn't valid.
|
||||||
def update_attribute(name, value)
|
def update_attribute(name, value)
|
||||||
self[name.to_s] = value
|
self[name] = value
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ def save_with_validation(perform_validation = true)
|
|||||||
# This is especially useful for boolean flags on existing records. The regular +update_attribute+ method
|
# This is especially useful for boolean flags on existing records. The regular +update_attribute+ method
|
||||||
# in Base is replaced with this when the validations module is mixed in, which it is by default.
|
# in Base is replaced with this when the validations module is mixed in, which it is by default.
|
||||||
def update_attribute_with_validation_skipping(name, value)
|
def update_attribute_with_validation_skipping(name, value)
|
||||||
@attributes[name] = value
|
self[name] = value
|
||||||
save(false)
|
save(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -367,6 +367,9 @@ def test_update_attribute
|
|||||||
assert !Topic.find(1).approved?
|
assert !Topic.find(1).approved?
|
||||||
Topic.find(1).update_attribute("approved", true)
|
Topic.find(1).update_attribute("approved", true)
|
||||||
assert Topic.find(1).approved?
|
assert Topic.find(1).approved?
|
||||||
|
|
||||||
|
Topic.find(1).update_attribute(:approved, false)
|
||||||
|
assert !Topic.find(1).approved?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mass_assignment_protection
|
def test_mass_assignment_protection
|
||||||
|
Loading…
Reference in New Issue
Block a user