DB: Integridade referencial

This commit is contained in:
2008-03-06 05:43:56 -03:00
parent e5bc6024ba
commit c58684c31c
12 changed files with 88 additions and 68 deletions

View File

@@ -17,36 +17,8 @@ class CourseTest < Test::Unit::TestCase
fixtures :courses
def test_orphaned_records
# Escolhe um curso qualquer
course = courses(:course_1)
# Cria alguns objetos associados ao curso
attachment = Attachment.create(:file_name => 'test', :content_type => 'text/plain',
:last_modified => Time.now, :description => 'test', :size => 1.megabyte,
:course_id => course.id)
wiki_page = WikiPage.create(:title => 'teste', :course_id => course.id)
shoutbox_message = Message.create(:title => 'test', :body => 'test body',
:timestamp => Time.now, :type => "CourseShoutboxMessage",
:sender_id => 0, :receiver_id => course.id)
news_message = Message.create(:title => 'test', :body => 'test body',
:timestamp => Time.now, :type => "News",
:sender_id => 0, :receiver_id => course.id)
event = Event.create(:title => 'test', :time => Time.now,
:created_by => 0, :course_id => course.id, :description => 'test')
# Deleta o curso
course.destroy
# Ve o que aconteceu com os objetos
assert_raises(ActiveRecord::RecordNotFound) { Attachment.find(attachment.id) }
assert_raises(ActiveRecord::RecordNotFound) { WikiPage.find(wiki_page.id) }
assert_raises(ActiveRecord::RecordNotFound) { CourseShoutboxMessage.find(shoutbox_message.id) }
assert_raises(ActiveRecord::RecordNotFound) { News.find(news_message.id) }
assert_raises(ActiveRecord::RecordNotFound) { Event.find(event.id) }
def test_truth
assert true
end
end