mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-19 16:50:12 +01:00
Fix #1223 for the single tag and single dependency case in the REST API
This commit is contained in:
parent
eb2f071c80
commit
960326efb4
3 changed files with 48 additions and 23 deletions
|
|
@ -1518,10 +1518,12 @@ class TodosController < ApplicationController
|
||||||
@attributes = params['request'] && params['request']['todo'] || params['todo']
|
@attributes = params['request'] && params['request']['todo'] || params['todo']
|
||||||
|
|
||||||
if @attributes && @attributes[:tags]
|
if @attributes && @attributes[:tags]
|
||||||
|
# for single tags, @attributed[:tags] returns a hash. For multiple tags,
|
||||||
|
# it with return an array of hashes. Make sure it is always an array of hashes
|
||||||
|
@attributes[:tags][:tag] = [@attributes[:tags][:tag]] unless @attributes[:tags][:tag].class == Array
|
||||||
# the REST api may use <tags> which will collide with tags association, so rename tags to add_tags
|
# the REST api may use <tags> which will collide with tags association, so rename tags to add_tags
|
||||||
add_tags = @attributes[:tags]
|
@attributes[:add_tags] = @attributes[:tags]
|
||||||
@attributes.delete :tags
|
@attributes.delete :tags
|
||||||
@attributes[:add_tags] = add_tags
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -299,24 +299,13 @@ class Todo < ActiveRecord::Base
|
||||||
# XML API fixups
|
# XML API fixups
|
||||||
def predecessor_dependencies=(params)
|
def predecessor_dependencies=(params)
|
||||||
value = params[:predecessor]
|
value = params[:predecessor]
|
||||||
|
return if value.nil?
|
||||||
|
|
||||||
if !value.nil?
|
# for multiple dependencies, value will be an array of id's, but for a single dependency,
|
||||||
if value.class == Array
|
# value will be a string. In that case convert to array
|
||||||
value.each do |ele|
|
value = [value] unless value.class == Array
|
||||||
if ele.is_a? String
|
|
||||||
add_predecessor(self.user.todos.find_by_id(ele.to_i)) unless ele.blank?
|
value.each { |ele| 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
|
end
|
||||||
|
|
||||||
alias_method :original_context=, :context=
|
alias_method :original_context=, :context=
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,10 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
||||||
assert_equal @user.todos.count, old_count + 1
|
assert_equal @user.todos.count, old_count + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_post_create_todo_with_dependencies
|
def test_post_create_todo_with_multiple_dependencies
|
||||||
authenticated_post_xml_to_todo_create "
|
authenticated_post_xml_to_todo_create "
|
||||||
<todo>
|
<todo>
|
||||||
<description>this will succeed 2</description>
|
<description>this will succeed 2.0</description>
|
||||||
<context_id>#{contexts(:office).id}</context_id>
|
<context_id>#{contexts(:office).id}</context_id>
|
||||||
<project_id>#{projects(:timemachine).id}</project_id>
|
<project_id>#{projects(:timemachine).id}</project_id>
|
||||||
<predecessor_dependencies>
|
<predecessor_dependencies>
|
||||||
|
|
@ -63,12 +63,29 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
||||||
</todo>"
|
</todo>"
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
todo = @user.todos.find_by_description("this will succeed 2")
|
todo = @user.todos.find_by_description("this will succeed 2.0")
|
||||||
assert_not_nil todo
|
assert_not_nil todo
|
||||||
assert !todo.uncompleted_predecessors.empty?
|
assert !todo.uncompleted_predecessors.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_post_create_todo_with_tags
|
def test_post_create_todo_with_single_dependency
|
||||||
|
authenticated_post_xml_to_todo_create "
|
||||||
|
<todo>
|
||||||
|
<description>this will succeed 2.1</description>
|
||||||
|
<context_id>#{contexts(:office).id}</context_id>
|
||||||
|
<project_id>#{projects(:timemachine).id}</project_id>
|
||||||
|
<predecessor_dependencies>
|
||||||
|
<predecessor>6</predecessor>
|
||||||
|
</predecessor_dependencies>
|
||||||
|
</todo>"
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
todo = @user.todos.find_by_description("this will succeed 2.1")
|
||||||
|
assert_not_nil todo
|
||||||
|
assert !todo.uncompleted_predecessors.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_post_create_todo_with_multiple_tags
|
||||||
authenticated_post_xml_to_todo_create "
|
authenticated_post_xml_to_todo_create "
|
||||||
<todo>
|
<todo>
|
||||||
<description>this will succeed 3</description>
|
<description>this will succeed 3</description>
|
||||||
|
|
@ -88,6 +105,23 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
||||||
assert todo.starred?
|
assert todo.starred?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_post_create_todo_with_single_tag
|
||||||
|
authenticated_post_xml_to_todo_create "
|
||||||
|
<todo>
|
||||||
|
<description>this will succeed 3.1</description>
|
||||||
|
<context_id>#{contexts(:office).id}</context_id>
|
||||||
|
<project_id>#{projects(:timemachine).id}</project_id>
|
||||||
|
<tags>
|
||||||
|
<tag><name>tracks</name></tag>
|
||||||
|
</tags>
|
||||||
|
</todo>"
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
todo = @user.todos.find_by_description("this will succeed 3.1")
|
||||||
|
assert_not_nil todo
|
||||||
|
assert_equal "tracks", todo.tag_list
|
||||||
|
end
|
||||||
|
|
||||||
def test_post_create_todo_with_new_context
|
def test_post_create_todo_with_new_context
|
||||||
authenticated_post_xml_to_todo_create "
|
authenticated_post_xml_to_todo_create "
|
||||||
<todo>
|
<todo>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue