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
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
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