diff options
author | Prathamesh Sonpatki <csonpatki@gmail.com> | 2015-01-11 13:53:28 +0530 |
---|---|---|
committer | Prathamesh Sonpatki <csonpatki@gmail.com> | 2015-01-18 20:00:57 +0530 |
commit | 0fcd4cf5c26c470623eef9af72a134ef6ba1a701 (patch) | |
tree | f1b09c2bcc6e467a0346de158c4218df65e80c46 /activerecord/test | |
parent | 8a87ebfd8f5f3ca2e7d7c063f8cc98158896e475 (diff) | |
download | rails-0fcd4cf5c26c470623eef9af72a134ef6ba1a701.tar.gz rails-0fcd4cf5c26c470623eef9af72a134ef6ba1a701.tar.bz2 rails-0fcd4cf5c26c470623eef9af72a134ef6ba1a701.zip |
Run SQL only if attribute changed for update_attribute method
- This is based on https://github.com/rails/rails/issues/18400 but
tackling same issue with update_attribute method instead of update method.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index d6816041bc..2803ad2de0 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -356,6 +356,16 @@ class PersistenceTest < ActiveRecord::TestCase assert_equal("David", topic_reloaded.author_name) end + def test_update_attribute_does_not_run_sql_if_attribute_is_not_changed + klass = Class.new(Topic) do + def self.name; 'Topic'; end + end + topic = klass.create(title: 'Another New Topic') + assert_queries(0) do + topic.update_attribute(:title, 'Another New Topic') + end + end + def test_delete topic = Topic.find(1) assert_equal topic, topic.delete, 'topic.delete did not return self' |