Skip to content

Loading…

Fix ActiveRecord#update_column return value #8083

Merged
merged 1 commit into from

5 participants

@saks

I think I have a fix for incorrect return value from ActiveRecord#update_column method.

@josevalim josevalim merged commit f5f57e2 into rails:3-2-stable
@fxn

The return value is not guaranteed to be a singleton, we should just test

assert return_value
@spastorino
Ruby on Rails member

We need a CHANGELOG entry for this

@carlosantoniodasilva
Ruby on Rails member

@spastorino is it really necessary in this case, since it was added right before the rc1 was released, in cherry pick cdfa4a5?

@spastorino
Ruby on Rails member

@carlosantoniodasilva got it, I doesn't need a CHANGELOG entry just an entry in rc2 release changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 31, 2012
  1. @saks
Showing with 7 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/persistence.rb
  2. +6 −0 activerecord/test/cases/persistence_test.rb
View
2 activerecord/lib/active_record/persistence.rb
@@ -194,7 +194,7 @@ def update_column(name, value)
raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name)
raise ActiveRecordError, "can not update on a new record object" unless persisted?
- updated_count = self.class.update_all({ name => value }, self.class.primary_key => id) == 1
+ updated_count = self.class.update_all({ name => value }, self.class.primary_key => id)
raw_write_attribute(name, value)
View
6 activerecord/test/cases/persistence_test.rb
@@ -513,6 +513,12 @@ def test_update_column_changing_id
assert_equal 123, topic.id
end
+ def test_update_column_should_return_correct_value
+ developer = Developer.find(1)
+ return_value = developer.update_column(:salary, 80001)
+ assert_equal return_value, true
+ end
+
def test_update_attributes
topic = Topic.find(1)
assert !topic.approved?
Something went wrong with that request. Please try again.