increase test coverage of some models

This commit is contained in:
Reinier Balt 2013-05-04 15:22:29 +02:00
parent 80ed0d2cef
commit 26a27e5cfe
4 changed files with 97 additions and 0 deletions

View file

@ -127,6 +127,7 @@ class ProjectTest < ActiveSupport::TestCase
assert !p.hidden? assert !p.hidden?
assert p.nil? assert p.nil?
assert_nil p.id assert_nil p.id
assert_equal "", p.name
end end
def test_name_removes_extra_spaces def test_name_removes_extra_spaces
@ -224,5 +225,17 @@ class ProjectTest < ActiveSupport::TestCase
assert p.todos.reload.deferred_or_blocked.empty?, "there should not be deferred or blocked todos" assert p.todos.reload.deferred_or_blocked.empty?, "there should not be deferred or blocked todos"
assert p.reload.stalled?, "project should be stalled" assert p.reload.stalled?, "project should be stalled"
end end
def test_age_in_days
p1 = users(:admin_user).projects.create!(:name => "test1")
assert_equal 1, p1.age_in_days, "newly created project has age or one day"
p2 = users(:admin_user).projects.create!(:name => "test7")
p2.created_at = 1.week.ago
p2.save!
p2.reload
assert_equal 8, p2.age_in_days
end
end end

View file

@ -6,7 +6,9 @@ class RecurringTodoTest < ActiveSupport::TestCase
@every_day = recurring_todos(:call_bill_gates_every_day) @every_day = recurring_todos(:call_bill_gates_every_day)
@every_workday = recurring_todos(:call_bill_gates_every_workday) @every_workday = recurring_todos(:call_bill_gates_every_workday)
@weekly_every_day = recurring_todos(:call_bill_gates_every_week) @weekly_every_day = recurring_todos(:call_bill_gates_every_week)
@every_week = @weekly_every_day
@monthly_every_last_friday = recurring_todos(:check_with_bill_every_last_friday_of_month) @monthly_every_last_friday = recurring_todos(:check_with_bill_every_last_friday_of_month)
@every_month = @monthly_every_last_friday
@yearly = recurring_todos(:birthday_reinier) @yearly = recurring_todos(:birthday_reinier)
@today = Time.now.utc @today = Time.now.utc
@ -319,4 +321,36 @@ class RecurringTodoTest < ActiveSupport::TestCase
assert_equal 0, @every_day.occurences_count assert_equal 0, @every_day.occurences_count
end end
def test_invalid_recurring_period_will_not_save
@every_day.recurring_period = 'invalid'
assert !@every_day.valid?
@every_month.recurrence_selector = 99
assert_raise(Exception){ @every_month.valid? }
@yearly.recurrence_selector = 99
assert_raise(Exception){ @yearly.valid? }
end
def test_every_n_the_day_must_be_filled
@every_day.every_other1 = nil
assert !@every_day.valid?
end
def test_every_n_week_must_be_filled
@every_week.every_other1 = nil
assert !@every_week.valid?
end
def test_every_n_month_must_be_filled
@every_month.every_other1 = nil
@every_month.every_other2 = nil
assert !@every_month.valid?
@every_month.recurrence_selector = 0
assert !@every_month.valid?
end
end end

View file

@ -20,4 +20,12 @@ class TagCloudTest < Test::Unit::TestCase
assert_equal 9, cloud.relative_size(FakeTag.new("whatever", 100)) assert_equal 9, cloud.relative_size(FakeTag.new("whatever", 100))
end end
def test_empty_tags
cloud = Stats::TagCloud.new([])
assert cloud.empty?
cloud = Stats::TagCloud.new([FakeTag.new("Tag", 1)])
assert !cloud.empty?
end
end end

View file

@ -173,6 +173,21 @@ class TodoTest < ActiveSupport::TestCase
assert t.show_from.nil? assert t.show_from.nil?
end end
def test_clearing_show_from_activates_todo
t = @not_completed1
t.show_from = 1.week.from_now
t.save!
t.reload
assert t.deferred?
t.show_from = nil
t.save!
t.reload
assert t.active?
end
def test_project_returns_null_object_when_nil def test_project_returns_null_object_when_nil
t = @not_completed1 t = @not_completed1
assert !t.project.is_a?(NullProject) assert !t.project.is_a?(NullProject)
@ -271,6 +286,22 @@ class TodoTest < ActiveSupport::TestCase
assert_equal 2, @predecessor_array.size assert_equal 2, @predecessor_array.size
end end
def test_add_and_remove_precesessor
@not_completed1.add_predecessor(@not_completed2)
@not_completed1.save_predecessors
# blocking is not done automagically
@not_completed1.block!
assert @not_completed1.uncompleted_predecessors?
assert @not_completed1.pending?, "a todo with predecessors should be pending"
@not_completed1.remove_predecessor(@not_completed2)
@not_completed1.save_predecessors
assert !@not_completed1.uncompleted_predecessors?
assert @not_completed1.active?, "removing last predecessor should activate todo"
end
def test_finding_todos_with_a_tag def test_finding_todos_with_a_tag
todo = @not_completed1 todo = @not_completed1
todo.tag_list = "a, b, c" todo.tag_list = "a, b, c"
@ -425,5 +456,16 @@ class TodoTest < ActiveSupport::TestCase
assert_equal "*test*", todo.notes assert_equal "*test*", todo.notes
assert_equal "<p><strong>test</strong></p>", todo.rendered_notes assert_equal "<p><strong>test</strong></p>", todo.rendered_notes
end end
def test_from_rich_message_adds_to_default_context
user = @completed.user
default_context_id = @completed.context_id
new_todo = Todo::from_rich_message(user, default_context_id, "new todo", "notes")
assert_not_nil new_todo
assert_equal "new todo", new_todo.description
assert_equal "notes", new_todo.notes
assert_equal default_context_id, new_todo.context_id
end
end end