mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
fix failing test and make sure that you can supply 'starred' tag. Refactor todo model
This commit is contained in:
parent
72edf10ad3
commit
906ff11633
4 changed files with 71 additions and 72 deletions
|
|
@ -90,7 +90,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
if @todo.errors.empty?
|
if @todo.errors.empty?
|
||||||
@todo.starred= (params[:new_todo_starred]||"").include? "true"
|
@todo.starred= (params[:new_todo_starred]||"").include? "true" if params[:new_todo_starred]
|
||||||
|
|
||||||
@todo.add_predecessor_list(predecessor_list)
|
@todo.add_predecessor_list(predecessor_list)
|
||||||
|
|
||||||
|
|
@ -1516,6 +1516,13 @@ class TodosController < ApplicationController
|
||||||
@params = params['request'] || params
|
@params = params['request'] || params
|
||||||
@prefs = prefs
|
@prefs = prefs
|
||||||
@attributes = params['request'] && params['request']['todo'] || params['todo']
|
@attributes = params['request'] && params['request']['todo'] || params['todo']
|
||||||
|
|
||||||
|
if @attributes[:tags]
|
||||||
|
# the REST api may use <tags> which will collide with tags association, so rename tags to add_tags
|
||||||
|
add_tags = @attributes[:tags]
|
||||||
|
@attributes.delete :tags
|
||||||
|
@attributes[:add_tags] = add_tags
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def attributes
|
def attributes
|
||||||
|
|
|
||||||
|
|
@ -353,22 +353,12 @@ class Todo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags=(params)
|
# used by the REST API. <tags> will also work, this is renamed to add_tags in TodosController::TodoCreateParamsHelper::initialize
|
||||||
value = params[:tag]
|
def add_tags=(params)
|
||||||
|
tag_with params[:tag].inject([]) { |list, value| list << value[:name] } unless params[:tag].nil?
|
||||||
if !value.nil?
|
|
||||||
if value.class == Array
|
|
||||||
value.each do |attrs|
|
|
||||||
tags.build(attrs)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
tags.build(value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rich Todo API
|
# Rich Todo API
|
||||||
|
|
||||||
def self.from_rich_message(user, default_context_id, description, notes)
|
def self.from_rich_message(user, default_context_id, description, notes)
|
||||||
fields = description.match(/([^>@]*)@?([^>]*)>?(.*)/)
|
fields = description.match(/([^>@]*)@?([^>]*)>?(.*)/)
|
||||||
description = fields[1].strip
|
description = fields[1].strip
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
||||||
<project_id>#{projects(:timemachine).id}</project_id>
|
<project_id>#{projects(:timemachine).id}</project_id>
|
||||||
<tags>
|
<tags>
|
||||||
<tag><name>starred</name></tag>
|
<tag><name>starred</name></tag>
|
||||||
|
<tag><name>starred1</name></tag>
|
||||||
<tag><name>starred2</name></tag>
|
<tag><name>starred2</name></tag>
|
||||||
</tags>
|
</tags>
|
||||||
</todo>"
|
</todo>"
|
||||||
|
|
@ -83,7 +84,8 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
||||||
assert_response :success
|
assert_response :success
|
||||||
todo = @user.todos.find_by_description("this will succeed 3")
|
todo = @user.todos.find_by_description("this will succeed 3")
|
||||||
assert_not_nil todo
|
assert_not_nil todo
|
||||||
assert !todo.starred?
|
assert_equal "starred, starred1, starred2", todo.tag_list
|
||||||
|
assert todo.starred?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_post_create_todo_with_new_context
|
def test_post_create_todo_with_new_context
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue