mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-29 04:06:11 +01:00
replace new repeating todo form with jquery dialog. And some refactoring
This commit is contained in:
parent
4b6aff5502
commit
6aa8b8d2f9
9 changed files with 228 additions and 195 deletions
|
|
@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
|||
|
||||
class RecurringTodosControllerTest < ActionController::TestCase
|
||||
fixtures :users, :preferences, :projects, :contexts, :todos, :tags, :taggings, :recurring_todos
|
||||
|
||||
|
||||
def setup
|
||||
@controller = RecurringTodosController.new
|
||||
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
||||
|
|
@ -12,30 +12,30 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
get :index
|
||||
assert_redirected_to :controller => 'login', :action => 'login'
|
||||
end
|
||||
|
||||
|
||||
def test_destroy_recurring_todo
|
||||
login_as(:admin_user)
|
||||
xhr :post, :destroy, :id => 1, :_source_view => 'todo'
|
||||
begin
|
||||
begin
|
||||
rc = RecurringTodo.find(1)
|
||||
rescue
|
||||
rc = nil
|
||||
rc = nil
|
||||
end
|
||||
assert_nil rc
|
||||
end
|
||||
|
||||
|
||||
def test_new_recurring_todo
|
||||
login_as(:admin_user)
|
||||
orig_rt_count = RecurringTodo.count
|
||||
orig_todo_count = Todo.count
|
||||
put :create,
|
||||
"context_name"=>"library",
|
||||
"project_name"=>"Build a working time machine",
|
||||
"recurring_todo" =>
|
||||
put :create,
|
||||
"context_name"=>"library",
|
||||
"project_name"=>"Build a working time machine",
|
||||
"recurring_todo" =>
|
||||
{
|
||||
"daily_every_x_days"=>"1",
|
||||
"daily_selector"=>"daily_every_x_day",
|
||||
"description"=>"new recurring pattern",
|
||||
"daily_every_x_days"=>"1",
|
||||
"daily_selector"=>"daily_every_x_day",
|
||||
"description"=>"new recurring pattern",
|
||||
"end_date" => "31/08/2010",
|
||||
"ends_on" => "ends_on_end_date",
|
||||
"monthly_day_of_week" => "1",
|
||||
|
|
@ -59,15 +59,15 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
"yearly_month_of_year2"=>"8",
|
||||
"yearly_month_of_year"=>"6",
|
||||
"yearly_selector"=>"yearly_every_x_day"
|
||||
},
|
||||
},
|
||||
"tag_list"=>"one, two, three, four"
|
||||
|
||||
|
||||
# check new recurring todo added
|
||||
assert_equal orig_rt_count+1, RecurringTodo.count
|
||||
assert_equal orig_rt_count+1, RecurringTodo.count
|
||||
# check new todo added
|
||||
assert_equal orig_todo_count+1, Todo.count
|
||||
end
|
||||
|
||||
|
||||
def test_recurring_todo_toggle_check
|
||||
# the test fixtures did add recurring_todos but not the corresponding todos,
|
||||
# so we check complete and uncheck to force creation of a todo from the
|
||||
|
|
@ -78,22 +78,22 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
xhr :post, :toggle_check, :id=>1, :_source_view=>""
|
||||
recurring_todo_1 = RecurringTodo.find(1)
|
||||
assert recurring_todo_1.completed?
|
||||
|
||||
|
||||
# remove remaining todo
|
||||
todo = Todo.find_by_recurring_todo_id(1)
|
||||
todo.recurring_todo_id = 2
|
||||
todo.save
|
||||
|
||||
|
||||
todo_count = Todo.count
|
||||
|
||||
|
||||
# mark as active
|
||||
xhr :post, :toggle_check, :id=>1, :_source_view=>""
|
||||
xhr :post, :toggle_check, :id=>1, :_source_view=>""
|
||||
recurring_todo_1.reload
|
||||
assert recurring_todo_1.active?
|
||||
|
||||
|
||||
# by making active, a new todo should be created from the pattern
|
||||
assert_equal todo_count+1, Todo.count
|
||||
|
||||
|
||||
# find the new todo and check its description
|
||||
new_todo = Todo.find_by_recurring_todo_id 1
|
||||
assert_equal "Call Bill Gates every day", new_todo.description
|
||||
|
|
@ -101,9 +101,9 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
|
||||
def test_creating_recurring_todo_with_show_from_in_past
|
||||
login_as(:admin_user)
|
||||
|
||||
|
||||
@yearly = RecurringTodo.find(5) # yearly on june 8th
|
||||
|
||||
|
||||
# change due date in four days from now and show from 10 days before, i.e. 6
|
||||
# days ago
|
||||
target_date = Time.now.utc + 4.days
|
||||
|
|
@ -114,37 +114,37 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
# @yearly.errors.each {|obj, error| puts error}
|
||||
# end
|
||||
assert @yearly.save
|
||||
|
||||
|
||||
# toggle twice to force generation of new todo
|
||||
xhr :post, :toggle_check, :id=>5, :_source_view=>""
|
||||
xhr :post, :toggle_check, :id=>5, :_source_view=>""
|
||||
|
||||
new_todo = Todo.find_by_recurring_todo_id 5
|
||||
|
||||
|
||||
# due date should be the target_date
|
||||
assert_equal users(:admin_user).at_midnight(Date.new(target_date.year, target_date.month, target_date.day)), new_todo.due
|
||||
|
||||
|
||||
# show_from should be nil since now+4.days-10.days is in the past
|
||||
assert_equal nil, new_todo.show_from
|
||||
end
|
||||
|
||||
|
||||
def test_last_sunday_of_march
|
||||
# this test is a duplicate of the unit test. Only this test covers the
|
||||
# codepath in the controllers
|
||||
|
||||
|
||||
login_as(:admin_user)
|
||||
|
||||
orig_rt_count = RecurringTodo.count
|
||||
orig_todo_count = Todo.count
|
||||
|
||||
put :create,
|
||||
"context_name"=>"library",
|
||||
"project_name"=>"Build a working time machine",
|
||||
"recurring_todo" =>
|
||||
put :create,
|
||||
"context_name"=>"library",
|
||||
"project_name"=>"Build a working time machine",
|
||||
"recurring_todo" =>
|
||||
{
|
||||
"daily_every_x_days"=>"1",
|
||||
"daily_selector"=>"daily_every_x_day",
|
||||
"description"=>"new recurring pattern",
|
||||
"daily_every_x_days"=>"1",
|
||||
"daily_selector"=>"daily_every_x_day",
|
||||
"description"=>"new recurring pattern",
|
||||
"end_date" => "",
|
||||
"ends_on" => "no_end_date",
|
||||
"monthly_day_of_week" => "1",
|
||||
|
|
@ -168,36 +168,36 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
"yearly_month_of_year2"=>"3",
|
||||
"yearly_month_of_year"=>"10",
|
||||
"yearly_selector"=>"yearly_every_xth_day"
|
||||
},
|
||||
},
|
||||
"tag_list"=>"one, two, three, four"
|
||||
|
||||
|
||||
# check new recurring todo added
|
||||
assert_equal orig_rt_count+1, RecurringTodo.count
|
||||
assert_equal orig_rt_count+1, RecurringTodo.count
|
||||
# check new todo added
|
||||
assert_equal orig_todo_count+1, Todo.count
|
||||
|
||||
# find the newly created todo
|
||||
new_todo = Todo.find_by_description("new recurring pattern")
|
||||
assert !new_todo.nil?
|
||||
|
||||
|
||||
# the date should be 31 march 2013
|
||||
assert_equal Time.zone.local(2013,3,31), new_todo.due
|
||||
end
|
||||
|
||||
|
||||
def test_recurring_todo_with_due_date_and_show_always
|
||||
login_as(:admin_user)
|
||||
|
||||
orig_rt_count = RecurringTodo.count
|
||||
orig_todo_count = Todo.count
|
||||
|
||||
put :create,
|
||||
"context_name"=>"library",
|
||||
"project_name"=>"Build a working time machine",
|
||||
"recurring_todo" =>
|
||||
put :create,
|
||||
"context_name"=>"library",
|
||||
"project_name"=>"Build a working time machine",
|
||||
"recurring_todo" =>
|
||||
{
|
||||
"daily_every_x_days"=>"1",
|
||||
"daily_selector"=>"daily_every_x_day",
|
||||
"description"=>"new recurring pattern",
|
||||
"daily_every_x_days"=>"1",
|
||||
"daily_selector"=>"daily_every_x_day",
|
||||
"description"=>"new recurring pattern",
|
||||
"end_date" => "",
|
||||
"ends_on" => "no_end_date",
|
||||
"monthly_day_of_week" => "1",
|
||||
|
|
@ -221,20 +221,50 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
"yearly_month_of_year2"=>"3",
|
||||
"yearly_month_of_year"=>"10",
|
||||
"yearly_selector"=>"yearly_every_xth_day"
|
||||
},
|
||||
},
|
||||
"tag_list"=>"one, two, three, four"
|
||||
|
||||
|
||||
# check new recurring todo added
|
||||
assert_equal orig_rt_count+1, RecurringTodo.count
|
||||
assert_equal orig_rt_count+1, RecurringTodo.count
|
||||
# check new todo added
|
||||
assert_equal orig_todo_count+1, Todo.count
|
||||
|
||||
# find the newly created recurring todo
|
||||
recurring_todo = RecurringTodo.find_by_description("new recurring pattern")
|
||||
assert !recurring_todo.nil?
|
||||
|
||||
|
||||
assert_equal "due_date", recurring_todo.target
|
||||
assert_equal true, recurring_todo.show_always?
|
||||
end
|
||||
|
||||
def test_find_and_inactivate
|
||||
login_as(:admin_user)
|
||||
|
||||
rt = RecurringTodo.find(recurring_todos(:call_bill_gates_every_day).id)
|
||||
todo = Todo.find_by_recurring_todo_id(rt.id)
|
||||
|
||||
assert_not_nil todo
|
||||
assert_equal "active", todo.state, "todo should be active"
|
||||
assert_equal "active", rt.state, "repeat pattern should be active"
|
||||
|
||||
get :index # will call find_and_inactivate
|
||||
|
||||
rt.reload
|
||||
assert_equal "active", rt.state, "repeat pattern should still be active"
|
||||
|
||||
# disconnect todo from pattern thus leaving the pattern without
|
||||
# any active todos, but in active state
|
||||
todo.reload
|
||||
todo.recurring_todo_id=nil
|
||||
todo.save!
|
||||
|
||||
todo.reload
|
||||
rt.reload
|
||||
assert_equal "active", rt.state, "repeat pattern should still be active and not changed"
|
||||
|
||||
get :index
|
||||
rt.reload
|
||||
assert_equal "completed", rt.state, "repeat pattern should be completed"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue