diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-04 23:01:42 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-04 23:01:42 +0000 |
commit | 10509933486ab651c4a185efc37a6340d503f47b (patch) | |
tree | bb7cebf898c6527605ea48d68f1d7fc8e36e27b7 | |
parent | 9e5ed4208b8dc531f77708e84f6d11eba3f1ca4a (diff) | |
download | redmine-10509933486ab651c4a185efc37a6340d503f47b.tar.gz redmine-10509933486ab651c4a185efc37a6340d503f47b.zip |
Removed unnecessary calculations in time entries index.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8085 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/timelog_controller.rb | 2 | ||||
-rw-r--r-- | app/models/time_entry.rb | 32 | ||||
-rw-r--r-- | test/functional/timelog_controller_test.rb | 10 | ||||
-rw-r--r-- | test/unit/time_entry_test.rb | 48 |
4 files changed, 17 insertions, 75 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index 719e0b864..d50c3d0de 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -320,8 +320,6 @@ private end @from, @to = @to, @from if @from && @to && @from > @to - @from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today) - @to ||= (TimeEntry.latest_date_for_project(@project) || Date.today) end def parse_params_for_bulk_time_entry_attributes(params) diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index f4716d0ac..c5c1d39bc 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -53,10 +53,18 @@ class TimeEntry < ActiveRecord::Base :include => :project, :conditions => project.project_condition(include_subprojects) }} - named_scope :spent_between, lambda {|from, to| { - :conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to] - }} - + named_scope :spent_between, lambda {|from, to| + if from && to + {:conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]} + elsif from + {:conditions => ["#{TimeEntry.table_name}.spent_on >= ?", from]} + elsif to + {:conditions => ["#{TimeEntry.table_name}.spent_on <= ?", to]} + else + {} + end + } + def after_initialize if new_record? && self.activity.nil? if default_activity = TimeEntryActivity.default @@ -96,20 +104,4 @@ class TimeEntry < ActiveRecord::Base def editable_by?(usr) (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project) end - - def self.earilest_date_for_project(project=nil) - finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries)) - if project - finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)] - end - TimeEntry.minimum(:spent_on, :include => :project, :conditions => finder_conditions.conditions) - end - - def self.latest_date_for_project(project=nil) - finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries)) - if project - finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)] - end - TimeEntry.maximum(:spent_on, :include => :project, :conditions => finder_conditions.conditions) - end end diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index fe2aea6e3..feb53747d 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -270,8 +270,8 @@ class TimelogControllerTest < ActionController::TestCase assert_not_nil assigns(:total_hours) assert_equal "162.90", "%.2f" % assigns(:total_hours) # display all time by default - assert_equal '2007-03-12'.to_date, assigns(:from) - assert_equal '2007-04-22'.to_date, assigns(:to) + assert_nil assigns(:from) + assert_nil assigns(:to) assert_tag :form, :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} end @@ -320,9 +320,9 @@ class TimelogControllerTest < ActionController::TestCase assert_equal 2, assigns(:entries).size assert_not_nil assigns(:total_hours) assert_equal 154.25, assigns(:total_hours) - # display all time based on what's been logged - assert_equal '2007-03-12'.to_date, assigns(:from) - assert_equal '2007-04-22'.to_date, assigns(:to) + # display all time + assert_nil assigns(:from) + assert_nil assigns(:to) # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes # to use /issues/:issue_id/time_entries assert_tag :form, diff --git a/test/unit/time_entry_test.rb b/test/unit/time_entry_test.rb index 97ec76ef1..a9d9fc157 100644 --- a/test/unit/time_entry_test.rb +++ b/test/unit/time_entry_test.rb @@ -125,52 +125,4 @@ class TimeEntryTest < ActiveSupport::TestCase :activity => activity) assert_equal project.id, te.project.id end - - context "#earilest_date_for_project" do - setup do - User.current = nil - @public_project = Project.generate!(:is_public => true) - @issue = Issue.generate_for_project!(@public_project) - TimeEntry.generate!(:spent_on => '2010-01-01', - :issue => @issue, - :project => @public_project) - end - - context "without a project" do - should "return the lowest spent_on value that is visible to the current user" do - assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s - end - end - - context "with a project" do - should "return the lowest spent_on value that is visible to the current user for that project and it's subprojects only" do - assert_equal "2010-01-01", TimeEntry.earilest_date_for_project(@public_project).to_s - end - end - - end - - context "#latest_date_for_project" do - setup do - User.current = nil - @public_project = Project.generate!(:is_public => true) - @issue = Issue.generate_for_project!(@public_project) - TimeEntry.generate!(:spent_on => '2010-01-01', - :issue => @issue, - :project => @public_project) - end - - context "without a project" do - should "return the highest spent_on value that is visible to the current user" do - assert_equal "2010-01-01", TimeEntry.latest_date_for_project.to_s - end - end - - context "with a project" do - should "return the highest spent_on value that is visible to the current user for that project and it's subprojects only" do - project = Project.find(1) - assert_equal "2007-04-22", TimeEntry.latest_date_for_project(project).to_s - end - end - end end |