Merge pull request #202 from TracksApp/extract-extras-from-user

Extract time and date concerns from User
This commit is contained in:
Matt Rogers 2013-08-01 14:59:17 -07:00
commit 6681df9530
17 changed files with 71 additions and 41 deletions

View file

@ -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 UserTime.new(user).midnight(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

View file

@ -13,16 +13,17 @@ class PreferenceTest < ActiveSupport::TestCase
def test_time_zone
assert_equal 'London', @admin_user.preference.time_zone
end
def test_show_project_on_todo_done
assert @other_user.preference.show_project_on_todo_done
assert !@admin_user.preference.show_project_on_todo_done
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
assert_nil @admin_user.preference.parse_date('')
end

View file

@ -84,12 +84,12 @@ class ProjectTest < ActiveSupport::TestCase
def test_review_project
assert_nil @timemachine.last_reviewed
assert @timemachine.needs_review?(nil)
assert @timemachine.needs_review?(users(:admin_user))
end
def test_review_completedprojects
@timemachine.complete!
assert !@timemachine.needs_review?(nil)
assert !@timemachine.needs_review?(users(:admin_user))
end
def test_complete_project

View file

@ -3,11 +3,18 @@ require_relative '../../lib/staleness'
class StalenessTest < Test::Unit::TestCase
FakeUser = Struct.new(:time)
FakePrefs = Struct.new(:time_zone)
FakeUser = Struct.new(:time) do
def prefs
@prefs ||= FakePrefs.new("UTC")
end
end
FakeTask = Struct.new(:due, :completed, :created_at) do
def completed?
self.completed
end
end
def now
@ -28,6 +35,11 @@ class StalenessTest < Test::Unit::TestCase
def setup
@current_user = FakeUser.new(now)
Timecop.freeze(Time.local(2013,02,28))
end
def teardown
Timecop.return
end
def test_item_with_due_date_is_not_stale_ever

View file

@ -3,7 +3,7 @@ require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
# set config for tests. Overwrite those read from config/site.yml. Use inject to avoid warning about changing CONSTANT
{"salt" => "change-me", "authentication_schemes" => ["database"], "prefered_auth" => "database"}.inject( SITE_CONFIG ) { |h, elem| h[elem[0]] = elem[1]; h }
{ "salt" => "change-me", "authentication_schemes" => ["database"], "prefered_auth" => "database"}.inject( SITE_CONFIG ) { |h, elem| h[elem[0]] = elem[1]; h }
class ActiveSupport::TestCase
ActiveRecord::Migration.check_pending!