mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-01 06:48:49 +01:00
that allows task creation using the same syntax as the "Send to kGTD" quicksilver plugin: Put an @ in front of context name and > in front of project name so "Call jim @calls > Fix house" would create the "Call jim" todo in the calls context and the Fix house project. If there aren't any exact matches, it selects the first context and project that starts with the given strings, so "Call jim @cal >Fix h" would also work. If no project and no context are give, it works exactly like the NewTodo. It also supports the ability to create a new project on the fly by prefacing the project with "new:", for example "Call jim @calls > new:Clean the porch" The new api method the new api method has the name NewRichTodo, which neither Tomas nor I like very much. Perhaps you have an idea for a better name? Closes #384. Also, I removed duplication between context and project models by introducing acts_as_namepart_finder and acts_as_todo_container. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@333 a4c988fc-2ded-0310-b66e-134b36920a42
79 lines
3.7 KiB
Ruby
79 lines
3.7 KiB
Ruby
require File.dirname(__FILE__) + '/../test_helper'
|
|
require 'backend_controller'
|
|
|
|
# Re-raise errors caught by the controller.
|
|
class BackendController; def rescue_action(e) raise e end; end
|
|
|
|
class BackendControllerTest < Test::Unit::TestCase
|
|
fixtures :users, :projects, :contexts, :todos, :notes
|
|
|
|
def setup
|
|
@controller = BackendController.new
|
|
request, response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
|
assert_equal "change-me", User.get_salt()
|
|
end
|
|
|
|
def test_new_todo_fails_with_incorrect_token
|
|
assert_raises_invalid_token { @controller.new_todo('admin', 'notthecorrecttoken', contexts('agenda').id, 'test') }
|
|
end
|
|
|
|
def test_new_todo_fails_with_context_that_does_not_belong_to_user
|
|
assert_raise(CannotAccessContext, "Cannot access a context that does not belong to this user.") { @controller.new_todo(users('other_user').login, users('other_user').word, contexts('agenda').id, 'test') }
|
|
end
|
|
|
|
def test_new_rich_todo_fails_with_incorrect_token
|
|
assert_raises_invalid_token { @controller.new_rich_todo('admin', 'notthecorrecttoken', contexts('agenda').id, 'test') }
|
|
end
|
|
|
|
#"Call mfox @call > Build a working time machine" should create the "Call mfox" todo in the 'call' context and the 'Build a working time machine' project.
|
|
def test_new_rich_todo_creates_todo_with_exact_match
|
|
assert_new_rich_todo_creates_mfox_todo("Call mfox @call > Build a working time machine")
|
|
end
|
|
|
|
#"Call mfox @cal > Build" should create the "Call mfox" todo in the 'call' context and the 'Build a working time machine' project.
|
|
def test_new_rich_todo_creates_todo_with_starts_with_match
|
|
assert_new_rich_todo_creates_mfox_todo("Call mfox @cal > Build")
|
|
end
|
|
|
|
#"Call mfox @call > new:Run for president" should create the 'Run for president' project, create the "Call mfox" todo in the 'call' context and the new project.
|
|
def test_new_rich_todo_creates_todo_with_new_project
|
|
max_todo_id = Todo.maximum('id')
|
|
max_project_id = Project.maximum('id')
|
|
@controller.new_rich_todo(users(:admin_user).login, users(:admin_user).word, contexts(:agenda).id, 'Call mfox @call > new:Run for president')
|
|
todo = Todo.find(:first, :conditions => ["id > ?", max_todo_id])
|
|
new_project = Project.find(:first, :conditions => ["id > ?", max_project_id])
|
|
assert_equal(users(:admin_user).id, todo.user_id)
|
|
assert_equal(contexts(:call).id, todo.context_id)
|
|
assert_equal(new_project.id, todo.project_id)
|
|
assert_equal("Call mfox", todo.description)
|
|
end
|
|
|
|
def assert_new_rich_todo_creates_mfox_todo(description_input)
|
|
max_id = Todo.maximum('id')
|
|
@controller.new_rich_todo(users(:admin_user).login, users(:admin_user).word, contexts(:agenda).id, 'Call mfox @cal > Build')
|
|
todo = Todo.find(:first, :conditions => ["id > ?", max_id])
|
|
assert_equal(users(:admin_user).id, todo.user_id)
|
|
assert_equal(contexts(:call).id, todo.context_id)
|
|
assert_equal(projects(:timemachine).id, todo.project_id)
|
|
assert_equal("Call mfox", todo.description)
|
|
end
|
|
|
|
def test_new_rich_todo_fails_with_context_that_does_not_belong_to_user
|
|
assert_raise(CannotAccessContext, "Cannot access a context that does not belong to this user.") { @controller.new_rich_todo(users('other_user').login, users('other_user').word, contexts('agenda').id, 'test') }
|
|
end
|
|
|
|
def test_list_projects_fails_with_incorrect_token
|
|
assert_raises_invalid_token { @controller.list_projects('admin', 'notthecorrecttoken') }
|
|
end
|
|
|
|
def test_list_contexts_fails_with_incorrect_token
|
|
assert_raises_invalid_token { @controller.list_contexts('admin', 'notthecorrecttoken') }
|
|
end
|
|
|
|
private
|
|
|
|
def assert_raises_invalid_token
|
|
assert_raise(InvalidToken, "Sorry, you don't have permission to perform this action.") { yield }
|
|
end
|
|
|
|
end
|