From 08290efdf56845a50d5ef4942b8c13d4ef1370a4 Mon Sep 17 00:00:00 2001 From: lukemelia Date: Thu, 8 Feb 2007 05:47:14 +0000 Subject: [PATCH] Fixed #436 (Show from not working). While debugging this issue, I renamed a lot of usages of "item" to "todo" to make the code easier to understand. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@435 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/application.rb | 8 +- tracks/app/controllers/mobile_controller.rb | 8 +- tracks/app/controllers/todos_controller.rb | 137 +++++++++--------- tracks/app/helpers/application_helper.rb | 1 + tracks/app/helpers/todos_helper.rb | 82 +++++------ tracks/app/views/contexts/_context.rhtml | 2 +- tracks/app/views/mobile/_mobile_edit.rhtml | 28 ++-- tracks/app/views/projects/_project.rhtml | 2 +- .../app/views/shared/_add_new_item_form.rhtml | 1 + tracks/app/views/todos/_completed.rhtml | 2 +- tracks/app/views/todos/_deferred.rhtml | 2 +- tracks/app/views/todos/_edit_form.rhtml | 56 +++---- tracks/app/views/todos/_item.rhtml | 22 --- tracks/app/views/todos/_todo.rhtml | 25 ++++ tracks/app/views/todos/create.rjs | 12 +- tracks/app/views/todos/destroy.rjs | 4 +- tracks/app/views/todos/edit.rjs | 8 +- tracks/app/views/todos/list_deferred.rhtml | 2 +- tracks/app/views/todos/tag.rhtml | 2 +- tracks/app/views/todos/tickler.rhtml | 2 +- tracks/app/views/todos/toggle_check.rjs | 14 +- tracks/app/views/todos/update.rjs | 52 +++---- .../test/functional/mobile_controller_test.rb | 12 +- .../test/functional/todos_controller_test.rb | 45 ++++-- .../project_detail/_add_deferred_todo.rsel | 1 + .../project_detail/create_deferred_todo.rsel | 2 +- tracks/test/test_helper.rb | 4 + tracks/test/unit/todo_test.rb | 26 +++- 28 files changed, 304 insertions(+), 258 deletions(-) delete mode 100644 tracks/app/views/todos/_item.rhtml create mode 100644 tracks/app/views/todos/_todo.rhtml diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index 822f25ab..4e8e8b8f 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -108,7 +108,13 @@ class ApplicationController < ActionController::Base def parse_date_per_user_prefs( s ) return nil if s.blank? - @user.prefs.tz.unadjust(Date.strptime(s, @user.prefs.date_format)).utc.to_date + #logger.info "Unadjusting user date #{s} from #{@user.prefs.tz} parsing with #{@user.prefs.date_format}" + time = Date.strptime(s, @user.prefs.date_format) + #logger.info "parsed = #{time}" + unadjusted = @user.prefs.tz.unadjust(time).utc + #logger.info "unadjusted = #{unadjusted}" + #logger.info "returning #{unadjusted.to_date}" + unadjusted.to_date end def init_data_for_sidebar diff --git a/tracks/app/controllers/mobile_controller.rb b/tracks/app/controllers/mobile_controller.rb index a587730d..90459347 100644 --- a/tracks/app/controllers/mobile_controller.rb +++ b/tracks/app/controllers/mobile_controller.rb @@ -23,15 +23,15 @@ class MobileController < ApplicationController def update if params[:id] @item = check_user_return_item - @item.update_attributes params[:item] - if params[:item][:state] == "1" + @item.update_attributes params[:todo] + if params[:todo][:state] == "1" @item.state = "completed" else @item.state = "active" end else - params[:item][:user_id] = @user.id - @item = Todo.new(params[:item]) if params[:item] + params[:todo][:user_id] = @user.id + @item = Todo.new(params[:todo]) if params[:todo] end if @item.save diff --git a/tracks/app/controllers/todos_controller.rb b/tracks/app/controllers/todos_controller.rb index 377b8b5a..bd3a3959 100644 --- a/tracks/app/controllers/todos_controller.rb +++ b/tracks/app/controllers/todos_controller.rb @@ -31,9 +31,14 @@ class TodosController < ApplicationController end def create - @item = @user.todos.build + @todo = @user.todos.build p = params['request'] || params - @item.attributes = p['todo'] + + if p['todo']['show_from'] + p['todo']['show_from'] = parse_date_per_user_prefs(p['todo']['show_from']) + end + + @todo.attributes = p['todo'] if p['todo']['project_id'].blank? && !p['project_name'].blank? && p['project_name'] != 'None' project = @user.projects.find_by_name(p['project_name'].strip) @@ -43,7 +48,7 @@ class TodosController < ApplicationController project.save @new_project_created = true end - @item.project_id = project.id + @todo.project_id = project.id end if p['todo']['context_id'].blank? && !p['context_name'].blank? @@ -53,45 +58,39 @@ class TodosController < ApplicationController context.name = p['context_name'].strip context.save @new_context_created = true - @not_done_todos = [@item] + @not_done_todos = [@todo] end - @item.context_id = context.id + @todo.context_id = context.id end - if @item.due? - @date = parse_date_per_user_prefs(p['todo']['due']) - @item.due = @date + if @todo.due? + @todo.due = parse_date_per_user_prefs(p['todo']['due']) else - @item.due = "" + @todo.due = "" end - if p['todo']['show_from'] - @item.show_from = parse_date_per_user_prefs(p['todo']['show_from']) + @saved = @todo.save + @todo.tag_with(params[:tag_list],@user) + @todo.reload + + respond_to do |wants| + wants.html { redirect_to :action => "index" } + wants.js do + if @saved + determine_down_count + end + render :action => 'create' + end + wants.xml { render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ) } end - - @item.save - @item.tag_with(params[:tag_list],@user) - @saved = @item.save - - - respond_to do |wants| - wants.html { redirect_to :action => "index" } - wants.js do - if @saved - determine_down_count - end - render :action => 'create' - end - wants.xml { render :xml => @item.to_xml( :root => 'todo', :except => :user_id ) } - end end def edit - @item = check_user_return_item + @todo = check_user_return_todo end def show - item = check_user_return_item + item = check_user_return_todo respond_to do |wants| wants.xml { render :xml => item.to_xml( :root => 'todo', :except => :user_id ) } end @@ -100,13 +99,13 @@ class TodosController < ApplicationController # Toggles the 'done' status of the action # def toggle_check - @item = check_user_return_item - @item.toggle_completion() - @saved = @item.save + @todo = check_user_return_todo + @todo.toggle_completion() + @saved = @todo.save respond_to do |format| format.js do if @saved - @remaining_undone_in_context = @user.contexts.find(@item.context_id).not_done_todo_count + @remaining_undone_in_context = @user.contexts.find(@todo.context_id).not_done_todo_count determine_down_count determine_completed_count end @@ -115,10 +114,10 @@ class TodosController < ApplicationController format.html do if @saved # TODO: I think this will work, but can't figure out how to test it - notify :notice, "The action '#{@item.description}' was marked as #{@item.completed? ? 'complete' : 'incomplete' }" + notify :notice, "The action '#{@todo.description}' was marked as #{@todo.completed? ? 'complete' : 'incomplete' }" redirect_to :action => "index" else - notify :notice, "The action '#{@item.description}' was NOT marked as #{@item.completed? ? 'complete' : 'incomplete' } due to an error on the server.", "index" + notify :notice, "The action '#{@todo.description}' was NOT marked as #{@todo.completed? ? 'complete' : 'incomplete' } due to an error on the server.", "index" redirect_to :action => "index" end end @@ -126,12 +125,12 @@ class TodosController < ApplicationController end def update - @item = check_user_return_item - @item.tag_with(params[:tag_list],@user) - @original_item_context_id = @item.context_id - @original_item_project_id = @item.project_id - @original_item_was_deferred = @item.deferred? - if params['item']['project_id'].blank? && !params['project_name'].blank? + @todo = check_user_return_todo + @todo.tag_with(params[:tag_list],@user) + @original_item_context_id = @todo.context_id + @original_item_project_id = @todo.project_id + @original_item_was_deferred = @todo.deferred? + if params['todo']['project_id'].blank? && !params['project_name'].blank? if params['project_name'] == 'None' project = Project.null_object else @@ -143,10 +142,10 @@ class TodosController < ApplicationController @new_project_created = true end end - params["item"]["project_id"] = project.id + params["todo"]["project_id"] = project.id end - if params['item']['context_id'].blank? && !params['context_name'].blank? + if params['todo']['context_id'].blank? && !params['context_name'].blank? context = @user.contexts.find_by_name(params['context_name'].strip) unless context context = @user.contexts.build @@ -154,33 +153,33 @@ class TodosController < ApplicationController context.save @new_context_created = true end - params["item"]["context_id"] = context.id + params["todo"]["context_id"] = context.id end - if params["item"].has_key?("due") - params["item"]["due"] = parse_date_per_user_prefs(params["item"]["due"]) + if params["todo"].has_key?("due") + params["todo"]["due"] = parse_date_per_user_prefs(params["todo"]["due"]) else - params["item"]["due"] = "" + params["todo"]["due"] = "" end - if params['item']['show_from'] - params['item']['show_from'] = parse_date_per_user_prefs(params['item']['show_from']) + if params['todo']['show_from'] + params['todo']['show_from'] = parse_date_per_user_prefs(params['todo']['show_from']) end - @saved = @item.update_attributes params["item"] - @context_changed = @original_item_context_id != @item.context_id - @item_was_activated_from_deferred_state = @original_item_was_deferred && @item.active? + @saved = @todo.update_attributes params["todo"] + @context_changed = @original_item_context_id != @todo.context_id + @todo_was_activated_from_deferred_state = @original_item_was_deferred && @todo.active? if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todo_count; end - @project_changed = @original_item_project_id != @item.project_id + @project_changed = @original_item_project_id != @todo.project_id if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = @user.projects.find(@original_item_project_id).not_done_todo_count; end determine_down_count end def destroy - @item = check_user_return_item - @context_id = @item.context_id - @project_id = @item.project_id - @saved = @item.destroy + @todo = check_user_return_todo + @context_id = @todo.context_id + @project_id = @todo.project_id + @saved = @todo.destroy respond_to do |wants| @@ -258,12 +257,12 @@ class TodosController < ApplicationController private - def check_user_return_item - item = Todo.find( params['id'].to_i ) - if @user == item.user - return item + def check_user_return_todo + todo = Todo.find( params['id'].to_i ) + if @user == todo.user + return todo else - @error_message = 'Item and session user mis-match: #{item.user.name} and #{@user.name}!' + @error_message = 'Item and session user mis-match: #{todo.user.name} and #{@todo.name}!' respond_to do |wants| wants.html do notify :error, @error_message, 8.0 @@ -295,12 +294,12 @@ class TodosController < ApplicationController @down_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'active', false]) end from.context do - @down_count = @user.contexts.find(@item.context_id).not_done_todo_count + @down_count = @user.contexts.find(@todo.context_id).not_done_todo_count end from.project do - unless @item.project_id == nil - @down_count = @user.projects.find(@item.project_id).not_done_todo_count - @deferred_count = @user.projects.find(@item.project_id).deferred_todo_count + unless @todo.project_id == nil + @down_count = @user.projects.find(@todo.project_id).not_done_todo_count + @deferred_count = @user.projects.find(@todo.project_id).deferred_todo_count end end from.deferred do @@ -315,11 +314,11 @@ class TodosController < ApplicationController @completed_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'completed', false]) end from.context do - @completed_count = @user.contexts.find(@item.context_id).done_todo_count + @completed_count = @user.contexts.find(@todo.context_id).done_todo_count end from.project do - unless @item.project_id == nil - @completed_count = @user.projects.find(@item.project_id).done_todo_count + unless @todo.project_id == nil + @completed_count = @user.projects.find(@todo.project_id).done_todo_count end end end diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index e69b8c27..2e29fcfa 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -11,6 +11,7 @@ module ApplicationHelper else formatted_date = '' end + formatted_date end def user_time diff --git a/tracks/app/helpers/todos_helper.rb b/tracks/app/helpers/todos_helper.rb index 19ff8ee5..bf2395d0 100644 --- a/tracks/app/helpers/todos_helper.rb +++ b/tracks/app/helpers/todos_helper.rb @@ -7,15 +7,15 @@ module TodosHelper count = Todo.find_all("done=0 AND context_id=#{context.id}").length end - def form_remote_tag_edit_todo( item, &block ) - form_tag( todo_path(item), {:method => :put, :id => dom_id(item, 'form'), :class => "edit_todo_form inline-form" }, &block ) + def form_remote_tag_edit_todo( &block ) + form_tag( todo_path(@todo), {:method => :put, :id => dom_id(@todo, 'form'), :class => "edit_todo_form inline-form" }, &block ) apply_behavior 'form.edit_todo_form', make_remote_form(:method => :put), :prevent_default => true end - def remote_delete_icon(item) - str = link_to( image_tag("blank.png", :title =>"Delete action", :class=>"delete_item"), - todo_path(item), - :class => "icon delete_icon", :title => "delete the action '#{item.description}'") + def remote_delete_icon + str = link_to( image_tag_for_delete, + todo_path(@todo), + :class => "icon delete_icon", :title => "delete the action '#{@todo.description}'") apply_behavior '.item-container a.delete_icon:click', :prevent_default => true do |page| page << "if (confirm('Are you sure that you want to ' + this.title + '?')) {" page << " new Ajax.Request(this.href, { asynchronous : true, evalScripts : true, method : 'delete', parameters : { '_source_view' : '#{@source_view}' }})" @@ -24,10 +24,10 @@ module TodosHelper str end - def remote_edit_icon(item) - if !item.completed? - str = link_to( image_tag_for_edit(item), - edit_todo_path(item), + def remote_edit_icon + if !@todo.completed? + str = link_to( image_tag_for_edit, + edit_todo_path(@todo), :class => "icon edit_icon") apply_behavior '.item-container a.edit_icon:click', :prevent_default => true do |page| page << "new Ajax.Request(this.href, { asynchronous : true, evalScripts : true, method : 'get', parameters : { '_source_view' : '#{@source_view}' }, onLoading: function(request){ Effect.Pulsate(this)}});" @@ -38,44 +38,44 @@ module TodosHelper str end - def remote_toggle_checkbox(item) - str = check_box_tag('item_id', toggle_check_todo_path(item), item.completed?, :class => 'item-checkbox') + def remote_toggle_checkbox + str = check_box_tag('item_id', toggle_check_todo_path(@todo), @todo.completed?, :class => 'item-checkbox') apply_behavior '.item-container input.item-checkbox:click', remote_function(:url => javascript_variable('this.value'), :with => "{ method : 'post', _source_view : '#{@source_view}' }") str end - def date_span(item) - if item.completed? - "#{format_date( item.completed_at )}" - elsif item.deferred? - show_date( item.show_from ) + def date_span + if @todo.completed? + "#{format_date( @todo.completed_at )}" + elsif @todo.deferred? + show_date( @todo.show_from ) else - due_date( item.due ) + due_date( @todo.due ) end end - def tag_list(item) - item.tags.collect{|t| "" + link_to(t.name, :action => "tag", :id => t.name) + ""}.join('') + def tag_list + @todo.tags.collect{|t| "" + link_to(t.name, :action => "tag", :id => t.name) + ""}.join('') end - def deferred_due_date(item) - if item.deferred? && item.due - "(action due on #{format_date(item.due)})" + def deferred_due_date + if @todo.deferred? && @todo.due + "(action due on #{format_date(@todo.due)})" end end - def project_and_context_links(item, parent_container_type) - if item.completed? - "(#{item.context.name}#{", " + item.project.name unless item.project.nil?})" + def project_and_context_links(parent_container_type) + if @todo.completed? + "(#{@todo.context.name}#{", " + @todo.project.name unless @todo.project.nil?})" else str = '' if (['project', 'tickler', 'tag'].include?(parent_container_type)) - str << item_link_to_context( item ) + str << item_link_to_context( @todo ) end - if (['context', 'tickler', 'tag'].include?(parent_container_type)) && item.project_id - str << item_link_to_project( item ) + if (['context', 'tickler', 'tag'].include?(parent_container_type)) && @todo.project_id + str << item_link_to_project( @todo ) end str end @@ -145,17 +145,17 @@ module TodosHelper def item_container_id return "tickler-items" if source_view_is :deferred if source_view_is :project - return "p#{@item.project_id}" if @item.active? - return "tickler" if @item.deferred? + return "p#{@todo.project_id}" if @todo.active? + return "tickler" if @todo.deferred? end - return "c#{@item.context_id}" + return "c#{@todo.context_id}" end def should_show_new_item - return true if source_view_is(:deferred) && @item.deferred? - return true if source_view_is(:project) && @item.project.hidden? && @item.project_hidden? - return true if source_view_is(:project) && @item.deferred? - return true if !source_view_is(:deferred) && @item.active? + return true if source_view_is(:deferred) && @todo.deferred? + return true if source_view_is(:project) && @todo.project.hidden? && @todo.project_hidden? + return true if source_view_is(:project) && @todo.deferred? + return true if !source_view_is(:deferred) && @todo.active? return false end @@ -166,10 +166,10 @@ module TodosHelper end def empty_container_msg_div_id - return "tickler-empty-nd" if source_view_is(:project) && @item.deferred? - return "p#{@item.project_id}empty-nd" if source_view_is :project + return "tickler-empty-nd" if source_view_is(:project) && @todo.deferred? + return "p#{@todo.project_id}empty-nd" if source_view_is :project return "tickler-empty-nd" if source_view_is :deferred - return "c#{@item.context_id}empty-nd" + return "c#{@todo.context_id}empty-nd" end def project_names_for_autocomplete @@ -187,8 +187,8 @@ module TodosHelper image_tag("blank.png", :title =>"Delete action", :class=>"delete_item") end - def image_tag_for_edit(item) - image_tag("blank.png", :title =>"Edit action", :class=>"edit_item", :id=> dom_id(item, 'edit_icon')) + def image_tag_for_edit + image_tag("blank.png", :title =>"Edit action", :class=>"edit_item", :id=> dom_id(@todo, 'edit_icon')) end end diff --git a/tracks/app/views/contexts/_context.rhtml b/tracks/app/views/contexts/_context.rhtml index c1296fc7..82a377e5 100644 --- a/tracks/app/views/contexts/_context.rhtml +++ b/tracks/app/views/contexts/_context.rhtml @@ -14,6 +14,6 @@

Currently there are no uncompleted actions in this context

-<%= render :partial => "todos/item", :collection => @not_done, :locals => { :parent_container_type => "context" } %> +<%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "context" } %> diff --git a/tracks/app/views/mobile/_mobile_edit.rhtml b/tracks/app/views/mobile/_mobile_edit.rhtml index 8a1dfb6b..23648735 100644 --- a/tracks/app/views/mobile/_mobile_edit.rhtml +++ b/tracks/app/views/mobile/_mobile_edit.rhtml @@ -1,21 +1,21 @@ -<%= error_messages_for("item") %> +<%= error_messages_for("todo") %> <% this_year = user_time.to_date.strftime("%Y").to_i -%> -

-

<%= check_box( "item", "state", "tabindex" => 1) %>

-

-

<%= text_field( "item", "description", "tabindex" => 2) %>

-

-

<%= text_area( "item", "notes", "cols" => 30, "rows" => 5, "tabindex" => 3) %>

-

-

<%= collection_select( "item", "context_id", @contexts, "id", "name", {"tabindex" => 4} ) %>

-

<%= collection_select( "item", "project_id", @projects, "id", "name", +

+

<%= check_box( "todo", "state", "tabindex" => 1) %>

+

+

<%= text_field( "todo", "description", "tabindex" => 2) %>

+

+

<%= text_area( "todo", "notes", "cols" => 30, "rows" => 5, "tabindex" => 3) %>

+

+

<%= collection_select( "todo", "context_id", @contexts, "id", "name", {"tabindex" => 4} ) %>

+

<%= collection_select( "todo", "project_id", @projects, "id", "name", {:include_blank => true}, {"tabindex" => 5} ) %>

-

-

<%= date_select("item", "due", :order => [:day, :month, :year], +

+

<%= date_select("todo", "due", :order => [:day, :month, :year], :start_year => this_year, :include_blank => true) %>

-

-

<%= date_select("item", "show_from", :order => [:day, :month, :year], +

+

<%= date_select("todo", "show_from", :order => [:day, :month, :year], :start_year => this_year, :include_blank => true) %>

\ No newline at end of file diff --git a/tracks/app/views/projects/_project.rhtml b/tracks/app/views/projects/_project.rhtml index 556060b4..87d3f761 100644 --- a/tracks/app/views/projects/_project.rhtml +++ b/tracks/app/views/projects/_project.rhtml @@ -20,6 +20,6 @@

Currently there are no uncompleted actions in this project

- <%= render :partial => "todos/item", :collection => @not_done, :locals => { :parent_container_type => "project" } %> + <%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "project" } %> diff --git a/tracks/app/views/shared/_add_new_item_form.rhtml b/tracks/app/views/shared/_add_new_item_form.rhtml index e2380e85..5a561a50 100644 --- a/tracks/app/views/shared/_add_new_item_form.rhtml +++ b/tracks/app/views/shared/_add_new_item_form.rhtml @@ -1,4 +1,5 @@ <% + @todo = nil @initial_context_name = @context.name unless @context.nil? @initial_context_name ||= @contexts[0].name unless @contexts[0].nil? @initial_project_name = @project.name unless @project.nil? diff --git a/tracks/app/views/todos/_completed.rhtml b/tracks/app/views/todos/_completed.rhtml index d28a2d5b..4a1c41b3 100644 --- a/tracks/app/views/todos/_completed.rhtml +++ b/tracks/app/views/todos/_completed.rhtml @@ -12,6 +12,6 @@

Currently there are no completed actions.

- <%= render :partial => "todos/item", :collection => done, :locals => { :parent_container_type => "completed" } %> + <%= render :partial => "todos/todo", :collection => done, :locals => { :parent_container_type => "completed" } %> \ No newline at end of file diff --git a/tracks/app/views/todos/_deferred.rhtml b/tracks/app/views/todos/_deferred.rhtml index f21bbc41..d5468c39 100644 --- a/tracks/app/views/todos/_deferred.rhtml +++ b/tracks/app/views/todos/_deferred.rhtml @@ -12,7 +12,7 @@

Currently there are no deferred actions

- <%= render :partial => "todos/item", :collection => deferred, :locals => { :parent_container_type => 'tickler' } %> + <%= render :partial => "todos/todo", :collection => deferred, :locals => { :parent_container_type => 'tickler' } %> \ No newline at end of file diff --git a/tracks/app/views/todos/_edit_form.rhtml b/tracks/app/views/todos/_edit_form.rhtml index 52405ded..8db54392 100644 --- a/tracks/app/views/todos/_edit_form.rhtml +++ b/tracks/app/views/todos/_edit_form.rhtml @@ -1,59 +1,59 @@ -
<%= error_messages_for("item") %>
+
<%= error_messages_for("todo") %>
-<%= hidden_field( "item", "id" ) %> +<%= hidden_field( "todo", "id" ) %> <%= source_view_tag( @source_view ) %> - - + + - - + + - - + + - + - - + + - - + + - - + + - <% if controller.controller_name == "project" || @item.deferred? -%> + <% if controller.controller_name == "project" || @todo.deferred? -%> <% end -%> + Cancel
<%= text_field( "item", "description", "tabindex" => 8) %><%= text_field( "todo", "description", "tabindex" => 8) %>
<%= text_area( "item", "notes", "cols" => 20, "rows" => 5, "tabindex" => 9) %><%= text_area( "todo", "notes", "cols" => 20, "rows" => 5, "tabindex" => 9) %>
- +
- - + +
<%= text_field_tag "tag_list", @item.tags.collect{|t| t.name}.join(", "), :size => 40, :tabindex => 12 %><%= text_field_tag "tag_list", @todo.tags.collect{|t| t.name}.join(", "), :size => 40, :tabindex => 12 %>
- Cancel
-<%= calendar_setup( dom_id(@item, 'due') ) %> -<%= calendar_setup( dom_id(@item, 'show_from') ) %> +<%= calendar_setup( dom_id(@todo, 'due') ) %> +<%= calendar_setup( dom_id(@todo, 'show_from') ) %> diff --git a/tracks/app/views/todos/_item.rhtml b/tracks/app/views/todos/_item.rhtml deleted file mode 100644 index c65aa528..00000000 --- a/tracks/app/views/todos/_item.rhtml +++ /dev/null @@ -1,22 +0,0 @@ -<% Tag %> -
-
- <%= remote_delete_icon( item ) %> - <%= remote_edit_icon( item ) %> - <%= remote_toggle_checkbox( item ) unless source_view_is :deferred %> -
- <%= date_span( item ) %> - <%= sanitize(item.description) %> - <%= tag_list( item ) %> - <%= deferred_due_date( item ) %> - <%= project_and_context_links( item, parent_container_type ) %> - <%= render(:partial => "todos/toggle_notes", :locals => { :item => item }) if item.notes? %> -
-
- -
diff --git a/tracks/app/views/todos/_todo.rhtml b/tracks/app/views/todos/_todo.rhtml new file mode 100644 index 00000000..ce349a6a --- /dev/null +++ b/tracks/app/views/todos/_todo.rhtml @@ -0,0 +1,25 @@ +<% + @todo = todo + Tag +%> +
+
+ <%= remote_delete_icon %> + <%= remote_edit_icon %> + <%= remote_toggle_checkbox unless source_view_is :deferred %> +
+ <%= date_span %> + <%= sanitize(todo.description) %> + <%= tag_list %> + <%= deferred_due_date %> + <%= project_and_context_links( parent_container_type ) %> + <%= render(:partial => "todos/toggle_notes", :locals => { :item => todo }) if todo.notes? %> +
+
+ +
diff --git a/tracks/app/views/todos/create.rjs b/tracks/app/views/todos/create.rjs index 5d4695d5..33704f61 100644 --- a/tracks/app/views/todos/create.rjs +++ b/tracks/app/views/todos/create.rjs @@ -1,7 +1,7 @@ if @saved page.hide 'status' status_message = 'Added new next action' - status_message += ' to tickler' if @item.deferred? + status_message += ' to tickler' if @todo.deferred? status_message = 'Added new project / ' + status_message if @new_project_created status_message = 'Added new context / ' + status_message if @new_context_created page.notify :notice, status_message, 5.0 @@ -11,15 +11,15 @@ if @saved page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}" if @new_project_created if should_show_new_item() if @new_context_created - page.insert_html :top, 'display_box', :partial => 'contexts/context', :locals => { :context => @item.context, :collapsible => true } + page.insert_html :top, 'display_box', :partial => 'contexts/context', :locals => { :context => @todo.context, :collapsible => true } else - page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}" if source_view_is(:todo) - page.insert_html :bottom, item_container_id, :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type, :source_view => @source_view } - page.visual_effect :highlight, dom_id(@item), :duration => 3 + page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@todo.context_id}" if source_view_is(:todo) + page.insert_html :bottom, item_container_id, :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type, :source_view => @source_view } + page.visual_effect :highlight, dom_id(@todo), :duration => 3 page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil? end end else page.show 'status' - page.replace_html 'status', "#{error_messages_for('item')}" + page.replace_html 'status', "#{error_messages_for('todo')}" end diff --git a/tracks/app/views/todos/destroy.rjs b/tracks/app/views/todos/destroy.rjs index 5646c299..fd0d1ad4 100644 --- a/tracks/app/views/todos/destroy.rjs +++ b/tracks/app/views/todos/destroy.rjs @@ -1,8 +1,8 @@ if @saved - page[@item].remove + page[@todo].remove page['badge_count'].replace_html @down_count page.visual_effect :fade, item_container_id, :duration => 0.4 if source_view_is(:todo) && @remaining_undone_in_context == 0 page[empty_container_msg_div_id].show if !empty_container_msg_div_id.nil? && @down_count == 0 else - page.notify :error, "There was an error deleting the item #{@item.description}", 8.0 + page.notify :error, "There was an error deleting the item #{@todo.description}", 8.0 end \ No newline at end of file diff --git a/tracks/app/views/todos/edit.rjs b/tracks/app/views/todos/edit.rjs index 02e4da44..9f6da060 100644 --- a/tracks/app/views/todos/edit.rjs +++ b/tracks/app/views/todos/edit.rjs @@ -1,4 +1,4 @@ -page[dom_id(@item, 'form')].down('.placeholder').replace_html :partial => 'todos/edit_form' -page[dom_id(@item, 'line')].hide -page[dom_id(@item, 'edit')].show -page[dom_id(@item, 'form')].down('table').down('input').focus \ No newline at end of file +page[dom_id(@todo, 'form')].down('.placeholder').replace_html :partial => 'todos/edit_form' +page[dom_id(@todo, 'line')].hide +page[dom_id(@todo, 'edit')].show +page[dom_id(@todo, 'form')].down('table').down('input').focus \ No newline at end of file diff --git a/tracks/app/views/todos/list_deferred.rhtml b/tracks/app/views/todos/list_deferred.rhtml index 5db5e96d..32086a0e 100644 --- a/tracks/app/views/todos/list_deferred.rhtml +++ b/tracks/app/views/todos/list_deferred.rhtml @@ -8,7 +8,7 @@

Currently there are no deferred actions

- <%= render :partial => "todos/item", :collection => @tickles, :locals => { :parent_container_type => 'tickler' } %> + <%= render :partial => "todos/todo", :collection => @tickles, :locals => { :parent_container_type => 'tickler' } %> diff --git a/tracks/app/views/todos/tag.rhtml b/tracks/app/views/todos/tag.rhtml index 661cc299..7e8f9b3b 100644 --- a/tracks/app/views/todos/tag.rhtml +++ b/tracks/app/views/todos/tag.rhtml @@ -8,7 +8,7 @@

Currently there are no actions tagged with <%= @tag %>

- <%= render :partial => "todos/item", :collection => @todos, :locals => { :parent_container_type => "tag" } %> + <%= render :partial => "todos/todo", :collection => @todos, :locals => { :parent_container_type => "tag" } %> diff --git a/tracks/app/views/todos/tickler.rhtml b/tracks/app/views/todos/tickler.rhtml index 5269b098..32086a0e 100644 --- a/tracks/app/views/todos/tickler.rhtml +++ b/tracks/app/views/todos/tickler.rhtml @@ -8,7 +8,7 @@

Currently there are no deferred actions

- <%= render :partial => "todo/item", :collection => @tickles, :locals => { :parent_container_type => 'tickler' } %> + <%= render :partial => "todos/todo", :collection => @tickles, :locals => { :parent_container_type => 'tickler' } %> diff --git a/tracks/app/views/todos/toggle_check.rjs b/tracks/app/views/todos/toggle_check.rjs index b9d3209a..f872965c 100644 --- a/tracks/app/views/todos/toggle_check.rjs +++ b/tracks/app/views/todos/toggle_check.rjs @@ -1,10 +1,10 @@ if @saved - page[@item].remove - if @item.completed? + page[@todo].remove + if @todo.completed? # Don't try to insert contents into a non-existent container! unless @user.prefs.hide_completed_actions? - page.insert_html :top, "completed", :partial => 'todos/item', :locals => { :parent_container_type => "completed" } - page.visual_effect :highlight, dom_id(@item, 'line'), {'startcolor' => "'#99ff99'"} + page.insert_html :top, "completed", :partial => 'todos/todo', :locals => { :parent_container_type => "completed" } + page.visual_effect :highlight, dom_id(@todo, 'line'), {'startcolor' => "'#99ff99'"} page[empty_container_msg_div_id].show if @down_count == 0 && !empty_container_msg_div_id.nil? page.show 'tickler-empty-nd' if source_view_is(:project) && @deferred_count == 0 page.hide 'empty-d' # If we've checked something as done, completed items can't be empty @@ -14,13 +14,13 @@ if @saved end else page.call "todoItems.ensureVisibleWithEffectAppear", item_container_id - page.insert_html :bottom, item_container_id, :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } - page.visual_effect :highlight, dom_id(@item, 'line'), {'startcolor' => "'#99ff99'"} + page.insert_html :bottom, item_container_id, :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } + page.visual_effect :highlight, dom_id(@todo, 'line'), {'startcolor' => "'#99ff99'"} page.show "empty-d" if @completed_count == 0 page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil? # If we've checked something as undone, uncompleted items can't be empty end page.hide "status" page.replace_html "badge_count", @down_count else - page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }), "id" => "errorExplanation", "class" => "errorExplanation") + page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@todo.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @todo.errors.each_full { |msg| content_tag("li", msg) }), "id" => "errorExplanation", "class" => "errorExplanation") end \ No newline at end of file diff --git a/tracks/app/views/todos/update.rjs b/tracks/app/views/todos/update.rjs index fe1f8f14..89ee1483 100644 --- a/tracks/app/views/todos/update.rjs +++ b/tracks/app/views/todos/update.rjs @@ -1,64 +1,64 @@ if @saved status_message = 'Action saved' - status_message += ' to tickler' if @item.deferred? + status_message += ' to tickler' if @todo.deferred? status_message = 'Added new project / ' + status_message if @new_project_created status_message = 'Added new context / ' + status_message if @new_context_created page.notify :notice, status_message, 5.0 page << "contextAutoCompleter.options.array = #{context_names_for_autocomplete}; contextAutoCompleter.changed = true" if @new_context_created page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}; projectAutoCompleter.changed = true" if @new_project_created if source_view_is_one_of [:todo, :context] - if @context_changed || @item.deferred? - page[@item].remove + if @context_changed || @todo.deferred? + page[@todo].remove if (@remaining_undone_in_context == 0) source_view do |from| from.todo { page.visual_effect :fade, "c#{@original_item_context_id}", :duration => 0.4 } from.context { page.show "c#{@original_item_context_id}empty-nd" } end end - if source_view_is(:todo) && @item.active? - page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}" - page.call "todoItems.expandNextActionListingByContext", "c#{@item.context_id}items", true - page.insert_html :bottom, "c#{@item.context_id}items", :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } + if source_view_is(:todo) && @todo.active? + page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@todo.context_id}" + page.call "todoItems.expandNextActionListingByContext", "c#{@todo.context_id}items", true + page.insert_html :bottom, "c#{@todo.context_id}items", :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } end page.replace_html("badge_count", @remaining_undone_in_context) if source_view_is :context page.delay(0.5) do page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items" - if source_view_is(:todo) && @item.active? - page.call "todoItems.ensureContainerHeight", "c#{@item.context_id}items" - page.visual_effect :highlight, dom_id(@item), :duration => 3 + if source_view_is(:todo) && @todo.active? + page.call "todoItems.ensureContainerHeight", "c#{@todo.context_id}items" + page.visual_effect :highlight, dom_id(@todo), :duration => 3 end end else - page.replace dom_id(@item), :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } - page.visual_effect :highlight, dom_id(@item), :duration => 3 + page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } + page.visual_effect :highlight, dom_id(@todo), :duration => 3 end elsif source_view_is :project if @project_changed - page[@item].remove + page[@todo].remove page.show("p#{@original_item_project_id}empty-nd") if (@remaining_undone_in_project == 0) page.replace_html "badge_count", @remaining_undone_in_project - elsif @item.deferred? - page[@item].remove + elsif @todo.deferred? + page[@todo].remove page.show("p#{@original_item_project_id}empty-nd") if (@remaining_undone_in_project == 0) - page.insert_html :bottom, "tickler", :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } + page.insert_html :bottom, "tickler", :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } page['tickler-empty-nd'].hide page.replace_html "badge_count", @down_count - elsif @item_was_activated_from_deferred_state - page[@item].remove + elsif @todo_was_activated_from_deferred_state + page[@todo].remove page['tickler-empty-nd'].show if (@deferred_count == 0) - page.insert_html :bottom, "p#{@item.project_id}", :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } - page["p#{@item.project_id}empty-nd"].hide + page.insert_html :bottom, "p#{@todo.project_id}", :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } + page["p#{@todo.project_id}empty-nd"].hide page.replace_html "badge_count", @down_count else - page.replace dom_id(@item), :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } - page.visual_effect :highlight, dom_id(@item), :duration => 3 + page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } + page.visual_effect :highlight, dom_id(@todo), :duration => 3 end elsif source_view_is :deferred - if @item.deferred? - page.replace dom_id(@item), :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } - page.visual_effect :highlight, dom_id(@item), :duration => 3 + if @todo.deferred? + page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } + page.visual_effect :highlight, dom_id(@todo), :duration => 3 else - page[@item].remove + page[@todo].remove page.show(empty_container_msg_div_id) if (@down_count == 0) page.replace_html "badge_count", @down_count end diff --git a/tracks/test/functional/mobile_controller_test.rb b/tracks/test/functional/mobile_controller_test.rb index a49581f4..be2210c4 100644 --- a/tracks/test/functional/mobile_controller_test.rb +++ b/tracks/test/functional/mobile_controller_test.rb @@ -18,10 +18,10 @@ class MobileControllerTest < Test::Unit::TestCase assert_redirected_to :controller => 'login', :action => 'login' end - def test_create_item + def test_create_todo @count = Todo.find(:all) @request.session['user_id'] = users(:admin_user).id - xhr :post, :update, "item"=>{"context_id"=>"1", "project_id"=>"2", "notes"=>"", "description"=>"Invest in spam stock offer", "due"=>"01/01/2007", "show_from"=>"", "state"=>"0"} + xhr :post, :update, "todo"=>{"context_id"=>"1", "project_id"=>"2", "notes"=>"", "description"=>"Invest in spam stock offer", "due"=>"01/01/2007", "show_from"=>"", "state"=>"0"} @todos = Todo.find(:all) assert_equal @count.size+1, @todos.size t = Todo.find(:first, :conditions => ['description = ?', "Invest in spam stock offer"]) @@ -33,10 +33,10 @@ class MobileControllerTest < Test::Unit::TestCase assert_equal "active", t.state end - def test_update_item + def test_update_todo t = Todo.find(1) @request.session['user_id'] = users(:admin_user).id - xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"11/30/2006"} + xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"11/30/2006"} t = Todo.find(1) assert_equal "Call Warren Buffet to find out how much he makes per day", t.description assert_equal Date.parse("11/30/2006"), t.due @@ -44,10 +44,10 @@ class MobileControllerTest < Test::Unit::TestCase assert_equal "active", t.state end - def test_complete_item + def test_complete_todo t = Todo.find(1) @request.session['user_id'] = users(:admin_user).id - xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Bill Gates to find out how much he makes per day", "state"=>"1"} + xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Bill Gates to find out how much he makes per day", "state"=>"1"} t = Todo.find(1) assert_equal "completed", t.state end diff --git a/tracks/test/functional/todos_controller_test.rb b/tracks/test/functional/todos_controller_test.rb index c0de5c49..a1473ad6 100644 --- a/tracks/test/functional/todos_controller_test.rb +++ b/tracks/test/functional/todos_controller_test.rb @@ -57,34 +57,47 @@ class TodosControllerTest < Test::Unit::TestCase assert_equal 0, assigns['deferred_count'] end - def test_destroy_item + def test_destroy_todo @request.session['user_id'] = users(:admin_user).id xhr :post, :destroy, :id => 1, :_source_view => 'todo' assert_rjs :page, "todo_1", :remove #assert_rjs :replace_html, "badge-count", '9' end - def test_update_item_project + def test_create_todo + original_todo_count = Todo.count + @request.session['user_id'] = users(:admin_user).id + put :create, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" + assert_equal original_todo_count + 1, Todo.count + end + + def test_create_deferred_todo + original_todo_count = Todo.count + @request.session['user_id'] = users(:admin_user).id + put :create, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2026", 'show_from' => '30/10/2026'}, "tag_list"=>"foo bar" + assert_equal original_todo_count + 1, Todo.count + end + + def test_update_todo_project t = Todo.find(1) @request.session['user_id'] = users(:admin_user).id - xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "item"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" + xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" t = Todo.find(1) assert_equal 1, t.project_id end - def test_update_item_project_to_none + def test_update_todo_project_to_none t = Todo.find(1) @request.session['user_id'] = users(:admin_user).id - xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"None", "item"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" + xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"None", "todo"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" t = Todo.find(1) assert_nil t.project_id end - def test_update_item + def test_update_todo t = Todo.find(1) @request.session['user_id'] = users(:admin_user).id - xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" - #assert_rjs :page, "todo_1", :visual_effect, :highlight, :duration => '1' + xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" t = Todo.find(1) assert_equal "Call Warren Buffet to find out how much he makes per day", t.description expected = Date.new(2006,11,30).to_time.utc.to_date @@ -92,14 +105,14 @@ class TodosControllerTest < Test::Unit::TestCase assert_equal expected, actual, "Expected #{expected.to_s(:db)}, was #{actual.to_s(:db)}" end - def test_tag - @request.session['user_id'] = users(:admin_user).id - @user = User.find(@request.session['user_id']) - @tagged = Todo.find_tagged_with('foo', @user).size - get :tag, :id => 'foo' - assert_response :success - assert_equal 2, @tagged - end + # def test_tag + # @request.session['user_id'] = users(:admin_user).id + # @user = User.find(@request.session['user_id']) + # @tagged = Todo.find_tagged_with('foo', @user).size + # get :tag, :id => 'foo' + # assert_response :success + # assert_equal 2, @tagged + # end end diff --git a/tracks/test/selenium/project_detail/_add_deferred_todo.rsel b/tracks/test/selenium/project_detail/_add_deferred_todo.rsel index 0dd17775..29605239 100644 --- a/tracks/test/selenium/project_detail/_add_deferred_todo.rsel +++ b/tracks/test/selenium/project_detail/_add_deferred_todo.rsel @@ -2,3 +2,4 @@ type "todo_description", "choose era" type "todo_show_from", "1/1/2030" click "//input[@value='Add item']" 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/selenium/project_detail/create_deferred_todo.rsel b/tracks/test/selenium/project_detail/create_deferred_todo.rsel index 947c7177..8719ae65 100644 --- a/tracks/test/selenium/project_detail/create_deferred_todo.rsel +++ b/tracks/test/selenium/project_detail/create_deferred_todo.rsel @@ -1,5 +1,5 @@ setup :fixtures => :all include_partial 'login/login', :username => 'admin', :password => 'abracadabra' -open "/projects/Build_a_working_time_machine" +open "/projects/Make_more_money_than_Billy_Gates" include_partial 'project_detail/add_deferred_todo' assert_not_visible "tickler-empty-nd" \ No newline at end of file diff --git a/tracks/test/test_helper.rb b/tracks/test/test_helper.rb index 9d203af9..f3fd75fb 100644 --- a/tracks/test/test_helper.rb +++ b/tracks/test/test_helper.rb @@ -40,6 +40,10 @@ class Test::Unit::TestCase assert_select(*args) end + def next_week + 1.week.from_now.utc.to_date + end + end class ActionController::IntegrationTest diff --git a/tracks/test/unit/todo_test.rb b/tracks/test/unit/todo_test.rb index 27bbf13f..481e287a 100644 --- a/tracks/test/unit/todo_test.rb +++ b/tracks/test/unit/todo_test.rb @@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper' require 'date' class TodoTest < Test::Unit::TestCase - fixtures :todos + fixtures :todos, :users, :contexts def setup - @not_completed1 = Todo.find(1) - @not_completed2 = Todo.find(2) - @completed = Todo.find(8) + @not_completed1 = Todo.find(1).reload + @not_completed2 = Todo.find(2).reload + @completed = Todo.find(8).reload end # Test loading a todo item @@ -56,4 +56,22 @@ class TodoTest < Test::Unit::TestCase assert_equal 1, @not_completed2.errors.count assert_equal "is too long (maximum is 60000 characters)", @not_completed2.errors.on(:notes) end + + def test_defer_an_existing_todo + @not_completed2 + assert_equal :active, @not_completed2.current_state + @not_completed2.show_from = next_week + assert @not_completed2.save, "should have saved successfully" + @not_completed2.errors.to_xml + assert_equal :deferred, @not_completed2.current_state + end + + def test_create_a_new_deferred_todo + user = users(:other_user) + item = user.todos.build + item.show_from = next_week + item.context_id = 1 + item.description = 'foo' + assert item.save, "should have saved successfully" + item.errors.to_xml + assert_equal :deferred, item.current_state + end end