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

decrease reliance on instantiated fixtures #980 [Jeremy Kemper]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1062 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-04-02 08:36:32 +00:00
parent 5d42774b62
commit f84044a83f

View file

@ -103,15 +103,14 @@ class BasicsTest < Test::Unit::TestCase
end end
def test_attributes_hash def test_attributes_hash
assert_equal @projects["action_controller"].to_hash, @action_controller.attributes assert_equal @projects['active_record'].to_hash, Project.find_first.attributes
end end
def test_create def test_create
topic = Topic.new topic = Topic.new
topic.title = "New Topic" topic.title = "New Topic"
topic.save topic.save
id = topic.id topicReloaded = Topic.find(topic.id)
topicReloaded = Topic.find(id)
assert_equal("New Topic", topicReloaded.title) assert_equal("New Topic", topicReloaded.title)
end end
@ -139,16 +138,13 @@ class BasicsTest < Test::Unit::TestCase
topic.title = "Another New Topic" topic.title = "Another New Topic"
topic.written_on = "2003-12-12 23:23:00" topic.written_on = "2003-12-12 23:23:00"
topic.save topic.save
id = topic.id topicReloaded = Topic.find(topic.id)
assert_equal(id, topic.id)
topicReloaded = Topic.find(id)
assert_equal("Another New Topic", topicReloaded.title) assert_equal("Another New Topic", topicReloaded.title)
topicReloaded.title = "Updated topic" topicReloaded.title = "Updated topic"
topicReloaded.save topicReloaded.save
topicReloadedAgain = Topic.find(id) topicReloadedAgain = Topic.find(topic.id)
assert_equal("Updated topic", topicReloadedAgain.title) assert_equal("Updated topic", topicReloadedAgain.title)
end end
@ -157,9 +153,8 @@ class BasicsTest < Test::Unit::TestCase
topic = Topic.new topic = Topic.new
topic.title = "Still another topic" topic.title = "Still another topic"
topic.save topic.save
id = topic.id
topicReloaded = Topic.find(id) topicReloaded = Topic.find(topic.id)
topicReloaded.title = "A New Topic" topicReloaded.title = "A New Topic"
topicReloaded.send :write_attribute, 'does_not_exist', 'test' topicReloaded.send :write_attribute, 'does_not_exist', 'test'
assert_nothing_raised { topicReloaded.save } assert_nothing_raised { topicReloaded.save }
@ -198,10 +193,9 @@ class BasicsTest < Test::Unit::TestCase
topic.title = "Yet Another New Topic" topic.title = "Yet Another New Topic"
topic.written_on = "2003-12-12 23:23:00" topic.written_on = "2003-12-12 23:23:00"
topic.save topic.save
id = topic.id
topic.destroy topic.destroy
assert_raise(TypeError) { topic.save }
assert_raises(ActiveRecord::RecordNotFound) { topicReloaded = Topic.find(id) } assert_raise(ActiveRecord::RecordNotFound) { Topic.find(topic.id) }
end end
def test_record_not_found_exception def test_record_not_found_exception
@ -353,7 +347,7 @@ class BasicsTest < Test::Unit::TestCase
def test_attribute_keys_on_new_instance def test_attribute_keys_on_new_instance
t = Topic.new t = Topic.new
assert_equal nil, t.title, "The topics table has a title column, so it should be nil" assert_equal nil, t.title, "The topics table has a title column, so it should be nil"
assert_raises(NoMethodError) { t.title2 } assert_raise(NoMethodError) { t.title2 }
end end
def test_class_name def test_class_name
@ -644,7 +638,7 @@ class BasicsTest < Test::Unit::TestCase
topic = Topic.create("content" => myobj) topic = Topic.create("content" => myobj)
Topic.serialize(:content, Hash) Topic.serialize(:content, Hash)
assert_raises(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).content } assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).content }
settings = { "color" => "blue" } settings = { "color" => "blue" }
Topic.find(topic.id).update_attribute("content", settings) Topic.find(topic.id).update_attribute("content", settings)
@ -660,19 +654,19 @@ class BasicsTest < Test::Unit::TestCase
def test_class_level_destroy def test_class_level_destroy
should_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world") should_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world")
@first.replies << should_be_destroyed_reply Topic.find(1).replies << should_be_destroyed_reply
Topic.destroy(1) Topic.destroy(1)
assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1) } assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1) }
assert_raises(ActiveRecord::RecordNotFound) { Reply.find(should_be_destroyed_reply.id) } assert_raise(ActiveRecord::RecordNotFound) { Reply.find(should_be_destroyed_reply.id) }
end end
def test_class_level_delete def test_class_level_delete
should_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world") should_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world")
@first.replies << should_be_destroyed_reply Topic.find(1).replies << should_be_destroyed_reply
Topic.delete(1) Topic.delete(1)
assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1) } assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1) }
assert_nothing_raised { Reply.find(should_be_destroyed_reply.id) } assert_nothing_raised { Reply.find(should_be_destroyed_reply.id) }
end end