mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-31 06:18:49 +01:00
commit
72edf10ad3
2 changed files with 143 additions and 11 deletions
|
|
@ -288,6 +288,8 @@ class Todo < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def add_predecessor(t)
|
||||
return if t.nil?
|
||||
|
||||
@predecessor_array = predecessors
|
||||
@predecessor_array << t
|
||||
end
|
||||
|
|
@ -309,7 +311,62 @@ class Todo < ActiveRecord::Base
|
|||
def raw_notes=(value)
|
||||
self[:notes] = value
|
||||
end
|
||||
|
||||
|
||||
# XML API fixups
|
||||
def predecessor_dependencies=(params)
|
||||
value = params[:predecessor]
|
||||
|
||||
if !value.nil?
|
||||
if value.class == Array
|
||||
value.each do |ele|
|
||||
if ele.is_a? String
|
||||
add_predecessor(self.user.todos.find_by_id(ele.to_i)) unless ele.blank?
|
||||
else
|
||||
predecessor_dependencies.build(value)
|
||||
end
|
||||
end
|
||||
else
|
||||
if ele.is_a? String
|
||||
add_predecessor(self.user.todos.find_by_id(ele.to_i)) unless ele.blank?
|
||||
else
|
||||
predecessor_dependencies.build(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :original_context=, :context=
|
||||
def context=(value)
|
||||
if value.is_a? Context
|
||||
self.original_context=(value)
|
||||
else
|
||||
self.original_context=(Context.create(value))
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :original_project=, :project=
|
||||
def project=(value)
|
||||
if value.is_a? Project
|
||||
self.original_project=(value)
|
||||
else
|
||||
self.original_project=(Project.create(value))
|
||||
end
|
||||
end
|
||||
|
||||
def tags=(params)
|
||||
value = params[:tag]
|
||||
|
||||
if !value.nil?
|
||||
if value.class == Array
|
||||
value.each do |attrs|
|
||||
tags.build(attrs)
|
||||
end
|
||||
else
|
||||
tags.build(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Rich Todo API
|
||||
|
||||
def self.from_rich_message(user, default_context_id, description, notes)
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
|||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
@user = users(:other_user)
|
||||
@password = 'sesame'
|
||||
@user = users(:admin_user)
|
||||
@password = 'abracadabra'
|
||||
end
|
||||
|
||||
def test_get_tickler_succeeds
|
||||
|
|
@ -25,10 +25,10 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
|||
assert_response 401
|
||||
end
|
||||
|
||||
def test_get_tickler_returns_all_deferred_todos
|
||||
number = @user.todos.deferred.count
|
||||
def test_get_tickler_returns_all_deferred_and_pending_todos
|
||||
number = @user.todos.deferred.count + @user.todos.pending.count
|
||||
authenticated_get_xml "/tickler", @user.login, @password, {}
|
||||
assert_tag :tag => "todos", :children => { :count => number, :only => { :tag => "todo" } }
|
||||
assert_tag :tag => "todos", :children => { :count => number }
|
||||
end
|
||||
|
||||
def test_get_tickler_omits_user_id
|
||||
|
|
@ -36,22 +36,97 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
|||
assert_no_tag :tag => "user_id"
|
||||
end
|
||||
|
||||
def test_create_todo_via_xml_show_from
|
||||
def test_create_todo_with_show_from
|
||||
old_count = @user.todos.count
|
||||
authenticated_post_xml_to_todo_create "
|
||||
<todo>
|
||||
<description>Call Warren Buffet to find out how much he makes per day</description>
|
||||
<project_id>#{projects(:attendrailsconf).id}</project_id>
|
||||
<context_id>#{contexts(:office_otheruser).id}</context_id>
|
||||
<context_id>#{contexts(:office).id}</context_id>
|
||||
<project_id>#{projects(:timemachine).id}</project_id>
|
||||
<show-from type=\"datetime\">#{1.week.from_now.xmlschema}</show-from>
|
||||
</todo>"
|
||||
|
||||
assert_response :success
|
||||
assert_equal @user.todos.count, old_count + 1
|
||||
end
|
||||
|
||||
def test_post_create_todo_with_dependencies
|
||||
authenticated_post_xml_to_todo_create "
|
||||
<todo>
|
||||
<description>this will succeed 2</description>
|
||||
<context_id>#{contexts(:office).id}</context_id>
|
||||
<project_id>#{projects(:timemachine).id}</project_id>
|
||||
<predecessor_dependencies>
|
||||
<predecessor>5</predecessor>
|
||||
<predecessor>6</predecessor>
|
||||
</predecessor_dependencies>
|
||||
</todo>"
|
||||
|
||||
assert_response :success
|
||||
todo = @user.todos.find_by_description("this will succeed 2")
|
||||
assert_not_nil todo
|
||||
assert !todo.uncompleted_predecessors.empty?
|
||||
end
|
||||
|
||||
def test_post_create_todo_with_tags
|
||||
authenticated_post_xml_to_todo_create "
|
||||
<todo>
|
||||
<description>this will succeed 3</description>
|
||||
<context_id>#{contexts(:office).id}</context_id>
|
||||
<project_id>#{projects(:timemachine).id}</project_id>
|
||||
<tags>
|
||||
<tag><name>starred</name></tag>
|
||||
<tag><name>starred2</name></tag>
|
||||
</tags>
|
||||
</todo>"
|
||||
|
||||
assert_response :success
|
||||
todo = @user.todos.find_by_description("this will succeed 3")
|
||||
assert_not_nil todo
|
||||
assert !todo.starred?
|
||||
end
|
||||
|
||||
def test_post_create_todo_with_new_context
|
||||
authenticated_post_xml_to_todo_create "
|
||||
<todo>
|
||||
<description>this will succeed 4</description>
|
||||
<project_id>#{projects(:timemachine).id}</project_id>
|
||||
<context>
|
||||
<name>@SomeNewContext</name>
|
||||
</context>
|
||||
</todo>"
|
||||
|
||||
assert_response :success
|
||||
todo = @user.todos.find_by_description("this will succeed 4")
|
||||
assert_not_nil todo
|
||||
assert_not_nil todo.context
|
||||
assert_equal todo.context.name, "@SomeNewContext"
|
||||
end
|
||||
|
||||
def test_post_create_todo_with_new_project
|
||||
authenticated_post_xml_to_todo_create "
|
||||
<todo>
|
||||
<description>this will succeed 5</description>
|
||||
<context_id>#{contexts(:office).id}</context_id>
|
||||
<project>
|
||||
<name>Make even more money</name>
|
||||
</project>
|
||||
</todo>"
|
||||
|
||||
assert_response :success
|
||||
todo = @user.todos.find_by_description("this will succeed 5")
|
||||
assert_not_nil todo
|
||||
assert_not_nil todo.project
|
||||
assert_equal todo.project.name, "Make even more money"
|
||||
end
|
||||
|
||||
def test_post_create_todo_with_wrong_project_and_context_id
|
||||
authenticated_post_xml_to_todo_create "<todo><description>this will fail</description><context_id type='integer'>-16</context_id><project_id type='integer'>-11</project_id></todo>"
|
||||
authenticated_post_xml_to_todo_create "
|
||||
<todo>
|
||||
<description>this will fail</description>
|
||||
<context_id type='integer'>-16</context_id>
|
||||
<project_id type='integer'>-11</project_id>
|
||||
</todo>"
|
||||
assert_response 422
|
||||
assert_xml_select 'errors' do
|
||||
assert_select 'error', 2
|
||||
|
|
@ -65,7 +140,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
|||
|
||||
private
|
||||
|
||||
def authenticated_post_xml_to_todo_create(postdata = @@valid_postdata, user = users(:other_user).login, password = 'sesame')
|
||||
def authenticated_post_xml_to_todo_create(postdata = @@valid_postdata, user = @user.login, password = @password)
|
||||
authenticated_post_xml "/todos", user, password, postdata
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue