Permalink
Browse files

decrease reliance on instantiated fixtures #980 [Jeremy Kemper]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1062 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 5d42774 commit f84044a83f6f9a1c8eeef4091649b862ab78c50d @dhh dhh committed Apr 2, 2005
Showing with 15 additions and 21 deletions.
  1. +15 −21 activerecord/test/base_test.rb
@@ -103,15 +103,14 @@ def test_update_array_content
end
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
-
+
def test_create
topic = Topic.new
topic.title = "New Topic"
topic.save
- id = topic.id
- topicReloaded = Topic.find(id)
+ topicReloaded = Topic.find(topic.id)
assert_equal("New Topic", topicReloaded.title)
end
@@ -139,16 +138,13 @@ def test_update
topic.title = "Another New Topic"
topic.written_on = "2003-12-12 23:23:00"
topic.save
- id = topic.id
- assert_equal(id, topic.id)
-
- topicReloaded = Topic.find(id)
+ topicReloaded = Topic.find(topic.id)
assert_equal("Another New Topic", topicReloaded.title)
topicReloaded.title = "Updated topic"
topicReloaded.save
- topicReloadedAgain = Topic.find(id)
+ topicReloadedAgain = Topic.find(topic.id)
assert_equal("Updated topic", topicReloadedAgain.title)
end
@@ -157,9 +153,8 @@ def test_update_columns_not_equal_attributes
topic = Topic.new
topic.title = "Still another topic"
topic.save
- id = topic.id
- topicReloaded = Topic.find(id)
+ topicReloaded = Topic.find(topic.id)
topicReloaded.title = "A New Topic"
topicReloaded.send :write_attribute, 'does_not_exist', 'test'
assert_nothing_raised { topicReloaded.save }
@@ -198,10 +193,9 @@ def test_destroy
topic.title = "Yet Another New Topic"
topic.written_on = "2003-12-12 23:23:00"
topic.save
- id = topic.id
topic.destroy
-
- assert_raises(ActiveRecord::RecordNotFound) { topicReloaded = Topic.find(id) }
+ assert_raise(TypeError) { topic.save }
+ assert_raise(ActiveRecord::RecordNotFound) { Topic.find(topic.id) }
end
def test_record_not_found_exception
@@ -353,7 +347,7 @@ def test_attribute_present
def test_attribute_keys_on_new_instance
t = Topic.new
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
def test_class_name
@@ -644,7 +638,7 @@ def test_serialized_attribute_with_class_constraint
topic = Topic.create("content" => myobj)
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" }
Topic.find(topic.id).update_attribute("content", settings)
@@ -660,19 +654,19 @@ def test_quote
def test_class_level_destroy
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)
- assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1) }
- assert_raises(ActiveRecord::RecordNotFound) { Reply.find(should_be_destroyed_reply.id) }
+ assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1) }
+ assert_raise(ActiveRecord::RecordNotFound) { Reply.find(should_be_destroyed_reply.id) }
end
def test_class_level_delete
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)
- assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1) }
+ assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1) }
assert_nothing_raised { Reply.find(should_be_destroyed_reply.id) }
end

0 comments on commit f84044a

Please sign in to comment.