Working with acts_as_state_machine, it's tricky to create an object with a state other than the one you've defined as the initial state. This caused a bug where deferred actions were not being created with a :deferred state. Fixed this. Fixes #400.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@349 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2006-11-18 05:01:23 +00:00
parent b9b4330b8d
commit 807cb1e759
3 changed files with 31 additions and 2 deletions

View file

@ -20,8 +20,7 @@ class DeferredController < ApplicationController
def create
@source_view = 'deferred'
@item = Todo.new
@item.defer!
@item = Todo.new_deferred
@item.attributes = params["todo"]
if params["todo"]["show_from"]
@item.show_from = parse_date_per_user_prefs(params["todo"]["show_from"])

View file

@ -63,6 +63,14 @@ class Todo < ActiveRecord::Base
original_project.nil? ? Project.null_object : original_project
end
def self.new_deferred
todo = self.new
def todo.set_initial_state
self.state = 'deferred'
end
todo
end
def self.not_done( id=id )
self.find(:all, :conditions =>[ "done = ? AND context_id = ?", false, id], :order =>"due IS NULL, due ASC, created_at ASC")
end

View file

@ -0,0 +1,22 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'deferred_controller'
# Re-raise errors caught by the controller.
class DeferredController; def rescue_action(e) raise e end; end
class DeferredControllerTest < Test::Unit::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos
def setup
@controller = DeferredController.new
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
end
def test_create
@request.session['user_id'] = users(:admin_user).id
xhr :post, :create, :todo => {:description => 'deferred controller test create', :notes => 'notes', :context_id => 1, :project_id => 1, :due => '', :show_from => '11/30/2030'}
t = Todo.find_by_description('deferred controller test create')
assert_equal :deferred, t.current_state.to_sym
end
end