aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/base_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-17 21:36:13 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-17 21:36:13 +0000
commit648b8fda54e5de742e4ffbb4bc8e6edf0b68a111 (patch)
tree6a827db4b218a2f0ff8e8680c0d340470eb07832 /activerecord/test/base_test.rb
parentcf78e736d29a60693eb9997d2c2678ae5d72cb1b (diff)
downloadrails-648b8fda54e5de742e4ffbb4bc8e6edf0b68a111.tar.gz
rails-648b8fda54e5de742e4ffbb4bc8e6edf0b68a111.tar.bz2
rails-648b8fda54e5de742e4ffbb4bc8e6edf0b68a111.zip
Added Base.destroy and Base.delete to remove records without holding a reference to them first.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@206 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/base_test.rb')
-rwxr-xr-xactiverecord/test/base_test.rb30
1 files changed, 23 insertions, 7 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index c362fd7139..b80f4ff6ef 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -26,9 +26,7 @@ end
class Booleantest < ActiveRecord::Base; end
class BasicsTest < Test::Unit::TestCase
- def setup
- @topic_fixtures, @companies = create_fixtures "topics", "companies"
- end
+ fixtures :topics, :companies
def test_set_attributes
topic = Topic.find(1)
@@ -36,7 +34,7 @@ class BasicsTest < Test::Unit::TestCase
topic.save
assert_equal("Budget", topic.title)
assert_equal("Jason", topic.author_name)
- assert_equal(@topic_fixtures["first"]["author_email_address"], Topic.find(1).author_email_address)
+ assert_equal(@topics["first"]["author_email_address"], Topic.find(1).author_email_address)
end
def test_integers_as_nil
@@ -187,14 +185,14 @@ class BasicsTest < Test::Unit::TestCase
def test_load
topics = Topic.find_all nil, "id"
assert_equal(2, topics.size)
- assert_equal(@topic_fixtures["first"]["title"], topics.first.title)
+ assert_equal(@topics["first"]["title"], topics.first.title)
end
def test_load_with_condition
topics = Topic.find_all "author_name = 'Mary'"
assert_equal(1, topics.size)
- assert_equal(@topic_fixtures["second"]["title"], topics.first.title)
+ assert_equal(@topics["second"]["title"], topics.first.title)
end
def test_table_name_guesses
@@ -556,4 +554,22 @@ class BasicsTest < Test::Unit::TestCase
topic = Topic.create('content' => content)
assert_equal content, Topic.find(topic.id).content
end
-end
+
+ def test_class_level_destroy
+ should_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world")
+ @first.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) }
+ end
+
+ def test_class_level_delete
+ should_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world")
+ @first.replies << should_be_destroyed_reply
+
+ Topic.delete(1)
+ assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1) }
+ assert_nothing_raised { Reply.find(should_be_destroyed_reply.id) }
+ end
+end \ No newline at end of file