diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index e234848d03..726c69d5b3 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 73f39f949e..56801a4ca8 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 3c135510ac..a541fc41fa 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