From 8900797adaf29adc447925b800d5457ca941795f Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 14 Sep 2010 19:02:20 +0000 Subject: [PATCH] Refactor: move method to Model. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4086 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/timelog_controller.rb | 4 ++-- app/models/time_entry.rb | 8 ++++++++ test/unit/time_entry_test.rb | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index e234848d0..726c69d5b 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -260,8 +260,8 @@ private end @from, @to = @to, @from if @from && @to && @from > @to - @from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) - 1 - @to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) + @from ||= (TimeEntry.earilest_date_for_project || Date.today) - 1 + @to ||= (TimeEntry.latest_date_for_project || Date.today) end def load_available_criterias diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 73f39f949..56801a4ca 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -81,4 +81,12 @@ class TimeEntry < ActiveRecord::Base yield end end + + def self.earilest_date_for_project + TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) + end + + def self.latest_date_for_project + TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) + end end diff --git a/test/unit/time_entry_test.rb b/test/unit/time_entry_test.rb index 3c135510a..a541fc41f 100644 --- a/test/unit/time_entry_test.rb +++ b/test/unit/time_entry_test.rb @@ -48,4 +48,19 @@ class TimeEntryTest < ActiveSupport::TestCase def test_hours_should_default_to_nil assert_nil TimeEntry.new.hours end + + context "#earilest_date_for_project" do + should "return the lowest spent_on value that is visible to the current user" do + User.current = nil + assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s + end + end + + context "#latest_date_for_project" do + should "return the highest spent_on value that is visible to the current user" do + User.current = nil + assert_equal "2007-04-22", TimeEntry.latest_date_for_project.to_s + end + end + end