@@ -1,48 +1,56 | |||||
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 VersionsHelper |
|
20 | module VersionsHelper | |
21 |
|
21 | |||
|
22 | def version_anchor(version) | |||
|
23 | if @project == version.project | |||
|
24 | anchor version.name | |||
|
25 | else | |||
|
26 | anchor "#{version.project.try(:identifier)}-#{version.name}" | |||
|
27 | end | |||
|
28 | end | |||
|
29 | ||||
22 | STATUS_BY_CRITERIAS = %w(tracker status priority author assigned_to category) |
|
30 | STATUS_BY_CRITERIAS = %w(tracker status priority author assigned_to category) | |
23 |
|
31 | |||
24 | def render_issue_status_by(version, criteria) |
|
32 | def render_issue_status_by(version, criteria) | |
25 | criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria) |
|
33 | criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria) | |
26 |
|
34 | |||
27 | h = Hash.new {|k,v| k[v] = [0, 0]} |
|
35 | h = Hash.new {|k,v| k[v] = [0, 0]} | |
28 | begin |
|
36 | begin | |
29 | # Total issue count |
|
37 | # Total issue count | |
30 | Issue.count(:group => criteria, |
|
38 | Issue.count(:group => criteria, | |
31 | :conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s} |
|
39 | :conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s} | |
32 | # Open issues count |
|
40 | # Open issues count | |
33 | Issue.count(:group => criteria, |
|
41 | Issue.count(:group => criteria, | |
34 | :include => :status, |
|
42 | :include => :status, | |
35 | :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s} |
|
43 | :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s} | |
36 | rescue ActiveRecord::RecordNotFound |
|
44 | rescue ActiveRecord::RecordNotFound | |
37 | # When grouping by an association, Rails throws this exception if there's no result (bug) |
|
45 | # When grouping by an association, Rails throws this exception if there's no result (bug) | |
38 | end |
|
46 | end | |
39 | counts = h.keys.compact.sort.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}} |
|
47 | counts = h.keys.compact.sort.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}} | |
40 | max = counts.collect {|c| c[:total]}.max |
|
48 | max = counts.collect {|c| c[:total]}.max | |
41 |
|
49 | |||
42 | render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max} |
|
50 | render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max} | |
43 | end |
|
51 | end | |
44 |
|
52 | |||
45 | def status_by_options_for_select(value) |
|
53 | def status_by_options_for_select(value) | |
46 | options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value) |
|
54 | options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value) | |
47 | end |
|
55 | end | |
48 | end |
|
56 | end |
@@ -1,68 +1,68 | |||||
1 | <div class="contextual"> |
|
1 | <div class="contextual"> | |
2 | <%= link_to l(:label_version_new), new_project_version_path(@project), :class => 'icon icon-add' if User.current.allowed_to?(:manage_versions, @project) %> |
|
2 | <%= link_to l(:label_version_new), new_project_version_path(@project), :class => 'icon icon-add' if User.current.allowed_to?(:manage_versions, @project) %> | |
3 | </div> |
|
3 | </div> | |
4 |
|
4 | |||
5 | <h2><%=l(:label_roadmap)%></h2> |
|
5 | <h2><%=l(:label_roadmap)%></h2> | |
6 |
|
6 | |||
7 | <% if @versions.empty? %> |
|
7 | <% if @versions.empty? %> | |
8 | <p class="nodata"><%= l(:label_no_data) %></p> |
|
8 | <p class="nodata"><%= l(:label_no_data) %></p> | |
9 | <% else %> |
|
9 | <% else %> | |
10 | <div id="roadmap"> |
|
10 | <div id="roadmap"> | |
11 | <% @versions.each do |version| %> |
|
11 | <% @versions.each do |version| %> | |
12 |
<h3 class="version"><%= link_to_version version, :name => anchor(version |
|
12 | <h3 class="version"><%= link_to_version version, :name => version_anchor(version) %></h3> | |
13 | <%= render :partial => 'versions/overview', :locals => {:version => version} %> |
|
13 | <%= render :partial => 'versions/overview', :locals => {:version => version} %> | |
14 | <%= render(:partial => "wiki/content", :locals => {:content => version.wiki_page.content}) if version.wiki_page %> |
|
14 | <%= render(:partial => "wiki/content", :locals => {:content => version.wiki_page.content}) if version.wiki_page %> | |
15 |
|
15 | |||
16 | <% if (issues = @issues_by_version[version]) && issues.size > 0 %> |
|
16 | <% if (issues = @issues_by_version[version]) && issues.size > 0 %> | |
17 | <%= form_tag({}) do -%> |
|
17 | <%= form_tag({}) do -%> | |
18 | <table class="list related-issues"> |
|
18 | <table class="list related-issues"> | |
19 | <caption><%= l(:label_related_issues) %></caption> |
|
19 | <caption><%= l(:label_related_issues) %></caption> | |
20 | <% issues.each do |issue| -%> |
|
20 | <% issues.each do |issue| -%> | |
21 | <tr class="hascontextmenu"> |
|
21 | <tr class="hascontextmenu"> | |
22 | <td class="checkbox"><%= check_box_tag 'ids[]', issue.id, false, :id => nil %></td> |
|
22 | <td class="checkbox"><%= check_box_tag 'ids[]', issue.id, false, :id => nil %></td> | |
23 | <td><%= link_to_issue(issue, :project => (@project != issue.project)) %></td> |
|
23 | <td><%= link_to_issue(issue, :project => (@project != issue.project)) %></td> | |
24 | </tr> |
|
24 | </tr> | |
25 | <% end -%> |
|
25 | <% end -%> | |
26 | </table> |
|
26 | </table> | |
27 | <% end %> |
|
27 | <% end %> | |
28 | <% end %> |
|
28 | <% end %> | |
29 | <%= call_hook :view_projects_roadmap_version_bottom, :version => version %> |
|
29 | <%= call_hook :view_projects_roadmap_version_bottom, :version => version %> | |
30 | <% end %> |
|
30 | <% end %> | |
31 | </div> |
|
31 | </div> | |
32 | <% end %> |
|
32 | <% end %> | |
33 |
|
33 | |||
34 | <% content_for :sidebar do %> |
|
34 | <% content_for :sidebar do %> | |
35 | <%= form_tag({}, :method => :get) do %> |
|
35 | <%= form_tag({}, :method => :get) do %> | |
36 | <h3><%= l(:label_roadmap) %></h3> |
|
36 | <h3><%= l(:label_roadmap) %></h3> | |
37 | <% @trackers.each do |tracker| %> |
|
37 | <% @trackers.each do |tracker| %> | |
38 | <label><%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s), :id => nil %> |
|
38 | <label><%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s), :id => nil %> | |
39 | <%=h tracker.name %></label><br /> |
|
39 | <%=h tracker.name %></label><br /> | |
40 | <% end %> |
|
40 | <% end %> | |
41 | <br /> |
|
41 | <br /> | |
42 | <label for="completed"><%= check_box_tag "completed", 1, params[:completed] %> <%= l(:label_show_completed_versions) %></label> |
|
42 | <label for="completed"><%= check_box_tag "completed", 1, params[:completed] %> <%= l(:label_show_completed_versions) %></label> | |
43 | <% if @project.descendants.active.any? %> |
|
43 | <% if @project.descendants.active.any? %> | |
44 | <%= hidden_field_tag 'with_subprojects', 0 %> |
|
44 | <%= hidden_field_tag 'with_subprojects', 0 %> | |
45 | <br /><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label> |
|
45 | <br /><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label> | |
46 | <% end %> |
|
46 | <% end %> | |
47 | <p><%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %></p> |
|
47 | <p><%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %></p> | |
48 | <% end %> |
|
48 | <% end %> | |
49 |
|
49 | |||
50 | <h3><%= l(:label_version_plural) %></h3> |
|
50 | <h3><%= l(:label_version_plural) %></h3> | |
51 | <% @versions.each do |version| %> |
|
51 | <% @versions.each do |version| %> | |
52 |
<%= link_to format_version_name(version), "##{anchor(version |
|
52 | <%= link_to format_version_name(version), "##{version_anchor(version)}" %><br /> | |
53 | <% end %> |
|
53 | <% end %> | |
54 | <% if @completed_versions.present? %> |
|
54 | <% if @completed_versions.present? %> | |
55 | <p> |
|
55 | <p> | |
56 | <%= link_to_function l(:label_completed_versions), |
|
56 | <%= link_to_function l(:label_completed_versions), | |
57 | '$("#toggle-completed-versions").toggleClass("collapsed"); $("#completed-versions").toggle()', |
|
57 | '$("#toggle-completed-versions").toggleClass("collapsed"); $("#completed-versions").toggle()', | |
58 | :id => 'toggle-completed-versions', :class => 'collapsible collapsed' %><br /> |
|
58 | :id => 'toggle-completed-versions', :class => 'collapsible collapsed' %><br /> | |
59 | <span id="completed-versions" style="display:none;"> |
|
59 | <span id="completed-versions" style="display:none;"> | |
60 | <%= @completed_versions.map {|version| link_to format_version_name(version), version_path(version)}.join("<br />\n").html_safe %> |
|
60 | <%= @completed_versions.map {|version| link_to format_version_name(version), version_path(version)}.join("<br />\n").html_safe %> | |
61 | </span> |
|
61 | </span> | |
62 | </p> |
|
62 | </p> | |
63 | <% end %> |
|
63 | <% end %> | |
64 | <% end %> |
|
64 | <% end %> | |
65 |
|
65 | |||
66 | <% html_title(l(:label_roadmap)) %> |
|
66 | <% html_title(l(:label_roadmap)) %> | |
67 |
|
67 | |||
68 | <%= context_menu issues_context_menu_path %> |
|
68 | <%= context_menu issues_context_menu_path %> |
@@ -1,212 +1,226 | |||||
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_index_should_prepend_shared_versions | |||
|
84 | get :index, :project_id => 1 | |||
|
85 | assert_response :success | |||
|
86 | ||||
|
87 | assert_select '#sidebar' do | |||
|
88 | assert_select 'a[href=?]', '#2.0', :text => '2.0' | |||
|
89 | assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0' | |||
|
90 | end | |||
|
91 | assert_select '#content' do | |||
|
92 | assert_select 'a[name=?]', '2.0', :text => '2.0' | |||
|
93 | assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0' | |||
|
94 | end | |||
|
95 | end | |||
|
96 | ||||
83 | def test_show |
|
97 | def test_show | |
84 | get :show, :id => 2 |
|
98 | get :show, :id => 2 | |
85 | assert_response :success |
|
99 | assert_response :success | |
86 | assert_template 'show' |
|
100 | assert_template 'show' | |
87 | assert_not_nil assigns(:version) |
|
101 | assert_not_nil assigns(:version) | |
88 |
|
102 | |||
89 | assert_tag :tag => 'h2', :content => /1.0/ |
|
103 | assert_tag :tag => 'h2', :content => /1.0/ | |
90 | end |
|
104 | end | |
91 |
|
105 | |||
92 | def test_new |
|
106 | def test_new | |
93 | @request.session[:user_id] = 2 |
|
107 | @request.session[:user_id] = 2 | |
94 | get :new, :project_id => '1' |
|
108 | get :new, :project_id => '1' | |
95 | assert_response :success |
|
109 | assert_response :success | |
96 | assert_template 'new' |
|
110 | assert_template 'new' | |
97 | end |
|
111 | end | |
98 |
|
112 | |||
99 | def test_new_from_issue_form |
|
113 | def test_new_from_issue_form | |
100 | @request.session[:user_id] = 2 |
|
114 | @request.session[:user_id] = 2 | |
101 | xhr :get, :new, :project_id => '1' |
|
115 | xhr :get, :new, :project_id => '1' | |
102 | assert_response :success |
|
116 | assert_response :success | |
103 | assert_template 'new' |
|
117 | assert_template 'new' | |
104 | assert_equal 'text/javascript', response.content_type |
|
118 | assert_equal 'text/javascript', response.content_type | |
105 | end |
|
119 | end | |
106 |
|
120 | |||
107 | def test_create |
|
121 | def test_create | |
108 | @request.session[:user_id] = 2 # manager |
|
122 | @request.session[:user_id] = 2 # manager | |
109 | assert_difference 'Version.count' do |
|
123 | assert_difference 'Version.count' do | |
110 | post :create, :project_id => '1', :version => {:name => 'test_add_version'} |
|
124 | post :create, :project_id => '1', :version => {:name => 'test_add_version'} | |
111 | end |
|
125 | end | |
112 | assert_redirected_to '/projects/ecookbook/settings/versions' |
|
126 | assert_redirected_to '/projects/ecookbook/settings/versions' | |
113 | version = Version.find_by_name('test_add_version') |
|
127 | version = Version.find_by_name('test_add_version') | |
114 | assert_not_nil version |
|
128 | assert_not_nil version | |
115 | assert_equal 1, version.project_id |
|
129 | assert_equal 1, version.project_id | |
116 | end |
|
130 | end | |
117 |
|
131 | |||
118 | def test_create_from_issue_form |
|
132 | def test_create_from_issue_form | |
119 | @request.session[:user_id] = 2 |
|
133 | @request.session[:user_id] = 2 | |
120 | assert_difference 'Version.count' do |
|
134 | assert_difference 'Version.count' do | |
121 | xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} |
|
135 | xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} | |
122 | end |
|
136 | end | |
123 | version = Version.find_by_name('test_add_version_from_issue_form') |
|
137 | version = Version.find_by_name('test_add_version_from_issue_form') | |
124 | assert_not_nil version |
|
138 | assert_not_nil version | |
125 | assert_equal 1, version.project_id |
|
139 | assert_equal 1, version.project_id | |
126 |
|
140 | |||
127 | assert_response :success |
|
141 | assert_response :success | |
128 | assert_template 'create' |
|
142 | assert_template 'create' | |
129 | assert_equal 'text/javascript', response.content_type |
|
143 | assert_equal 'text/javascript', response.content_type | |
130 | assert_include 'test_add_version_from_issue_form', response.body |
|
144 | assert_include 'test_add_version_from_issue_form', response.body | |
131 | end |
|
145 | end | |
132 |
|
146 | |||
133 | def test_create_from_issue_form_with_failure |
|
147 | def test_create_from_issue_form_with_failure | |
134 | @request.session[:user_id] = 2 |
|
148 | @request.session[:user_id] = 2 | |
135 | assert_no_difference 'Version.count' do |
|
149 | assert_no_difference 'Version.count' do | |
136 | xhr :post, :create, :project_id => '1', :version => {:name => ''} |
|
150 | xhr :post, :create, :project_id => '1', :version => {:name => ''} | |
137 | end |
|
151 | end | |
138 | assert_response :success |
|
152 | assert_response :success | |
139 | assert_template 'new' |
|
153 | assert_template 'new' | |
140 | assert_equal 'text/javascript', response.content_type |
|
154 | assert_equal 'text/javascript', response.content_type | |
141 | end |
|
155 | end | |
142 |
|
156 | |||
143 | def test_get_edit |
|
157 | def test_get_edit | |
144 | @request.session[:user_id] = 2 |
|
158 | @request.session[:user_id] = 2 | |
145 | get :edit, :id => 2 |
|
159 | get :edit, :id => 2 | |
146 | assert_response :success |
|
160 | assert_response :success | |
147 | assert_template 'edit' |
|
161 | assert_template 'edit' | |
148 | end |
|
162 | end | |
149 |
|
163 | |||
150 | def test_close_completed |
|
164 | def test_close_completed | |
151 | Version.update_all("status = 'open'") |
|
165 | Version.update_all("status = 'open'") | |
152 | @request.session[:user_id] = 2 |
|
166 | @request.session[:user_id] = 2 | |
153 | put :close_completed, :project_id => 'ecookbook' |
|
167 | put :close_completed, :project_id => 'ecookbook' | |
154 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
168 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
155 | assert_not_nil Version.find_by_status('closed') |
|
169 | assert_not_nil Version.find_by_status('closed') | |
156 | end |
|
170 | end | |
157 |
|
171 | |||
158 | def test_post_update |
|
172 | def test_post_update | |
159 | @request.session[:user_id] = 2 |
|
173 | @request.session[:user_id] = 2 | |
160 | put :update, :id => 2, |
|
174 | put :update, :id => 2, | |
161 | :version => { :name => 'New version name', |
|
175 | :version => { :name => 'New version name', | |
162 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
176 | :effective_date => Date.today.strftime("%Y-%m-%d")} | |
163 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
177 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
164 | version = Version.find(2) |
|
178 | version = Version.find(2) | |
165 | assert_equal 'New version name', version.name |
|
179 | assert_equal 'New version name', version.name | |
166 | assert_equal Date.today, version.effective_date |
|
180 | assert_equal Date.today, version.effective_date | |
167 | end |
|
181 | end | |
168 |
|
182 | |||
169 | def test_post_update_with_validation_failure |
|
183 | def test_post_update_with_validation_failure | |
170 | @request.session[:user_id] = 2 |
|
184 | @request.session[:user_id] = 2 | |
171 | put :update, :id => 2, |
|
185 | put :update, :id => 2, | |
172 | :version => { :name => '', |
|
186 | :version => { :name => '', | |
173 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
187 | :effective_date => Date.today.strftime("%Y-%m-%d")} | |
174 | assert_response :success |
|
188 | assert_response :success | |
175 | assert_template 'edit' |
|
189 | assert_template 'edit' | |
176 | end |
|
190 | end | |
177 |
|
191 | |||
178 | def test_destroy |
|
192 | def test_destroy | |
179 | @request.session[:user_id] = 2 |
|
193 | @request.session[:user_id] = 2 | |
180 | assert_difference 'Version.count', -1 do |
|
194 | assert_difference 'Version.count', -1 do | |
181 | delete :destroy, :id => 3 |
|
195 | delete :destroy, :id => 3 | |
182 | end |
|
196 | end | |
183 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
197 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
184 | assert_nil Version.find_by_id(3) |
|
198 | assert_nil Version.find_by_id(3) | |
185 | end |
|
199 | end | |
186 |
|
200 | |||
187 | def test_destroy_version_in_use_should_fail |
|
201 | def test_destroy_version_in_use_should_fail | |
188 | @request.session[:user_id] = 2 |
|
202 | @request.session[:user_id] = 2 | |
189 | assert_no_difference 'Version.count' do |
|
203 | assert_no_difference 'Version.count' do | |
190 | delete :destroy, :id => 2 |
|
204 | delete :destroy, :id => 2 | |
191 | end |
|
205 | end | |
192 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
206 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
193 | assert flash[:error].match(/Unable to delete version/) |
|
207 | assert flash[:error].match(/Unable to delete version/) | |
194 | assert Version.find_by_id(2) |
|
208 | assert Version.find_by_id(2) | |
195 | end |
|
209 | end | |
196 |
|
210 | |||
197 | def test_issue_status_by |
|
211 | def test_issue_status_by | |
198 | xhr :get, :status_by, :id => 2 |
|
212 | xhr :get, :status_by, :id => 2 | |
199 | assert_response :success |
|
213 | assert_response :success | |
200 | assert_template 'status_by' |
|
214 | assert_template 'status_by' | |
201 | assert_template '_issue_counts' |
|
215 | assert_template '_issue_counts' | |
202 | end |
|
216 | end | |
203 |
|
217 | |||
204 | def test_issue_status_by_status |
|
218 | def test_issue_status_by_status | |
205 | xhr :get, :status_by, :id => 2, :status_by => 'status' |
|
219 | xhr :get, :status_by, :id => 2, :status_by => 'status' | |
206 | assert_response :success |
|
220 | assert_response :success | |
207 | assert_template 'status_by' |
|
221 | assert_template 'status_by' | |
208 | assert_template '_issue_counts' |
|
222 | assert_template '_issue_counts' | |
209 | assert_include 'Assigned', response.body |
|
223 | assert_include 'Assigned', response.body | |
210 | assert_include 'Closed', response.body |
|
224 | assert_include 'Closed', response.body | |
211 | end |
|
225 | end | |
212 | end |
|
226 | end |
General Comments 0
You need to be logged in to leave comments.
Login now