@@ -260,8 +260,8 private | |||||
260 | end |
|
260 | end | |
261 |
|
261 | |||
262 | @from, @to = @to, @from if @from && @to && @from > @to |
|
262 | @from, @to = @to, @from if @from && @to && @from > @to | |
263 |
@from ||= (TimeEntry.earilest_date_for_project || Date.today) |
|
263 | @from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today) | |
264 | @to ||= (TimeEntry.latest_date_for_project || Date.today) |
|
264 | @to ||= (TimeEntry.latest_date_for_project(@project) || Date.today) | |
265 | end |
|
265 | end | |
266 |
|
266 | |||
267 | def load_available_criterias |
|
267 | def load_available_criterias |
@@ -449,6 +449,15 class Project < ActiveRecord::Base | |||||
449 | enabled_modules.clear |
|
449 | enabled_modules.clear | |
450 | end |
|
450 | end | |
451 | end |
|
451 | end | |
|
452 | ||||
|
453 | # Returns an array of projects that are in this project's hierarchy | |||
|
454 | # | |||
|
455 | # Example: parents, children, siblings | |||
|
456 | def hierarchy | |||
|
457 | parents = project.self_and_ancestors || [] | |||
|
458 | descendants = project.descendants || [] | |||
|
459 | project_hierarchy = parents | descendants # Set union | |||
|
460 | end | |||
452 |
|
461 | |||
453 | # Returns an auto-generated project identifier based on the last identifier used |
|
462 | # Returns an auto-generated project identifier based on the last identifier used | |
454 | def self.next_identifier |
|
463 | def self.next_identifier |
@@ -82,11 +82,19 class TimeEntry < ActiveRecord::Base | |||||
82 | end |
|
82 | end | |
83 | end |
|
83 | end | |
84 |
|
84 | |||
85 | def self.earilest_date_for_project |
|
85 | def self.earilest_date_for_project(project=nil) | |
86 |
|
|
86 | finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries)) | |
|
87 | if project | |||
|
88 | finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)] | |||
|
89 | end | |||
|
90 | TimeEntry.minimum(:spent_on, :include => :project, :conditions => finder_conditions.conditions) | |||
87 | end |
|
91 | end | |
88 |
|
92 | |||
89 | def self.latest_date_for_project |
|
93 | def self.latest_date_for_project(project=nil) | |
90 |
|
|
94 | finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries)) | |
|
95 | if project | |||
|
96 | finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)] | |||
|
97 | end | |||
|
98 | TimeEntry.maximum(:spent_on, :include => :project, :conditions => finder_conditions.conditions) | |||
91 | end |
|
99 | end | |
92 | end |
|
100 | end |
@@ -283,7 +283,7 class TimelogControllerTest < ActionController::TestCase | |||||
283 | assert_not_nil assigns(:total_hours) |
|
283 | assert_not_nil assigns(:total_hours) | |
284 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
284 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
285 | # display all time by default |
|
285 | # display all time by default | |
286 |
assert_equal '2007-03-1 |
|
286 | assert_equal '2007-03-12'.to_date, assigns(:from) | |
287 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
287 | assert_equal '2007-04-22'.to_date, assigns(:to) | |
288 | end |
|
288 | end | |
289 |
|
289 | |||
@@ -325,8 +325,8 class TimelogControllerTest < ActionController::TestCase | |||||
325 | assert_equal 2, assigns(:entries).size |
|
325 | assert_equal 2, assigns(:entries).size | |
326 | assert_not_nil assigns(:total_hours) |
|
326 | assert_not_nil assigns(:total_hours) | |
327 | assert_equal 154.25, assigns(:total_hours) |
|
327 | assert_equal 154.25, assigns(:total_hours) | |
328 |
# display all time b |
|
328 | # display all time based on what's been logged | |
329 |
assert_equal '2007-03-1 |
|
329 | assert_equal '2007-03-12'.to_date, assigns(:from) | |
330 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
330 | assert_equal '2007-04-22'.to_date, assigns(:to) | |
331 | end |
|
331 | end | |
332 |
|
332 |
@@ -50,17 +50,50 class TimeEntryTest < ActiveSupport::TestCase | |||||
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | context "#earilest_date_for_project" do |
|
52 | context "#earilest_date_for_project" do | |
53 | should "return the lowest spent_on value that is visible to the current user" do |
|
53 | setup do | |
54 | User.current = nil |
|
54 | User.current = nil | |
55 | assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s |
|
55 | @public_project = Project.generate!(:is_public => true) | |
|
56 | @issue = Issue.generate_for_project!(@public_project) | |||
|
57 | TimeEntry.generate!(:spent_on => '2010-01-01', | |||
|
58 | :issue => @issue, | |||
|
59 | :project => @public_project) | |||
56 | end |
|
60 | end | |
|
61 | ||||
|
62 | context "without a project" do | |||
|
63 | should "return the lowest spent_on value that is visible to the current user" do | |||
|
64 | assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s | |||
|
65 | end | |||
|
66 | end | |||
|
67 | ||||
|
68 | context "with a project" do | |||
|
69 | should "return the lowest spent_on value that is visible to the current user for that project and it's subprojects only" do | |||
|
70 | assert_equal "2010-01-01", TimeEntry.earilest_date_for_project(@public_project).to_s | |||
|
71 | end | |||
|
72 | end | |||
|
73 | ||||
57 | end |
|
74 | end | |
58 |
|
75 | |||
59 | context "#latest_date_for_project" do |
|
76 | context "#latest_date_for_project" do | |
60 | should "return the highest spent_on value that is visible to the current user" do |
|
77 | setup do | |
61 | User.current = nil |
|
78 | User.current = nil | |
62 | assert_equal "2007-04-22", TimeEntry.latest_date_for_project.to_s |
|
79 | @public_project = Project.generate!(:is_public => true) | |
|
80 | @issue = Issue.generate_for_project!(@public_project) | |||
|
81 | TimeEntry.generate!(:spent_on => '2010-01-01', | |||
|
82 | :issue => @issue, | |||
|
83 | :project => @public_project) | |||
63 | end |
|
84 | end | |
64 | end |
|
85 | ||
65 |
|
86 | context "without a project" do | ||
|
87 | should "return the highest spent_on value that is visible to the current user" do | |||
|
88 | assert_equal "2010-01-01", TimeEntry.latest_date_for_project.to_s | |||
|
89 | end | |||
|
90 | end | |||
|
91 | ||||
|
92 | context "with a project" do | |||
|
93 | should "return the highest spent_on value that is visible to the current user for that project and it's subprojects only" do | |||
|
94 | project = Project.find(1) | |||
|
95 | assert_equal "2007-04-22", TimeEntry.latest_date_for_project(project).to_s | |||
|
96 | end | |||
|
97 | end | |||
|
98 | end | |||
66 | end |
|
99 | end |
General Comments 0
You need to be logged in to leave comments.
Login now