mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-10 01:24:19 +01:00
Changed all Date objects to Datetimes and migrated everything appropriately. Tests & specs pass, but this still needs a thorough review.
This commit is contained in:
parent
c85c5fd957
commit
778427405a
11 changed files with 49 additions and 16 deletions
|
|
@ -68,6 +68,8 @@ 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)
|
||||
activate! if deferred? && date.blank?
|
||||
defer! if active? && !date.blank? && date > user.date
|
||||
self[:show_from] = date
|
||||
|
|
|
|||
|
|
@ -169,7 +169,11 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def date
|
||||
time.to_date
|
||||
time.midnight
|
||||
end
|
||||
|
||||
def at_midnight(date)
|
||||
return TimeZone[prefs.time_zone].local(date.year, date.month, date.day, 0, 0, 0)
|
||||
end
|
||||
|
||||
def generate_token
|
||||
|
|
|
|||
28
db/migrate/041_change_dates_to_datetimes.rb
Normal file
28
db/migrate/041_change_dates_to_datetimes.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
class ChangeDatesToDatetimes < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_column :todos, :show_from, :datetime
|
||||
change_column :todos, :due, :datetime
|
||||
change_column :recurring_todos, :start_from, :datetime
|
||||
change_column :recurring_todos, :end_date, :datetime
|
||||
|
||||
User.all(:include => [:todos, :recurring_todos]).each do |user|
|
||||
zone = TimeZone[user.prefs.time_zone]
|
||||
user.todos.each do |todo|
|
||||
todo.update_attribute(:show_from, user.at_midnight(todo.show_from)) unless d.nil?
|
||||
todo.update_attribute(:due, user.at_midnight(todo.due)) unless d.nil?
|
||||
end
|
||||
|
||||
user.recurring_todos.each do |todo|
|
||||
todo.update_attribute(:start_from, user.at_midnight(todo.start_from)) unless d.nil?
|
||||
todo.update_attribute(:end_date, user.at_midnight(todo.end_date)) unless d.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
change_column :todos, :show_from, :date
|
||||
change_column :todos, :due, :date
|
||||
change_column :recurring_todos, :start_from, :date
|
||||
change_column :recurring_todos, :end_date, :date
|
||||
end
|
||||
end
|
||||
|
|
@ -25,7 +25,7 @@ class ProjectsControllerTest < TodoContainerControllerTestBase
|
|||
assert_equal 1, assigns['deferred'].size
|
||||
|
||||
t = p.not_done_todos[0]
|
||||
t.show_from = 1.days.from_now.utc.to_date
|
||||
t.show_from = 1.days.from_now.utc
|
||||
t.save!
|
||||
|
||||
get :show, :id => p.to_param
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class TodosControllerTest < Test::Rails::TestCase
|
|||
assert_equal "Call Warren Buffet to find out how much he makes per day", t.description
|
||||
assert_equal "foo, bar", t.tag_list
|
||||
expected = Date.new(2006,11,30)
|
||||
actual = t.due
|
||||
actual = t.due.to_date
|
||||
assert_equal expected, actual, "Expected #{expected.to_s(:db)}, was #{actual.to_s(:db)}"
|
||||
end
|
||||
|
||||
|
|
@ -328,7 +328,7 @@ class TodosControllerTest < Test::Rails::TestCase
|
|||
assert t.active?
|
||||
assert_equal 'test notes', t.notes
|
||||
assert_nil t.show_from
|
||||
assert_equal Date.new(2007,1,2).to_s, t.due.to_s
|
||||
assert_equal Date.new(2007,1,2), t.due.to_date
|
||||
end
|
||||
|
||||
def test_mobile_create_action_redirects_to_mobile_home_page_when_successful
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class Test::Rails::TestCase < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def next_week
|
||||
1.week.from_now.utc.to_date
|
||||
1.week.from_now.utc
|
||||
end
|
||||
|
||||
# Courtesy of http://habtm.com/articles/2006/02/20/assert-yourself-man-redirecting-with-rjs
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ class ProjectTest < Test::Rails::TestCase
|
|||
def test_deferred_todos
|
||||
assert_equal 1, @timemachine.deferred_todos.size
|
||||
t = @timemachine.not_done_todos[0]
|
||||
t.show_from = 1.days.from_now.utc.to_date
|
||||
t.show_from = 1.days.from_now.utc
|
||||
t.save!
|
||||
assert_equal 2, Project.find(@timemachine.id).deferred_todos.size
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class TodoCreateParamsHelperTest < Test::Rails::TestCase
|
|||
end
|
||||
|
||||
def test_show_from_accessor
|
||||
expected_date = Time.now.to_date
|
||||
expected_date = Time.now
|
||||
params = { 'todo' => { 'show_from' => expected_date}}
|
||||
prefs = flexmock()
|
||||
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
|
||||
|
|
@ -26,7 +26,7 @@ class TodoCreateParamsHelperTest < Test::Rails::TestCase
|
|||
end
|
||||
|
||||
def test_due_accessor
|
||||
expected_date = Time.now.to_date
|
||||
expected_date = Time.now
|
||||
params = { 'todo' => { 'due' => expected_date}}
|
||||
prefs = flexmock()
|
||||
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
|
||||
|
|
|
|||
|
|
@ -68,9 +68,8 @@ class TodoTest < Test::Rails::TestCase
|
|||
|
||||
def test_validate_show_from_must_be_a_date_in_the_future
|
||||
t = @not_completed2
|
||||
t[:show_from] = 1.week.ago.to_date # we have to set this via the indexer because show_from=() updates the state
|
||||
t[:show_from] = 1.week.ago # we have to set this via the indexer because show_from=() updates the state
|
||||
# and actual show_from value appropriately based on the date
|
||||
assert_equal 1.week.ago.to_date, t.show_from
|
||||
assert !t.save
|
||||
assert_equal 1, t.errors.count
|
||||
assert_equal "must be a date in the future", t.errors.on(:show_from)
|
||||
|
|
@ -118,7 +117,7 @@ class TodoTest < Test::Rails::TestCase
|
|||
|
||||
def test_activate_also_saves
|
||||
t = @not_completed1
|
||||
t.show_from = 1.week.from_now.to_date
|
||||
t.show_from = 1.week.from_now
|
||||
t.save!
|
||||
assert t.deferred?
|
||||
t.reload
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ class UserTest < Test::Rails::TestCase
|
|||
|
||||
def test_find_and_activate_deferred_todos_that_are_ready
|
||||
assert_equal 1, @admin_user.deferred_todos.count
|
||||
@admin_user.deferred_todos[0].show_from = @admin_user.time.to_date
|
||||
@admin_user.deferred_todos[0].show_from = @admin_user.date
|
||||
@admin_user.deferred_todos[0].save
|
||||
@admin_user.deferred_todos.reload
|
||||
@admin_user.deferred_todos.find_and_activate_ready
|
||||
|
|
|
|||
|
|
@ -20,28 +20,28 @@ class TodosHelperTest < Test::Rails::HelperTestCase
|
|||
end
|
||||
|
||||
def test_show_date_in_past
|
||||
date = 3.days.ago.to_date
|
||||
date = 3.days.ago
|
||||
html = show_date(date)
|
||||
formatted_date = format_date(date)
|
||||
assert_equal %Q{<a title="#{formatted_date}"><span class="red">Scheduled to show 3 days ago</span></a> }, html
|
||||
end
|
||||
|
||||
def test_show_date_today
|
||||
date = Time.zone.now.to_date
|
||||
date = Time.zone.now
|
||||
html = show_date(date)
|
||||
formatted_date = format_date(date)
|
||||
assert_equal %Q{<a title="#{formatted_date}"><span class="amber">Show Today</span></a> }, html
|
||||
end
|
||||
|
||||
def test_show_date_tomorrow
|
||||
date = 1.day.from_now.to_date
|
||||
date = 1.day.from_now
|
||||
html = show_date(date)
|
||||
formatted_date = format_date(date)
|
||||
assert_equal %Q{<a title="#{formatted_date}"><span class="amber">Show Tomorrow</span></a> }, html
|
||||
end
|
||||
|
||||
def test_show_date_future
|
||||
date = 10.days.from_now.to_date
|
||||
date = 10.days.from_now
|
||||
html = show_date(date)
|
||||
formatted_date = format_date(date)
|
||||
assert_equal %Q{<a title="#{formatted_date}"><span class="green">Show in 10 days</span></a> }, html
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue