mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-27 20:38:48 +01:00
fix clearing show_from fails
caused by slightly different (better) workings of aasm
This commit is contained in:
parent
883ea2b968
commit
f891ee86fe
8 changed files with 80 additions and 32 deletions
|
|
@ -4,12 +4,28 @@ module Todos
|
|||
attr_reader :new_project_created, :new_context_created
|
||||
|
||||
def initialize(params, user)
|
||||
@params = params['request'] || params
|
||||
@attributes = params['request'] && params['request']['todo'] || params['todo']
|
||||
@attributes = {} if @attributes.nil? # make sure there is at least an empty hash
|
||||
set_params(params)
|
||||
filter_attributes
|
||||
filter_tags
|
||||
filter_starred
|
||||
|
||||
@user = user
|
||||
@errors = []
|
||||
|
||||
@new_project_created = find_or_create_group(:project, user.projects, project_name)
|
||||
@new_context_created = find_or_create_group(:context, user.contexts, context_name)
|
||||
end
|
||||
|
||||
def set_params(params)
|
||||
@params = params['request'] || params
|
||||
end
|
||||
|
||||
def filter_attributes
|
||||
@attributes = @params['request'] && @params['request']['todo'] || @params['todo']
|
||||
@attributes = {} if @attributes.nil? # make sure there is at least an empty hash
|
||||
end
|
||||
|
||||
def filter_tags
|
||||
if @attributes[:tags]
|
||||
# for single tags, @attributed[:tags] returns a hash. For multiple tags,
|
||||
# it with return an array of hashes. Make sure it is always an array of hashes
|
||||
|
|
@ -18,11 +34,13 @@ module Todos
|
|||
@attributes[:add_tags] = @attributes[:tags]
|
||||
@attributes.delete :tags
|
||||
end
|
||||
end
|
||||
|
||||
@new_project_created = find_or_create_group(:project, user.projects, project_name)
|
||||
@new_context_created = find_or_create_group(:context, user.contexts, context_name)
|
||||
@attributes["starred"] = (params[:new_todo_starred]||"").include? "true" if params[:new_todo_starred]
|
||||
end
|
||||
def filter_starred
|
||||
if @params[:new_todo_starred]
|
||||
@attributes["starred"] = (@params[:new_todo_starred]||"").include? "true"
|
||||
end
|
||||
end
|
||||
|
||||
def attributes
|
||||
@attributes
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ class TodosController < ApplicationController
|
|||
@predecessor = todo
|
||||
end
|
||||
else
|
||||
@todos = @todos_init
|
||||
@todos = @build_todos
|
||||
@saved = false
|
||||
end
|
||||
|
||||
|
|
@ -194,6 +194,8 @@ class TodosController < ApplicationController
|
|||
determine_down_count if @saved
|
||||
@contexts = current_user.contexts if p.new_context_created
|
||||
@projects = current_user.projects if p.new_project_created
|
||||
@new_project_created = p.new_project_created
|
||||
@new_context_created = p.new_context_created
|
||||
@initial_context_name = params['default_context_name']
|
||||
@initial_project_name = params['default_project_name']
|
||||
@initial_tags = params['initial_tag_list']
|
||||
|
|
|
|||
|
|
@ -70,10 +70,10 @@ class Todo < ActiveRecord::Base
|
|||
|
||||
aasm :column => :state do
|
||||
|
||||
state :active
|
||||
state :active #, :enter => Proc.new{|t| puts "$$$ activating #{t.aasm_current_state} - #{t.show_from} "}
|
||||
state :project_hidden
|
||||
state :completed, :enter => Proc.new { |t| t.completed_at = Time.zone.now }, :exit => Proc.new { |t| t.completed_at = nil}
|
||||
state :deferred, :after_exit => Proc.new { |t| t[:show_from] = nil}
|
||||
state :completed, :before_enter => Proc.new { |t| t.completed_at = Time.zone.now }, :before_exit => Proc.new { |t| t.completed_at = nil}
|
||||
state :deferred, :after_exit => Proc.new { |t| t[:show_from] = nil }
|
||||
state :pending
|
||||
|
||||
event :defer do
|
||||
|
|
@ -253,16 +253,19 @@ class Todo < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def show_from=(date)
|
||||
# parse Date objects into the proper timezone
|
||||
date = user.at_midnight(date) if (date.is_a? Date)
|
||||
if deferred? && date.blank?
|
||||
activate
|
||||
else
|
||||
# parse Date objects into the proper timezone
|
||||
date = user.at_midnight(date) if (date.is_a? Date)
|
||||
|
||||
# show_from needs to be set before state_change because of "bug" in aasm.
|
||||
# If show_from is not set, the todo will not validate and thus aasm will not save
|
||||
# (see http://stackoverflow.com/questions/682920/persisting-the-state-column-on-transition-using-rubyist-aasm-acts-as-state-machi)
|
||||
self[:show_from] = date
|
||||
# show_from needs to be set before state_change because of "bug" in aasm.
|
||||
# If show_from is not set, the todo will not validate and thus aasm will not save
|
||||
# (see http://stackoverflow.com/questions/682920/persisting-the-state-column-on-transition-using-rubyist-aasm-acts-as-state-machi)
|
||||
self[:show_from] = date
|
||||
|
||||
activate! if deferred? && date.blank?
|
||||
defer! if active? && !date.blank? && date > user.date
|
||||
defer if active? && !date.blank? && date > user.date
|
||||
end
|
||||
end
|
||||
|
||||
def starred?
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@
|
|||
}
|
||||
|
||||
function html_for_new_context() {
|
||||
return "<%= @saved && @new_context_created ? escape_javascript(render(:partial => @todo.context, :locals => { :settings => {:collapsible => true} })) : "" %>";
|
||||
return "<%= @new_context_created ? escape_javascript(render(:partial => @todo.context, :locals => { :settings => {:collapsible => true} })) : "" %>";
|
||||
}
|
||||
|
||||
<% end -%>
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ Feature: Add new next action from every page
|
|||
| context |
|
||||
|
||||
|
||||
@javascript
|
||||
@javascript
|
||||
Scenario: I need to fill in at least one description and a context
|
||||
When I go to the home page
|
||||
And I follow "Add multiple next actions"
|
||||
|
|
|
|||
|
|
@ -71,19 +71,20 @@ module TracksStepHelper
|
|||
project = @current_user.projects.where(:name => project_name).first
|
||||
project.should_not be_nil
|
||||
return project
|
||||
end
|
||||
end
|
||||
|
||||
def container_list_find_index(container, object)
|
||||
div_id = "#{container}_#{object.id}"
|
||||
containers = page.all("div.#{container}").map { |x| x[:id] }
|
||||
return containers.find_index(div_id)
|
||||
end
|
||||
|
||||
def context_list_find_index(context_name)
|
||||
div_id = "context_#{find_context(context_name).id}"
|
||||
contexts = page.all("div.context").map { |x| x[:id] }
|
||||
return contexts.find_index(div_id)
|
||||
return container_list_find_index(:context, find_context(context_name))
|
||||
end
|
||||
|
||||
def project_list_find_index(project_name)
|
||||
# TODO: refactor with context_list_find_index
|
||||
div_id = "project_#{find_project(project_name).id}"
|
||||
project = page.all("div.project").map { |x| x[:id] }
|
||||
return project.find_index(div_id)
|
||||
return container_list_find_index(:project, find_project(project_name))
|
||||
end
|
||||
|
||||
def format_date(date)
|
||||
|
|
@ -100,7 +101,8 @@ module TracksStepHelper
|
|||
submenu_arrow = "div#line_todo_#{todo.id} img.todo-submenu"
|
||||
page.should have_css(submenu_arrow, :visible=>true)
|
||||
page.find(submenu_arrow, :match => :first).click
|
||||
|
||||
sleep 0.1
|
||||
|
||||
submenu_css = "div#line_todo_#{todo.id} ul#ultodo_#{todo.id}"
|
||||
submenu = page.find(submenu_css)
|
||||
wait_until { submenu.visible? }
|
||||
|
|
|
|||
|
|
@ -384,6 +384,28 @@ class TodosControllerTest < ActionController::TestCase
|
|||
assert_equal context.id, todo.reload.context.id, 'context of todo should be changed'
|
||||
end
|
||||
|
||||
def test_update_clearing_show_from_makes_todo_active
|
||||
t = Todo.find(1)
|
||||
t.show_from = "01/01/2030"
|
||||
assert t.deferred?
|
||||
login_as(:admin_user)
|
||||
xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"show_from"=>""}, "tag_list"=>""
|
||||
t = Todo.find(1)
|
||||
assert t.active?
|
||||
assert_nil t.show_from
|
||||
end
|
||||
|
||||
def test_update_setting_show_from_makes_todo_deferred
|
||||
t = Todo.find(1)
|
||||
assert t.active?
|
||||
login_as(:admin_user)
|
||||
xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"show_from"=>"01/01/2030"}, "tag_list"=>""
|
||||
t = Todo.find(1)
|
||||
assert t.deferred?
|
||||
assert_not_nil t.show_from
|
||||
end
|
||||
|
||||
|
||||
#######
|
||||
# feeds
|
||||
#######
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
|
||||
first_todo = @moremoney.todos[0]
|
||||
first_todo.show_from = Time.zone.now + 1.week
|
||||
first_todo.save!
|
||||
assert_equal :deferred, @moremoney.todos[0].aasm_current_state
|
||||
|
||||
assert_equal 1, @moremoney.todos.deferred.count
|
||||
|
|
@ -219,8 +220,8 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
|
||||
p.activate!
|
||||
p.todos.each{|t| t.complete!}
|
||||
assert p.todos.active.empty?, "project should not have active todos"
|
||||
assert p.todos.deferred_or_blocked.empty?, "there should not be deferred or blocked todos"
|
||||
assert p.todos.reload.active.empty?, "project should not have active todos"
|
||||
assert p.todos.reload.deferred_or_blocked.empty?, "there should not be deferred or blocked todos"
|
||||
assert p.reload.stalled?, "project should be stalled"
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue