mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-31 22:38:49 +01:00
Added an XML representation of an indvidual context and context.
Updated some HTTP error status codes to play better with ActiveResource. Added date_field_tag helper method and make it format the date properly. Used beginning_of_day() instead of to_date().to_time(). Verified all tests pass on Win32. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@542 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
453fb34036
commit
bd51916561
12 changed files with 57 additions and 34 deletions
|
|
@ -22,7 +22,18 @@ class ContextsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@page_title = "TRACKS::Context: #{@context.name}"
|
||||
if (@context.nil?)
|
||||
respond_to do |format|
|
||||
format.html { render :text => 'Context not found', :status => 404 }
|
||||
format.xml { render :xml => '<error>Context not found</error>', :status => 404 }
|
||||
end
|
||||
else
|
||||
@page_title = "TRACKS::Context: #{@context.name}"
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @context.to_xml( :except => :user_id ) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type: application/xml'
|
||||
|
|
@ -32,7 +43,7 @@ class ContextsController < ApplicationController
|
|||
#
|
||||
def create
|
||||
if params[:format] == 'application/xml' && params['exception']
|
||||
render_failure "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>."
|
||||
render_failure "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>.", 400
|
||||
return
|
||||
end
|
||||
@context = @user.contexts.build
|
||||
|
|
@ -47,11 +58,11 @@ class ContextsController < ApplicationController
|
|||
format.js
|
||||
format.xml do
|
||||
if @context.new_record? && params_are_invalid
|
||||
render_failure "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>."
|
||||
render_failure "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>.", 400
|
||||
elsif @context.new_record?
|
||||
render_failure @context.errors.to_xml
|
||||
render_failure @context.errors.to_xml, 409
|
||||
else
|
||||
render :xml => @context.to_xml( :except => :user_id )
|
||||
render :xml => @context.to_xml( :except => :user_id ), :status => 201
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -125,6 +136,8 @@ class ContextsController < ApplicationController
|
|||
|
||||
def set_context_from_params
|
||||
@context = @user.contexts.find_by_params(params)
|
||||
rescue
|
||||
@context = nil
|
||||
end
|
||||
|
||||
def init
|
||||
|
|
@ -137,14 +150,16 @@ class ContextsController < ApplicationController
|
|||
|
||||
def init_todos
|
||||
set_context_from_params
|
||||
@done = @context.done_todos
|
||||
# @not_done_todos = @context.not_done_todos
|
||||
# TODO: Temporarily doing this search manually until I can work out a way
|
||||
# to do the same thing using not_done_todos acts_as_todo_container method
|
||||
# Hides actions in hidden projects from context.
|
||||
@not_done_todos = @context.todos.find(:all, :conditions => ['todos.state = ?', 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => :project)
|
||||
@count = @not_done_todos.size
|
||||
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
|
||||
unless @context.nil?
|
||||
@done = @context.done_todos
|
||||
# @not_done_todos = @context.not_done_todos
|
||||
# TODO: Temporarily doing this search manually until I can work out a way
|
||||
# to do the same thing using not_done_todos acts_as_todo_container method
|
||||
# Hides actions in hidden projects from context.
|
||||
@not_done_todos = @context.todos.find(:all, :conditions => ['todos.state = ?', 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => :project)
|
||||
@count = @not_done_todos.size
|
||||
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ class ProjectsController < ApplicationController
|
|||
@next_project = @user.projects.next_from(@project)
|
||||
@previous_project = @user.projects.previous_from(@project)
|
||||
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @project.to_xml( :except => :user_id ) }
|
||||
end
|
||||
end
|
||||
|
||||
# Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type: application/xml'
|
||||
|
|
|
|||
|
|
@ -189,6 +189,10 @@ module TodosHelper
|
|||
s = will_paginate(@down_count, 6)
|
||||
(s.gsub /(<\/[^<]+>)/, '\1 ').chomp(' ')
|
||||
end
|
||||
|
||||
def date_field_tag(name, id, value = nil, options = {})
|
||||
text_field_tag name, value, {"size" => 12, "id" => id, "class" => "Date", "onfocus" => "Calendar.setup", "autocomplete" => "off"}.update(options.stringify_keys)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ class Todo < ActiveRecord::Base
|
|||
validates_presence_of :description
|
||||
validates_length_of :description, :maximum => 100
|
||||
validates_length_of :notes, :maximum => 60000, :allow_nil => true
|
||||
# validates_chronic_date :due, :allow_nil => true
|
||||
validates_presence_of :show_from, :if => :deferred?
|
||||
validates_presence_of :context
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class User < ActiveRecord::Base
|
|||
:order => 'position ASC',
|
||||
:dependent => :delete_all do
|
||||
def find_by_params(params)
|
||||
find(params['id'] || params['context_id'])
|
||||
find(params['id'] || params['context_id']) || nil
|
||||
end
|
||||
end
|
||||
has_many :projects,
|
||||
|
|
@ -57,7 +57,7 @@ class User < ActiveRecord::Base
|
|||
:conditions => [ 'state = ?', 'deferred' ],
|
||||
:order => 'show_from ASC, todos.created_at DESC' do
|
||||
def find_and_activate_ready
|
||||
find(:all, :conditions => ['show_from <= ?', Time.now.utc.to_date.to_time ]).collect { |t| t.activate_and_save! }
|
||||
find(:all, :conditions => ['show_from <= ?', Time.now.utc.beginning_of_day ]).collect { |t| t.activate_and_save! }
|
||||
end
|
||||
end
|
||||
has_many :completed_todos,
|
||||
|
|
|
|||
|
|
@ -47,12 +47,12 @@ Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "click", <%= dom_id(@to
|
|||
|
||||
<div class="due_input">
|
||||
<label for="<%= dom_id(@todo, 'due') %>">Due</label>
|
||||
<%= text_field("todo", "due", "size" => 12, "id" => dom_id(@todo, 'due'), "class" => "Date", "onfocus" => "Calendar.setup", "tabindex" => 13, "autocomplete" => "off") %>
|
||||
<%= date_field_tag("todo[due]", dom_id(@todo, 'due'), format_date(@todo.due), "tabindex" => 13) %>
|
||||
</div>
|
||||
|
||||
<div class="show_from_input">
|
||||
<label for="<%= dom_id(@todo, 'show_from') %>">Show from</label>
|
||||
<%= text_field("todo", "show_from", "size" => 12, "id" => dom_id(@todo, 'show_from'), "class" => "Date", "onfocus" => "Calendar.setup", "tabindex" => 14, "autocomplete" => "off") %>
|
||||
<%= date_field_tag("todo[show_from]", dom_id(@todo, 'show_from'), format_date(@todo.show_from), "tabindex" => 14) %>
|
||||
</div>
|
||||
|
||||
<% if controller.controller_name == "project" || @todo.deferred? -%>
|
||||
|
|
|
|||
6
tracks/test/fixtures/projects.yml
vendored
6
tracks/test/fixtures/projects.yml
vendored
|
|
@ -1,10 +1,8 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
<%
|
||||
|
||||
<%
|
||||
def today
|
||||
Time.now.utc.to_date.to_time.to_s(:db)
|
||||
Time.now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
%>
|
||||
|
||||
timemachine:
|
||||
|
|
|
|||
10
tracks/test/fixtures/todos.yml
vendored
10
tracks/test/fixtures/todos.yml
vendored
|
|
@ -2,19 +2,19 @@
|
|||
<%
|
||||
|
||||
def today
|
||||
Time.now.utc.to_date.to_time.to_s(:db)
|
||||
Time.now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def next_week
|
||||
1.week.from_now.to_date.to_time.utc.to_s(:db)
|
||||
1.week.from_now.beginning_of_day.utc.to_s(:db)
|
||||
end
|
||||
|
||||
def last_week
|
||||
1.week.ago.utc.to_date.to_time.to_s(:db)
|
||||
1.week.ago.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
def two_weeks_hence
|
||||
2.weeks.from_now.utc.to_date.to_time.to_s(:db)
|
||||
2.weeks.from_now.utc.beginning_of_day.to_s(:db)
|
||||
end
|
||||
|
||||
%>
|
||||
|
|
@ -197,7 +197,7 @@ end
|
|||
created_at: <%= today %>
|
||||
due: ~
|
||||
completed_at: ~
|
||||
show_from: <%= today %>
|
||||
show_from: <%= next_week %>
|
||||
user_id: 1
|
||||
|
||||
16:
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class ContextXmlApiTest < ActionController::IntegrationTest
|
|||
def test_fails_with_too_long_name
|
||||
invalid_with_long_name_postdata = "<request><context><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></context></request>"
|
||||
authenticated_post_xml_to_context_create invalid_with_long_name_postdata
|
||||
assert_response 404
|
||||
assert_response 409
|
||||
assert_xml_select 'errors' do
|
||||
assert_select 'error', 1, 'Name context name must be less than 256 characters'
|
||||
end
|
||||
|
|
@ -48,7 +48,7 @@ class ContextXmlApiTest < ActionController::IntegrationTest
|
|||
|
||||
def test_fails_with_comma_in_name
|
||||
authenticated_post_xml_to_context_create "<request><context><name>foo,bar</name></context></request>"
|
||||
assert_response 404
|
||||
assert_response 409
|
||||
assert_xml_select 'errors' do
|
||||
assert_select 'error', 1, 'Name cannot contain the comma (\',\') character'
|
||||
end
|
||||
|
|
@ -57,7 +57,7 @@ class ContextXmlApiTest < ActionController::IntegrationTest
|
|||
def test_creates_new_context
|
||||
initial_count = Context.count
|
||||
authenticated_post_xml_to_context_create
|
||||
assert_response 200
|
||||
assert_response 201
|
||||
assert_xml_select 'context' do
|
||||
assert_select 'created-at', /\d{4}+-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/
|
||||
assert_select 'hide', /false|0/ #TODO: Figure out schema issues
|
||||
|
|
@ -78,7 +78,7 @@ class ContextXmlApiTest < ActionController::IntegrationTest
|
|||
end
|
||||
|
||||
def assert_404_invalid_xml
|
||||
assert_response_and_body 404, "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>."
|
||||
assert_response_and_body 400, "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>."
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
type "todo_description", "choose era"
|
||||
type "todo_show_from", "1/1/2030"
|
||||
click "//input[@value='Add item']"
|
||||
click "//input[@value='Add action']"
|
||||
wait_for_element_present "xpath=//div[@id='tickler'] //div[@class='item-container']"
|
||||
wait_for_element_present "xpath=//div[@id='tickler'] //div[@class='item-container'] //a[@title='01/01/2030']"
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ class TodoTest < Test::Unit::TestCase
|
|||
assert_equal "Call Bill Gates to find out how much he makes per day", @not_completed1.description
|
||||
assert_nil @not_completed1.notes
|
||||
assert @not_completed1.completed? == false
|
||||
assert_equal 1.week.ago.utc.to_date.to_time.strftime("%Y-%m-%d %H:%M"), @not_completed1.created_at.strftime("%Y-%m-%d %H:%M")
|
||||
assert_equal 2.week.from_now.utc.to_date.to_time.strftime("%Y-%m-%d"), @not_completed1.due.strftime("%Y-%m-%d")
|
||||
assert_equal 1.week.ago.utc.beginning_of_day.strftime("%Y-%m-%d %H:%M"), @not_completed1.created_at.strftime("%Y-%m-%d %H:%M")
|
||||
assert_equal 2.week.from_now.utc.beginning_of_day.strftime("%Y-%m-%d"), @not_completed1.due.strftime("%Y-%m-%d")
|
||||
assert_nil @not_completed1.completed_at
|
||||
assert_equal 1, @not_completed1.user_id
|
||||
end
|
||||
|
|
|
|||
|
|
@ -255,6 +255,9 @@ class UserTest < Test::Unit::TestCase
|
|||
|
||||
def test_find_and_activate_deferred_todos_that_are_ready
|
||||
assert_equal 1, @admin_user.deferred_todos.count
|
||||
@admin_user.deferred_todos[0].show_from = Time.now.utc.to_date
|
||||
@admin_user.deferred_todos[0].save
|
||||
@admin_user.deferred_todos.reload
|
||||
@admin_user.deferred_todos.find_and_activate_ready
|
||||
@admin_user.deferred_todos.reload
|
||||
assert_equal 0, @admin_user.deferred_todos.count
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue