Tests for courses
This commit is contained in:
5
Gemfile
5
Gemfile
@@ -22,6 +22,11 @@ gem 'icalendar', '~>1.0'
|
|||||||
gem 'jquery-rails'
|
gem 'jquery-rails'
|
||||||
gem 'shoulda', "~>2.11"
|
gem 'shoulda', "~>2.11"
|
||||||
gem 'will_paginate', "~>3.0"
|
gem 'will_paginate', "~>3.0"
|
||||||
|
gem 'simplecov'
|
||||||
|
|
||||||
|
group :test do
|
||||||
|
gem 'turn'
|
||||||
|
end
|
||||||
|
|
||||||
#group :development, :production do
|
#group :development, :production do
|
||||||
# gem 'brazilian-rails', '3.3.0', :path => './vendor/gems/brazilian-rails/brI18n/'
|
# gem 'brazilian-rails', '3.3.0', :path => './vendor/gems/brazilian-rails/brI18n/'
|
||||||
|
|||||||
13
Gemfile.lock
13
Gemfile.lock
@@ -44,6 +44,7 @@ GEM
|
|||||||
activerecord (>= 3.0)
|
activerecord (>= 3.0)
|
||||||
acts_as_paranoid (0.4.2)
|
acts_as_paranoid (0.4.2)
|
||||||
activerecord (~> 3.2)
|
activerecord (~> 3.2)
|
||||||
|
ansi (1.5.0)
|
||||||
arel (3.0.2)
|
arel (3.0.2)
|
||||||
builder (3.0.4)
|
builder (3.0.4)
|
||||||
calendar_helper (0.2.5)
|
calendar_helper (0.2.5)
|
||||||
@@ -55,6 +56,7 @@ GEM
|
|||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.6.3)
|
coffee-script-source (1.6.3)
|
||||||
|
docile (1.1.5)
|
||||||
dynamic_form (1.1.4)
|
dynamic_form (1.1.4)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
execjs (1.4.0)
|
execjs (1.4.0)
|
||||||
@@ -73,6 +75,7 @@ GEM
|
|||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
mime-types (1.23)
|
mime-types (1.23)
|
||||||
|
minitest (4.7.5)
|
||||||
multi_json (1.7.7)
|
multi_json (1.7.7)
|
||||||
open4 (1.3.0)
|
open4 (1.3.0)
|
||||||
polyglot (0.3.3)
|
polyglot (0.3.3)
|
||||||
@@ -107,6 +110,11 @@ GEM
|
|||||||
sass (>= 3.1.10)
|
sass (>= 3.1.10)
|
||||||
tilt (~> 1.3)
|
tilt (~> 1.3)
|
||||||
shoulda (2.11.3)
|
shoulda (2.11.3)
|
||||||
|
simplecov (0.10.0)
|
||||||
|
docile (~> 1.1.0)
|
||||||
|
json (~> 1.8)
|
||||||
|
simplecov-html (~> 0.10.0)
|
||||||
|
simplecov-html (0.10.0)
|
||||||
sprockets (2.2.2)
|
sprockets (2.2.2)
|
||||||
hike (~> 1.2)
|
hike (~> 1.2)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
@@ -118,6 +126,9 @@ GEM
|
|||||||
treetop (1.4.14)
|
treetop (1.4.14)
|
||||||
polyglot
|
polyglot
|
||||||
polyglot (>= 0.3.1)
|
polyglot (>= 0.3.1)
|
||||||
|
turn (0.9.7)
|
||||||
|
ansi
|
||||||
|
minitest (~> 4)
|
||||||
tzinfo (0.3.37)
|
tzinfo (0.3.37)
|
||||||
uglifier (2.1.2)
|
uglifier (2.1.2)
|
||||||
execjs (>= 0.3.0)
|
execjs (>= 0.3.0)
|
||||||
@@ -143,7 +154,9 @@ DEPENDENCIES
|
|||||||
rails (~> 3.2)
|
rails (~> 3.2)
|
||||||
sass-rails (~> 3.2.3)
|
sass-rails (~> 3.2.3)
|
||||||
shoulda (~> 2.11)
|
shoulda (~> 2.11)
|
||||||
|
simplecov
|
||||||
sqlite3
|
sqlite3
|
||||||
|
turn
|
||||||
uglifier (>= 1.0.3)
|
uglifier (>= 1.0.3)
|
||||||
will_paginate (~> 3.0)
|
will_paginate (~> 3.0)
|
||||||
|
|
||||||
|
|||||||
@@ -17,59 +17,63 @@
|
|||||||
|
|
||||||
class Course < ActiveRecord::Base
|
class Course < ActiveRecord::Base
|
||||||
|
|
||||||
# Plugins
|
acts_as_paranoid
|
||||||
acts_as_paranoid
|
|
||||||
|
|
||||||
# Associacoes
|
has_many :attachments,
|
||||||
has_many :attachments,
|
:order => 'path is not null, path, file_name',
|
||||||
:order => "path is not null, path, file_name",
|
:dependent => :destroy
|
||||||
:dependent => :destroy
|
|
||||||
|
|
||||||
has_many :events,
|
has_many :events,
|
||||||
:order => "time asc",
|
:order => 'time asc',
|
||||||
:dependent => :destroy
|
:dependent => :destroy
|
||||||
|
|
||||||
has_many :news,
|
has_many :news,
|
||||||
:foreign_key => "receiver_id",
|
:foreign_key => 'receiver_id',
|
||||||
:order => "id desc",
|
:order => 'id desc',
|
||||||
:dependent => :destroy
|
:class_name => 'News',
|
||||||
|
:dependent => :destroy
|
||||||
|
|
||||||
has_many :log_entries,
|
has_many :log_entries,
|
||||||
:order => "created_at desc",
|
:order => 'created_at desc',
|
||||||
:dependent => :destroy
|
:dependent => :destroy
|
||||||
|
|
||||||
has_many :wiki_pages,
|
has_many :wiki_pages,
|
||||||
:order => "position",
|
:order => 'position',
|
||||||
:dependent => :destroy
|
:dependent => :destroy
|
||||||
|
|
||||||
has_and_belongs_to_many :users,
|
has_and_belongs_to_many :users,
|
||||||
:order => "last_seen desc"
|
:order => 'last_seen desc'
|
||||||
|
|
||||||
# Validacao
|
validates_presence_of :short_name
|
||||||
validates_presence_of :short_name
|
validates_presence_of :full_name
|
||||||
validates_presence_of :full_name
|
validates_presence_of :code
|
||||||
validates_presence_of :code
|
validates_numericality_of :grade, :only_integer => true
|
||||||
validates_numericality_of :grade, :only_integer => true
|
validates_inclusion_of :hidden, :in => [true, false], :allow_nil => false
|
||||||
validates_inclusion_of :hidden, :in => [true, false], :allow_nil => false
|
validates_format_of :short_name, :with => /^[^0-9]/
|
||||||
validates_format_of :short_name, :with => /^[^0-9]/
|
|
||||||
|
|
||||||
def related_courses
|
after_create :add_initial_wiki_pages
|
||||||
Course.find(:all, :conditions => [ 'short_name = ?', self.short_name], :limit => 4, :order => 'period desc')
|
|
||||||
end
|
|
||||||
|
|
||||||
def recent_news
|
def related_courses
|
||||||
self.news.find(:all, :conditions => [ 'timestamp > ?', 7.days.ago ])
|
Course.all(:conditions => ['short_name = ?', self.short_name], :limit => 4,
|
||||||
end
|
:order => 'period desc')
|
||||||
|
end
|
||||||
|
|
||||||
def after_create
|
def recent_news
|
||||||
App.inital_wiki_pages.each do |page_title|
|
self.news.all(:conditions => ['timestamp > ?', 7.days.ago])
|
||||||
wiki_page = WikiPage.new(:title => page_title, :version => 1, :content => App.initial_wiki_page_content)
|
end
|
||||||
self.wiki_pages << wiki_page
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_param
|
def add_initial_wiki_pages
|
||||||
return self.short_name if self.period == App.current_period
|
App.initial_wiki_pages.each do |page_title|
|
||||||
return self.id.to_s
|
wiki_page = WikiPage.new(:title => page_title, :description => 'New course',
|
||||||
end
|
:content => App.initial_wiki_page_content)
|
||||||
|
wiki_page.user = User.first
|
||||||
|
self.wiki_pages << wiki_page
|
||||||
|
wiki_page.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_param
|
||||||
|
return self.short_name if self.period == App.current_period
|
||||||
|
return self.id.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,25 +17,25 @@
|
|||||||
|
|
||||||
class Message < ActiveRecord::Base
|
class Message < ActiveRecord::Base
|
||||||
|
|
||||||
# Plugins
|
acts_as_paranoid
|
||||||
acts_as_paranoid
|
acts_as_versioned :if_changed => [:title, :body]
|
||||||
acts_as_versioned :if_changed => [ :title, :body ]
|
self.non_versioned_columns << 'deleted_at'
|
||||||
self.non_versioned_columns << 'deleted_at'
|
|
||||||
|
|
||||||
#acts_as_paranoid_versioned
|
#acts_as_paranoid_versioned
|
||||||
self.versioned_class.class_eval do
|
self.versioned_class.class_eval do
|
||||||
def self.delete_all(conditions = nil); return; end
|
def self.delete_all(conditions = nil)
|
||||||
end
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Associacoes
|
belongs_to :user,
|
||||||
belongs_to :user,
|
:foreign_key => "sender_id",
|
||||||
:foreign_key => "sender_id",
|
:with_deleted => true
|
||||||
:with_deleted => true
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class News < Message
|
class News < Message
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
belongs_to :course,
|
belongs_to :course,
|
||||||
:foreign_key => "receiver_id"
|
:foreign_key => "receiver_id"
|
||||||
end
|
end
|
||||||
|
|||||||
8
test/fixtures/courses.yml
vendored
8
test/fixtures/courses.yml
vendored
@@ -29,3 +29,11 @@ old_course:
|
|||||||
description: Description goes here
|
description: Description goes here
|
||||||
period: 1970.1
|
period: 1970.1
|
||||||
hidden: false
|
hidden: false
|
||||||
|
|
||||||
|
related_course:
|
||||||
|
id: 3
|
||||||
|
short_name: course1
|
||||||
|
full_name: Third course
|
||||||
|
description: Hello world
|
||||||
|
period: 1970.2
|
||||||
|
hidden: false
|
||||||
|
|||||||
@@ -14,15 +14,47 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#require File.dirname(__FILE__) + '/../test_helper'
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
#
|
|
||||||
#class CourseTest < ActiveSupport::TestCase
|
class CourseTest < ActiveSupport::TestCase
|
||||||
#
|
|
||||||
# fixtures :courses
|
fixtures :courses
|
||||||
#
|
|
||||||
# def test_truth
|
def test_related_courses
|
||||||
# assert true
|
course = courses(:course_1)
|
||||||
# end
|
related = courses(:related_course)
|
||||||
#
|
assert course.related_courses.include?(related)
|
||||||
#end
|
end
|
||||||
#
|
|
||||||
|
def test_initial_wiki_pages
|
||||||
|
Course.create!(:short_name => 'course999',
|
||||||
|
:full_name => 'Course 999', :code => 123, :grade => 1)
|
||||||
|
course = Course.find_by_short_name('course999')
|
||||||
|
assert course.wiki_pages.length == App.initial_wiki_pages.length
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_param
|
||||||
|
current_course = courses(:course_1)
|
||||||
|
old_course = courses(:related_course)
|
||||||
|
assert current_course.to_param == current_course.short_name
|
||||||
|
assert old_course.to_param == old_course.id.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_recent_news
|
||||||
|
course = courses(:related_course)
|
||||||
|
user = User.first
|
||||||
|
|
||||||
|
assert course.news.length == 0
|
||||||
|
|
||||||
|
news = course.news.create!(:title => 'hello', :body => 'hello',
|
||||||
|
:timestamp => 1.hour.ago, :sender_id => user.id,
|
||||||
|
:receiver_id => course.id, :version => 1)
|
||||||
|
assert course.recent_news.include?(news)
|
||||||
|
|
||||||
|
news = course.news.create!(:title => 'hello', :body => 'hello',
|
||||||
|
:timestamp => 1.month.ago, :sender_id => user.id,
|
||||||
|
:receiver_id => course.id, :version => 1)
|
||||||
|
assert !course.recent_news.include?(news)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user