Skip to content

Commit

Permalink
make sure toggle_check and deleting of todos, recurring_todos and pro…
Browse files Browse the repository at this point in the history
…jects work in the new done views
  • Loading branch information
lrbalt committed Jul 9, 2011
1 parent 35f947e commit 6e97541
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 41 deletions.
5 changes: 2 additions & 3 deletions app/controllers/recurring_todos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RecurringTodosController < ApplicationController

def index
@page_title = t('todos.recurring_actions_title')

@source_view = params['_source_view'] || 'recurring_todo'
find_and_inactivate
@recurring_todos = current_user.recurring_todos.active
@completed_recurring_todos = current_user.recurring_todos.completed.find(:all, :limit => 10)
Expand All @@ -27,6 +27,7 @@ def show

def done
@page_title = t('todos.completed_recurring_actions_title')
@source_view = params['_source_view'] || 'recurring_todo'
items_per_page = 20
page = params[:page] || 1
@completed_recurring_todos = current_user.recurring_todos.completed.paginate :page => params[:page], :per_page => items_per_page
Expand Down Expand Up @@ -141,7 +142,6 @@ def create
end

def destroy

# remove all references to this recurring todo
@todos = @recurring_todo.todos
@number_of_todos = @todos.size
Expand Down Expand Up @@ -186,7 +186,6 @@ def toggle_check
@completed_remaining = current_user.recurring_todos.completed.count

# from completed back to active -> check if there is an active todo
# current_user.todos.count(:all, {:conditions => ["state = ? AND recurring_todo_id = ?", 'active',params[:id]]})
@active_todos = @recurring_todo.todos.active.count
# create todo if there is no active todo belonging to the activated
# recurring_todo
Expand Down
22 changes: 7 additions & 15 deletions app/controllers/todos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,11 @@ def toggle_check
# check if this todo has a related recurring_todo. If so, create next todo
@new_recurring_todo = check_for_next_todo(@todo) if @saved

if @todo.completed?
@pending_to_activate = @todo.pending_to_activate
@pending_to_activate.each do |t|
t.activate!
end
else
@active_to_block = @todo.active_to_block
@active_to_block.each do |t|
t.block!
if @saved
if @todo.completed?
@pending_to_activate = @todo.activate_pending_todos
else
@active_to_block = @todo.block_successors
end
end

Expand Down Expand Up @@ -1214,17 +1210,13 @@ def update_due_and_show_from_dates
def update_completed_state
if params['done'] == '1' && !@todo.completed?
@todo.complete!
@todo.pending_to_activate.each do |t|
t.activate!
end
@todo.activate_pending_todos
end
# strange. if checkbox is not checked, there is no 'done' in params.
# Therefore I've used the negation
if !(params['done'] == '1') && @todo.completed?
@todo.activate!
@todo.active_to_block.each do |t|
t.block!
end
@todo.block_successors
end
end

Expand Down
8 changes: 1 addition & 7 deletions app/models/recurring_todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,7 @@ def has_next_todo(previous)
end

def toggle_completion!
saved = false
if completed?
saved = activate!
else
saved = complete!
end
return saved
return completed? ? activate! : complete!
end

def toggle_star!
Expand Down
22 changes: 10 additions & 12 deletions app/models/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,7 @@ def update_state_from_project
end

def toggle_completion!
saved = false
if completed?
saved = activate!
else
saved = complete!
end
return saved
return completed? ? activate! : complete!
end

def show_from
Expand Down Expand Up @@ -287,14 +281,18 @@ def add_predecessor(t)
@predecessor_array << t
end

# Return todos that should be activated if the current todo is completed
def pending_to_activate
return successors.find_all {|t| t.uncompleted_predecessors.empty?}
# activate todos that should be activated if the current todo is completed
def activate_pending_todos
pending_todos = successors.find_all {|t| t.uncompleted_predecessors.empty?}
pending_todos.each {|t| t.activate! }
return pending_todos
end

# Return todos that should be blocked if the current todo is undone
def active_to_block
return successors.find_all {|t| t.active? or t.deferred?}
def block_successors
active_successors = successors.find_all {|t| t.active? or t.deferred?}
active_successors.each {|t| t.block!}
return active_successors
end

def raw_notes=(value)
Expand Down
2 changes: 1 addition & 1 deletion app/views/recurring_todos/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%- if @saved -%>
show_empty_messages();
TracksPages.page_notify('notice', '<%= escape_javascript(t('todos.recurring_deleted_success') + t(:todo_removed, :count => @number_of_todos)) %>', 5);
TracksPages.page_notify('notice', '<%= escape_javascript(t('todos.recurring_deleted_success') + t('todos.recurring_pattern_removed', :count => pluralize(@number_of_todos,t('common.todo')))) %>', 5);
remove_recurring_todo_from_page();
<%- else -%>
TracksPages.page_notify('error', '<%= t('todos.error_deleting_recurring', :description => @recurring_todo.description) %>', 8);
Expand Down
4 changes: 2 additions & 2 deletions app/views/todos/toggle_check.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
animation << "activate_pending_todos"
animation << "remove_source_container"
else
animation << "add_todo_to_context"
animation << "add_todo_to_context" unless source_view_is(:done)
animation << "block_predecessors"
end
animation << "update_empty_container" if source_view_is_one_of(:tag, :todo) -%>
Expand Down Expand Up @@ -161,7 +161,7 @@ function remove_source_container(next_steps) {
}

function html_for_todo() {
return "<%= @saved ? escape_javascript(render(:partial => @todo, :locals => {
return "<%= @saved && !source_view_is(:done) ? escape_javascript(render(:partial => @todo, :locals => {
:parent_container_type => parent_container_type,
:suppress_project => source_view_is(:project),
:suppress_context => source_view_is(:context)
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ en:
context: "Context"
action: "Action"
actions: "Actions"
todo: 'todo'
server_error: "An error occurred on the server."
contexts: "Contexts"
numbered_step: "Step %{number}"
Expand Down Expand Up @@ -485,6 +486,7 @@ en:
no_completed_recurring: "Currently there are no completed recurring todos"
add_new_recurring: "Add a new recurring action"
recurring_deleted_success: "The recurring action was deleted succesfully."
recurring_pattern_removed: "The recurrence pattern is removed from %{count}"
deleted_success: "The action was deleted succesfully."
error_deleting_recurring: "There was an error deleting the recurring todo \'%{description}\'"
error_saving_recurring: "There was an error saving the recurring todo \'%{description}\'"
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20110621082432_make_old_recurring_todos_validate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class MakeOldRecurringTodosValidate < ActiveRecord::Migration
def self.up
RecurringTodo.find(:all).each do |rt|
# show_always may not be nil
rt.show_always = false if rt.show_always.nil?
# start date should be filled
rt.start_from = rt.created_at if rt.start_from.nil? || rt.start_from.blank?
rt.save!
end
end

def self.down
# no down: leave them validatable
end
end
21 changes: 20 additions & 1 deletion features/step_definitions/container_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,23 @@

selenium.wait_for_element("xpath=#{xpath}", :timeout_in_seconds => 5)
selenium.is_visible(xpath).should be_true
end
end

Then /^I should see "([^"]*)" in the active recurring todos container$/ do |repeat_pattern|
repeat = @current_user.recurring_todos.find_by_description(repeat_pattern)
repeat.should_not be_nil

xpath = "//div[@id='active_recurring_todos_container']//div[@id='recurring_todo_#{repeat.id}']"
selenium.wait_for_element("xpath=#{xpath}", :timeout_in_seconds => 5)
selenium.is_visible(xpath).should be_true
end

Then /^I should not see "([^"]*)" in the completed recurring todos container$/ do |repeat_pattern|
repeat = @current_user.recurring_todos.find_by_description(repeat_pattern)
repeat.should_not be_nil

xpath = "//div[@id='completed_recurring_todos_container']//div[@id='recurring_todo_#{repeat.id}']"
selenium.wait_for_element("xpath=#{xpath}", :timeout_in_seconds => 5)
selenium.is_visible(xpath).should be_true
end

28 changes: 28 additions & 0 deletions features/view_done.feature
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,31 @@ Feature: Show done
When I follow "2"
Then I should be on the done recurring todos page
And the page should be "2"

@selenium
Scenario: I can toggle a done recurring todo active from done page
Given I have a completed repeat pattern "test"
When I go to the done recurring todos page
Then I should see "test"
When I mark the pattern "test" as active
Then I should not see "test" in the completed recurring todos container
When I go to the recurring todos page
Then I should see "test" in the active recurring todos container

Scenario: I can delete a recurring todo from the done page
Given this scenario is pending

Scenario: I can toggle a todo active from the done page
Given this scenario is pending

Scenario: I can toggle a todo active from the all done page
Given this scenario is pending

Scenario: I can toggle a todo active from the project done page
Given this scenario is pending

Scenario: I can toggle a todo active from the context done page
Given this scenario is pending

Scenario: I can edit a project to active from the project done page
Given this scenario is pending

0 comments on commit 6e97541

Please sign in to comment.