diff options
Diffstat (limited to 'activerecord/test/cases/dup_test.rb')
-rw-r--r-- | activerecord/test/cases/dup_test.rb | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/activerecord/test/cases/dup_test.rb b/activerecord/test/cases/dup_test.rb index 4e2adff344..638cffe0e6 100644 --- a/activerecord/test/cases/dup_test.rb +++ b/activerecord/test/cases/dup_test.rb @@ -1,4 +1,5 @@ require "cases/helper" +require 'models/reply' require 'models/topic' module ActiveRecord @@ -32,6 +33,14 @@ module ActiveRecord assert duped.new_record?, 'topic is new' end + def test_dup_not_destroyed + topic = Topic.first + topic.destroy + + duped = topic.dup + assert_not duped.destroyed? + end + def test_dup_has_no_id topic = Topic.first duped = topic.dup @@ -108,18 +117,41 @@ module ActiveRecord end def test_dup_validity_is_independent - Topic.validates_presence_of :title - topic = Topic.new("title" => "Litterature") - topic.valid? + repair_validations(Topic) do + Topic.validates_presence_of :title + topic = Topic.new("title" => "Literature") + topic.valid? + + duped = topic.dup + duped.title = nil + assert duped.invalid? + + topic.title = nil + duped.title = 'Mathematics' + assert topic.invalid? + assert duped.valid? + end + end - duped = topic.dup - duped.title = nil - assert duped.invalid? + def test_dup_with_default_scope + prev_default_scopes = Topic.default_scopes + Topic.default_scopes = [proc { Topic.where(:approved => true) }] + topic = Topic.new(:approved => false) + assert !topic.dup.approved?, "should not be overridden by default scopes" + ensure + Topic.default_scopes = prev_default_scopes + end + + def test_dup_without_primary_key + klass = Class.new(ActiveRecord::Base) do + self.table_name = 'parrots_pirates' + end + + record = klass.create! - topic.title = nil - duped.title = 'Mathematics' - assert topic.invalid? - assert duped.valid? + assert_nothing_raised do + record.dup + end end end end |