diff --git a/tracks/app/controllers/contexts_controller.rb b/tracks/app/controllers/contexts_controller.rb
index effe065c..2f5addbd 100644
--- a/tracks/app/controllers/contexts_controller.rb
+++ b/tracks/app/controllers/contexts_controller.rb
@@ -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 => 'Context not found', :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: context name."
+ render_failure "Expected post format is valid xml like so: context name.", 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: context name."
+ render_failure "Expected post format is valid xml like so: context name.", 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
diff --git a/tracks/app/controllers/projects_controller.rb b/tracks/app/controllers/projects_controller.rb
index 2ff0c91f..3dc87036 100644
--- a/tracks/app/controllers/projects_controller.rb
+++ b/tracks/app/controllers/projects_controller.rb
@@ -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'
diff --git a/tracks/app/helpers/todos_helper.rb b/tracks/app/helpers/todos_helper.rb
index 62e8bf94..88b550a5 100644
--- a/tracks/app/helpers/todos_helper.rb
+++ b/tracks/app/helpers/todos_helper.rb
@@ -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
diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb
index b0080439..fc85b878 100644
--- a/tracks/app/models/todo.rb
+++ b/tracks/app/models/todo.rb
@@ -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
diff --git a/tracks/app/models/user.rb b/tracks/app/models/user.rb
index f27fe3ec..b8f85852 100644
--- a/tracks/app/models/user.rb
+++ b/tracks/app/models/user.rb
@@ -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,
diff --git a/tracks/app/views/todos/_edit_form.rhtml b/tracks/app/views/todos/_edit_form.rhtml
index 5f511800..d6be00d8 100644
--- a/tracks/app/views/todos/_edit_form.rhtml
+++ b/tracks/app/views/todos/_edit_form.rhtml
@@ -47,12 +47,12 @@ Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "click", <%= dom_id(@to
-<%= 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) %>
- <%= 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) %>
<% if controller.controller_name == "project" || @todo.deferred? -%>
diff --git a/tracks/test/fixtures/projects.yml b/tracks/test/fixtures/projects.yml
index a013cd07..daac4ced 100644
--- a/tracks/test/fixtures/projects.yml
+++ b/tracks/test/fixtures/projects.yml
@@ -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:
diff --git a/tracks/test/fixtures/todos.yml b/tracks/test/fixtures/todos.yml
index ba68df30..3bcf2f5d 100644
--- a/tracks/test/fixtures/todos.yml
+++ b/tracks/test/fixtures/todos.yml
@@ -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:
diff --git a/tracks/test/integration/context_xml_api_test.rb b/tracks/test/integration/context_xml_api_test.rb
index 3d06a522..022bb846 100644
--- a/tracks/test/integration/context_xml_api_test.rb
+++ b/tracks/test/integration/context_xml_api_test.rb
@@ -40,7 +40,7 @@ class ContextXmlApiTest < ActionController::IntegrationTest
def test_fails_with_too_long_name
invalid_with_long_name_postdata = "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar"
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 "foo,bar"
- 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: context name."
+ assert_response_and_body 400, "Expected post format is valid xml like so: context name."
end
end
\ No newline at end of file
diff --git a/tracks/test/selenium/project_detail/_add_deferred_todo.rsel b/tracks/test/selenium/project_detail/_add_deferred_todo.rsel
index 29605239..2bea0ca5 100644
--- a/tracks/test/selenium/project_detail/_add_deferred_todo.rsel
+++ b/tracks/test/selenium/project_detail/_add_deferred_todo.rsel
@@ -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']"
diff --git a/tracks/test/unit/todo_test.rb b/tracks/test/unit/todo_test.rb
index 951508cc..0ede3f20 100644
--- a/tracks/test/unit/todo_test.rb
+++ b/tracks/test/unit/todo_test.rb
@@ -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
diff --git a/tracks/test/unit/user_test.rb b/tracks/test/unit/user_test.rb
index 03a9c7b4..8db1cbca 100644
--- a/tracks/test/unit/user_test.rb
+++ b/tracks/test/unit/user_test.rb
@@ -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