mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-23 18:50:12 +01:00
get all unit tests running again. Seems we have some pretty old code in there :-)
This commit is contained in:
parent
e964769553
commit
fd4fb6df9e
19 changed files with 255 additions and 284 deletions
|
|
@ -8,18 +8,32 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
@moremoney = projects(:moremoney)
|
||||
end
|
||||
|
||||
# associations
|
||||
|
||||
def test_has_default_context
|
||||
assert !@timemachine.default_context.nil?
|
||||
assert @timemachine.default_context.name == contexts(:lab).name
|
||||
|
||||
p = Project.new
|
||||
assert_equal '', p.default_context.name
|
||||
p.default_context = contexts(:agenda)
|
||||
assert_equal 'agenda', p.default_context.name
|
||||
end
|
||||
|
||||
# validations
|
||||
|
||||
def test_validate_presence_of_name
|
||||
@timemachine.name = ""
|
||||
assert !@timemachine.save
|
||||
assert_equal 1, @timemachine.errors.count
|
||||
assert_equal "project must have a name", @timemachine.errors.on(:name)
|
||||
assert_equal "project must have a name", @timemachine.errors[:name][0]
|
||||
end
|
||||
|
||||
def test_validate_name_is_less_than_256
|
||||
@timemachine.name = "a"*256
|
||||
@timemachine.name = generate_random_string(256)
|
||||
assert !@timemachine.save
|
||||
assert_equal 1, @timemachine.errors.count
|
||||
assert_equal "project name must be less than 256 characters", @timemachine.errors.on(:name)
|
||||
assert_equal "project name must be less than 256 characters", @timemachine.errors[:name][0]
|
||||
end
|
||||
|
||||
def test_validate_name_is_unique
|
||||
|
|
@ -28,29 +42,10 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
newproj.user_id = projects(:timemachine).user_id
|
||||
assert !newproj.save
|
||||
assert_equal 1, newproj.errors.count
|
||||
assert_equal "already exists", newproj.errors.on(:name)
|
||||
end
|
||||
|
||||
def test_validate_name_can_contain_comma
|
||||
newproj = Project.new
|
||||
newproj.name = "Buy iPhones for Luke,bsag,David Allen"
|
||||
assert newproj.save
|
||||
assert_equal 0, newproj.errors.count
|
||||
assert_equal "Buy iPhones for Luke,bsag,David Allen", newproj.name
|
||||
end
|
||||
|
||||
def test_name_removes_extra_spaces
|
||||
newproj = Project.new
|
||||
newproj.name = "These Words Have Proximity Issues "
|
||||
assert newproj.save
|
||||
assert_equal 0, newproj.errors.count
|
||||
assert_equal "These Words Have Proximity Issues", newproj.name
|
||||
|
||||
# and on update...
|
||||
@timemachine.name = " a time machine needs lots of spaaaaaaace "
|
||||
assert @timemachine.save
|
||||
assert_equal "a time machine needs lots of spaaaaaaace", @timemachine.name
|
||||
assert_equal "already exists", newproj.errors[:name][0]
|
||||
end
|
||||
|
||||
# state machine
|
||||
|
||||
def test_project_initial_state_is_active
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
|
|
@ -69,6 +64,24 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
assert @timemachine.active?
|
||||
end
|
||||
|
||||
def test_transition_to_another_state
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
@timemachine.transition_to(:hidden)
|
||||
assert_equal :hidden, @timemachine.aasm_current_state
|
||||
@timemachine.transition_to(:completed)
|
||||
assert_equal :completed, @timemachine.aasm_current_state
|
||||
@timemachine.transition_to(:active)
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
end
|
||||
|
||||
def test_transition_to_same_state
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
@timemachine.transition_to(:active)
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
end
|
||||
|
||||
# other tests
|
||||
|
||||
def test_review_project
|
||||
assert_nil @timemachine.last_reviewed
|
||||
assert @timemachine.needs_review?(nil)
|
||||
|
|
@ -88,43 +101,15 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
assert_in_delta Time.now, @timemachine.completed_at, 1
|
||||
end
|
||||
|
||||
def test_find_project_by_namepart_with_exact_match
|
||||
p = Project.find_by_namepart('Build a working time machine')
|
||||
assert_not_nil p
|
||||
assert_equal @timemachine.id, p.id
|
||||
end
|
||||
|
||||
def test_find_project_by_namepart_with_starts_with
|
||||
p = Project.find_by_namepart('Build a')
|
||||
assert_not_nil p
|
||||
assert_equal @timemachine.id, p.id
|
||||
end
|
||||
|
||||
def test_delete_project_deletes_todos_within_it
|
||||
assert_equal 3, @timemachine.todos.count
|
||||
timemachine_todo_ids = @timemachine.todos.map{ |t| t.id }
|
||||
@timemachine.destroy
|
||||
timemachine_todo_ids.each do |t_id|
|
||||
assert !Todo.exists?(t_id)
|
||||
assert !Todo.exists?(t_id)
|
||||
end
|
||||
end
|
||||
|
||||
def test_not_done_todos
|
||||
assert_equal 3, @timemachine.todos.not_completed.size
|
||||
t = @timemachine.todos.not_completed[0]
|
||||
t.complete!
|
||||
t.save!
|
||||
assert_equal 2, Project.find(@timemachine.id).todos.not_completed.size
|
||||
end
|
||||
|
||||
def test_done_todos
|
||||
assert_equal 0, @timemachine.todos.completed.size
|
||||
t = @timemachine.todos.not_completed[0]
|
||||
t.complete!
|
||||
t.save!
|
||||
assert_equal 1, Project.find(@timemachine.id).todos.completed.size
|
||||
end
|
||||
|
||||
def test_deferred_todos
|
||||
assert_equal 1, @timemachine.todos.deferred.size
|
||||
t = @timemachine.todos.not_completed[0]
|
||||
|
|
@ -149,29 +134,26 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
assert_equal 'Tracks Projects', opts[:title], 'Unexpected value for :title key of feed_options'
|
||||
assert_equal 'Lists all the projects for Admin Schmadmin', opts[:description], 'Unexpected value for :description key of feed_options'
|
||||
end
|
||||
|
||||
def test_transition_to_another_state
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
@timemachine.transition_to(:hidden)
|
||||
assert_equal :hidden, @timemachine.aasm_current_state
|
||||
@timemachine.transition_to(:completed)
|
||||
assert_equal :completed, @timemachine.aasm_current_state
|
||||
@timemachine.transition_to(:active)
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
|
||||
def test_name_removes_extra_spaces
|
||||
newproj = Project.new
|
||||
newproj.name = "These Words Have Proximity Issues "
|
||||
assert newproj.save
|
||||
assert_equal 0, newproj.errors.count
|
||||
assert_equal "These Words Have Proximity Issues", newproj.name
|
||||
|
||||
# and on update...
|
||||
@timemachine.name = " a time machine needs lots of spaaaaaaace "
|
||||
assert @timemachine.save
|
||||
assert_equal "a time machine needs lots of spaaaaaaace", @timemachine.name
|
||||
end
|
||||
|
||||
def test_transition_to_same_state
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
@timemachine.transition_to(:active)
|
||||
assert_equal :active, @timemachine.aasm_current_state
|
||||
end
|
||||
|
||||
|
||||
def test_deferred_todo_count
|
||||
assert_equal 1, @timemachine.todos.deferred.count
|
||||
assert_equal 0, @moremoney.todos.deferred.count
|
||||
|
||||
first_todo = @moremoney.todos[0]
|
||||
first_todo.show_from = next_week
|
||||
first_todo.show_from = Time.zone.now + 1.week
|
||||
assert_equal :deferred, @moremoney.todos[0].aasm_current_state
|
||||
|
||||
assert_equal 1, @moremoney.todos.deferred.count
|
||||
|
|
@ -191,11 +173,4 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
assert_equal 3, @moremoney.todos.not_completed.count
|
||||
end
|
||||
|
||||
def test_default_context_name
|
||||
p = Project.new
|
||||
assert_equal '', p.default_context.name
|
||||
p.default_context = contexts(:agenda)
|
||||
assert_equal 'agenda', p.default_context.name
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue