Refactor: move method to Model.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4086 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-09-14 19:02:20 +00:00
parent 1b90703157
commit 8900797ada
3 changed files with 25 additions and 2 deletions

View File

@ -260,8 +260,8 @@ private
end end
@from, @to = @to, @from if @from && @to && @from > @to @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 @from ||= (TimeEntry.earilest_date_for_project || Date.today) - 1
@to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) @to ||= (TimeEntry.latest_date_for_project || Date.today)
end end
def load_available_criterias def load_available_criterias

View File

@ -81,4 +81,12 @@ class TimeEntry < ActiveRecord::Base
yield yield
end end
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 end

View File

@ -48,4 +48,19 @@ class TimeEntryTest < ActiveSupport::TestCase
def test_hours_should_default_to_nil def test_hours_should_default_to_nil
assert_nil TimeEntry.new.hours assert_nil TimeEntry.new.hours
end 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 end