From 24c2b57b4af66176b218f24394421cf4bf8b73f7 Mon Sep 17 00:00:00 2001 From: Eric Allen Date: Sat, 4 Oct 2008 13:41:37 -0400 Subject: [PATCH 1/4] Make migration 42 more resilient: don't freak out when user has no prefs object --- db/migrate/042_change_dates_to_datetimes.rb | 31 +++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/db/migrate/042_change_dates_to_datetimes.rb b/db/migrate/042_change_dates_to_datetimes.rb index 99e75179..57b62ed5 100644 --- a/db/migrate/042_change_dates_to_datetimes.rb +++ b/db/migrate/042_change_dates_to_datetimes.rb @@ -6,18 +6,33 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration change_column :recurring_todos, :end_date, :datetime User.all(:include => [:todos, :recurring_todos]).each do |user| - user.todos.each do |todo| - todo.update_attribute(:show_from, user.at_midnight(todo.show_from)) unless todo.show_from.nil? - todo.update_attribute(:due, user.at_midnight(todo.due)) unless todo.due.nil? - end + if user.prefs + user.todos.each do |todo| + todo.update_attribute(:show_from, user.at_midnight(todo.show_from)) unless todo.show_from.nil? + todo.update_attribute(:due, user.at_midnight(todo.due)) unless todo.due.nil? + end - user.recurring_todos.each do |todo| - todo.update_attribute(:start_from, user.at_midnight(todo.start_from)) unless todo.start_from.nil? - todo.update_attribute(:end_date, user.at_midnight(todo.end_date)) unless todo.end_date.nil? - end + user.recurring_todos.each do |todo| + todo.update_attribute(:start_from, user.at_midnight(todo.start_from)) unless todo.start_from.nil? + todo.update_attribute(:end_date, user.at_midnight(todo.end_date)) unless todo.end_date.nil? + end + else # weird...no preferences for this user + user.todos.each do |todo| + todo.update_attribute(:show_from, at_midnight(todo.show_from)) unless todo.show_from.nil? + todo.update_attribute(:due, at_midnight(todo.due)) unless todo.due.nil? + end + + user.recurring_todos.each do |todo| + todo.update_attribute(:start_from, at_midnight(todo.start_from)) unless todo.start_from.nil? + todo.update_attribute(:end_date, at_midnight(todo.end_date)) unless todo.end_date.nil? + end end end + def at_midnight(date) + return Time.zone.local(date.year, date.month, date.day, 0, 0, 0) + end + def self.down change_column :todos, :show_from, :date change_column :todos, :due, :date From 51b0a2bd9bc3dd310e39ea3e7265850dc83b9570 Mon Sep 17 00:00:00 2001 From: Eric Allen Date: Sat, 4 Oct 2008 13:44:38 -0400 Subject: [PATCH 2/4] Informative alt text for defer buttons --- app/helpers/todos_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index b989b432..aee59c90 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -281,7 +281,7 @@ module TodosHelper end def defer_link(days) - link_to_remote image_tag("defer_#{days}.png"), :url => {:controller => 'todos', :action => 'defer', :id => @todo.id, :days => days, :_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")} + link_to_remote image_tag("defer_#{days}.png", :alt => "Defer #{pluralize(days, 'day')}"), :url => {:controller => 'todos', :action => 'defer', :id => @todo.id, :days => days, :_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")} end end From b36ed968137183bb24b62c23236be9119da17547 Mon Sep 17 00:00:00 2001 From: Eric Allen Date: Wed, 8 Oct 2008 23:47:59 -0400 Subject: [PATCH 3/4] Wow I broke the migration. Oops. --- db/migrate/042_change_dates_to_datetimes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/db/migrate/042_change_dates_to_datetimes.rb b/db/migrate/042_change_dates_to_datetimes.rb index 57b62ed5..1ea940b0 100644 --- a/db/migrate/042_change_dates_to_datetimes.rb +++ b/db/migrate/042_change_dates_to_datetimes.rb @@ -26,6 +26,7 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration todo.update_attribute(:start_from, at_midnight(todo.start_from)) unless todo.start_from.nil? todo.update_attribute(:end_date, at_midnight(todo.end_date)) unless todo.end_date.nil? end + end end end From a9a02896a021b652904990db3a60156193031e64 Mon Sep 17 00:00:00 2001 From: Eric Allen Date: Thu, 9 Oct 2008 10:14:26 -0400 Subject: [PATCH 4/4] Another shot at fixing migration 42. Actually tested to work. --- db/migrate/042_change_dates_to_datetimes.rb | 42 ++++++++++----------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/db/migrate/042_change_dates_to_datetimes.rb b/db/migrate/042_change_dates_to_datetimes.rb index 1ea940b0..d534c642 100644 --- a/db/migrate/042_change_dates_to_datetimes.rb +++ b/db/migrate/042_change_dates_to_datetimes.rb @@ -6,32 +6,28 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration change_column :recurring_todos, :end_date, :datetime User.all(:include => [:todos, :recurring_todos]).each do |user| - if user.prefs - user.todos.each do |todo| - todo.update_attribute(:show_from, user.at_midnight(todo.show_from)) unless todo.show_from.nil? - todo.update_attribute(:due, user.at_midnight(todo.due)) unless todo.due.nil? - end - - user.recurring_todos.each do |todo| - todo.update_attribute(:start_from, user.at_midnight(todo.start_from)) unless todo.start_from.nil? - todo.update_attribute(:end_date, user.at_midnight(todo.end_date)) unless todo.end_date.nil? - end - else # weird...no preferences for this user - user.todos.each do |todo| - todo.update_attribute(:show_from, at_midnight(todo.show_from)) unless todo.show_from.nil? - todo.update_attribute(:due, at_midnight(todo.due)) unless todo.due.nil? - end - - user.recurring_todos.each do |todo| - todo.update_attribute(:start_from, at_midnight(todo.start_from)) unless todo.start_from.nil? - todo.update_attribute(:end_date, at_midnight(todo.end_date)) unless todo.end_date.nil? + if !user.prefs ## ugly hack for strange edge-case of not having preferences object + user.instance_eval do + def at_midnight(date) + return Time.zone.local(date.year, date.month, date.day, 0, 0, 0) + end + def time + Time.zone.now + end end end - end - end + user.todos.each do |todo| + todo[:show_from] = user.at_midnight(todo.show_from) unless todo.show_from.nil? + todo[:due] = user.at_midnight(todo.due) unless todo.due.nil? + todo.save_with_validation(false) + end - def at_midnight(date) - return Time.zone.local(date.year, date.month, date.day, 0, 0, 0) + user.recurring_todos.each do |todo| + todo[:start_from] = user.at_midnight(todo.start_from) unless todo.start_from.nil? + todo[:end_date] = user.at_midnight(todo.end_date) unless todo.end_date.nil? + todo.save_with_validation(false) + end + end end def self.down