Skip to content

Commit

Permalink
Fix ActiveRecord#update_column return value
Browse files Browse the repository at this point in the history
  • Loading branch information
saks committed Oct 31, 2012
1 parent d5b275d commit 68307a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/persistence.rb
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/persistence_test.rb
Expand Up @@ -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

This comment has been minimized.

Copy link
@fxn

fxn Oct 31, 2012

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

assert return_value
end

def test_update_attributes
topic = Topic.find(1)
assert !topic.approved?
Expand Down

0 comments on commit 68307a1

Please sign in to comment.