You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.4 KiB
115 lines
3.4 KiB
# Engenharia de Software 2007.1
|
|
# Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
|
|
class CourseTest < Test::Unit::TestCase
|
|
|
|
fixtures :courses
|
|
|
|
def test_crud
|
|
# Create
|
|
old_count = Course.count
|
|
|
|
c = Course.new
|
|
c.short_name = 'teste'
|
|
c.full_name = 'teste'
|
|
c.description = 'teste'
|
|
|
|
assert c.save
|
|
assert_equal old_count + 1, Course.count
|
|
|
|
# Retrieve
|
|
c2 = Course.find(c.id)
|
|
assert_equal c2.description, c.description
|
|
assert_equal c2.full_name, c.full_name
|
|
assert_equal c2.short_name, c.short_name
|
|
|
|
# Update
|
|
assert c.update_attributes(:short_name => 'teste29')
|
|
assert_equal c.short_name, 'teste2'
|
|
|
|
# Delete
|
|
id = c.id
|
|
assert c.destroy
|
|
assert_raises(ActiveRecord::RecordNotFound) { Course.find(id) }
|
|
assert_equal old_count, Course.count
|
|
end
|
|
|
|
|
|
def test_validates_presence
|
|
required_fields = [:short_name, :full_name, :description]
|
|
required_fields.each do |attr|
|
|
c = courses(:course_1).clone
|
|
c.short_name = 'new_test'
|
|
c.send("#{attr}=", "")
|
|
|
|
assert !c.valid?, attr
|
|
assert_equal 1, c.errors.count, attr
|
|
assert_not_nil c.errors[attr], attr
|
|
end
|
|
end
|
|
|
|
|
|
def test_validates_uniqueness_of_short_name
|
|
c = courses(:course_1).clone
|
|
assert !c.save
|
|
assert_not_nil c.errors[:short_name]
|
|
end
|
|
|
|
|
|
def test_associations
|
|
associations = [:attachments, :wiki_pages, :shoutbox_messages, :news, :events]
|
|
c = courses(:course_1)
|
|
associations.each do |a|
|
|
assert_nothing_raised {
|
|
c.send("#{a}").find(:all)
|
|
}
|
|
end
|
|
end
|
|
|
|
|
|
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', :date => Time.now, :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) }
|
|
end
|
|
end
|