Skip to content

Commit

Permalink
fix corner case that were failing the cucumber tests. On the calendar…
Browse files Browse the repository at this point in the history
… page at the end of the month, a todo may occur twice on the page. This was not taken into account for update an destroy
  • Loading branch information
lrbalt committed Apr 30, 2011
1 parent 0ccf42d commit 7f27a6e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.tmproj
.dotest
/.emacs-project
/.redcar
config/database.yml
config/site.yml
config/deploy.rb
Expand Down
14 changes: 12 additions & 2 deletions app/controllers/todos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def calendar
due_this_week_date = Time.zone.now.end_of_week
due_next_week_date = due_this_week_date + 7.days
due_this_month_date = Time.zone.now.end_of_month

@due_today = current_user.todos.not_completed.find(:all,
:include => [:taggings, :tags],
:conditions => ['todos.due <= ?', due_today_date],
Expand All @@ -646,7 +646,7 @@ def calendar
:include => [:taggings, :tags],
:conditions => ['todos.due > ?', due_this_month_date],
:order => "due")

@count = current_user.todos.not_completed.are_due.count

respond_to do |format|
Expand Down Expand Up @@ -1278,6 +1278,16 @@ def context_specified_by_name(context_name)
return false if context_name.blank?
true
end

def determine_non_uniq_todo
# for calendar view. TODO: unused
all_list_uniq_ids = (@due_today.map(&:id) + @due_this_week.map(&:id) +
@due_next_week.map(&:id) + @due_this_month.map(&:id) + @due_after_this_month.map(&:id)).uniq
all_list_count = @due_today.count + @due_this_week.count +
@due_next_week.count + @due_this_month.count + @due_after_this_month.count

return !( all_list_uniq_ids.length == all_list_count )
end

class FindConditionBuilder

Expand Down
25 changes: 15 additions & 10 deletions app/views/todos/destroy.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ function show_empty_messages() {

function remove_todo_from_page() {
<% if (@remaining_in_context == 0) && update_needs_to_hide_context
# remove context with deleted todo
# remove context with deleted todo
-%>
$('#c<%[email protected]_id%>').fadeOut(400, function() {
$('#<%=dom_id(@todo)%>').remove();
});
<%= show_empty_message_in_source_container -%>
$('#c<%[email protected]_id%>').fadeOut(400, function() {
$('#<%=dom_id(@todo)%>').remove();
});
<%= show_empty_message_in_source_container -%>
<% else
# remove only the todo
# remove only the todo
-%>
<%= show_empty_message_in_source_container %>
$('#<%=dom_id(@todo)%>').slideUp(400, function() {
$('#<%=dom_id(@todo)%>').remove();
});
<%= show_empty_message_in_source_container %>
$('#<%=dom_id(@todo)%>').slideUp(400, function() {
$('#<%=dom_id(@todo)%>').remove();
<% if source_view_is :calendar
# in calendar view it is possible to have a todo twice on the page
-%>
$('#<%=dom_id(@todo)%>').remove();
<% end %>
});
<% end -%>
}

Expand Down
5 changes: 5 additions & 0 deletions app/views/todos/update.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
function remove_todo(next_steps) {
$('#<%= dom_id(@todo) %>').fadeOut(400, function() {
$('#<%= dom_id(@todo) %>').remove();
<% if source_view_is :calendar
# in calendar view it is possible to have a todo twice on the page
-%>
$('#<%= dom_id(@todo) %>').remove();
<% end %>
<%= show_empty_message_in_source_container -%>
next_steps.go();
});
Expand Down
2 changes: 1 addition & 1 deletion config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ nl:
show_tomorrow: Toon morgen
calendar:
get_in_ical_format: Ontvang deze agenda in iCal-formaat
due_next_week: Deadline deze week
due_next_week: Deadline volgende week
due_this_week: Deadline in rest van deze week
no_actions_due_next_week: Geen acties met deadline in volgende week
due_today: Deadline vandaag
Expand Down
4 changes: 2 additions & 2 deletions features/calendar.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Feature: Show all due actions in a calendar view
Then the badge should show 1
And I should see "a new next action"

@selenium
@selenium
Scenario: Clearing the due date of a todo will remove it from the calendar
When I go to the home page
And I submit a new action with description "a new next action" in the context "@calendar"
Expand All @@ -32,7 +32,7 @@ Feature: Show all due actions in a calendar view
When I clear the due date of "a new next action"
Then I should not see "a new next action"

@selenium
@selenium
Scenario: Marking a todo complete will remove it from the calendar
Given I have a todo "a new next action" in the context "@calendar" which is due tomorrow
When I go to the calendar page
Expand Down

0 comments on commit 7f27a6e

Please sign in to comment.