mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +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
|
end
|
||||||
|
|
||||||
def days_from_today(date)
|
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
|
end
|
||||||
|
|
||||||
# Check due date in comparison to today's date Flag up date appropriately with
|
# Check due date in comparison to today's date Flag up date appropriately with
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,10 @@ class Project < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def needs_review?(current_user)
|
def needs_review?(user)
|
||||||
|
current_time = UserTime.new(user).time
|
||||||
return active? && ( last_reviewed.nil? ||
|
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
|
end
|
||||||
|
|
||||||
def blocked?
|
def blocked?
|
||||||
|
|
|
||||||
|
|
@ -159,10 +159,6 @@ class User < ActiveRecord::Base
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def time
|
|
||||||
Time.now.in_time_zone(prefs.time_zone)
|
|
||||||
end
|
|
||||||
|
|
||||||
def date
|
def date
|
||||||
UserTime.new(self).midnight(Time.now)
|
UserTime.new(self).midnight(Time.now)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
<div id="recurring_timespan">
|
<div id="recurring_timespan">
|
||||||
<br/>
|
<br/>
|
||||||
<label for="recurring_todo[start_from]"><%= t('todos.recurrence.starts_on') %>:</label><%=
|
<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/>
|
<br/>
|
||||||
<label for="recurring_todo[ends_on]"><%= t('todos.recurrence.ends_on') %>:</label><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/>
|
<%= 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">
|
<span class="errors">
|
||||||
<%= get_list_of_error_messages_for(@todo) if @todo %>
|
<%= get_list_of_error_messages_for(@todo) if @todo %>
|
||||||
</span>
|
</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>
|
<h2><label for="todo_description"><%= t('common.description') %></label></h2>
|
||||||
<%= text_field( "todo", "description", "tabindex" => 1, "maxlength" => 100, "size" => 50) %>
|
<%= text_field( "todo", "description", "tabindex" => 1, "maxlength" => 100, "size" => 50) %>
|
||||||
<h2><label for="tag_list"><%= t('todos.tags') %></label></h2>
|
<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|
|
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"
|
step "I have a project \"#{project_name}\" with #{num_todos} todos"
|
||||||
@project = @current_user.projects.where(:name => project_name).first
|
@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
|
@project.save
|
||||||
end
|
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|
|
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}\""
|
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!
|
@todo.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ Given /^I have ([0-9]+) deferred todos$/ do |count|
|
||||||
context = @current_user.contexts.create!(:name => "context B")
|
context = @current_user.contexts.create!(:name => "context B")
|
||||||
count.to_i.downto 1 do |i|
|
count.to_i.downto 1 do |i|
|
||||||
todo = @current_user.todos.create!(:context_id => context.id, :description => "todo #{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!
|
todo.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -102,7 +102,7 @@ end
|
||||||
Given /^I have a deferred todo "([^"]*)" in the context "([^"]*)"$/ do |description, context_name|
|
Given /^I have a deferred todo "([^"]*)" in the context "([^"]*)"$/ do |description, context_name|
|
||||||
context = @current_user.contexts.where(:name => context_name).first_or_create
|
context = @current_user.contexts.where(:name => context_name).first_or_create
|
||||||
todo = @current_user.todos.create!(:context_id => context.id, :description => description)
|
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!
|
todo.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -112,13 +112,13 @@ end
|
||||||
|
|
||||||
Given /^I have a deferred todo "([^"]*)" in context "([^"]*)" with tags "([^"]*)"$/ do |action_description, context_name, tag_list|
|
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}\""
|
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!
|
@todo.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^I have a deferred todo "(.*?)" in the context "(.*?)" in the project "(.*?)"$/) do |action_description, context_name, project_name|
|
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}\""
|
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!
|
@todo.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -293,7 +293,7 @@ end
|
||||||
|
|
||||||
When(/^I submit a new deferred action with description "([^"]*)"$/) do |description|
|
When(/^I submit a new deferred action with description "([^"]*)"$/) do |description|
|
||||||
fill_in "todo[description]", :with => 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
|
submit_next_action_form
|
||||||
end
|
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 "todo_context_name", :with => context_name
|
||||||
|
|
||||||
fill_in "tag_list", :with => tags
|
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
|
end
|
||||||
submit_next_action_form
|
submit_next_action_form
|
||||||
end
|
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[description]", :with => description
|
||||||
fill_in "todo_project_name", :with => project_name
|
fill_in "todo_project_name", :with => project_name
|
||||||
fill_in "tag_list", :with => tags
|
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
|
end
|
||||||
submit_next_action_form
|
submit_next_action_form
|
||||||
end
|
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_project_name", :with => project_name
|
||||||
fill_in "todo_context_name", :with => context_name
|
fill_in "todo_context_name", :with => context_name
|
||||||
fill_in "tag_list", :with => tags
|
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
|
end
|
||||||
|
|
||||||
submit_next_action_form
|
submit_next_action_form
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ module TracksLoginHelper
|
||||||
Rails.application.routes_reloader.paths.each{ |path| load(path) }
|
Rails.application.routes_reloader.paths.each{ |path| load(path) }
|
||||||
_routes.draw do
|
_routes.draw do
|
||||||
# here you can add any route you want
|
# here you can add any route you want
|
||||||
match "/test_login_backdoor", to: "session_backdoor#create"
|
get "/test_login_backdoor", to: "session_backdoor#create"
|
||||||
match "login/expire_session", to: "session_backdoor#expire_session"
|
get "login/expire_session", to: "session_backdoor#expire_session"
|
||||||
end
|
end
|
||||||
ActiveSupport.on_load(:action_controller) { _routes.finalize! }
|
ActiveSupport.on_load(:action_controller) { _routes.finalize! }
|
||||||
ensure
|
ensure
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ class Staleness
|
||||||
SECONDS_PER_DAY = 86400
|
SECONDS_PER_DAY = 86400
|
||||||
def self.days_stale(item, current_user)
|
def self.days_stale(item, current_user)
|
||||||
return 0 if cannot_be_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
|
end
|
||||||
|
|
||||||
def self.cannot_be_stale(item, current_user)
|
def self.cannot_be_stale(item, current_user)
|
||||||
return true if item.due || item.completed?
|
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
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,12 @@ class UserTime
|
||||||
def midnight(date)
|
def midnight(date)
|
||||||
timezone.local(date.year, date.month, date.day, 0, 0, 0)
|
timezone.local(date.year, date.month, date.day, 0, 0, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def time
|
||||||
|
timezone.now
|
||||||
|
end
|
||||||
|
|
||||||
|
def date
|
||||||
|
time.to_date
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -84,12 +84,12 @@ class ProjectTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_review_project
|
def test_review_project
|
||||||
assert_nil @timemachine.last_reviewed
|
assert_nil @timemachine.last_reviewed
|
||||||
assert @timemachine.needs_review?(nil)
|
assert @timemachine.needs_review?(users(:admin_user))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_review_completedprojects
|
def test_review_completedprojects
|
||||||
@timemachine.complete!
|
@timemachine.complete!
|
||||||
assert !@timemachine.needs_review?(nil)
|
assert !@timemachine.needs_review?(users(:admin_user))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_complete_project
|
def test_complete_project
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,18 @@ require_relative '../../lib/staleness'
|
||||||
|
|
||||||
|
|
||||||
class StalenessTest < Test::Unit::TestCase
|
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
|
FakeTask = Struct.new(:due, :completed, :created_at) do
|
||||||
def completed?
|
def completed?
|
||||||
self.completed
|
self.completed
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def now
|
def now
|
||||||
|
|
@ -28,6 +35,11 @@ class StalenessTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@current_user = FakeUser.new(now)
|
@current_user = FakeUser.new(now)
|
||||||
|
Timecop.freeze(Time.local(2013,02,28))
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
Timecop.return
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_item_with_due_date_is_not_stale_ever
|
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'
|
require 'rails/test_help'
|
||||||
|
|
||||||
# set config for tests. Overwrite those read from config/site.yml. Use inject to avoid warning about changing CONSTANT
|
# 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
|
class ActiveSupport::TestCase
|
||||||
ActiveRecord::Migration.check_pending!
|
ActiveRecord::Migration.check_pending!
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue