diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-27 21:44:30 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-27 21:44:30 -0700 |
commit | 3ba552fb2900ce67409af57f3c7a1f9fda4c10d3 (patch) | |
tree | fa3db96769d699bc7bdb4623d727c7302b0d6159 /activerecord/test/cases/persistence_test.rb | |
parent | 307ec3db0fe26cbd1811d34a27e6637726ce23ce (diff) | |
parent | e780e2fda326fa5ea616e1441a6ed81b2890085c (diff) | |
download | rails-3ba552fb2900ce67409af57f3c7a1f9fda4c10d3.tar.gz rails-3ba552fb2900ce67409af57f3c7a1f9fda4c10d3.tar.bz2 rails-3ba552fb2900ce67409af57f3c7a1f9fda4c10d3.zip |
Merge pull request #18225 from DanOlson/update-without-changing-timestamps
Provide :touch option to save() to accommodate saving without updating t...
Diffstat (limited to 'activerecord/test/cases/persistence_test.rb')
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 6fc4731f01..cf5a5de3a0 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -878,4 +878,35 @@ class PersistenceTest < ActiveRecord::TestCase assert_equal "Welcome to the weblog", post.title assert_not post.new_record? end + + class SaveTest < ActiveRecord::TestCase + self.use_transactional_fixtures = false + + def test_save_touch_false + widget = Class.new(ActiveRecord::Base) do + connection.create_table :widgets, force: true do |t| + t.string :name + t.timestamps null: false + end + + self.table_name = :widgets + end + + instance = widget.create!({ + name: 'Bob', + created_at: 1.day.ago, + updated_at: 1.day.ago + }) + + created_at = instance.created_at + updated_at = instance.updated_at + + instance.name = 'Barb' + instance.save!(touch: false) + assert_equal instance.created_at, created_at + assert_equal instance.updated_at, updated_at + ensure + ActiveRecord::Base.connection.drop_table :widgets + end + end end |