1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/duplication_test.rb

62 lines
1.3 KiB
Ruby
Raw Normal View History

2010-11-23 13:13:43 -05:00
require "cases/helper"
require 'models/topic'
module ActiveRecord
class DuplicationTest < ActiveRecord::TestCase
fixtures :topics
def test_dup
2010-11-23 13:58:19 -05:00
assert !Topic.new.freeze.dup.frozen?
2010-11-23 13:13:43 -05:00
end
def test_dup_not_persisted
topic = Topic.first
duped = topic.dup
assert !duped.persisted?, 'topic not persisted'
assert duped.new_record?, 'topic is new'
end
def test_dup_has_no_id
topic = Topic.first
duped = topic.dup
assert_nil duped.id
end
2010-11-23 13:58:19 -05:00
def test_dup_with_modified_attributes
topic = Topic.first
topic.author_name = 'Aaron'
duped = topic.dup
assert_equal 'Aaron', duped.author_name
end
def test_dup_with_changes
topic = Topic.first
topic.author_name = 'Aaron'
duped = topic.dup
assert_equal topic.changes, duped.changes
2010-11-23 13:13:43 -05:00
end
def test_dup_topics_are_independent
topic = Topic.first
topic.author_name = 'Aaron'
duped = topic.dup
duped.author_name = 'meow'
assert_not_equal topic.changes, duped.changes
end
def test_dup_attributes_are_independent
topic = Topic.first
duped = topic.dup
duped.author_name = 'meow'
topic.author_name = 'Aaron'
assert_equal 'Aaron', topic.author_name
assert_equal 'meow', duped.author_name
end
2010-11-23 13:13:43 -05:00
end
end