@@ -1,110 +1,106 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
9 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | module ProjectsHelper |
|
20 | module ProjectsHelper | |
21 | def link_to_version(version, options = {}) |
|
21 | def link_to_version(version, options = {}) | |
22 | return '' unless version && version.is_a?(Version) |
|
22 | return '' unless version && version.is_a?(Version) | |
23 | link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options |
|
23 | link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | def project_settings_tabs |
|
26 | def project_settings_tabs | |
27 | tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural}, |
|
27 | tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural}, | |
28 | {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural}, |
|
28 | {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural}, | |
29 | {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural}, |
|
29 | {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural}, | |
30 | {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural}, |
|
30 | {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural}, | |
31 | {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural}, |
|
31 | {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural}, | |
32 | {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki}, |
|
32 | {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki}, | |
33 | {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural}, |
|
33 | {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural}, | |
34 | {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}, |
|
34 | {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}, | |
35 | {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities} |
|
35 | {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities} | |
36 | ] |
|
36 | ] | |
37 | tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} |
|
37 | tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | def parent_project_select_tag(project) |
|
40 | def parent_project_select_tag(project) | |
41 | selected = project.parent |
|
41 | selected = project.parent | |
42 | # retrieve the requested parent project |
|
42 | # retrieve the requested parent project | |
43 | parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id] |
|
43 | parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id] | |
44 | if parent_id |
|
44 | if parent_id | |
45 | selected = (parent_id.blank? ? nil : Project.find(parent_id)) |
|
45 | selected = (parent_id.blank? ? nil : Project.find(parent_id)) | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | options = '' |
|
48 | options = '' | |
49 | options << "<option value=''></option>" if project.allowed_parents.include?(nil) |
|
49 | options << "<option value=''></option>" if project.allowed_parents.include?(nil) | |
50 | options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected) |
|
50 | options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected) | |
51 | content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id') |
|
51 | content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id') | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | # Renders a tree of projects as a nested set of unordered lists |
|
54 | # Renders a tree of projects as a nested set of unordered lists | |
55 | # The given collection may be a subset of the whole project tree |
|
55 | # The given collection may be a subset of the whole project tree | |
56 | # (eg. some intermediate nodes are private and can not be seen) |
|
56 | # (eg. some intermediate nodes are private and can not be seen) | |
57 | def render_project_hierarchy(projects) |
|
57 | def render_project_hierarchy(projects) | |
58 | s = '' |
|
58 | s = '' | |
59 | if projects.any? |
|
59 | if projects.any? | |
60 | ancestors = [] |
|
60 | ancestors = [] | |
61 | original_project = @project |
|
61 | original_project = @project | |
62 | projects.each do |project| |
|
62 | projects.each do |project| | |
63 | # set the project environment to please macros. |
|
63 | # set the project environment to please macros. | |
64 | @project = project |
|
64 | @project = project | |
65 | if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) |
|
65 | if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) | |
66 | s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" |
|
66 | s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" | |
67 | else |
|
67 | else | |
68 | ancestors.pop |
|
68 | ancestors.pop | |
69 | s << "</li>" |
|
69 | s << "</li>" | |
70 | while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) |
|
70 | while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) | |
71 | ancestors.pop |
|
71 | ancestors.pop | |
72 | s << "</ul></li>\n" |
|
72 | s << "</ul></li>\n" | |
73 | end |
|
73 | end | |
74 | end |
|
74 | end | |
75 | classes = (ancestors.empty? ? 'root' : 'child') |
|
75 | classes = (ancestors.empty? ? 'root' : 'child') | |
76 | s << "<li class='#{classes}'><div class='#{classes}'>" + |
|
76 | s << "<li class='#{classes}'><div class='#{classes}'>" + | |
77 | link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}") |
|
77 | link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}") | |
78 | s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? |
|
78 | s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? | |
79 | s << "</div>\n" |
|
79 | s << "</div>\n" | |
80 | ancestors << project |
|
80 | ancestors << project | |
81 | end |
|
81 | end | |
82 | s << ("</li></ul>\n" * ancestors.size) |
|
82 | s << ("</li></ul>\n" * ancestors.size) | |
83 | @project = original_project |
|
83 | @project = original_project | |
84 | end |
|
84 | end | |
85 | s.html_safe |
|
85 | s.html_safe | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | # Returns a set of options for a select field, grouped by project. |
|
88 | # Returns a set of options for a select field, grouped by project. | |
89 | def version_options_for_select(versions, selected=nil) |
|
89 | def version_options_for_select(versions, selected=nil) | |
90 | grouped = Hash.new {|h,k| h[k] = []} |
|
90 | grouped = Hash.new {|h,k| h[k] = []} | |
91 | versions.each do |version| |
|
91 | versions.each do |version| | |
92 | grouped[version.project.name] << [version.name, version.id] |
|
92 | grouped[version.project.name] << [version.name, version.id] | |
93 | end |
|
93 | end | |
94 | # Add in the selected |
|
|||
95 | if selected && !versions.include?(selected) |
|
|||
96 | grouped[selected.project.name] << [selected.name, selected.id] |
|
|||
97 | end |
|
|||
98 |
|
94 | |||
99 | if grouped.keys.size > 1 |
|
95 | if grouped.keys.size > 1 | |
100 | grouped_options_for_select(grouped, selected && selected.id) |
|
96 | grouped_options_for_select(grouped, selected && selected.id) | |
101 | else |
|
97 | else | |
102 | options_for_select((grouped.values.first || []), selected && selected.id) |
|
98 | options_for_select((grouped.values.first || []), selected && selected.id) | |
103 | end |
|
99 | end | |
104 | end |
|
100 | end | |
105 |
|
101 | |||
106 | def format_version_sharing(sharing) |
|
102 | def format_version_sharing(sharing) | |
107 | sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) |
|
103 | sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) | |
108 | l("label_version_sharing_#{sharing}") |
|
104 | l("label_version_sharing_#{sharing}") | |
109 | end |
|
105 | end | |
110 | end |
|
106 | end |
@@ -1,211 +1,212 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 | require 'versions_controller' |
|
19 | require 'versions_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class VersionsController; def rescue_action(e) raise e end; end |
|
22 | class VersionsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class VersionsControllerTest < ActionController::TestCase |
|
24 | class VersionsControllerTest < ActionController::TestCase | |
25 | fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses |
|
25 | fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = VersionsController.new |
|
28 | @controller = VersionsController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_index |
|
34 | def test_index | |
35 | get :index, :project_id => 1 |
|
35 | get :index, :project_id => 1 | |
36 | assert_response :success |
|
36 | assert_response :success | |
37 | assert_template 'index' |
|
37 | assert_template 'index' | |
38 | assert_not_nil assigns(:versions) |
|
38 | assert_not_nil assigns(:versions) | |
39 | # Version with no date set appears |
|
39 | # Version with no date set appears | |
40 | assert assigns(:versions).include?(Version.find(3)) |
|
40 | assert assigns(:versions).include?(Version.find(3)) | |
41 | # Completed version doesn't appear |
|
41 | # Completed version doesn't appear | |
42 | assert !assigns(:versions).include?(Version.find(1)) |
|
42 | assert !assigns(:versions).include?(Version.find(1)) | |
43 | # Context menu on issues |
|
43 | # Context menu on issues | |
44 | assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')")) |
|
44 | assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')")) | |
45 | # Links to versions anchors |
|
45 | # Links to versions anchors | |
46 | assert_tag 'a', :attributes => {:href => '#2.0'}, |
|
46 | assert_tag 'a', :attributes => {:href => '#2.0'}, | |
47 | :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}} |
|
47 | :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}} | |
48 | # Links to completed versions in the sidebar |
|
48 | # Links to completed versions in the sidebar | |
49 | assert_tag 'a', :attributes => {:href => '/versions/1'}, |
|
49 | assert_tag 'a', :attributes => {:href => '/versions/1'}, | |
50 | :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}} |
|
50 | :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}} | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_index_with_completed_versions |
|
53 | def test_index_with_completed_versions | |
54 | get :index, :project_id => 1, :completed => 1 |
|
54 | get :index, :project_id => 1, :completed => 1 | |
55 | assert_response :success |
|
55 | assert_response :success | |
56 | assert_template 'index' |
|
56 | assert_template 'index' | |
57 | assert_not_nil assigns(:versions) |
|
57 | assert_not_nil assigns(:versions) | |
58 | # Version with no date set appears |
|
58 | # Version with no date set appears | |
59 | assert assigns(:versions).include?(Version.find(3)) |
|
59 | assert assigns(:versions).include?(Version.find(3)) | |
60 | # Completed version appears |
|
60 | # Completed version appears | |
61 | assert assigns(:versions).include?(Version.find(1)) |
|
61 | assert assigns(:versions).include?(Version.find(1)) | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_index_with_tracker_ids |
|
64 | def test_index_with_tracker_ids | |
65 | get :index, :project_id => 1, :tracker_ids => [1, 3] |
|
65 | get :index, :project_id => 1, :tracker_ids => [1, 3] | |
66 | assert_response :success |
|
66 | assert_response :success | |
67 | assert_template 'index' |
|
67 | assert_template 'index' | |
68 | assert_not_nil assigns(:issues_by_version) |
|
68 | assert_not_nil assigns(:issues_by_version) | |
69 | assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2} |
|
69 | assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2} | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_index_showing_subprojects_versions |
|
72 | def test_index_showing_subprojects_versions | |
73 | @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version") |
|
73 | @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version") | |
74 | get :index, :project_id => 1, :with_subprojects => 1 |
|
74 | get :index, :project_id => 1, :with_subprojects => 1 | |
75 | assert_response :success |
|
75 | assert_response :success | |
76 | assert_template 'index' |
|
76 | assert_template 'index' | |
77 | assert_not_nil assigns(:versions) |
|
77 | assert_not_nil assigns(:versions) | |
78 |
|
78 | |||
79 | assert assigns(:versions).include?(Version.find(4)), "Shared version not found" |
|
79 | assert assigns(:versions).include?(Version.find(4)), "Shared version not found" | |
80 | assert assigns(:versions).include?(@subproject_version), "Subproject version not found" |
|
80 | assert assigns(:versions).include?(@subproject_version), "Subproject version not found" | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | def test_show |
|
83 | def test_show | |
84 | get :show, :id => 2 |
|
84 | get :show, :id => 2 | |
85 | assert_response :success |
|
85 | assert_response :success | |
86 | assert_template 'show' |
|
86 | assert_template 'show' | |
87 | assert_not_nil assigns(:version) |
|
87 | assert_not_nil assigns(:version) | |
88 |
|
88 | |||
89 | assert_tag :tag => 'h2', :content => /1.0/ |
|
89 | assert_tag :tag => 'h2', :content => /1.0/ | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def test_new |
|
92 | def test_new | |
93 | @request.session[:user_id] = 2 |
|
93 | @request.session[:user_id] = 2 | |
94 | get :new, :project_id => '1' |
|
94 | get :new, :project_id => '1' | |
95 | assert_response :success |
|
95 | assert_response :success | |
96 | assert_template 'new' |
|
96 | assert_template 'new' | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def test_new_from_issue_form |
|
99 | def test_new_from_issue_form | |
100 | @request.session[:user_id] = 2 |
|
100 | @request.session[:user_id] = 2 | |
101 | xhr :get, :new, :project_id => '1' |
|
101 | xhr :get, :new, :project_id => '1' | |
102 | assert_response :success |
|
102 | assert_response :success | |
103 | assert_template 'new' |
|
103 | assert_template 'new' | |
104 | assert_equal 'text/javascript', response.content_type |
|
104 | assert_equal 'text/javascript', response.content_type | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def test_create |
|
107 | def test_create | |
108 | @request.session[:user_id] = 2 # manager |
|
108 | @request.session[:user_id] = 2 # manager | |
109 | assert_difference 'Version.count' do |
|
109 | assert_difference 'Version.count' do | |
110 | post :create, :project_id => '1', :version => {:name => 'test_add_version'} |
|
110 | post :create, :project_id => '1', :version => {:name => 'test_add_version'} | |
111 | end |
|
111 | end | |
112 | assert_redirected_to '/projects/ecookbook/settings/versions' |
|
112 | assert_redirected_to '/projects/ecookbook/settings/versions' | |
113 | version = Version.find_by_name('test_add_version') |
|
113 | version = Version.find_by_name('test_add_version') | |
114 | assert_not_nil version |
|
114 | assert_not_nil version | |
115 | assert_equal 1, version.project_id |
|
115 | assert_equal 1, version.project_id | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | def test_create_from_issue_form |
|
118 | def test_create_from_issue_form | |
119 | @request.session[:user_id] = 2 |
|
119 | @request.session[:user_id] = 2 | |
120 | assert_difference 'Version.count' do |
|
120 | assert_difference 'Version.count' do | |
121 | xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} |
|
121 | xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} | |
122 | end |
|
122 | end | |
123 | version = Version.find_by_name('test_add_version_from_issue_form') |
|
123 | version = Version.find_by_name('test_add_version_from_issue_form') | |
124 | assert_not_nil version |
|
124 | assert_not_nil version | |
125 | assert_equal 1, version.project_id |
|
125 | assert_equal 1, version.project_id | |
126 |
|
126 | |||
127 | assert_response :success |
|
127 | assert_response :success | |
128 | assert_template 'create' |
|
128 | assert_template 'create' | |
129 | assert_equal 'text/javascript', response.content_type |
|
129 | assert_equal 'text/javascript', response.content_type | |
|
130 | assert_include 'test_add_version_from_issue_form', response.body | |||
130 | end |
|
131 | end | |
131 |
|
132 | |||
132 | def test_create_from_issue_form_with_failure |
|
133 | def test_create_from_issue_form_with_failure | |
133 | @request.session[:user_id] = 2 |
|
134 | @request.session[:user_id] = 2 | |
134 | assert_no_difference 'Version.count' do |
|
135 | assert_no_difference 'Version.count' do | |
135 | xhr :post, :create, :project_id => '1', :version => {:name => ''} |
|
136 | xhr :post, :create, :project_id => '1', :version => {:name => ''} | |
136 | end |
|
137 | end | |
137 | assert_response :success |
|
138 | assert_response :success | |
138 | assert_template 'new' |
|
139 | assert_template 'new' | |
139 | assert_equal 'text/javascript', response.content_type |
|
140 | assert_equal 'text/javascript', response.content_type | |
140 | end |
|
141 | end | |
141 |
|
142 | |||
142 | def test_get_edit |
|
143 | def test_get_edit | |
143 | @request.session[:user_id] = 2 |
|
144 | @request.session[:user_id] = 2 | |
144 | get :edit, :id => 2 |
|
145 | get :edit, :id => 2 | |
145 | assert_response :success |
|
146 | assert_response :success | |
146 | assert_template 'edit' |
|
147 | assert_template 'edit' | |
147 | end |
|
148 | end | |
148 |
|
149 | |||
149 | def test_close_completed |
|
150 | def test_close_completed | |
150 | Version.update_all("status = 'open'") |
|
151 | Version.update_all("status = 'open'") | |
151 | @request.session[:user_id] = 2 |
|
152 | @request.session[:user_id] = 2 | |
152 | put :close_completed, :project_id => 'ecookbook' |
|
153 | put :close_completed, :project_id => 'ecookbook' | |
153 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
154 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
154 | assert_not_nil Version.find_by_status('closed') |
|
155 | assert_not_nil Version.find_by_status('closed') | |
155 | end |
|
156 | end | |
156 |
|
157 | |||
157 | def test_post_update |
|
158 | def test_post_update | |
158 | @request.session[:user_id] = 2 |
|
159 | @request.session[:user_id] = 2 | |
159 | put :update, :id => 2, |
|
160 | put :update, :id => 2, | |
160 | :version => { :name => 'New version name', |
|
161 | :version => { :name => 'New version name', | |
161 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
162 | :effective_date => Date.today.strftime("%Y-%m-%d")} | |
162 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
163 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
163 | version = Version.find(2) |
|
164 | version = Version.find(2) | |
164 | assert_equal 'New version name', version.name |
|
165 | assert_equal 'New version name', version.name | |
165 | assert_equal Date.today, version.effective_date |
|
166 | assert_equal Date.today, version.effective_date | |
166 | end |
|
167 | end | |
167 |
|
168 | |||
168 | def test_post_update_with_validation_failure |
|
169 | def test_post_update_with_validation_failure | |
169 | @request.session[:user_id] = 2 |
|
170 | @request.session[:user_id] = 2 | |
170 | put :update, :id => 2, |
|
171 | put :update, :id => 2, | |
171 | :version => { :name => '', |
|
172 | :version => { :name => '', | |
172 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
173 | :effective_date => Date.today.strftime("%Y-%m-%d")} | |
173 | assert_response :success |
|
174 | assert_response :success | |
174 | assert_template 'edit' |
|
175 | assert_template 'edit' | |
175 | end |
|
176 | end | |
176 |
|
177 | |||
177 | def test_destroy |
|
178 | def test_destroy | |
178 | @request.session[:user_id] = 2 |
|
179 | @request.session[:user_id] = 2 | |
179 | assert_difference 'Version.count', -1 do |
|
180 | assert_difference 'Version.count', -1 do | |
180 | delete :destroy, :id => 3 |
|
181 | delete :destroy, :id => 3 | |
181 | end |
|
182 | end | |
182 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
183 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
183 | assert_nil Version.find_by_id(3) |
|
184 | assert_nil Version.find_by_id(3) | |
184 | end |
|
185 | end | |
185 |
|
186 | |||
186 | def test_destroy_version_in_use_should_fail |
|
187 | def test_destroy_version_in_use_should_fail | |
187 | @request.session[:user_id] = 2 |
|
188 | @request.session[:user_id] = 2 | |
188 | assert_no_difference 'Version.count' do |
|
189 | assert_no_difference 'Version.count' do | |
189 | delete :destroy, :id => 2 |
|
190 | delete :destroy, :id => 2 | |
190 | end |
|
191 | end | |
191 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
192 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
192 | assert flash[:error].match(/Unable to delete version/) |
|
193 | assert flash[:error].match(/Unable to delete version/) | |
193 | assert Version.find_by_id(2) |
|
194 | assert Version.find_by_id(2) | |
194 | end |
|
195 | end | |
195 |
|
196 | |||
196 | def test_issue_status_by |
|
197 | def test_issue_status_by | |
197 | xhr :get, :status_by, :id => 2 |
|
198 | xhr :get, :status_by, :id => 2 | |
198 | assert_response :success |
|
199 | assert_response :success | |
199 | assert_template 'status_by' |
|
200 | assert_template 'status_by' | |
200 | assert_template '_issue_counts' |
|
201 | assert_template '_issue_counts' | |
201 | end |
|
202 | end | |
202 |
|
203 | |||
203 | def test_issue_status_by_status |
|
204 | def test_issue_status_by_status | |
204 | xhr :get, :status_by, :id => 2, :status_by => 'status' |
|
205 | xhr :get, :status_by, :id => 2, :status_by => 'status' | |
205 | assert_response :success |
|
206 | assert_response :success | |
206 | assert_template 'status_by' |
|
207 | assert_template 'status_by' | |
207 | assert_template '_issue_counts' |
|
208 | assert_template '_issue_counts' | |
208 | assert_include 'Assigned', response.body |
|
209 | assert_include 'Assigned', response.body | |
209 | assert_include 'Closed', response.body |
|
210 | assert_include 'Closed', response.body | |
210 | end |
|
211 | end | |
211 | end |
|
212 | end |
@@ -1,77 +1,77 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class ProjectsHelperTest < ActionView::TestCase |
|
20 | class ProjectsHelperTest < ActionView::TestCase | |
21 | include ApplicationHelper |
|
21 | include ApplicationHelper | |
22 | include ProjectsHelper |
|
22 | include ProjectsHelper | |
23 | include ERB::Util |
|
23 | include ERB::Util | |
24 |
|
24 | |||
25 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
25 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
26 | :enumerations, :users, :issue_categories, |
|
26 | :enumerations, :users, :issue_categories, | |
27 | :versions, |
|
27 | :versions, | |
28 | :projects_trackers, |
|
28 | :projects_trackers, | |
29 | :member_roles, |
|
29 | :member_roles, | |
30 | :members, |
|
30 | :members, | |
31 | :groups_users, |
|
31 | :groups_users, | |
32 | :enabled_modules, |
|
32 | :enabled_modules, | |
33 | :workflows |
|
33 | :workflows | |
34 |
|
34 | |||
35 | def setup |
|
35 | def setup | |
36 | super |
|
36 | super | |
37 | set_language_if_valid('en') |
|
37 | set_language_if_valid('en') | |
38 | User.current = nil |
|
38 | User.current = nil | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def test_link_to_version_within_project |
|
41 | def test_link_to_version_within_project | |
42 | @project = Project.find(2) |
|
42 | @project = Project.find(2) | |
43 | User.current = User.find(1) |
|
43 | User.current = User.find(1) | |
44 | assert_equal '<a href="/versions/5">Alpha</a>', link_to_version(Version.find(5)) |
|
44 | assert_equal '<a href="/versions/5">Alpha</a>', link_to_version(Version.find(5)) | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def test_link_to_version |
|
47 | def test_link_to_version | |
48 | User.current = User.find(1) |
|
48 | User.current = User.find(1) | |
49 | assert_equal '<a href="/versions/5">OnlineStore - Alpha</a>', link_to_version(Version.find(5)) |
|
49 | assert_equal '<a href="/versions/5">OnlineStore - Alpha</a>', link_to_version(Version.find(5)) | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_link_to_private_version |
|
52 | def test_link_to_private_version | |
53 | assert_equal 'OnlineStore - Alpha', link_to_version(Version.find(5)) |
|
53 | assert_equal 'OnlineStore - Alpha', link_to_version(Version.find(5)) | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def test_link_to_version_invalid_version |
|
56 | def test_link_to_version_invalid_version | |
57 | assert_equal '', link_to_version(Object) |
|
57 | assert_equal '', link_to_version(Object) | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def test_format_version_name_within_project |
|
60 | def test_format_version_name_within_project | |
61 | @project = Project.find(1) |
|
61 | @project = Project.find(1) | |
62 | assert_equal "0.1", format_version_name(Version.find(1)) |
|
62 | assert_equal "0.1", format_version_name(Version.find(1)) | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def test_format_version_name |
|
65 | def test_format_version_name | |
66 | assert_equal "eCookbook - 0.1", format_version_name(Version.find(1)) |
|
66 | assert_equal "eCookbook - 0.1", format_version_name(Version.find(1)) | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def test_format_version_name_for_system_version |
|
69 | def test_format_version_name_for_system_version | |
70 | assert_equal "OnlineStore - Systemwide visible version", format_version_name(Version.find(7)) |
|
70 | assert_equal "OnlineStore - Systemwide visible version", format_version_name(Version.find(7)) | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def test_version_options_for_select_with_no_versions |
|
73 | def test_version_options_for_select_with_no_versions | |
74 | assert_equal '', version_options_for_select([]) |
|
74 | assert_equal '', version_options_for_select([]) | |
75 |
assert_equal ' |
|
75 | assert_equal '', version_options_for_select([], Version.find(1)) | |
76 | end |
|
76 | end | |
77 | end |
|
77 | end |
General Comments 0
You need to be logged in to leave comments.
Login now