mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Remove User#at_midnight
Replace it with a class called DateUtils with a method called `#midnight_for` that takes a preference instance and date to convert to midnight.
This commit is contained in:
parent
e7c6142684
commit
a1aaa283f1
6 changed files with 12 additions and 8 deletions
|
|
@ -22,6 +22,6 @@ class Preference < ActiveRecord::Base
|
|||
raise ArgumentError.new("Bad argument type:#{s.class}")
|
||||
end
|
||||
|
||||
user.at_midnight(date)
|
||||
DateUtils::midnight_for(self, date)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ class Todo < ActiveRecord::Base
|
|||
activate
|
||||
else
|
||||
# parse Date objects into the proper timezone
|
||||
date = user.at_midnight(date) if (date.is_a? Date)
|
||||
date = DateUtils.midnight_for(user.prefs, date) if (date.is_a? Date)
|
||||
|
||||
# show_from needs to be set before state_change because of "bug" in aasm.
|
||||
# If show_from is not set, the todo will not validate and thus aasm will not save
|
||||
|
|
|
|||
|
|
@ -167,10 +167,6 @@ class User < ActiveRecord::Base
|
|||
time.midnight
|
||||
end
|
||||
|
||||
def at_midnight(date)
|
||||
return ActiveSupport::TimeZone[prefs.time_zone].local(date.year, date.month, date.day, 0, 0, 0)
|
||||
end
|
||||
|
||||
def generate_token
|
||||
self.token = Digest::SHA1.hexdigest "#{Time.now.to_i}#{rand}"
|
||||
end
|
||||
|
|
|
|||
5
lib/date_utils.rb
Normal file
5
lib/date_utils.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class DateUtils
|
||||
def self.midnight_for(prefs, date)
|
||||
ActiveSupport::TimeZone[prefs.time_zone].local(date.year, date.month, date.day, 0, 0, 0)
|
||||
end
|
||||
end
|
||||
|
|
@ -117,7 +117,9 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
new_todo = Todo.where(:recurring_todo_id => 5).first
|
||||
|
||||
# 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
|
||||
user = users(:admin_user)
|
||||
target_date = Date.new(target_date.year, target_date.month, target_date.day)
|
||||
assert_equal DateUtils.midnight_for(user.prefs, target_date), 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
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ class PreferenceTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_parse_date
|
||||
assert_equal @admin_user.at_midnight(Date.new(2007, 5, 20)).to_s, @admin_user.preference.parse_date('20/5/2007').to_s
|
||||
date = Time.new(2007, 05, 20).in_time_zone(@admin_user.preference.time_zone).at_midnight
|
||||
assert_equal date.to_s, @admin_user.preference.parse_date('20/5/2007').to_s
|
||||
end
|
||||
|
||||
def test_parse_date_returns_nil_if_string_is_empty
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue