fix #1229. Thanks popsch for the testscript and the initial pull request

This commit is contained in:
Reinier Balt 2012-03-19 20:04:56 +01:00
parent 322248963b
commit c7e68aa8b6
2 changed files with 41 additions and 2 deletions

View file

@ -340,7 +340,10 @@ class Todo < ActiveRecord::Base
# used by the REST API. <tags> will also work, this is renamed to add_tags in TodosController::TodoCreateParamsHelper::initialize
def add_tags=(params)
tag_with params[:tag].inject([]) { |list, value| list << value[:name] } unless params[:tag].nil?
unless params[:tag].nil?
tag_list = params[:tag].inject([]) { |list, value| list << value[:name] }
tag_with tag_list.join(", ")
end
end
# Rich Todo API

View file

@ -104,7 +104,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
assert_equal "starred, starred1, starred2", todo.tag_list
assert todo.starred?
end
def test_post_create_todo_with_single_tag
authenticated_post_xml_to_todo_create "
<todo>
@ -122,6 +122,42 @@ class TodoXmlApiTest < ActionController::IntegrationTest
assert_equal "tracks", todo.tag_list
end
def test_post_create_todo_with_multiple_tags_and_space
# testing fix for #1229
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>foo </name></tag>
<tag><name> bar</name></tag>
<tag><name> bingo </name></tag>
</tags>
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 3")
assert_not_nil todo
assert_equal "bar, bingo, foo", todo.tag_list
authenticated_post_xml_to_todo_create "
<todo>
<description>this will succeed 4</description>
<context_id>#{contexts(:office).id}</context_id>
<project_id>#{projects(:timemachine).id}</project_id>
<tags>
<tag><name>foo</name></tag>
<tag><name>bar</name></tag>
<tag><name>bingo</name></tag>
</tags>
</todo>"
assert_response :success
todo = @user.todos.find_by_description("this will succeed 4")
assert_not_nil todo
assert_equal "bar, bingo, foo", todo.tag_list
end
def test_post_create_todo_with_new_context
authenticated_post_xml_to_todo_create "
<todo>