mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-23 18:50:12 +01:00
add parameter to REST api for todos to limit result to active todos. Fixes #1388
This commit is contained in:
parent
4cde8ce78b
commit
595806be87
3 changed files with 27 additions and 2 deletions
|
|
@ -47,7 +47,10 @@ class TodosController < ApplicationController
|
||||||
headers['Content-Type']=Mime::TEXT.to_s
|
headers['Content-Type']=Mime::TEXT.to_s
|
||||||
render :content_type => Mime::TEXT
|
render :content_type => Mime::TEXT
|
||||||
end
|
end
|
||||||
format.xml { render :xml => @todos.to_xml( *todo_xml_params ) }
|
format.xml do
|
||||||
|
@xml_todos = params[:limit_to_active_todos] ? @not_done_todos : @todos
|
||||||
|
render :xml => @xml_todos.to_xml( *todo_xml_params )
|
||||||
|
end
|
||||||
format.any(:rss, :atom) { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" }
|
format.any(:rss, :atom) { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" }
|
||||||
format.ics
|
format.ics
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,15 @@ field to <code>ID, created_at, modified_at, completed_at</code> by adding the pa
|
||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
If you only want to get the active todos, you add the parameter <code>limit_to_active_todos</code> and set it to some value like this:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<code>
|
||||||
|
$ curl -u username:p4ssw0rd -H "Content-Type: text/xml" \
|
||||||
|
<%= root_url %>todos.xml?limit_to_active_todos=1
|
||||||
|
</code>
|
||||||
|
</pre>
|
||||||
|
|
||||||
<h2>Writing to the API</h2>
|
<h2>Writing to the API</h2>
|
||||||
|
|
||||||
<p>The API provides mechanisms for adding, updating and deleting resources using the HTTP methods <code>PUT</code>, <code>POST</code> and <code>DELETE</code> in combination with the content.</p>
|
<p>The API provides mechanisms for adding, updating and deleting resources using the HTTP methods <code>PUT</code>, <code>POST</code> and <code>DELETE</code> in combination with the content.</p>
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class TodoXmlApiTest < ActionDispatch::IntegrationTest
|
||||||
get '/tickler.xml', {}, {}
|
get '/tickler.xml', {}, {}
|
||||||
assert_response 401
|
assert_response 401
|
||||||
|
|
||||||
get "/tickler.xml", {}, {'HTT_AUTHORIZATION' => "Basic " + Base64.encode64("wrong:wrong"),'ACCEPT' => 'application/xml'}
|
get "/tickler.xml", {}, {'HTTP_AUTHORIZATION' => "Basic " + Base64.encode64("wrong:wrong"),'ACCEPT' => 'application/xml'}
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -32,6 +32,19 @@ class TodoXmlApiTest < ActionDispatch::IntegrationTest
|
||||||
assert_no_tag :tag => "user_id"
|
assert_no_tag :tag => "user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_get_index_with_only_active_todos
|
||||||
|
authenticated_get_xml "/todos.xml", @user.login, @password, {}
|
||||||
|
assert_response 200
|
||||||
|
|
||||||
|
all_todo_count = assigns['xml_todos']
|
||||||
|
|
||||||
|
authenticated_get_xml "/todos.xml?limit_to_active_todos=1", @user.login, @password, {}
|
||||||
|
assert_response 200
|
||||||
|
|
||||||
|
active_todo_count = assigns['xml_todos']
|
||||||
|
assert all_todo_count != active_todo_count, "active should be less than all todos"
|
||||||
|
end
|
||||||
|
|
||||||
def test_create_todo_with_show_from
|
def test_create_todo_with_show_from
|
||||||
old_count = @user.todos.count
|
old_count = @user.todos.count
|
||||||
authenticated_post_xml_to_todo_create "
|
authenticated_post_xml_to_todo_create "
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue