Permalink
Browse files

Merge pull request #26616 from prathamesh-sonpatki/backport-update-at…

…tribute-new

Return true if attribute is not changed for update_attribute
  • Loading branch information...
eileencodes committed Sep 25, 2016
2 parents 7a65bcd + 75f274c commit bab76cd46ff1b4df5f8c1c8901252ba86db24919
@@ -1,3 +1,10 @@
* Return `true` from `update_attribute` when the value of the attribute
to be updated is unchanged.
Fixes #26593.
*Prathamesh Sonpatki*
* Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`
*Trung Duc Tran*
@@ -252,7 +252,8 @@ def update_attribute(name, value)
name = name.to_s
verify_readonly_attribute(name)
public_send("#{name}=", value)
save(validate: false) if changed?
changed? ? save(validate: false) : true
end
# Updates the attributes of the model from the passed-in hash and saves the
@@ -391,14 +391,14 @@ def self.name; 'Topic'; end
end
topic = klass.create(title: 'Another New Topic')
assert_queries(0) do
topic.update_attribute(:title, 'Another New Topic')
assert topic.update_attribute(:title, "Another New Topic")
end
end
def test_update_does_not_run_sql_if_record_has_not_changed
topic = Topic.create(title: 'Another New Topic')
assert_queries(0) { topic.update(title: 'Another New Topic') }
assert_queries(0) { topic.update_attributes(title: 'Another New Topic') }
topic = Topic.create(title: "Another New Topic")
assert_queries(0) { assert topic.update(title: "Another New Topic") }
assert_queries(0) { assert topic.update_attributes(title: "Another New Topic") }
end
def test_delete

0 comments on commit bab76cd

Please sign in to comment.