mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 07:10:12 +01:00
Replace User#time with UserTime#time
This commit is contained in:
parent
8512e8db3b
commit
96777c2e3a
13 changed files with 44 additions and 27 deletions
|
|
@ -29,7 +29,7 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def days_from_today(date)
|
||||
(date.in_time_zone.to_date - current_user.time.to_date).to_i
|
||||
(date.in_time_zone.to_date - UserTime.new(current_user).date).to_i
|
||||
end
|
||||
|
||||
# Check due date in comparison to today's date Flag up date appropriately with
|
||||
|
|
|
|||
|
|
@ -99,9 +99,10 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def needs_review?(current_user)
|
||||
def needs_review?(user)
|
||||
current_time = UserTime.new(user).time
|
||||
return active? && ( last_reviewed.nil? ||
|
||||
(last_reviewed < current_user.time - current_user.prefs.review_period.days))
|
||||
(last_reviewed < current_time - user.prefs.review_period.days))
|
||||
end
|
||||
|
||||
def blocked?
|
||||
|
|
|
|||
|
|
@ -159,10 +159,6 @@ class User < ActiveRecord::Base
|
|||
save!
|
||||
end
|
||||
|
||||
def time
|
||||
Time.now.in_time_zone(prefs.time_zone)
|
||||
end
|
||||
|
||||
def date
|
||||
UserTime.new(self).midnight(Time.now)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
<div id="recurring_timespan">
|
||||
<br/>
|
||||
<label for="recurring_todo[start_from]"><%= t('todos.recurrence.starts_on') %>:</label><%=
|
||||
text_field(:recurring_todo, :start_from, "value" => format_date(current_user.time), "size" => 12, "class" => "Date", "autocomplete" => "off") %><br/>
|
||||
text_field(:recurring_todo, :start_from, "value" => format_date(UserTime.new(current_user).time), "size" => 12, "class" => "Date", "autocomplete" => "off") %><br/>
|
||||
<br/>
|
||||
<label for="recurring_todo[ends_on]"><%= t('todos.recurrence.ends_on') %>:</label><br/>
|
||||
<%= radio_button_tag('recurring_todo[ends_on]', 'no_end_date', true)%> <%= t('todos.recurrence.no_end_date') %><br/>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<span class="errors">
|
||||
<%= get_list_of_error_messages_for(@todo) if @todo %>
|
||||
</span>
|
||||
<% this_year = current_user.time.to_date.strftime("%Y").to_i -%>
|
||||
<% this_year = UserTime.new(current_user).date.strftime("%Y").to_i -%>
|
||||
<h2><label for="todo_description"><%= t('common.description') %></label></h2>
|
||||
<%= text_field( "todo", "description", "tabindex" => 1, "maxlength" => 100, "size" => 50) %>
|
||||
<h2><label for="tag_list"><%= t('todos.tags') %></label></h2>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ end
|
|||
Given /^I have an outdated project "([^"]*)" with (\d+) todos$/ do |project_name, num_todos|
|
||||
step "I have a project \"#{project_name}\" with #{num_todos} todos"
|
||||
@project = @current_user.projects.where(:name => project_name).first
|
||||
@project.last_reviewed = @current_user.time - @current_user.prefs.review_period.days-1
|
||||
@project.last_reviewed = UserTime.new(@current_user).time - @current_user.prefs.review_period.days-1
|
||||
@project.save
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ end
|
|||
|
||||
Given /^I have a todo with description "([^"]*)" in project "([^"]*)" with tags "([^"]*)" in the context "([^"]*)" that is due next week$/ do |action_description, project_name, tags, context_name|
|
||||
step "I have a todo with description \"#{action_description}\" in project \"#{project_name}\" with tags \"#{tags}\" in the context \"#{context_name}\""
|
||||
@todo.due = @current_user.time + 1.week
|
||||
@todo.due = UserTime.new(@current_user).time + 1.week
|
||||
@todo.save!
|
||||
end
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ Given /^I have ([0-9]+) deferred todos$/ do |count|
|
|||
context = @current_user.contexts.create!(:name => "context B")
|
||||
count.to_i.downto 1 do |i|
|
||||
todo = @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}")
|
||||
todo.show_from = @current_user.time + 1.week
|
||||
todo.show_from = UserTime.new(@current_user).time + 1.week
|
||||
todo.save!
|
||||
end
|
||||
end
|
||||
|
|
@ -102,7 +102,7 @@ end
|
|||
Given /^I have a deferred todo "([^"]*)" in the context "([^"]*)"$/ do |description, context_name|
|
||||
context = @current_user.contexts.where(:name => context_name).first_or_create
|
||||
todo = @current_user.todos.create!(:context_id => context.id, :description => description)
|
||||
todo.show_from = @current_user.time + 1.week
|
||||
todo.show_from = UserTime.new(@current_user).time + 1.week
|
||||
todo.save!
|
||||
end
|
||||
|
||||
|
|
@ -112,13 +112,13 @@ end
|
|||
|
||||
Given /^I have a deferred todo "([^"]*)" in context "([^"]*)" with tags "([^"]*)"$/ do |action_description, context_name, tag_list|
|
||||
step "I have a todo \"#{action_description}\" in context \"#{context_name}\" with tags \"#{tag_list}\""
|
||||
@todo.show_from = @current_user.time + 1.week
|
||||
@todo.show_from = UserTime.new(@current_user).time + 1.week
|
||||
@todo.save!
|
||||
end
|
||||
|
||||
Given(/^I have a deferred todo "(.*?)" in the context "(.*?)" in the project "(.*?)"$/) do |action_description, context_name, project_name|
|
||||
step "I have a todo \"#{action_description}\" in the context \"#{context_name}\" in the project \"#{project_name}\""
|
||||
@todo.show_from = @current_user.time + 1.week
|
||||
@todo.show_from = UserTime.new(@current_user).time + 1.week
|
||||
@todo.save!
|
||||
end
|
||||
|
||||
|
|
@ -293,7 +293,7 @@ end
|
|||
|
||||
When(/^I submit a new deferred action with description "([^"]*)"$/) do |description|
|
||||
fill_in "todo[description]", :with => description
|
||||
fill_in "todo[show_from]", :with => format_date(@current_user.time + 1.week)
|
||||
fill_in "todo[show_from]", :with => format_date(UserTime.new(@current_user).time + 1.week)
|
||||
submit_next_action_form
|
||||
end
|
||||
|
||||
|
|
@ -305,7 +305,7 @@ When /^I submit a new deferred action with description "([^"]*)" and the tags "(
|
|||
fill_in "todo_context_name", :with => context_name
|
||||
|
||||
fill_in "tag_list", :with => tags
|
||||
fill_in "todo[show_from]", :with => format_date(@current_user.time + 1.week)
|
||||
fill_in "todo[show_from]", :with => format_date(UserTime.new(@current_user).time + 1.week)
|
||||
end
|
||||
submit_next_action_form
|
||||
end
|
||||
|
|
@ -315,7 +315,7 @@ When(/^I submit a new deferred action with description "([^"]*)" to project "(.*
|
|||
fill_in "todo[description]", :with => description
|
||||
fill_in "todo_project_name", :with => project_name
|
||||
fill_in "tag_list", :with => tags
|
||||
fill_in "todo[show_from]", :with => format_date(@current_user.time + 1.week)
|
||||
fill_in "todo[show_from]", :with => format_date(UserTime.new(@current_user).time + 1.week)
|
||||
end
|
||||
submit_next_action_form
|
||||
end
|
||||
|
|
@ -330,7 +330,7 @@ When /^I submit a new deferred action with description "([^"]*)" to project "([^
|
|||
fill_in "todo_project_name", :with => project_name
|
||||
fill_in "todo_context_name", :with => context_name
|
||||
fill_in "tag_list", :with => tags
|
||||
fill_in "todo[show_from]", :with => format_date(@current_user.time + 1.week)
|
||||
fill_in "todo[show_from]", :with => format_date(UserTime.new(@current_user).time + 1.week)
|
||||
end
|
||||
|
||||
submit_next_action_form
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ module TracksLoginHelper
|
|||
Rails.application.routes_reloader.paths.each{ |path| load(path) }
|
||||
_routes.draw do
|
||||
# here you can add any route you want
|
||||
match "/test_login_backdoor", to: "session_backdoor#create"
|
||||
match "login/expire_session", to: "session_backdoor#expire_session"
|
||||
get "/test_login_backdoor", to: "session_backdoor#create"
|
||||
get "login/expire_session", to: "session_backdoor#expire_session"
|
||||
end
|
||||
ActiveSupport.on_load(:action_controller) { _routes.finalize! }
|
||||
ensure
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ class Staleness
|
|||
SECONDS_PER_DAY = 86400
|
||||
def self.days_stale(item, current_user)
|
||||
return 0 if cannot_be_stale(item, current_user)
|
||||
(current_user.time - item.created_at).to_i / SECONDS_PER_DAY
|
||||
(UserTime.new(current_user).time - item.created_at).to_i / SECONDS_PER_DAY
|
||||
end
|
||||
|
||||
def self.cannot_be_stale(item, current_user)
|
||||
return true if item.due || item.completed?
|
||||
return true if item.created_at > current_user.time
|
||||
return true if item.created_at > UserTime.new(current_user).time
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,4 +11,12 @@ class UserTime
|
|||
def midnight(date)
|
||||
timezone.local(date.year, date.month, date.day, 0, 0, 0)
|
||||
end
|
||||
|
||||
def time
|
||||
timezone.now
|
||||
end
|
||||
|
||||
def date
|
||||
time.to_date
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue