test/paranoia_test.rb in paranoia-2.1.4 vs test/paranoia_test.rb in paranoia-2.1.5

- old
+ new

@@ -18,10 +18,11 @@ 'paranoid_models' => 'parent_model_id INTEGER, deleted_at DATETIME', 'paranoid_model_with_belongs' => 'parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_id INTEGER', 'paranoid_model_with_build_belongs' => 'parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_and_build_id INTEGER, name VARCHAR(32)', 'paranoid_model_with_anthor_class_name_belongs' => 'parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_id INTEGER', 'paranoid_model_with_foreign_key_belongs' => 'parent_model_id INTEGER, deleted_at DATETIME, has_one_foreign_key_id INTEGER', + 'paranoid_model_with_timestamps' => 'parent_model_id INTEGER, created_at DATETIME, updated_at DATETIME, deleted_at DATETIME', 'not_paranoid_model_with_belongs' => 'parent_model_id INTEGER, paranoid_model_with_has_one_id INTEGER', 'paranoid_model_with_has_one_and_builds' => 'parent_model_id INTEGER, color VARCHAR(32), deleted_at DATETIME, has_one_foreign_key_id INTEGER', 'featureful_models' => 'deleted_at DATETIME, name VARCHAR(32)', 'plain_models' => 'deleted_at DATETIME', 'callback_models' => 'deleted_at DATETIME', @@ -755,10 +756,23 @@ a = Employer.create!(name: "A") b = Employer.new(name: "A") refute b.valid? end + def test_updated_at_modification_on_restore + parent1 = ParentModel.create + pt1 = ParanoidModelWithTimestamp.create(:parent_model => parent1) + ParanoidModelWithTimestamp.record_timestamps = false + pt1.update_columns(created_at: 20.years.ago, updated_at: 10.years.ago, deleted_at: 10.years.ago) + ParanoidModelWithTimestamp.record_timestamps = true + assert pt1.updated_at < 10.minutes.ago + refute pt1.deleted_at.nil? + pt1.restore! + assert pt1.deleted_at.nil? + assert pt1.updated_at > 10.minutes.ago + end + def test_i_am_the_destroyer expected = %Q{ Sharon: "There should be a method called I_AM_THE_DESTROYER!" Ryan: "What should this method do?" Sharon: "It should fix all the spelling errors on the page!" @@ -1118,9 +1132,14 @@ end class ParanoidModelWithForeignKeyBelong < ActiveRecord::Base acts_as_paranoid belongs_to :paranoid_model_with_has_one +end + +class ParanoidModelWithTimestamp < ActiveRecord::Base + belongs_to :parent_model + acts_as_paranoid end class NotParanoidModelWithBelong < ActiveRecord::Base belongs_to :paranoid_model_with_has_one end