Commit 8900797a authored by Eric Davis's avatar Eric Davis

Refactor: move method to Model.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4086 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 1b907031
......@@ -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
......
......@@ -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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment