Mercurial > hg > soundsoftware-site
comparison test/unit/lib/redmine/helpers/gantt_test.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | 433d4f72a19b |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
24 :projects_trackers, | 24 :projects_trackers, |
25 :roles, | 25 :roles, |
26 :member_roles, | 26 :member_roles, |
27 :members, | 27 :members, |
28 :enabled_modules, | 28 :enabled_modules, |
29 :workflows, | |
30 :versions, | 29 :versions, |
31 :groups_users | 30 :groups_users |
32 | 31 |
33 include ApplicationHelper | 32 include ApplicationHelper |
34 include ProjectsHelper | 33 include ProjectsHelper |
35 include IssuesHelper | 34 include IssuesHelper |
36 include ERB::Util | 35 include ERB::Util |
36 include Rails.application.routes.url_helpers | |
37 | 37 |
38 def setup | 38 def setup |
39 setup_with_controller | 39 setup_with_controller |
40 User.current = User.find(1) | 40 User.current = User.find(1) |
41 end | 41 end |
47 # Creates a Gantt chart for a 4 week span | 47 # Creates a Gantt chart for a 4 week span |
48 def create_gantt(project=Project.generate!, options={}) | 48 def create_gantt(project=Project.generate!, options={}) |
49 @project = project | 49 @project = project |
50 @gantt = Redmine::Helpers::Gantt.new(options) | 50 @gantt = Redmine::Helpers::Gantt.new(options) |
51 @gantt.project = @project | 51 @gantt.project = @project |
52 @gantt.query = Query.create!(:project => @project, :name => 'Gantt') | 52 @gantt.query = IssueQuery.create!(:project => @project, :name => 'Gantt') |
53 @gantt.view = self | 53 @gantt.view = self |
54 @gantt.instance_variable_set('@date_from', options[:date_from] || (today - 14)) | 54 @gantt.instance_variable_set('@date_from', options[:date_from] || (today - 14)) |
55 @gantt.instance_variable_set('@date_to', options[:date_to] || (today + 14)) | 55 @gantt.instance_variable_set('@date_to', options[:date_to] || (today + 14)) |
56 end | 56 end |
57 | 57 |
58 context "#number_of_rows" do | 58 context "#number_of_rows" do |
59 context "with one project" do | 59 context "with one project" do |
60 should "return the number of rows just for that project" | 60 should "return the number of rows just for that project" do |
61 p1, p2 = Project.generate!, Project.generate! | |
62 i1, i2 = Issue.generate!(:project => p1), Issue.generate!(:project => p2) | |
63 create_gantt(p1) | |
64 assert_equal 2, @gantt.number_of_rows | |
65 end | |
61 end | 66 end |
62 | 67 |
63 context "with no project" do | 68 context "with no project" do |
64 should "return the total number of rows for all the projects, resursively" | 69 should "return the total number of rows for all the projects, resursively" do |
70 p1, p2 = Project.generate!, Project.generate! | |
71 create_gantt(nil) | |
72 #fix the return value of #number_of_rows_on_project() to an arbitrary value | |
73 #so that we really only test #number_of_rows | |
74 @gantt.stubs(:number_of_rows_on_project).returns(7) | |
75 #also fix #projects because we want to test #number_of_rows in isolation | |
76 @gantt.stubs(:projects).returns(Project.all) | |
77 #actual test | |
78 assert_equal Project.count*7, @gantt.number_of_rows | |
79 end | |
65 end | 80 end |
66 | 81 |
67 should "not exceed max_rows option" do | 82 should "not exceed max_rows option" do |
68 p = Project.generate! | 83 p = Project.generate! |
69 5.times do | 84 5.times do |
744 end | 759 end |
745 | 760 |
746 context "#to_pdf" do | 761 context "#to_pdf" do |
747 should "be tested" | 762 should "be tested" |
748 end | 763 end |
764 | |
765 def test_sort_issues_no_date | |
766 project = Project.generate! | |
767 issue1 = Issue.generate!(:subject => "test", :project => project) | |
768 issue2 = Issue.generate!(:subject => "test", :project => project) | |
769 assert issue1.root_id < issue2.root_id | |
770 child1 = Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child', | |
771 :project => project) | |
772 child2 = Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child', | |
773 :project => project) | |
774 child3 = Issue.generate!(:parent_issue_id => child1.id, :subject => 'child', | |
775 :project => project) | |
776 assert_equal child1.root_id, child2.root_id | |
777 assert child1.lft < child2.lft | |
778 assert child3.lft < child2.lft | |
779 issues = [child3, child2, child1, issue2, issue1] | |
780 Redmine::Helpers::Gantt.sort_issues!(issues) | |
781 assert_equal [issue1.id, child1.id, child3.id, child2.id, issue2.id], | |
782 issues.map{|v| v.id} | |
783 end | |
784 | |
785 def test_sort_issues_root_only | |
786 project = Project.generate! | |
787 issue1 = Issue.generate!(:subject => "test", :project => project) | |
788 issue2 = Issue.generate!(:subject => "test", :project => project) | |
789 issue3 = Issue.generate!(:subject => "test", :project => project, | |
790 :start_date => (today - 1)) | |
791 issue4 = Issue.generate!(:subject => "test", :project => project, | |
792 :start_date => (today - 2)) | |
793 issues = [issue4, issue3, issue2, issue1] | |
794 Redmine::Helpers::Gantt.sort_issues!(issues) | |
795 assert_equal [issue1.id, issue2.id, issue4.id, issue3.id], | |
796 issues.map{|v| v.id} | |
797 end | |
798 | |
799 def test_sort_issues_tree | |
800 project = Project.generate! | |
801 issue1 = Issue.generate!(:subject => "test", :project => project) | |
802 issue2 = Issue.generate!(:subject => "test", :project => project, | |
803 :start_date => (today - 2)) | |
804 issue1_child1 = | |
805 Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child', | |
806 :project => project) | |
807 issue1_child2 = | |
808 Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child', | |
809 :project => project, :start_date => (today - 10)) | |
810 issue1_child1_child1 = | |
811 Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child', | |
812 :project => project, :start_date => (today - 8)) | |
813 issue1_child1_child2 = | |
814 Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child', | |
815 :project => project, :start_date => (today - 9)) | |
816 issue1_child1_child1_logic = Redmine::Helpers::Gantt.sort_issue_logic(issue1_child1_child1) | |
817 assert_equal [[today - 10, issue1.id], [today - 9, issue1_child1.id], | |
818 [today - 8, issue1_child1_child1.id]], | |
819 issue1_child1_child1_logic | |
820 issue1_child1_child2_logic = Redmine::Helpers::Gantt.sort_issue_logic(issue1_child1_child2) | |
821 assert_equal [[today - 10, issue1.id], [today - 9, issue1_child1.id], | |
822 [today - 9, issue1_child1_child2.id]], | |
823 issue1_child1_child2_logic | |
824 issues = [issue1_child1_child2, issue1_child1_child1, issue1_child2, | |
825 issue1_child1, issue2, issue1] | |
826 Redmine::Helpers::Gantt.sort_issues!(issues) | |
827 assert_equal [issue1.id, issue1_child1.id, issue1_child2.id, | |
828 issue1_child1_child2.id, issue1_child1_child1.id, issue2.id], | |
829 issues.map{|v| v.id} | |
830 end | |
831 | |
832 def test_sort_versions | |
833 project = Project.generate! | |
834 version1 = Version.create!(:project => project, :name => 'test1') | |
835 version2 = Version.create!(:project => project, :name => 'test2', :effective_date => '2013-10-25') | |
836 version3 = Version.create!(:project => project, :name => 'test3') | |
837 version4 = Version.create!(:project => project, :name => 'test4', :effective_date => '2013-10-02') | |
838 | |
839 assert_equal versions.sort, Redmine::Helpers::Gantt.sort_versions!(versions) | |
840 end | |
749 end | 841 end |