diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 8cc33444..e5e3f716 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -127,6 +127,7 @@ class ProjectTest < ActiveSupport::TestCase assert !p.hidden? assert p.nil? assert_nil p.id + assert_equal "", p.name end 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.reload.stalled?, "project should be stalled" 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 diff --git a/test/unit/recurring_todo_test.rb b/test/unit/recurring_todo_test.rb index 502e64b7..5abaa790 100644 --- a/test/unit/recurring_todo_test.rb +++ b/test/unit/recurring_todo_test.rb @@ -6,7 +6,9 @@ class RecurringTodoTest < ActiveSupport::TestCase @every_day = recurring_todos(:call_bill_gates_every_day) @every_workday = recurring_todos(:call_bill_gates_every_workday) @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) + @every_month = @monthly_every_last_friday @yearly = recurring_todos(:birthday_reinier) @today = Time.now.utc @@ -319,4 +321,36 @@ class RecurringTodoTest < ActiveSupport::TestCase assert_equal 0, @every_day.occurences_count 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 diff --git a/test/unit/tag_cloud_test.rb b/test/unit/tag_cloud_test.rb index 6ba8b5d1..e52f70f6 100644 --- a/test/unit/tag_cloud_test.rb +++ b/test/unit/tag_cloud_test.rb @@ -20,4 +20,12 @@ class TagCloudTest < Test::Unit::TestCase assert_equal 9, cloud.relative_size(FakeTag.new("whatever", 100)) 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 diff --git a/test/unit/todo_test.rb b/test/unit/todo_test.rb index 59770e3b..7d8c1777 100644 --- a/test/unit/todo_test.rb +++ b/test/unit/todo_test.rb @@ -173,6 +173,21 @@ class TodoTest < ActiveSupport::TestCase assert t.show_from.nil? 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 t = @not_completed1 assert !t.project.is_a?(NullProject) @@ -271,6 +286,22 @@ class TodoTest < ActiveSupport::TestCase assert_equal 2, @predecessor_array.size 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 todo = @not_completed1 todo.tag_list = "a, b, c" @@ -425,5 +456,16 @@ class TodoTest < ActiveSupport::TestCase assert_equal "*test*", todo.notes assert_equal "
test
", todo.rendered_notes 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