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