]> source.dussan.org Git - redmine.git/commitdiff
Refactor: move method to Model.
authorEric Davis <edavis@littlestreamsoftware.com>
Tue, 14 Sep 2010 19:02:20 +0000 (19:02 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Tue, 14 Sep 2010 19:02:20 +0000 (19:02 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4086 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/timelog_controller.rb
app/models/time_entry.rb
test/unit/time_entry_test.rb

index e234848d03681271a087d84dde1ae081bb695b5f..726c69d5b31bf66d34539a358248b3f7dc428c9a 100644 (file)
@@ -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
index 73f39f949ea0b2a06b1bbcd71c48593e09e4d161..56801a4ca856c3368504001ca998be5bc563b28d 100644 (file)
@@ -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
index 3c135510ace5e3443a2ae3826ef8d545eab1809f..a541fc41fab4dea8ef41946b74fdfea8b04c98b1 100644 (file)
@@ -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