aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/persistence_test.rb
diff options
context:
space:
mode:
authorDan Olson <olson_dan@yahoo.com>2014-12-27 17:17:57 -0600
committerDan Olson <olson_dan@yahoo.com>2014-12-27 22:22:37 -0600
commite780e2fda326fa5ea616e1441a6ed81b2890085c (patch)
treefa3db96769d699bc7bdb4623d727c7302b0d6159 /activerecord/test/cases/persistence_test.rb
parent307ec3db0fe26cbd1811d34a27e6637726ce23ce (diff)
downloadrails-e780e2fda326fa5ea616e1441a6ed81b2890085c.tar.gz
rails-e780e2fda326fa5ea616e1441a6ed81b2890085c.tar.bz2
rails-e780e2fda326fa5ea616e1441a6ed81b2890085c.zip
Provide :touch option to save() to accommodate saving without updating timestamps. [#18202]
Diffstat (limited to 'activerecord/test/cases/persistence_test.rb')
-rw-r--r--activerecord/test/cases/persistence_test.rb31
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