##// END OF EJS Templates
Shorten query[column_names] param name....
Jean-Philippe Lang -
r5184:3c06f66d716c
parent child
Show More
@@ -1,77 +1,80
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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 class QueriesController < ApplicationController
18 class QueriesController < ApplicationController
19 menu_item :issues
19 menu_item :issues
20 before_filter :find_query, :except => :new
20 before_filter :find_query, :except => :new
21 before_filter :find_optional_project, :only => :new
21 before_filter :find_optional_project, :only => :new
22
22
23 def new
23 def new
24 @query = Query.new(params[:query])
24 @query = Query.new(params[:query])
25 @query.project = params[:query_is_for_all] ? nil : @project
25 @query.project = params[:query_is_for_all] ? nil : @project
26 @query.user = User.current
26 @query.user = User.current
27 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
27 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
28 @query.column_names = nil if params[:default_columns]
29
28
30 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f]
29 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f]
31 @query.group_by ||= params[:group_by]
30 @query.group_by ||= params[:group_by]
31 @query.column_names = params[:c] if params[:c]
32 @query.column_names = nil if params[:default_columns]
32
33
33 if request.post? && params[:confirm] && @query.save
34 if request.post? && params[:confirm] && @query.save
34 flash[:notice] = l(:notice_successful_create)
35 flash[:notice] = l(:notice_successful_create)
35 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
36 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
36 return
37 return
37 end
38 end
38 render :layout => false if request.xhr?
39 render :layout => false if request.xhr?
39 end
40 end
40
41
41 def edit
42 def edit
42 if request.post?
43 if request.post?
43 @query.filters = {}
44 @query.filters = {}
44 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f]
45 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f]
45 @query.attributes = params[:query]
46 @query.attributes = params[:query]
46 @query.project = nil if params[:query_is_for_all]
47 @query.project = nil if params[:query_is_for_all]
47 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
48 @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
49 @query.group_by ||= params[:group_by]
50 @query.column_names = params[:c] if params[:c]
48 @query.column_names = nil if params[:default_columns]
51 @query.column_names = nil if params[:default_columns]
49
52
50 if @query.save
53 if @query.save
51 flash[:notice] = l(:notice_successful_update)
54 flash[:notice] = l(:notice_successful_update)
52 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
55 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
53 end
56 end
54 end
57 end
55 end
58 end
56
59
57 def destroy
60 def destroy
58 @query.destroy if request.post?
61 @query.destroy if request.post?
59 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
62 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
60 end
63 end
61
64
62 private
65 private
63 def find_query
66 def find_query
64 @query = Query.find(params[:id])
67 @query = Query.find(params[:id])
65 @project = @query.project
68 @project = @query.project
66 render_403 unless @query.editable_by?(User.current)
69 render_403 unless @query.editable_by?(User.current)
67 rescue ActiveRecord::RecordNotFound
70 rescue ActiveRecord::RecordNotFound
68 render_404
71 render_404
69 end
72 end
70
73
71 def find_optional_project
74 def find_optional_project
72 @project = Project.find(params[:project_id]) if params[:project_id]
75 @project = Project.find(params[:project_id]) if params[:project_id]
73 render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
76 render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true)
74 rescue ActiveRecord::RecordNotFound
77 rescue ActiveRecord::RecordNotFound
75 render_404
78 render_404
76 end
79 end
77 end
80 end
@@ -1,99 +1,99
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 module QueriesHelper
18 module QueriesHelper
19
19
20 def operators_for_select(filter_type)
20 def operators_for_select(filter_type)
21 Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]}
21 Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]}
22 end
22 end
23
23
24 def column_header(column)
24 def column_header(column)
25 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
25 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
26 :default_order => column.default_order) :
26 :default_order => column.default_order) :
27 content_tag('th', column.caption)
27 content_tag('th', column.caption)
28 end
28 end
29
29
30 def column_content(column, issue)
30 def column_content(column, issue)
31 value = column.value(issue)
31 value = column.value(issue)
32
32
33 case value.class.name
33 case value.class.name
34 when 'String'
34 when 'String'
35 if column.name == :subject
35 if column.name == :subject
36 link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
36 link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
37 else
37 else
38 h(value)
38 h(value)
39 end
39 end
40 when 'Time'
40 when 'Time'
41 format_time(value)
41 format_time(value)
42 when 'Date'
42 when 'Date'
43 format_date(value)
43 format_date(value)
44 when 'Fixnum', 'Float'
44 when 'Fixnum', 'Float'
45 if column.name == :done_ratio
45 if column.name == :done_ratio
46 progress_bar(value, :width => '80px')
46 progress_bar(value, :width => '80px')
47 else
47 else
48 value.to_s
48 value.to_s
49 end
49 end
50 when 'User'
50 when 'User'
51 link_to_user value
51 link_to_user value
52 when 'Project'
52 when 'Project'
53 link_to_project value
53 link_to_project value
54 when 'Version'
54 when 'Version'
55 link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
55 link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
56 when 'TrueClass'
56 when 'TrueClass'
57 l(:general_text_Yes)
57 l(:general_text_Yes)
58 when 'FalseClass'
58 when 'FalseClass'
59 l(:general_text_No)
59 l(:general_text_No)
60 when 'Issue'
60 when 'Issue'
61 link_to_issue(value, :subject => false)
61 link_to_issue(value, :subject => false)
62 else
62 else
63 h(value)
63 h(value)
64 end
64 end
65 end
65 end
66
66
67 # Retrieve query from session or build a new query
67 # Retrieve query from session or build a new query
68 def retrieve_query
68 def retrieve_query
69 if !params[:query_id].blank?
69 if !params[:query_id].blank?
70 cond = "project_id IS NULL"
70 cond = "project_id IS NULL"
71 cond << " OR project_id = #{@project.id}" if @project
71 cond << " OR project_id = #{@project.id}" if @project
72 @query = Query.find(params[:query_id], :conditions => cond)
72 @query = Query.find(params[:query_id], :conditions => cond)
73 @query.project = @project
73 @query.project = @project
74 session[:query] = {:id => @query.id, :project_id => @query.project_id}
74 session[:query] = {:id => @query.id, :project_id => @query.project_id}
75 sort_clear
75 sort_clear
76 else
76 else
77 if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
77 if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
78 # Give it a name, required to be valid
78 # Give it a name, required to be valid
79 @query = Query.new(:name => "_")
79 @query = Query.new(:name => "_")
80 @query.project = @project
80 @query.project = @project
81 if params[:fields] || params[:f]
81 if params[:fields] || params[:f]
82 @query.filters = {}
82 @query.filters = {}
83 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
83 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
84 else
84 else
85 @query.available_filters.keys.each do |field|
85 @query.available_filters.keys.each do |field|
86 @query.add_short_filter(field, params[field]) if params[field]
86 @query.add_short_filter(field, params[field]) if params[field]
87 end
87 end
88 end
88 end
89 @query.group_by = params[:group_by]
89 @query.group_by = params[:group_by]
90 @query.column_names = params[:query] && params[:query][:column_names]
90 @query.column_names = params[:c] || (params[:query] && params[:query][:column_names])
91 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
91 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
92 else
92 else
93 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
93 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
94 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
94 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
95 @query.project = @project
95 @query.project = @project
96 end
96 end
97 end
97 end
98 end
98 end
99 end
99 end
@@ -1,26 +1,26
1 <table style="border-collapse: collapse; border:0;">
1 <table style="border-collapse: collapse; border:0;">
2 <tr>
2 <tr>
3 <td style="padding-left:0"><%= select_tag 'available_columns',
3 <td style="padding-left:0"><%= select_tag 'available_columns',
4 options_for_select((query.available_columns - query.columns).collect {|column| [column.caption, column.name]}),
4 options_for_select((query.available_columns - query.columns).collect {|column| [column.caption, column.name]}),
5 :multiple => true, :size => 10, :style => "width:150px" %>
5 :multiple => true, :size => 10, :style => "width:150px" %>
6 </td>
6 </td>
7 <td align="center" valign="middle">
7 <td align="center" valign="middle">
8 <input type="button" value="&#8594;"
8 <input type="button" value="&#8594;"
9 onclick="moveOptions(this.form.available_columns, this.form.selected_columns);" /><br />
9 onclick="moveOptions(this.form.available_columns, this.form.selected_columns);" /><br />
10 <input type="button" value="&#8592;"
10 <input type="button" value="&#8592;"
11 onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" />
11 onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" />
12 </td>
12 </td>
13 <td><%= select_tag 'query[column_names][]',
13 <td><%= select_tag 'c[]',
14 options_for_select(query.columns.collect {|column| [column.caption, column.name]}),
14 options_for_select(query.columns.collect {|column| [column.caption, column.name]}),
15 :id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px" %>
15 :id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px" %>
16 </td>
16 </td>
17 <td align="center" valign="middle">
17 <td align="center" valign="middle">
18 <input type="button" value="&#8593;" onclick="moveOptionUp(this.form.selected_columns);" /><br />
18 <input type="button" value="&#8593;" onclick="moveOptionUp(this.form.selected_columns);" /><br />
19 <input type="button" value="&#8595;" onclick="moveOptionDown(this.form.selected_columns);" />
19 <input type="button" value="&#8595;" onclick="moveOptionDown(this.form.selected_columns);" />
20 </td>
20 </td>
21 </tr>
21 </tr>
22 </table>
22 </table>
23
23
24 <% content_for :header_tags do %>
24 <% content_for :header_tags do %>
25 <%= javascript_include_tag 'select_list_move' %>
25 <%= javascript_include_tag 'select_list_move' %>
26 <% end %>
26 <% end %>
@@ -1,1344 +1,1344
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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 'issues_controller'
19 require 'issues_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class IssuesController; def rescue_action(e) raise e end; end
22 class IssuesController; def rescue_action(e) raise e end; end
23
23
24 class IssuesControllerTest < ActionController::TestCase
24 class IssuesControllerTest < ActionController::TestCase
25 fixtures :projects,
25 fixtures :projects,
26 :users,
26 :users,
27 :roles,
27 :roles,
28 :members,
28 :members,
29 :member_roles,
29 :member_roles,
30 :issues,
30 :issues,
31 :issue_statuses,
31 :issue_statuses,
32 :versions,
32 :versions,
33 :trackers,
33 :trackers,
34 :projects_trackers,
34 :projects_trackers,
35 :issue_categories,
35 :issue_categories,
36 :enabled_modules,
36 :enabled_modules,
37 :enumerations,
37 :enumerations,
38 :attachments,
38 :attachments,
39 :workflows,
39 :workflows,
40 :custom_fields,
40 :custom_fields,
41 :custom_values,
41 :custom_values,
42 :custom_fields_projects,
42 :custom_fields_projects,
43 :custom_fields_trackers,
43 :custom_fields_trackers,
44 :time_entries,
44 :time_entries,
45 :journals,
45 :journals,
46 :journal_details,
46 :journal_details,
47 :queries
47 :queries
48
48
49 def setup
49 def setup
50 @controller = IssuesController.new
50 @controller = IssuesController.new
51 @request = ActionController::TestRequest.new
51 @request = ActionController::TestRequest.new
52 @response = ActionController::TestResponse.new
52 @response = ActionController::TestResponse.new
53 User.current = nil
53 User.current = nil
54 end
54 end
55
55
56 def test_index
56 def test_index
57 Setting.default_language = 'en'
57 Setting.default_language = 'en'
58
58
59 get :index
59 get :index
60 assert_response :success
60 assert_response :success
61 assert_template 'index.rhtml'
61 assert_template 'index.rhtml'
62 assert_not_nil assigns(:issues)
62 assert_not_nil assigns(:issues)
63 assert_nil assigns(:project)
63 assert_nil assigns(:project)
64 assert_tag :tag => 'a', :content => /Can't print recipes/
64 assert_tag :tag => 'a', :content => /Can't print recipes/
65 assert_tag :tag => 'a', :content => /Subproject issue/
65 assert_tag :tag => 'a', :content => /Subproject issue/
66 # private projects hidden
66 # private projects hidden
67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
69 # project column
69 # project column
70 assert_tag :tag => 'th', :content => /Project/
70 assert_tag :tag => 'th', :content => /Project/
71 end
71 end
72
72
73 def test_index_should_not_list_issues_when_module_disabled
73 def test_index_should_not_list_issues_when_module_disabled
74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 get :index
75 get :index
76 assert_response :success
76 assert_response :success
77 assert_template 'index.rhtml'
77 assert_template 'index.rhtml'
78 assert_not_nil assigns(:issues)
78 assert_not_nil assigns(:issues)
79 assert_nil assigns(:project)
79 assert_nil assigns(:project)
80 assert_no_tag :tag => 'a', :content => /Can't print recipes/
80 assert_no_tag :tag => 'a', :content => /Can't print recipes/
81 assert_tag :tag => 'a', :content => /Subproject issue/
81 assert_tag :tag => 'a', :content => /Subproject issue/
82 end
82 end
83
83
84 def test_index_should_not_list_issues_when_module_disabled
84 def test_index_should_not_list_issues_when_module_disabled
85 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
85 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
86 get :index
86 get :index
87 assert_response :success
87 assert_response :success
88 assert_template 'index.rhtml'
88 assert_template 'index.rhtml'
89 assert_not_nil assigns(:issues)
89 assert_not_nil assigns(:issues)
90 assert_nil assigns(:project)
90 assert_nil assigns(:project)
91 assert_no_tag :tag => 'a', :content => /Can't print recipes/
91 assert_no_tag :tag => 'a', :content => /Can't print recipes/
92 assert_tag :tag => 'a', :content => /Subproject issue/
92 assert_tag :tag => 'a', :content => /Subproject issue/
93 end
93 end
94
94
95 def test_index_with_project
95 def test_index_with_project
96 Setting.display_subprojects_issues = 0
96 Setting.display_subprojects_issues = 0
97 get :index, :project_id => 1
97 get :index, :project_id => 1
98 assert_response :success
98 assert_response :success
99 assert_template 'index.rhtml'
99 assert_template 'index.rhtml'
100 assert_not_nil assigns(:issues)
100 assert_not_nil assigns(:issues)
101 assert_tag :tag => 'a', :content => /Can't print recipes/
101 assert_tag :tag => 'a', :content => /Can't print recipes/
102 assert_no_tag :tag => 'a', :content => /Subproject issue/
102 assert_no_tag :tag => 'a', :content => /Subproject issue/
103 end
103 end
104
104
105 def test_index_with_project_and_subprojects
105 def test_index_with_project_and_subprojects
106 Setting.display_subprojects_issues = 1
106 Setting.display_subprojects_issues = 1
107 get :index, :project_id => 1
107 get :index, :project_id => 1
108 assert_response :success
108 assert_response :success
109 assert_template 'index.rhtml'
109 assert_template 'index.rhtml'
110 assert_not_nil assigns(:issues)
110 assert_not_nil assigns(:issues)
111 assert_tag :tag => 'a', :content => /Can't print recipes/
111 assert_tag :tag => 'a', :content => /Can't print recipes/
112 assert_tag :tag => 'a', :content => /Subproject issue/
112 assert_tag :tag => 'a', :content => /Subproject issue/
113 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
113 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
114 end
114 end
115
115
116 def test_index_with_project_and_subprojects_should_show_private_subprojects
116 def test_index_with_project_and_subprojects_should_show_private_subprojects
117 @request.session[:user_id] = 2
117 @request.session[:user_id] = 2
118 Setting.display_subprojects_issues = 1
118 Setting.display_subprojects_issues = 1
119 get :index, :project_id => 1
119 get :index, :project_id => 1
120 assert_response :success
120 assert_response :success
121 assert_template 'index.rhtml'
121 assert_template 'index.rhtml'
122 assert_not_nil assigns(:issues)
122 assert_not_nil assigns(:issues)
123 assert_tag :tag => 'a', :content => /Can't print recipes/
123 assert_tag :tag => 'a', :content => /Can't print recipes/
124 assert_tag :tag => 'a', :content => /Subproject issue/
124 assert_tag :tag => 'a', :content => /Subproject issue/
125 assert_tag :tag => 'a', :content => /Issue of a private subproject/
125 assert_tag :tag => 'a', :content => /Issue of a private subproject/
126 end
126 end
127
127
128 def test_index_with_project_and_default_filter
128 def test_index_with_project_and_default_filter
129 get :index, :project_id => 1, :set_filter => 1
129 get :index, :project_id => 1, :set_filter => 1
130 assert_response :success
130 assert_response :success
131 assert_template 'index.rhtml'
131 assert_template 'index.rhtml'
132 assert_not_nil assigns(:issues)
132 assert_not_nil assigns(:issues)
133
133
134 query = assigns(:query)
134 query = assigns(:query)
135 assert_not_nil query
135 assert_not_nil query
136 # default filter
136 # default filter
137 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
137 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
138 end
138 end
139
139
140 def test_index_with_project_and_filter
140 def test_index_with_project_and_filter
141 get :index, :project_id => 1, :set_filter => 1,
141 get :index, :project_id => 1, :set_filter => 1,
142 :f => ['tracker_id'],
142 :f => ['tracker_id'],
143 :op => {'tracker_id' => '='},
143 :op => {'tracker_id' => '='},
144 :v => {'tracker_id' => ['1']}
144 :v => {'tracker_id' => ['1']}
145 assert_response :success
145 assert_response :success
146 assert_template 'index.rhtml'
146 assert_template 'index.rhtml'
147 assert_not_nil assigns(:issues)
147 assert_not_nil assigns(:issues)
148
148
149 query = assigns(:query)
149 query = assigns(:query)
150 assert_not_nil query
150 assert_not_nil query
151 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
151 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
152 end
152 end
153
153
154 def test_index_with_project_and_empty_filters
154 def test_index_with_project_and_empty_filters
155 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
155 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
156 assert_response :success
156 assert_response :success
157 assert_template 'index.rhtml'
157 assert_template 'index.rhtml'
158 assert_not_nil assigns(:issues)
158 assert_not_nil assigns(:issues)
159
159
160 query = assigns(:query)
160 query = assigns(:query)
161 assert_not_nil query
161 assert_not_nil query
162 # no filter
162 # no filter
163 assert_equal({}, query.filters)
163 assert_equal({}, query.filters)
164 end
164 end
165
165
166 def test_index_with_query
166 def test_index_with_query
167 get :index, :project_id => 1, :query_id => 5
167 get :index, :project_id => 1, :query_id => 5
168 assert_response :success
168 assert_response :success
169 assert_template 'index.rhtml'
169 assert_template 'index.rhtml'
170 assert_not_nil assigns(:issues)
170 assert_not_nil assigns(:issues)
171 assert_nil assigns(:issue_count_by_group)
171 assert_nil assigns(:issue_count_by_group)
172 end
172 end
173
173
174 def test_index_with_query_grouped_by_tracker
174 def test_index_with_query_grouped_by_tracker
175 get :index, :project_id => 1, :query_id => 6
175 get :index, :project_id => 1, :query_id => 6
176 assert_response :success
176 assert_response :success
177 assert_template 'index.rhtml'
177 assert_template 'index.rhtml'
178 assert_not_nil assigns(:issues)
178 assert_not_nil assigns(:issues)
179 assert_not_nil assigns(:issue_count_by_group)
179 assert_not_nil assigns(:issue_count_by_group)
180 end
180 end
181
181
182 def test_index_with_query_grouped_by_list_custom_field
182 def test_index_with_query_grouped_by_list_custom_field
183 get :index, :project_id => 1, :query_id => 9
183 get :index, :project_id => 1, :query_id => 9
184 assert_response :success
184 assert_response :success
185 assert_template 'index.rhtml'
185 assert_template 'index.rhtml'
186 assert_not_nil assigns(:issues)
186 assert_not_nil assigns(:issues)
187 assert_not_nil assigns(:issue_count_by_group)
187 assert_not_nil assigns(:issue_count_by_group)
188 end
188 end
189
189
190 def test_index_sort_by_field_not_included_in_columns
190 def test_index_sort_by_field_not_included_in_columns
191 Setting.issue_list_default_columns = %w(subject author)
191 Setting.issue_list_default_columns = %w(subject author)
192 get :index, :sort => 'tracker'
192 get :index, :sort => 'tracker'
193 end
193 end
194
194
195 def test_index_csv_with_project
195 def test_index_csv_with_project
196 Setting.default_language = 'en'
196 Setting.default_language = 'en'
197
197
198 get :index, :format => 'csv'
198 get :index, :format => 'csv'
199 assert_response :success
199 assert_response :success
200 assert_not_nil assigns(:issues)
200 assert_not_nil assigns(:issues)
201 assert_equal 'text/csv', @response.content_type
201 assert_equal 'text/csv', @response.content_type
202 assert @response.body.starts_with?("#,")
202 assert @response.body.starts_with?("#,")
203
203
204 get :index, :project_id => 1, :format => 'csv'
204 get :index, :project_id => 1, :format => 'csv'
205 assert_response :success
205 assert_response :success
206 assert_not_nil assigns(:issues)
206 assert_not_nil assigns(:issues)
207 assert_equal 'text/csv', @response.content_type
207 assert_equal 'text/csv', @response.content_type
208 end
208 end
209
209
210 def test_index_pdf
210 def test_index_pdf
211 get :index, :format => 'pdf'
211 get :index, :format => 'pdf'
212 assert_response :success
212 assert_response :success
213 assert_not_nil assigns(:issues)
213 assert_not_nil assigns(:issues)
214 assert_equal 'application/pdf', @response.content_type
214 assert_equal 'application/pdf', @response.content_type
215
215
216 get :index, :project_id => 1, :format => 'pdf'
216 get :index, :project_id => 1, :format => 'pdf'
217 assert_response :success
217 assert_response :success
218 assert_not_nil assigns(:issues)
218 assert_not_nil assigns(:issues)
219 assert_equal 'application/pdf', @response.content_type
219 assert_equal 'application/pdf', @response.content_type
220
220
221 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
221 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
222 assert_response :success
222 assert_response :success
223 assert_not_nil assigns(:issues)
223 assert_not_nil assigns(:issues)
224 assert_equal 'application/pdf', @response.content_type
224 assert_equal 'application/pdf', @response.content_type
225 end
225 end
226
226
227 def test_index_pdf_with_query_grouped_by_list_custom_field
227 def test_index_pdf_with_query_grouped_by_list_custom_field
228 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
228 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
229 assert_response :success
229 assert_response :success
230 assert_not_nil assigns(:issues)
230 assert_not_nil assigns(:issues)
231 assert_not_nil assigns(:issue_count_by_group)
231 assert_not_nil assigns(:issue_count_by_group)
232 assert_equal 'application/pdf', @response.content_type
232 assert_equal 'application/pdf', @response.content_type
233 end
233 end
234
234
235 def test_index_sort
235 def test_index_sort
236 get :index, :sort => 'tracker,id:desc'
236 get :index, :sort => 'tracker,id:desc'
237 assert_response :success
237 assert_response :success
238
238
239 sort_params = @request.session['issues_index_sort']
239 sort_params = @request.session['issues_index_sort']
240 assert sort_params.is_a?(String)
240 assert sort_params.is_a?(String)
241 assert_equal 'tracker,id:desc', sort_params
241 assert_equal 'tracker,id:desc', sort_params
242
242
243 issues = assigns(:issues)
243 issues = assigns(:issues)
244 assert_not_nil issues
244 assert_not_nil issues
245 assert !issues.empty?
245 assert !issues.empty?
246 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
246 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
247 end
247 end
248
248
249 def test_index_with_columns
249 def test_index_with_columns
250 columns = ['tracker', 'subject', 'assigned_to']
250 columns = ['tracker', 'subject', 'assigned_to']
251 get :index, :set_filter => 1, :query => { 'column_names' => columns}
251 get :index, :set_filter => 1, :c => columns
252 assert_response :success
252 assert_response :success
253
253
254 # query should use specified columns
254 # query should use specified columns
255 query = assigns(:query)
255 query = assigns(:query)
256 assert_kind_of Query, query
256 assert_kind_of Query, query
257 assert_equal columns, query.column_names.map(&:to_s)
257 assert_equal columns, query.column_names.map(&:to_s)
258
258
259 # columns should be stored in session
259 # columns should be stored in session
260 assert_kind_of Hash, session[:query]
260 assert_kind_of Hash, session[:query]
261 assert_kind_of Array, session[:query][:column_names]
261 assert_kind_of Array, session[:query][:column_names]
262 assert_equal columns, session[:query][:column_names].map(&:to_s)
262 assert_equal columns, session[:query][:column_names].map(&:to_s)
263 end
263 end
264
264
265 def test_show_by_anonymous
265 def test_show_by_anonymous
266 get :show, :id => 1
266 get :show, :id => 1
267 assert_response :success
267 assert_response :success
268 assert_template 'show.rhtml'
268 assert_template 'show.rhtml'
269 assert_not_nil assigns(:issue)
269 assert_not_nil assigns(:issue)
270 assert_equal Issue.find(1), assigns(:issue)
270 assert_equal Issue.find(1), assigns(:issue)
271
271
272 # anonymous role is allowed to add a note
272 # anonymous role is allowed to add a note
273 assert_tag :tag => 'form',
273 assert_tag :tag => 'form',
274 :descendant => { :tag => 'fieldset',
274 :descendant => { :tag => 'fieldset',
275 :child => { :tag => 'legend',
275 :child => { :tag => 'legend',
276 :content => /Notes/ } }
276 :content => /Notes/ } }
277 end
277 end
278
278
279 def test_show_by_manager
279 def test_show_by_manager
280 @request.session[:user_id] = 2
280 @request.session[:user_id] = 2
281 get :show, :id => 1
281 get :show, :id => 1
282 assert_response :success
282 assert_response :success
283
283
284 assert_tag :tag => 'a',
284 assert_tag :tag => 'a',
285 :content => /Quote/
285 :content => /Quote/
286
286
287 assert_tag :tag => 'form',
287 assert_tag :tag => 'form',
288 :descendant => { :tag => 'fieldset',
288 :descendant => { :tag => 'fieldset',
289 :child => { :tag => 'legend',
289 :child => { :tag => 'legend',
290 :content => /Change properties/ } },
290 :content => /Change properties/ } },
291 :descendant => { :tag => 'fieldset',
291 :descendant => { :tag => 'fieldset',
292 :child => { :tag => 'legend',
292 :child => { :tag => 'legend',
293 :content => /Log time/ } },
293 :content => /Log time/ } },
294 :descendant => { :tag => 'fieldset',
294 :descendant => { :tag => 'fieldset',
295 :child => { :tag => 'legend',
295 :child => { :tag => 'legend',
296 :content => /Notes/ } }
296 :content => /Notes/ } }
297 end
297 end
298
298
299 def test_show_should_deny_anonymous_access_without_permission
299 def test_show_should_deny_anonymous_access_without_permission
300 Role.anonymous.remove_permission!(:view_issues)
300 Role.anonymous.remove_permission!(:view_issues)
301 get :show, :id => 1
301 get :show, :id => 1
302 assert_response :redirect
302 assert_response :redirect
303 end
303 end
304
304
305 def test_show_should_deny_non_member_access_without_permission
305 def test_show_should_deny_non_member_access_without_permission
306 Role.non_member.remove_permission!(:view_issues)
306 Role.non_member.remove_permission!(:view_issues)
307 @request.session[:user_id] = 9
307 @request.session[:user_id] = 9
308 get :show, :id => 1
308 get :show, :id => 1
309 assert_response 403
309 assert_response 403
310 end
310 end
311
311
312 def test_show_should_deny_member_access_without_permission
312 def test_show_should_deny_member_access_without_permission
313 Role.find(1).remove_permission!(:view_issues)
313 Role.find(1).remove_permission!(:view_issues)
314 @request.session[:user_id] = 2
314 @request.session[:user_id] = 2
315 get :show, :id => 1
315 get :show, :id => 1
316 assert_response 403
316 assert_response 403
317 end
317 end
318
318
319 def test_show_should_not_disclose_relations_to_invisible_issues
319 def test_show_should_not_disclose_relations_to_invisible_issues
320 Setting.cross_project_issue_relations = '1'
320 Setting.cross_project_issue_relations = '1'
321 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
321 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
322 # Relation to a private project issue
322 # Relation to a private project issue
323 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
323 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
324
324
325 get :show, :id => 1
325 get :show, :id => 1
326 assert_response :success
326 assert_response :success
327
327
328 assert_tag :div, :attributes => { :id => 'relations' },
328 assert_tag :div, :attributes => { :id => 'relations' },
329 :descendant => { :tag => 'a', :content => /#2$/ }
329 :descendant => { :tag => 'a', :content => /#2$/ }
330 assert_no_tag :div, :attributes => { :id => 'relations' },
330 assert_no_tag :div, :attributes => { :id => 'relations' },
331 :descendant => { :tag => 'a', :content => /#4$/ }
331 :descendant => { :tag => 'a', :content => /#4$/ }
332 end
332 end
333
333
334 def test_show_atom
334 def test_show_atom
335 get :show, :id => 2, :format => 'atom'
335 get :show, :id => 2, :format => 'atom'
336 assert_response :success
336 assert_response :success
337 assert_template 'journals/index.rxml'
337 assert_template 'journals/index.rxml'
338 # Inline image
338 # Inline image
339 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
339 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
340 end
340 end
341
341
342 def test_show_export_to_pdf
342 def test_show_export_to_pdf
343 get :show, :id => 3, :format => 'pdf'
343 get :show, :id => 3, :format => 'pdf'
344 assert_response :success
344 assert_response :success
345 assert_equal 'application/pdf', @response.content_type
345 assert_equal 'application/pdf', @response.content_type
346 assert @response.body.starts_with?('%PDF')
346 assert @response.body.starts_with?('%PDF')
347 assert_not_nil assigns(:issue)
347 assert_not_nil assigns(:issue)
348 end
348 end
349
349
350 def test_get_new
350 def test_get_new
351 @request.session[:user_id] = 2
351 @request.session[:user_id] = 2
352 get :new, :project_id => 1, :tracker_id => 1
352 get :new, :project_id => 1, :tracker_id => 1
353 assert_response :success
353 assert_response :success
354 assert_template 'new'
354 assert_template 'new'
355
355
356 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
356 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
357 :value => 'Default string' }
357 :value => 'Default string' }
358 end
358 end
359
359
360 def test_get_new_without_tracker_id
360 def test_get_new_without_tracker_id
361 @request.session[:user_id] = 2
361 @request.session[:user_id] = 2
362 get :new, :project_id => 1
362 get :new, :project_id => 1
363 assert_response :success
363 assert_response :success
364 assert_template 'new'
364 assert_template 'new'
365
365
366 issue = assigns(:issue)
366 issue = assigns(:issue)
367 assert_not_nil issue
367 assert_not_nil issue
368 assert_equal Project.find(1).trackers.first, issue.tracker
368 assert_equal Project.find(1).trackers.first, issue.tracker
369 end
369 end
370
370
371 def test_get_new_with_no_default_status_should_display_an_error
371 def test_get_new_with_no_default_status_should_display_an_error
372 @request.session[:user_id] = 2
372 @request.session[:user_id] = 2
373 IssueStatus.delete_all
373 IssueStatus.delete_all
374
374
375 get :new, :project_id => 1
375 get :new, :project_id => 1
376 assert_response 500
376 assert_response 500
377 assert_error_tag :content => /No default issue/
377 assert_error_tag :content => /No default issue/
378 end
378 end
379
379
380 def test_get_new_with_no_tracker_should_display_an_error
380 def test_get_new_with_no_tracker_should_display_an_error
381 @request.session[:user_id] = 2
381 @request.session[:user_id] = 2
382 Tracker.delete_all
382 Tracker.delete_all
383
383
384 get :new, :project_id => 1
384 get :new, :project_id => 1
385 assert_response 500
385 assert_response 500
386 assert_error_tag :content => /No tracker/
386 assert_error_tag :content => /No tracker/
387 end
387 end
388
388
389 def test_update_new_form
389 def test_update_new_form
390 @request.session[:user_id] = 2
390 @request.session[:user_id] = 2
391 xhr :post, :new, :project_id => 1,
391 xhr :post, :new, :project_id => 1,
392 :issue => {:tracker_id => 2,
392 :issue => {:tracker_id => 2,
393 :subject => 'This is the test_new issue',
393 :subject => 'This is the test_new issue',
394 :description => 'This is the description',
394 :description => 'This is the description',
395 :priority_id => 5}
395 :priority_id => 5}
396 assert_response :success
396 assert_response :success
397 assert_template 'attributes'
397 assert_template 'attributes'
398
398
399 issue = assigns(:issue)
399 issue = assigns(:issue)
400 assert_kind_of Issue, issue
400 assert_kind_of Issue, issue
401 assert_equal 1, issue.project_id
401 assert_equal 1, issue.project_id
402 assert_equal 2, issue.tracker_id
402 assert_equal 2, issue.tracker_id
403 assert_equal 'This is the test_new issue', issue.subject
403 assert_equal 'This is the test_new issue', issue.subject
404 end
404 end
405
405
406 def test_post_create
406 def test_post_create
407 @request.session[:user_id] = 2
407 @request.session[:user_id] = 2
408 assert_difference 'Issue.count' do
408 assert_difference 'Issue.count' do
409 post :create, :project_id => 1,
409 post :create, :project_id => 1,
410 :issue => {:tracker_id => 3,
410 :issue => {:tracker_id => 3,
411 :status_id => 2,
411 :status_id => 2,
412 :subject => 'This is the test_new issue',
412 :subject => 'This is the test_new issue',
413 :description => 'This is the description',
413 :description => 'This is the description',
414 :priority_id => 5,
414 :priority_id => 5,
415 :start_date => '2010-11-07',
415 :start_date => '2010-11-07',
416 :estimated_hours => '',
416 :estimated_hours => '',
417 :custom_field_values => {'2' => 'Value for field 2'}}
417 :custom_field_values => {'2' => 'Value for field 2'}}
418 end
418 end
419 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
419 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
420
420
421 issue = Issue.find_by_subject('This is the test_new issue')
421 issue = Issue.find_by_subject('This is the test_new issue')
422 assert_not_nil issue
422 assert_not_nil issue
423 assert_equal 2, issue.author_id
423 assert_equal 2, issue.author_id
424 assert_equal 3, issue.tracker_id
424 assert_equal 3, issue.tracker_id
425 assert_equal 2, issue.status_id
425 assert_equal 2, issue.status_id
426 assert_equal Date.parse('2010-11-07'), issue.start_date
426 assert_equal Date.parse('2010-11-07'), issue.start_date
427 assert_nil issue.estimated_hours
427 assert_nil issue.estimated_hours
428 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
428 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
429 assert_not_nil v
429 assert_not_nil v
430 assert_equal 'Value for field 2', v.value
430 assert_equal 'Value for field 2', v.value
431 end
431 end
432
432
433 def test_post_create_without_start_date
433 def test_post_create_without_start_date
434 @request.session[:user_id] = 2
434 @request.session[:user_id] = 2
435 assert_difference 'Issue.count' do
435 assert_difference 'Issue.count' do
436 post :create, :project_id => 1,
436 post :create, :project_id => 1,
437 :issue => {:tracker_id => 3,
437 :issue => {:tracker_id => 3,
438 :status_id => 2,
438 :status_id => 2,
439 :subject => 'This is the test_new issue',
439 :subject => 'This is the test_new issue',
440 :description => 'This is the description',
440 :description => 'This is the description',
441 :priority_id => 5,
441 :priority_id => 5,
442 :start_date => '',
442 :start_date => '',
443 :estimated_hours => '',
443 :estimated_hours => '',
444 :custom_field_values => {'2' => 'Value for field 2'}}
444 :custom_field_values => {'2' => 'Value for field 2'}}
445 end
445 end
446 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
446 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
447
447
448 issue = Issue.find_by_subject('This is the test_new issue')
448 issue = Issue.find_by_subject('This is the test_new issue')
449 assert_not_nil issue
449 assert_not_nil issue
450 assert_nil issue.start_date
450 assert_nil issue.start_date
451 end
451 end
452
452
453 def test_post_create_and_continue
453 def test_post_create_and_continue
454 @request.session[:user_id] = 2
454 @request.session[:user_id] = 2
455 post :create, :project_id => 1,
455 post :create, :project_id => 1,
456 :issue => {:tracker_id => 3,
456 :issue => {:tracker_id => 3,
457 :subject => 'This is first issue',
457 :subject => 'This is first issue',
458 :priority_id => 5},
458 :priority_id => 5},
459 :continue => ''
459 :continue => ''
460 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook',
460 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook',
461 :issue => {:tracker_id => 3}
461 :issue => {:tracker_id => 3}
462 end
462 end
463
463
464 def test_post_create_without_custom_fields_param
464 def test_post_create_without_custom_fields_param
465 @request.session[:user_id] = 2
465 @request.session[:user_id] = 2
466 assert_difference 'Issue.count' do
466 assert_difference 'Issue.count' do
467 post :create, :project_id => 1,
467 post :create, :project_id => 1,
468 :issue => {:tracker_id => 1,
468 :issue => {:tracker_id => 1,
469 :subject => 'This is the test_new issue',
469 :subject => 'This is the test_new issue',
470 :description => 'This is the description',
470 :description => 'This is the description',
471 :priority_id => 5}
471 :priority_id => 5}
472 end
472 end
473 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
473 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
474 end
474 end
475
475
476 def test_post_create_with_required_custom_field_and_without_custom_fields_param
476 def test_post_create_with_required_custom_field_and_without_custom_fields_param
477 field = IssueCustomField.find_by_name('Database')
477 field = IssueCustomField.find_by_name('Database')
478 field.update_attribute(:is_required, true)
478 field.update_attribute(:is_required, true)
479
479
480 @request.session[:user_id] = 2
480 @request.session[:user_id] = 2
481 post :create, :project_id => 1,
481 post :create, :project_id => 1,
482 :issue => {:tracker_id => 1,
482 :issue => {:tracker_id => 1,
483 :subject => 'This is the test_new issue',
483 :subject => 'This is the test_new issue',
484 :description => 'This is the description',
484 :description => 'This is the description',
485 :priority_id => 5}
485 :priority_id => 5}
486 assert_response :success
486 assert_response :success
487 assert_template 'new'
487 assert_template 'new'
488 issue = assigns(:issue)
488 issue = assigns(:issue)
489 assert_not_nil issue
489 assert_not_nil issue
490 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
490 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
491 end
491 end
492
492
493 def test_post_create_with_watchers
493 def test_post_create_with_watchers
494 @request.session[:user_id] = 2
494 @request.session[:user_id] = 2
495 ActionMailer::Base.deliveries.clear
495 ActionMailer::Base.deliveries.clear
496
496
497 assert_difference 'Watcher.count', 2 do
497 assert_difference 'Watcher.count', 2 do
498 post :create, :project_id => 1,
498 post :create, :project_id => 1,
499 :issue => {:tracker_id => 1,
499 :issue => {:tracker_id => 1,
500 :subject => 'This is a new issue with watchers',
500 :subject => 'This is a new issue with watchers',
501 :description => 'This is the description',
501 :description => 'This is the description',
502 :priority_id => 5,
502 :priority_id => 5,
503 :watcher_user_ids => ['2', '3']}
503 :watcher_user_ids => ['2', '3']}
504 end
504 end
505 issue = Issue.find_by_subject('This is a new issue with watchers')
505 issue = Issue.find_by_subject('This is a new issue with watchers')
506 assert_not_nil issue
506 assert_not_nil issue
507 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
507 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
508
508
509 # Watchers added
509 # Watchers added
510 assert_equal [2, 3], issue.watcher_user_ids.sort
510 assert_equal [2, 3], issue.watcher_user_ids.sort
511 assert issue.watched_by?(User.find(3))
511 assert issue.watched_by?(User.find(3))
512 # Watchers notified
512 # Watchers notified
513 mail = ActionMailer::Base.deliveries.last
513 mail = ActionMailer::Base.deliveries.last
514 assert_kind_of TMail::Mail, mail
514 assert_kind_of TMail::Mail, mail
515 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
515 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
516 end
516 end
517
517
518 def test_post_create_subissue
518 def test_post_create_subissue
519 @request.session[:user_id] = 2
519 @request.session[:user_id] = 2
520
520
521 assert_difference 'Issue.count' do
521 assert_difference 'Issue.count' do
522 post :create, :project_id => 1,
522 post :create, :project_id => 1,
523 :issue => {:tracker_id => 1,
523 :issue => {:tracker_id => 1,
524 :subject => 'This is a child issue',
524 :subject => 'This is a child issue',
525 :parent_issue_id => 2}
525 :parent_issue_id => 2}
526 end
526 end
527 issue = Issue.find_by_subject('This is a child issue')
527 issue = Issue.find_by_subject('This is a child issue')
528 assert_not_nil issue
528 assert_not_nil issue
529 assert_equal Issue.find(2), issue.parent
529 assert_equal Issue.find(2), issue.parent
530 end
530 end
531
531
532 def test_post_create_subissue_with_non_numeric_parent_id
532 def test_post_create_subissue_with_non_numeric_parent_id
533 @request.session[:user_id] = 2
533 @request.session[:user_id] = 2
534
534
535 assert_difference 'Issue.count' do
535 assert_difference 'Issue.count' do
536 post :create, :project_id => 1,
536 post :create, :project_id => 1,
537 :issue => {:tracker_id => 1,
537 :issue => {:tracker_id => 1,
538 :subject => 'This is a child issue',
538 :subject => 'This is a child issue',
539 :parent_issue_id => 'ABC'}
539 :parent_issue_id => 'ABC'}
540 end
540 end
541 issue = Issue.find_by_subject('This is a child issue')
541 issue = Issue.find_by_subject('This is a child issue')
542 assert_not_nil issue
542 assert_not_nil issue
543 assert_nil issue.parent
543 assert_nil issue.parent
544 end
544 end
545
545
546 def test_post_create_should_send_a_notification
546 def test_post_create_should_send_a_notification
547 ActionMailer::Base.deliveries.clear
547 ActionMailer::Base.deliveries.clear
548 @request.session[:user_id] = 2
548 @request.session[:user_id] = 2
549 assert_difference 'Issue.count' do
549 assert_difference 'Issue.count' do
550 post :create, :project_id => 1,
550 post :create, :project_id => 1,
551 :issue => {:tracker_id => 3,
551 :issue => {:tracker_id => 3,
552 :subject => 'This is the test_new issue',
552 :subject => 'This is the test_new issue',
553 :description => 'This is the description',
553 :description => 'This is the description',
554 :priority_id => 5,
554 :priority_id => 5,
555 :estimated_hours => '',
555 :estimated_hours => '',
556 :custom_field_values => {'2' => 'Value for field 2'}}
556 :custom_field_values => {'2' => 'Value for field 2'}}
557 end
557 end
558 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
558 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
559
559
560 assert_equal 1, ActionMailer::Base.deliveries.size
560 assert_equal 1, ActionMailer::Base.deliveries.size
561 end
561 end
562
562
563 def test_post_create_should_preserve_fields_values_on_validation_failure
563 def test_post_create_should_preserve_fields_values_on_validation_failure
564 @request.session[:user_id] = 2
564 @request.session[:user_id] = 2
565 post :create, :project_id => 1,
565 post :create, :project_id => 1,
566 :issue => {:tracker_id => 1,
566 :issue => {:tracker_id => 1,
567 # empty subject
567 # empty subject
568 :subject => '',
568 :subject => '',
569 :description => 'This is a description',
569 :description => 'This is a description',
570 :priority_id => 6,
570 :priority_id => 6,
571 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
571 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
572 assert_response :success
572 assert_response :success
573 assert_template 'new'
573 assert_template 'new'
574
574
575 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
575 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
576 :content => 'This is a description'
576 :content => 'This is a description'
577 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
577 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
578 :child => { :tag => 'option', :attributes => { :selected => 'selected',
578 :child => { :tag => 'option', :attributes => { :selected => 'selected',
579 :value => '6' },
579 :value => '6' },
580 :content => 'High' }
580 :content => 'High' }
581 # Custom fields
581 # Custom fields
582 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
582 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
583 :child => { :tag => 'option', :attributes => { :selected => 'selected',
583 :child => { :tag => 'option', :attributes => { :selected => 'selected',
584 :value => 'Oracle' },
584 :value => 'Oracle' },
585 :content => 'Oracle' }
585 :content => 'Oracle' }
586 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
586 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
587 :value => 'Value for field 2'}
587 :value => 'Value for field 2'}
588 end
588 end
589
589
590 def test_post_create_should_ignore_non_safe_attributes
590 def test_post_create_should_ignore_non_safe_attributes
591 @request.session[:user_id] = 2
591 @request.session[:user_id] = 2
592 assert_nothing_raised do
592 assert_nothing_raised do
593 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
593 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
594 end
594 end
595 end
595 end
596
596
597 context "without workflow privilege" do
597 context "without workflow privilege" do
598 setup do
598 setup do
599 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
599 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
600 Role.anonymous.add_permission! :add_issues, :add_issue_notes
600 Role.anonymous.add_permission! :add_issues, :add_issue_notes
601 end
601 end
602
602
603 context "#new" do
603 context "#new" do
604 should "propose default status only" do
604 should "propose default status only" do
605 get :new, :project_id => 1
605 get :new, :project_id => 1
606 assert_response :success
606 assert_response :success
607 assert_template 'new'
607 assert_template 'new'
608 assert_tag :tag => 'select',
608 assert_tag :tag => 'select',
609 :attributes => {:name => 'issue[status_id]'},
609 :attributes => {:name => 'issue[status_id]'},
610 :children => {:count => 1},
610 :children => {:count => 1},
611 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
611 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
612 end
612 end
613
613
614 should "accept default status" do
614 should "accept default status" do
615 assert_difference 'Issue.count' do
615 assert_difference 'Issue.count' do
616 post :create, :project_id => 1,
616 post :create, :project_id => 1,
617 :issue => {:tracker_id => 1,
617 :issue => {:tracker_id => 1,
618 :subject => 'This is an issue',
618 :subject => 'This is an issue',
619 :status_id => 1}
619 :status_id => 1}
620 end
620 end
621 issue = Issue.last(:order => 'id')
621 issue = Issue.last(:order => 'id')
622 assert_equal IssueStatus.default, issue.status
622 assert_equal IssueStatus.default, issue.status
623 end
623 end
624
624
625 should "accept default status" do
625 should "accept default status" do
626 assert_difference 'Issue.count' do
626 assert_difference 'Issue.count' do
627 post :create, :project_id => 1,
627 post :create, :project_id => 1,
628 :issue => {:tracker_id => 1,
628 :issue => {:tracker_id => 1,
629 :subject => 'This is an issue',
629 :subject => 'This is an issue',
630 :status_id => 1}
630 :status_id => 1}
631 end
631 end
632 issue = Issue.last(:order => 'id')
632 issue = Issue.last(:order => 'id')
633 assert_equal IssueStatus.default, issue.status
633 assert_equal IssueStatus.default, issue.status
634 end
634 end
635
635
636 should "ignore unauthorized status" do
636 should "ignore unauthorized status" do
637 assert_difference 'Issue.count' do
637 assert_difference 'Issue.count' do
638 post :create, :project_id => 1,
638 post :create, :project_id => 1,
639 :issue => {:tracker_id => 1,
639 :issue => {:tracker_id => 1,
640 :subject => 'This is an issue',
640 :subject => 'This is an issue',
641 :status_id => 3}
641 :status_id => 3}
642 end
642 end
643 issue = Issue.last(:order => 'id')
643 issue = Issue.last(:order => 'id')
644 assert_equal IssueStatus.default, issue.status
644 assert_equal IssueStatus.default, issue.status
645 end
645 end
646 end
646 end
647
647
648 context "#update" do
648 context "#update" do
649 should "ignore status change" do
649 should "ignore status change" do
650 assert_difference 'Journal.count' do
650 assert_difference 'Journal.count' do
651 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
651 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
652 end
652 end
653 assert_equal 1, Issue.find(1).status_id
653 assert_equal 1, Issue.find(1).status_id
654 end
654 end
655
655
656 should "ignore attributes changes" do
656 should "ignore attributes changes" do
657 assert_difference 'Journal.count' do
657 assert_difference 'Journal.count' do
658 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
658 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
659 end
659 end
660 issue = Issue.find(1)
660 issue = Issue.find(1)
661 assert_equal "Can't print recipes", issue.subject
661 assert_equal "Can't print recipes", issue.subject
662 assert_nil issue.assigned_to
662 assert_nil issue.assigned_to
663 end
663 end
664 end
664 end
665 end
665 end
666
666
667 context "with workflow privilege" do
667 context "with workflow privilege" do
668 setup do
668 setup do
669 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
669 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
670 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
670 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
671 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
671 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
672 Role.anonymous.add_permission! :add_issues, :add_issue_notes
672 Role.anonymous.add_permission! :add_issues, :add_issue_notes
673 end
673 end
674
674
675 context "#update" do
675 context "#update" do
676 should "accept authorized status" do
676 should "accept authorized status" do
677 assert_difference 'Journal.count' do
677 assert_difference 'Journal.count' do
678 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
678 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
679 end
679 end
680 assert_equal 3, Issue.find(1).status_id
680 assert_equal 3, Issue.find(1).status_id
681 end
681 end
682
682
683 should "ignore unauthorized status" do
683 should "ignore unauthorized status" do
684 assert_difference 'Journal.count' do
684 assert_difference 'Journal.count' do
685 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
685 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
686 end
686 end
687 assert_equal 1, Issue.find(1).status_id
687 assert_equal 1, Issue.find(1).status_id
688 end
688 end
689
689
690 should "accept authorized attributes changes" do
690 should "accept authorized attributes changes" do
691 assert_difference 'Journal.count' do
691 assert_difference 'Journal.count' do
692 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
692 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
693 end
693 end
694 issue = Issue.find(1)
694 issue = Issue.find(1)
695 assert_equal 2, issue.assigned_to_id
695 assert_equal 2, issue.assigned_to_id
696 end
696 end
697
697
698 should "ignore unauthorized attributes changes" do
698 should "ignore unauthorized attributes changes" do
699 assert_difference 'Journal.count' do
699 assert_difference 'Journal.count' do
700 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
700 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
701 end
701 end
702 issue = Issue.find(1)
702 issue = Issue.find(1)
703 assert_equal "Can't print recipes", issue.subject
703 assert_equal "Can't print recipes", issue.subject
704 end
704 end
705 end
705 end
706
706
707 context "and :edit_issues permission" do
707 context "and :edit_issues permission" do
708 setup do
708 setup do
709 Role.anonymous.add_permission! :add_issues, :edit_issues
709 Role.anonymous.add_permission! :add_issues, :edit_issues
710 end
710 end
711
711
712 should "accept authorized status" do
712 should "accept authorized status" do
713 assert_difference 'Journal.count' do
713 assert_difference 'Journal.count' do
714 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
714 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
715 end
715 end
716 assert_equal 3, Issue.find(1).status_id
716 assert_equal 3, Issue.find(1).status_id
717 end
717 end
718
718
719 should "ignore unauthorized status" do
719 should "ignore unauthorized status" do
720 assert_difference 'Journal.count' do
720 assert_difference 'Journal.count' do
721 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
721 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
722 end
722 end
723 assert_equal 1, Issue.find(1).status_id
723 assert_equal 1, Issue.find(1).status_id
724 end
724 end
725
725
726 should "accept authorized attributes changes" do
726 should "accept authorized attributes changes" do
727 assert_difference 'Journal.count' do
727 assert_difference 'Journal.count' do
728 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
728 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
729 end
729 end
730 issue = Issue.find(1)
730 issue = Issue.find(1)
731 assert_equal "changed", issue.subject
731 assert_equal "changed", issue.subject
732 assert_equal 2, issue.assigned_to_id
732 assert_equal 2, issue.assigned_to_id
733 end
733 end
734 end
734 end
735 end
735 end
736
736
737 def test_copy_issue
737 def test_copy_issue
738 @request.session[:user_id] = 2
738 @request.session[:user_id] = 2
739 get :new, :project_id => 1, :copy_from => 1
739 get :new, :project_id => 1, :copy_from => 1
740 assert_template 'new'
740 assert_template 'new'
741 assert_not_nil assigns(:issue)
741 assert_not_nil assigns(:issue)
742 orig = Issue.find(1)
742 orig = Issue.find(1)
743 assert_equal orig.subject, assigns(:issue).subject
743 assert_equal orig.subject, assigns(:issue).subject
744 end
744 end
745
745
746 def test_get_edit
746 def test_get_edit
747 @request.session[:user_id] = 2
747 @request.session[:user_id] = 2
748 get :edit, :id => 1
748 get :edit, :id => 1
749 assert_response :success
749 assert_response :success
750 assert_template 'edit'
750 assert_template 'edit'
751 assert_not_nil assigns(:issue)
751 assert_not_nil assigns(:issue)
752 assert_equal Issue.find(1), assigns(:issue)
752 assert_equal Issue.find(1), assigns(:issue)
753 end
753 end
754
754
755 def test_get_edit_with_params
755 def test_get_edit_with_params
756 @request.session[:user_id] = 2
756 @request.session[:user_id] = 2
757 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
757 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
758 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
758 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
759 assert_response :success
759 assert_response :success
760 assert_template 'edit'
760 assert_template 'edit'
761
761
762 issue = assigns(:issue)
762 issue = assigns(:issue)
763 assert_not_nil issue
763 assert_not_nil issue
764
764
765 assert_equal 5, issue.status_id
765 assert_equal 5, issue.status_id
766 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
766 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
767 :child => { :tag => 'option',
767 :child => { :tag => 'option',
768 :content => 'Closed',
768 :content => 'Closed',
769 :attributes => { :selected => 'selected' } }
769 :attributes => { :selected => 'selected' } }
770
770
771 assert_equal 7, issue.priority_id
771 assert_equal 7, issue.priority_id
772 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
772 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
773 :child => { :tag => 'option',
773 :child => { :tag => 'option',
774 :content => 'Urgent',
774 :content => 'Urgent',
775 :attributes => { :selected => 'selected' } }
775 :attributes => { :selected => 'selected' } }
776
776
777 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
777 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
778 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
778 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
779 :child => { :tag => 'option',
779 :child => { :tag => 'option',
780 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
780 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
781 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
781 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
782 end
782 end
783
783
784 def test_update_edit_form
784 def test_update_edit_form
785 @request.session[:user_id] = 2
785 @request.session[:user_id] = 2
786 xhr :post, :new, :project_id => 1,
786 xhr :post, :new, :project_id => 1,
787 :id => 1,
787 :id => 1,
788 :issue => {:tracker_id => 2,
788 :issue => {:tracker_id => 2,
789 :subject => 'This is the test_new issue',
789 :subject => 'This is the test_new issue',
790 :description => 'This is the description',
790 :description => 'This is the description',
791 :priority_id => 5}
791 :priority_id => 5}
792 assert_response :success
792 assert_response :success
793 assert_template 'attributes'
793 assert_template 'attributes'
794
794
795 issue = assigns(:issue)
795 issue = assigns(:issue)
796 assert_kind_of Issue, issue
796 assert_kind_of Issue, issue
797 assert_equal 1, issue.id
797 assert_equal 1, issue.id
798 assert_equal 1, issue.project_id
798 assert_equal 1, issue.project_id
799 assert_equal 2, issue.tracker_id
799 assert_equal 2, issue.tracker_id
800 assert_equal 'This is the test_new issue', issue.subject
800 assert_equal 'This is the test_new issue', issue.subject
801 end
801 end
802
802
803 def test_update_using_invalid_http_verbs
803 def test_update_using_invalid_http_verbs
804 @request.session[:user_id] = 2
804 @request.session[:user_id] = 2
805 subject = 'Updated by an invalid http verb'
805 subject = 'Updated by an invalid http verb'
806
806
807 get :update, :id => 1, :issue => {:subject => subject}
807 get :update, :id => 1, :issue => {:subject => subject}
808 assert_not_equal subject, Issue.find(1).subject
808 assert_not_equal subject, Issue.find(1).subject
809
809
810 post :update, :id => 1, :issue => {:subject => subject}
810 post :update, :id => 1, :issue => {:subject => subject}
811 assert_not_equal subject, Issue.find(1).subject
811 assert_not_equal subject, Issue.find(1).subject
812
812
813 delete :update, :id => 1, :issue => {:subject => subject}
813 delete :update, :id => 1, :issue => {:subject => subject}
814 assert_not_equal subject, Issue.find(1).subject
814 assert_not_equal subject, Issue.find(1).subject
815 end
815 end
816
816
817 def test_put_update_without_custom_fields_param
817 def test_put_update_without_custom_fields_param
818 @request.session[:user_id] = 2
818 @request.session[:user_id] = 2
819 ActionMailer::Base.deliveries.clear
819 ActionMailer::Base.deliveries.clear
820
820
821 issue = Issue.find(1)
821 issue = Issue.find(1)
822 assert_equal '125', issue.custom_value_for(2).value
822 assert_equal '125', issue.custom_value_for(2).value
823 old_subject = issue.subject
823 old_subject = issue.subject
824 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
824 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
825
825
826 assert_difference('Journal.count') do
826 assert_difference('Journal.count') do
827 assert_difference('JournalDetail.count', 2) do
827 assert_difference('JournalDetail.count', 2) do
828 put :update, :id => 1, :issue => {:subject => new_subject,
828 put :update, :id => 1, :issue => {:subject => new_subject,
829 :priority_id => '6',
829 :priority_id => '6',
830 :category_id => '1' # no change
830 :category_id => '1' # no change
831 }
831 }
832 end
832 end
833 end
833 end
834 assert_redirected_to :action => 'show', :id => '1'
834 assert_redirected_to :action => 'show', :id => '1'
835 issue.reload
835 issue.reload
836 assert_equal new_subject, issue.subject
836 assert_equal new_subject, issue.subject
837 # Make sure custom fields were not cleared
837 # Make sure custom fields were not cleared
838 assert_equal '125', issue.custom_value_for(2).value
838 assert_equal '125', issue.custom_value_for(2).value
839
839
840 mail = ActionMailer::Base.deliveries.last
840 mail = ActionMailer::Base.deliveries.last
841 assert_kind_of TMail::Mail, mail
841 assert_kind_of TMail::Mail, mail
842 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
842 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
843 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
843 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
844 end
844 end
845
845
846 def test_put_update_with_custom_field_change
846 def test_put_update_with_custom_field_change
847 @request.session[:user_id] = 2
847 @request.session[:user_id] = 2
848 issue = Issue.find(1)
848 issue = Issue.find(1)
849 assert_equal '125', issue.custom_value_for(2).value
849 assert_equal '125', issue.custom_value_for(2).value
850
850
851 assert_difference('Journal.count') do
851 assert_difference('Journal.count') do
852 assert_difference('JournalDetail.count', 3) do
852 assert_difference('JournalDetail.count', 3) do
853 put :update, :id => 1, :issue => {:subject => 'Custom field change',
853 put :update, :id => 1, :issue => {:subject => 'Custom field change',
854 :priority_id => '6',
854 :priority_id => '6',
855 :category_id => '1', # no change
855 :category_id => '1', # no change
856 :custom_field_values => { '2' => 'New custom value' }
856 :custom_field_values => { '2' => 'New custom value' }
857 }
857 }
858 end
858 end
859 end
859 end
860 assert_redirected_to :action => 'show', :id => '1'
860 assert_redirected_to :action => 'show', :id => '1'
861 issue.reload
861 issue.reload
862 assert_equal 'New custom value', issue.custom_value_for(2).value
862 assert_equal 'New custom value', issue.custom_value_for(2).value
863
863
864 mail = ActionMailer::Base.deliveries.last
864 mail = ActionMailer::Base.deliveries.last
865 assert_kind_of TMail::Mail, mail
865 assert_kind_of TMail::Mail, mail
866 assert mail.body.include?("Searchable field changed from 125 to New custom value")
866 assert mail.body.include?("Searchable field changed from 125 to New custom value")
867 end
867 end
868
868
869 def test_put_update_with_status_and_assignee_change
869 def test_put_update_with_status_and_assignee_change
870 issue = Issue.find(1)
870 issue = Issue.find(1)
871 assert_equal 1, issue.status_id
871 assert_equal 1, issue.status_id
872 @request.session[:user_id] = 2
872 @request.session[:user_id] = 2
873 assert_difference('TimeEntry.count', 0) do
873 assert_difference('TimeEntry.count', 0) do
874 put :update,
874 put :update,
875 :id => 1,
875 :id => 1,
876 :issue => { :status_id => 2, :assigned_to_id => 3 },
876 :issue => { :status_id => 2, :assigned_to_id => 3 },
877 :notes => 'Assigned to dlopper',
877 :notes => 'Assigned to dlopper',
878 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
878 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
879 end
879 end
880 assert_redirected_to :action => 'show', :id => '1'
880 assert_redirected_to :action => 'show', :id => '1'
881 issue.reload
881 issue.reload
882 assert_equal 2, issue.status_id
882 assert_equal 2, issue.status_id
883 j = Journal.find(:first, :order => 'id DESC')
883 j = Journal.find(:first, :order => 'id DESC')
884 assert_equal 'Assigned to dlopper', j.notes
884 assert_equal 'Assigned to dlopper', j.notes
885 assert_equal 2, j.details.size
885 assert_equal 2, j.details.size
886
886
887 mail = ActionMailer::Base.deliveries.last
887 mail = ActionMailer::Base.deliveries.last
888 assert mail.body.include?("Status changed from New to Assigned")
888 assert mail.body.include?("Status changed from New to Assigned")
889 # subject should contain the new status
889 # subject should contain the new status
890 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
890 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
891 end
891 end
892
892
893 def test_put_update_with_note_only
893 def test_put_update_with_note_only
894 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
894 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
895 # anonymous user
895 # anonymous user
896 put :update,
896 put :update,
897 :id => 1,
897 :id => 1,
898 :notes => notes
898 :notes => notes
899 assert_redirected_to :action => 'show', :id => '1'
899 assert_redirected_to :action => 'show', :id => '1'
900 j = Journal.find(:first, :order => 'id DESC')
900 j = Journal.find(:first, :order => 'id DESC')
901 assert_equal notes, j.notes
901 assert_equal notes, j.notes
902 assert_equal 0, j.details.size
902 assert_equal 0, j.details.size
903 assert_equal User.anonymous, j.user
903 assert_equal User.anonymous, j.user
904
904
905 mail = ActionMailer::Base.deliveries.last
905 mail = ActionMailer::Base.deliveries.last
906 assert mail.body.include?(notes)
906 assert mail.body.include?(notes)
907 end
907 end
908
908
909 def test_put_update_with_note_and_spent_time
909 def test_put_update_with_note_and_spent_time
910 @request.session[:user_id] = 2
910 @request.session[:user_id] = 2
911 spent_hours_before = Issue.find(1).spent_hours
911 spent_hours_before = Issue.find(1).spent_hours
912 assert_difference('TimeEntry.count') do
912 assert_difference('TimeEntry.count') do
913 put :update,
913 put :update,
914 :id => 1,
914 :id => 1,
915 :notes => '2.5 hours added',
915 :notes => '2.5 hours added',
916 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
916 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
917 end
917 end
918 assert_redirected_to :action => 'show', :id => '1'
918 assert_redirected_to :action => 'show', :id => '1'
919
919
920 issue = Issue.find(1)
920 issue = Issue.find(1)
921
921
922 j = Journal.find(:first, :order => 'id DESC')
922 j = Journal.find(:first, :order => 'id DESC')
923 assert_equal '2.5 hours added', j.notes
923 assert_equal '2.5 hours added', j.notes
924 assert_equal 0, j.details.size
924 assert_equal 0, j.details.size
925
925
926 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
926 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
927 assert_not_nil t
927 assert_not_nil t
928 assert_equal 2.5, t.hours
928 assert_equal 2.5, t.hours
929 assert_equal spent_hours_before + 2.5, issue.spent_hours
929 assert_equal spent_hours_before + 2.5, issue.spent_hours
930 end
930 end
931
931
932 def test_put_update_with_attachment_only
932 def test_put_update_with_attachment_only
933 set_tmp_attachments_directory
933 set_tmp_attachments_directory
934
934
935 # Delete all fixtured journals, a race condition can occur causing the wrong
935 # Delete all fixtured journals, a race condition can occur causing the wrong
936 # journal to get fetched in the next find.
936 # journal to get fetched in the next find.
937 Journal.delete_all
937 Journal.delete_all
938
938
939 # anonymous user
939 # anonymous user
940 put :update,
940 put :update,
941 :id => 1,
941 :id => 1,
942 :notes => '',
942 :notes => '',
943 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
943 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
944 assert_redirected_to :action => 'show', :id => '1'
944 assert_redirected_to :action => 'show', :id => '1'
945 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
945 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
946 assert j.notes.blank?
946 assert j.notes.blank?
947 assert_equal 1, j.details.size
947 assert_equal 1, j.details.size
948 assert_equal 'testfile.txt', j.details.first.value
948 assert_equal 'testfile.txt', j.details.first.value
949 assert_equal User.anonymous, j.user
949 assert_equal User.anonymous, j.user
950
950
951 mail = ActionMailer::Base.deliveries.last
951 mail = ActionMailer::Base.deliveries.last
952 assert mail.body.include?('testfile.txt')
952 assert mail.body.include?('testfile.txt')
953 end
953 end
954
954
955 def test_put_update_with_attachment_that_fails_to_save
955 def test_put_update_with_attachment_that_fails_to_save
956 set_tmp_attachments_directory
956 set_tmp_attachments_directory
957
957
958 # Delete all fixtured journals, a race condition can occur causing the wrong
958 # Delete all fixtured journals, a race condition can occur causing the wrong
959 # journal to get fetched in the next find.
959 # journal to get fetched in the next find.
960 Journal.delete_all
960 Journal.delete_all
961
961
962 # Mock out the unsaved attachment
962 # Mock out the unsaved attachment
963 Attachment.any_instance.stubs(:create).returns(Attachment.new)
963 Attachment.any_instance.stubs(:create).returns(Attachment.new)
964
964
965 # anonymous user
965 # anonymous user
966 put :update,
966 put :update,
967 :id => 1,
967 :id => 1,
968 :notes => '',
968 :notes => '',
969 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
969 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
970 assert_redirected_to :action => 'show', :id => '1'
970 assert_redirected_to :action => 'show', :id => '1'
971 assert_equal '1 file(s) could not be saved.', flash[:warning]
971 assert_equal '1 file(s) could not be saved.', flash[:warning]
972
972
973 end if Object.const_defined?(:Mocha)
973 end if Object.const_defined?(:Mocha)
974
974
975 def test_put_update_with_no_change
975 def test_put_update_with_no_change
976 issue = Issue.find(1)
976 issue = Issue.find(1)
977 issue.journals.clear
977 issue.journals.clear
978 ActionMailer::Base.deliveries.clear
978 ActionMailer::Base.deliveries.clear
979
979
980 put :update,
980 put :update,
981 :id => 1,
981 :id => 1,
982 :notes => ''
982 :notes => ''
983 assert_redirected_to :action => 'show', :id => '1'
983 assert_redirected_to :action => 'show', :id => '1'
984
984
985 issue.reload
985 issue.reload
986 assert issue.journals.empty?
986 assert issue.journals.empty?
987 # No email should be sent
987 # No email should be sent
988 assert ActionMailer::Base.deliveries.empty?
988 assert ActionMailer::Base.deliveries.empty?
989 end
989 end
990
990
991 def test_put_update_should_send_a_notification
991 def test_put_update_should_send_a_notification
992 @request.session[:user_id] = 2
992 @request.session[:user_id] = 2
993 ActionMailer::Base.deliveries.clear
993 ActionMailer::Base.deliveries.clear
994 issue = Issue.find(1)
994 issue = Issue.find(1)
995 old_subject = issue.subject
995 old_subject = issue.subject
996 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
996 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
997
997
998 put :update, :id => 1, :issue => {:subject => new_subject,
998 put :update, :id => 1, :issue => {:subject => new_subject,
999 :priority_id => '6',
999 :priority_id => '6',
1000 :category_id => '1' # no change
1000 :category_id => '1' # no change
1001 }
1001 }
1002 assert_equal 1, ActionMailer::Base.deliveries.size
1002 assert_equal 1, ActionMailer::Base.deliveries.size
1003 end
1003 end
1004
1004
1005 def test_put_update_with_invalid_spent_time_hours_only
1005 def test_put_update_with_invalid_spent_time_hours_only
1006 @request.session[:user_id] = 2
1006 @request.session[:user_id] = 2
1007 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1007 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1008
1008
1009 assert_no_difference('Journal.count') do
1009 assert_no_difference('Journal.count') do
1010 put :update,
1010 put :update,
1011 :id => 1,
1011 :id => 1,
1012 :notes => notes,
1012 :notes => notes,
1013 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1013 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1014 end
1014 end
1015 assert_response :success
1015 assert_response :success
1016 assert_template 'edit'
1016 assert_template 'edit'
1017
1017
1018 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1018 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1019 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1019 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1020 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1020 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1021 end
1021 end
1022
1022
1023 def test_put_update_with_invalid_spent_time_comments_only
1023 def test_put_update_with_invalid_spent_time_comments_only
1024 @request.session[:user_id] = 2
1024 @request.session[:user_id] = 2
1025 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1025 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1026
1026
1027 assert_no_difference('Journal.count') do
1027 assert_no_difference('Journal.count') do
1028 put :update,
1028 put :update,
1029 :id => 1,
1029 :id => 1,
1030 :notes => notes,
1030 :notes => notes,
1031 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1031 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1032 end
1032 end
1033 assert_response :success
1033 assert_response :success
1034 assert_template 'edit'
1034 assert_template 'edit'
1035
1035
1036 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1036 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1037 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1037 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1038 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1038 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1039 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1039 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1040 end
1040 end
1041
1041
1042 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1042 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1043 issue = Issue.find(2)
1043 issue = Issue.find(2)
1044 @request.session[:user_id] = 2
1044 @request.session[:user_id] = 2
1045
1045
1046 put :update,
1046 put :update,
1047 :id => issue.id,
1047 :id => issue.id,
1048 :issue => {
1048 :issue => {
1049 :fixed_version_id => 4
1049 :fixed_version_id => 4
1050 }
1050 }
1051
1051
1052 assert_response :redirect
1052 assert_response :redirect
1053 issue.reload
1053 issue.reload
1054 assert_equal 4, issue.fixed_version_id
1054 assert_equal 4, issue.fixed_version_id
1055 assert_not_equal issue.project_id, issue.fixed_version.project_id
1055 assert_not_equal issue.project_id, issue.fixed_version.project_id
1056 end
1056 end
1057
1057
1058 def test_put_update_should_redirect_back_using_the_back_url_parameter
1058 def test_put_update_should_redirect_back_using_the_back_url_parameter
1059 issue = Issue.find(2)
1059 issue = Issue.find(2)
1060 @request.session[:user_id] = 2
1060 @request.session[:user_id] = 2
1061
1061
1062 put :update,
1062 put :update,
1063 :id => issue.id,
1063 :id => issue.id,
1064 :issue => {
1064 :issue => {
1065 :fixed_version_id => 4
1065 :fixed_version_id => 4
1066 },
1066 },
1067 :back_url => '/issues'
1067 :back_url => '/issues'
1068
1068
1069 assert_response :redirect
1069 assert_response :redirect
1070 assert_redirected_to '/issues'
1070 assert_redirected_to '/issues'
1071 end
1071 end
1072
1072
1073 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1073 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1074 issue = Issue.find(2)
1074 issue = Issue.find(2)
1075 @request.session[:user_id] = 2
1075 @request.session[:user_id] = 2
1076
1076
1077 put :update,
1077 put :update,
1078 :id => issue.id,
1078 :id => issue.id,
1079 :issue => {
1079 :issue => {
1080 :fixed_version_id => 4
1080 :fixed_version_id => 4
1081 },
1081 },
1082 :back_url => 'http://google.com'
1082 :back_url => 'http://google.com'
1083
1083
1084 assert_response :redirect
1084 assert_response :redirect
1085 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1085 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1086 end
1086 end
1087
1087
1088 def test_get_bulk_edit
1088 def test_get_bulk_edit
1089 @request.session[:user_id] = 2
1089 @request.session[:user_id] = 2
1090 get :bulk_edit, :ids => [1, 2]
1090 get :bulk_edit, :ids => [1, 2]
1091 assert_response :success
1091 assert_response :success
1092 assert_template 'bulk_edit'
1092 assert_template 'bulk_edit'
1093
1093
1094 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1094 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1095
1095
1096 # Project specific custom field, date type
1096 # Project specific custom field, date type
1097 field = CustomField.find(9)
1097 field = CustomField.find(9)
1098 assert !field.is_for_all?
1098 assert !field.is_for_all?
1099 assert_equal 'date', field.field_format
1099 assert_equal 'date', field.field_format
1100 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1100 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1101
1101
1102 # System wide custom field
1102 # System wide custom field
1103 assert CustomField.find(1).is_for_all?
1103 assert CustomField.find(1).is_for_all?
1104 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1104 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1105 end
1105 end
1106
1106
1107 def test_get_bulk_edit_on_different_projects
1107 def test_get_bulk_edit_on_different_projects
1108 @request.session[:user_id] = 2
1108 @request.session[:user_id] = 2
1109 get :bulk_edit, :ids => [1, 2, 6]
1109 get :bulk_edit, :ids => [1, 2, 6]
1110 assert_response :success
1110 assert_response :success
1111 assert_template 'bulk_edit'
1111 assert_template 'bulk_edit'
1112
1112
1113 # Can not set issues from different projects as children of an issue
1113 # Can not set issues from different projects as children of an issue
1114 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1114 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1115
1115
1116 # Project specific custom field, date type
1116 # Project specific custom field, date type
1117 field = CustomField.find(9)
1117 field = CustomField.find(9)
1118 assert !field.is_for_all?
1118 assert !field.is_for_all?
1119 assert !field.project_ids.include?(Issue.find(6).project_id)
1119 assert !field.project_ids.include?(Issue.find(6).project_id)
1120 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1120 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1121 end
1121 end
1122
1122
1123 def test_bulk_update
1123 def test_bulk_update
1124 @request.session[:user_id] = 2
1124 @request.session[:user_id] = 2
1125 # update issues priority
1125 # update issues priority
1126 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1126 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1127 :issue => {:priority_id => 7,
1127 :issue => {:priority_id => 7,
1128 :assigned_to_id => '',
1128 :assigned_to_id => '',
1129 :custom_field_values => {'2' => ''}}
1129 :custom_field_values => {'2' => ''}}
1130
1130
1131 assert_response 302
1131 assert_response 302
1132 # check that the issues were updated
1132 # check that the issues were updated
1133 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1133 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1134
1134
1135 issue = Issue.find(1)
1135 issue = Issue.find(1)
1136 journal = issue.journals.find(:first, :order => 'created_on DESC')
1136 journal = issue.journals.find(:first, :order => 'created_on DESC')
1137 assert_equal '125', issue.custom_value_for(2).value
1137 assert_equal '125', issue.custom_value_for(2).value
1138 assert_equal 'Bulk editing', journal.notes
1138 assert_equal 'Bulk editing', journal.notes
1139 assert_equal 1, journal.details.size
1139 assert_equal 1, journal.details.size
1140 end
1140 end
1141
1141
1142 def test_bulk_update_on_different_projects
1142 def test_bulk_update_on_different_projects
1143 @request.session[:user_id] = 2
1143 @request.session[:user_id] = 2
1144 # update issues priority
1144 # update issues priority
1145 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1145 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1146 :issue => {:priority_id => 7,
1146 :issue => {:priority_id => 7,
1147 :assigned_to_id => '',
1147 :assigned_to_id => '',
1148 :custom_field_values => {'2' => ''}}
1148 :custom_field_values => {'2' => ''}}
1149
1149
1150 assert_response 302
1150 assert_response 302
1151 # check that the issues were updated
1151 # check that the issues were updated
1152 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1152 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1153
1153
1154 issue = Issue.find(1)
1154 issue = Issue.find(1)
1155 journal = issue.journals.find(:first, :order => 'created_on DESC')
1155 journal = issue.journals.find(:first, :order => 'created_on DESC')
1156 assert_equal '125', issue.custom_value_for(2).value
1156 assert_equal '125', issue.custom_value_for(2).value
1157 assert_equal 'Bulk editing', journal.notes
1157 assert_equal 'Bulk editing', journal.notes
1158 assert_equal 1, journal.details.size
1158 assert_equal 1, journal.details.size
1159 end
1159 end
1160
1160
1161 def test_bulk_update_on_different_projects_without_rights
1161 def test_bulk_update_on_different_projects_without_rights
1162 @request.session[:user_id] = 3
1162 @request.session[:user_id] = 3
1163 user = User.find(3)
1163 user = User.find(3)
1164 action = { :controller => "issues", :action => "bulk_update" }
1164 action = { :controller => "issues", :action => "bulk_update" }
1165 assert user.allowed_to?(action, Issue.find(1).project)
1165 assert user.allowed_to?(action, Issue.find(1).project)
1166 assert ! user.allowed_to?(action, Issue.find(6).project)
1166 assert ! user.allowed_to?(action, Issue.find(6).project)
1167 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1167 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1168 :issue => {:priority_id => 7,
1168 :issue => {:priority_id => 7,
1169 :assigned_to_id => '',
1169 :assigned_to_id => '',
1170 :custom_field_values => {'2' => ''}}
1170 :custom_field_values => {'2' => ''}}
1171 assert_response 403
1171 assert_response 403
1172 assert_not_equal "Bulk should fail", Journal.last.notes
1172 assert_not_equal "Bulk should fail", Journal.last.notes
1173 end
1173 end
1174
1174
1175 def test_bullk_update_should_send_a_notification
1175 def test_bullk_update_should_send_a_notification
1176 @request.session[:user_id] = 2
1176 @request.session[:user_id] = 2
1177 ActionMailer::Base.deliveries.clear
1177 ActionMailer::Base.deliveries.clear
1178 post(:bulk_update,
1178 post(:bulk_update,
1179 {
1179 {
1180 :ids => [1, 2],
1180 :ids => [1, 2],
1181 :notes => 'Bulk editing',
1181 :notes => 'Bulk editing',
1182 :issue => {
1182 :issue => {
1183 :priority_id => 7,
1183 :priority_id => 7,
1184 :assigned_to_id => '',
1184 :assigned_to_id => '',
1185 :custom_field_values => {'2' => ''}
1185 :custom_field_values => {'2' => ''}
1186 }
1186 }
1187 })
1187 })
1188
1188
1189 assert_response 302
1189 assert_response 302
1190 assert_equal 2, ActionMailer::Base.deliveries.size
1190 assert_equal 2, ActionMailer::Base.deliveries.size
1191 end
1191 end
1192
1192
1193 def test_bulk_update_status
1193 def test_bulk_update_status
1194 @request.session[:user_id] = 2
1194 @request.session[:user_id] = 2
1195 # update issues priority
1195 # update issues priority
1196 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1196 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1197 :issue => {:priority_id => '',
1197 :issue => {:priority_id => '',
1198 :assigned_to_id => '',
1198 :assigned_to_id => '',
1199 :status_id => '5'}
1199 :status_id => '5'}
1200
1200
1201 assert_response 302
1201 assert_response 302
1202 issue = Issue.find(1)
1202 issue = Issue.find(1)
1203 assert issue.closed?
1203 assert issue.closed?
1204 end
1204 end
1205
1205
1206 def test_bulk_update_parent_id
1206 def test_bulk_update_parent_id
1207 @request.session[:user_id] = 2
1207 @request.session[:user_id] = 2
1208 post :bulk_update, :ids => [1, 3],
1208 post :bulk_update, :ids => [1, 3],
1209 :notes => 'Bulk editing parent',
1209 :notes => 'Bulk editing parent',
1210 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1210 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1211
1211
1212 assert_response 302
1212 assert_response 302
1213 parent = Issue.find(2)
1213 parent = Issue.find(2)
1214 assert_equal parent.id, Issue.find(1).parent_id
1214 assert_equal parent.id, Issue.find(1).parent_id
1215 assert_equal parent.id, Issue.find(3).parent_id
1215 assert_equal parent.id, Issue.find(3).parent_id
1216 assert_equal [1, 3], parent.children.collect(&:id).sort
1216 assert_equal [1, 3], parent.children.collect(&:id).sort
1217 end
1217 end
1218
1218
1219 def test_bulk_update_custom_field
1219 def test_bulk_update_custom_field
1220 @request.session[:user_id] = 2
1220 @request.session[:user_id] = 2
1221 # update issues priority
1221 # update issues priority
1222 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1222 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1223 :issue => {:priority_id => '',
1223 :issue => {:priority_id => '',
1224 :assigned_to_id => '',
1224 :assigned_to_id => '',
1225 :custom_field_values => {'2' => '777'}}
1225 :custom_field_values => {'2' => '777'}}
1226
1226
1227 assert_response 302
1227 assert_response 302
1228
1228
1229 issue = Issue.find(1)
1229 issue = Issue.find(1)
1230 journal = issue.journals.find(:first, :order => 'created_on DESC')
1230 journal = issue.journals.find(:first, :order => 'created_on DESC')
1231 assert_equal '777', issue.custom_value_for(2).value
1231 assert_equal '777', issue.custom_value_for(2).value
1232 assert_equal 1, journal.details.size
1232 assert_equal 1, journal.details.size
1233 assert_equal '125', journal.details.first.old_value
1233 assert_equal '125', journal.details.first.old_value
1234 assert_equal '777', journal.details.first.value
1234 assert_equal '777', journal.details.first.value
1235 end
1235 end
1236
1236
1237 def test_bulk_update_unassign
1237 def test_bulk_update_unassign
1238 assert_not_nil Issue.find(2).assigned_to
1238 assert_not_nil Issue.find(2).assigned_to
1239 @request.session[:user_id] = 2
1239 @request.session[:user_id] = 2
1240 # unassign issues
1240 # unassign issues
1241 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1241 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1242 assert_response 302
1242 assert_response 302
1243 # check that the issues were updated
1243 # check that the issues were updated
1244 assert_nil Issue.find(2).assigned_to
1244 assert_nil Issue.find(2).assigned_to
1245 end
1245 end
1246
1246
1247 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1247 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1248 @request.session[:user_id] = 2
1248 @request.session[:user_id] = 2
1249
1249
1250 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1250 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1251
1251
1252 assert_response :redirect
1252 assert_response :redirect
1253 issues = Issue.find([1,2])
1253 issues = Issue.find([1,2])
1254 issues.each do |issue|
1254 issues.each do |issue|
1255 assert_equal 4, issue.fixed_version_id
1255 assert_equal 4, issue.fixed_version_id
1256 assert_not_equal issue.project_id, issue.fixed_version.project_id
1256 assert_not_equal issue.project_id, issue.fixed_version.project_id
1257 end
1257 end
1258 end
1258 end
1259
1259
1260 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1260 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1261 @request.session[:user_id] = 2
1261 @request.session[:user_id] = 2
1262 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1262 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1263
1263
1264 assert_response :redirect
1264 assert_response :redirect
1265 assert_redirected_to '/issues'
1265 assert_redirected_to '/issues'
1266 end
1266 end
1267
1267
1268 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1268 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1269 @request.session[:user_id] = 2
1269 @request.session[:user_id] = 2
1270 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1270 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1271
1271
1272 assert_response :redirect
1272 assert_response :redirect
1273 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1273 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1274 end
1274 end
1275
1275
1276 def test_destroy_issue_with_no_time_entries
1276 def test_destroy_issue_with_no_time_entries
1277 assert_nil TimeEntry.find_by_issue_id(2)
1277 assert_nil TimeEntry.find_by_issue_id(2)
1278 @request.session[:user_id] = 2
1278 @request.session[:user_id] = 2
1279 post :destroy, :id => 2
1279 post :destroy, :id => 2
1280 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1280 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1281 assert_nil Issue.find_by_id(2)
1281 assert_nil Issue.find_by_id(2)
1282 end
1282 end
1283
1283
1284 def test_destroy_issues_with_time_entries
1284 def test_destroy_issues_with_time_entries
1285 @request.session[:user_id] = 2
1285 @request.session[:user_id] = 2
1286 post :destroy, :ids => [1, 3]
1286 post :destroy, :ids => [1, 3]
1287 assert_response :success
1287 assert_response :success
1288 assert_template 'destroy'
1288 assert_template 'destroy'
1289 assert_not_nil assigns(:hours)
1289 assert_not_nil assigns(:hours)
1290 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1290 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1291 end
1291 end
1292
1292
1293 def test_destroy_issues_and_destroy_time_entries
1293 def test_destroy_issues_and_destroy_time_entries
1294 @request.session[:user_id] = 2
1294 @request.session[:user_id] = 2
1295 post :destroy, :ids => [1, 3], :todo => 'destroy'
1295 post :destroy, :ids => [1, 3], :todo => 'destroy'
1296 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1296 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1297 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1297 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1298 assert_nil TimeEntry.find_by_id([1, 2])
1298 assert_nil TimeEntry.find_by_id([1, 2])
1299 end
1299 end
1300
1300
1301 def test_destroy_issues_and_assign_time_entries_to_project
1301 def test_destroy_issues_and_assign_time_entries_to_project
1302 @request.session[:user_id] = 2
1302 @request.session[:user_id] = 2
1303 post :destroy, :ids => [1, 3], :todo => 'nullify'
1303 post :destroy, :ids => [1, 3], :todo => 'nullify'
1304 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1304 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1305 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1305 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1306 assert_nil TimeEntry.find(1).issue_id
1306 assert_nil TimeEntry.find(1).issue_id
1307 assert_nil TimeEntry.find(2).issue_id
1307 assert_nil TimeEntry.find(2).issue_id
1308 end
1308 end
1309
1309
1310 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1310 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1311 @request.session[:user_id] = 2
1311 @request.session[:user_id] = 2
1312 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1312 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1313 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1313 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1314 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1314 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1315 assert_equal 2, TimeEntry.find(1).issue_id
1315 assert_equal 2, TimeEntry.find(1).issue_id
1316 assert_equal 2, TimeEntry.find(2).issue_id
1316 assert_equal 2, TimeEntry.find(2).issue_id
1317 end
1317 end
1318
1318
1319 def test_destroy_issues_from_different_projects
1319 def test_destroy_issues_from_different_projects
1320 @request.session[:user_id] = 2
1320 @request.session[:user_id] = 2
1321 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1321 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1322 assert_redirected_to :controller => 'issues', :action => 'index'
1322 assert_redirected_to :controller => 'issues', :action => 'index'
1323 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1323 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1324 end
1324 end
1325
1325
1326 def test_destroy_parent_and_child_issues
1326 def test_destroy_parent_and_child_issues
1327 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1327 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1328 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1328 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1329 assert child.is_descendant_of?(parent.reload)
1329 assert child.is_descendant_of?(parent.reload)
1330
1330
1331 @request.session[:user_id] = 2
1331 @request.session[:user_id] = 2
1332 assert_difference 'Issue.count', -2 do
1332 assert_difference 'Issue.count', -2 do
1333 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1333 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1334 end
1334 end
1335 assert_response 302
1335 assert_response 302
1336 end
1336 end
1337
1337
1338 def test_default_search_scope
1338 def test_default_search_scope
1339 get :index
1339 get :index
1340 assert_tag :div, :attributes => {:id => 'quick-search'},
1340 assert_tag :div, :attributes => {:id => 'quick-search'},
1341 :child => {:tag => 'form',
1341 :child => {:tag => 'form',
1342 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1342 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1343 end
1343 end
1344 end
1344 end
@@ -1,240 +1,241
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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 'queries_controller'
19 require 'queries_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class QueriesController; def rescue_action(e) raise e end; end
22 class QueriesController; def rescue_action(e) raise e end; end
23
23
24 class QueriesControllerTest < ActionController::TestCase
24 class QueriesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries
25 fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries
26
26
27 def setup
27 def setup
28 @controller = QueriesController.new
28 @controller = QueriesController.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_get_new_project_query
34 def test_get_new_project_query
35 @request.session[:user_id] = 2
35 @request.session[:user_id] = 2
36 get :new, :project_id => 1
36 get :new, :project_id => 1
37 assert_response :success
37 assert_response :success
38 assert_template 'new'
38 assert_template 'new'
39 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
39 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
40 :name => 'query[is_public]',
40 :name => 'query[is_public]',
41 :checked => nil }
41 :checked => nil }
42 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
42 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
43 :name => 'query_is_for_all',
43 :name => 'query_is_for_all',
44 :checked => nil,
44 :checked => nil,
45 :disabled => nil }
45 :disabled => nil }
46 end
46 end
47
47
48 def test_get_new_global_query
48 def test_get_new_global_query
49 @request.session[:user_id] = 2
49 @request.session[:user_id] = 2
50 get :new
50 get :new
51 assert_response :success
51 assert_response :success
52 assert_template 'new'
52 assert_template 'new'
53 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
53 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
54 :name => 'query[is_public]' }
54 :name => 'query[is_public]' }
55 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
55 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
56 :name => 'query_is_for_all',
56 :name => 'query_is_for_all',
57 :checked => 'checked',
57 :checked => 'checked',
58 :disabled => nil }
58 :disabled => nil }
59 end
59 end
60
60
61 def test_new_project_public_query
61 def test_new_project_public_query
62 @request.session[:user_id] = 2
62 @request.session[:user_id] = 2
63 post :new,
63 post :new,
64 :project_id => 'ecookbook',
64 :project_id => 'ecookbook',
65 :confirm => '1',
65 :confirm => '1',
66 :default_columns => '1',
66 :default_columns => '1',
67 :f => ["status_id", "assigned_to_id"],
67 :f => ["status_id", "assigned_to_id"],
68 :op => {"assigned_to_id" => "=", "status_id" => "o"},
68 :op => {"assigned_to_id" => "=", "status_id" => "o"},
69 :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
69 :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
70 :query => {"name" => "test_new_project_public_query", "is_public" => "1"}
70 :query => {"name" => "test_new_project_public_query", "is_public" => "1"}
71
71
72 q = Query.find_by_name('test_new_project_public_query')
72 q = Query.find_by_name('test_new_project_public_query')
73 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
73 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
74 assert q.is_public?
74 assert q.is_public?
75 assert q.has_default_columns?
75 assert q.has_default_columns?
76 assert q.valid?
76 assert q.valid?
77 end
77 end
78
78
79 def test_new_project_private_query
79 def test_new_project_private_query
80 @request.session[:user_id] = 3
80 @request.session[:user_id] = 3
81 post :new,
81 post :new,
82 :project_id => 'ecookbook',
82 :project_id => 'ecookbook',
83 :confirm => '1',
83 :confirm => '1',
84 :default_columns => '1',
84 :default_columns => '1',
85 :fields => ["status_id", "assigned_to_id"],
85 :fields => ["status_id", "assigned_to_id"],
86 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
86 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
87 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
87 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
88 :query => {"name" => "test_new_project_private_query", "is_public" => "1"}
88 :query => {"name" => "test_new_project_private_query", "is_public" => "1"}
89
89
90 q = Query.find_by_name('test_new_project_private_query')
90 q = Query.find_by_name('test_new_project_private_query')
91 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
91 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
92 assert !q.is_public?
92 assert !q.is_public?
93 assert q.has_default_columns?
93 assert q.has_default_columns?
94 assert q.valid?
94 assert q.valid?
95 end
95 end
96
96
97 def test_new_global_private_query_with_custom_columns
97 def test_new_global_private_query_with_custom_columns
98 @request.session[:user_id] = 3
98 @request.session[:user_id] = 3
99 post :new,
99 post :new,
100 :confirm => '1',
100 :confirm => '1',
101 :fields => ["status_id", "assigned_to_id"],
101 :fields => ["status_id", "assigned_to_id"],
102 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
102 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
103 :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
103 :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
104 :query => {"name" => "test_new_global_private_query", "is_public" => "1", "column_names" => ["", "tracker", "subject", "priority", "category"]}
104 :query => {"name" => "test_new_global_private_query", "is_public" => "1"},
105 :c => ["", "tracker", "subject", "priority", "category"]
105
106
106 q = Query.find_by_name('test_new_global_private_query')
107 q = Query.find_by_name('test_new_global_private_query')
107 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
108 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
108 assert !q.is_public?
109 assert !q.is_public?
109 assert !q.has_default_columns?
110 assert !q.has_default_columns?
110 assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
111 assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
111 assert q.valid?
112 assert q.valid?
112 end
113 end
113
114
114 def test_new_with_sort
115 def test_new_with_sort
115 @request.session[:user_id] = 1
116 @request.session[:user_id] = 1
116 post :new,
117 post :new,
117 :confirm => '1',
118 :confirm => '1',
118 :default_columns => '1',
119 :default_columns => '1',
119 :operators => {"status_id" => "o"},
120 :operators => {"status_id" => "o"},
120 :values => {"status_id" => ["1"]},
121 :values => {"status_id" => ["1"]},
121 :query => {:name => "test_new_with_sort",
122 :query => {:name => "test_new_with_sort",
122 :is_public => "1",
123 :is_public => "1",
123 :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}}
124 :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}}
124
125
125 query = Query.find_by_name("test_new_with_sort")
126 query = Query.find_by_name("test_new_with_sort")
126 assert_not_nil query
127 assert_not_nil query
127 assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria
128 assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria
128 end
129 end
129
130
130 def test_get_edit_global_public_query
131 def test_get_edit_global_public_query
131 @request.session[:user_id] = 1
132 @request.session[:user_id] = 1
132 get :edit, :id => 4
133 get :edit, :id => 4
133 assert_response :success
134 assert_response :success
134 assert_template 'edit'
135 assert_template 'edit'
135 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
136 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
136 :name => 'query[is_public]',
137 :name => 'query[is_public]',
137 :checked => 'checked' }
138 :checked => 'checked' }
138 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
139 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
139 :name => 'query_is_for_all',
140 :name => 'query_is_for_all',
140 :checked => 'checked',
141 :checked => 'checked',
141 :disabled => 'disabled' }
142 :disabled => 'disabled' }
142 end
143 end
143
144
144 def test_edit_global_public_query
145 def test_edit_global_public_query
145 @request.session[:user_id] = 1
146 @request.session[:user_id] = 1
146 post :edit,
147 post :edit,
147 :id => 4,
148 :id => 4,
148 :confirm => '1',
149 :confirm => '1',
149 :default_columns => '1',
150 :default_columns => '1',
150 :fields => ["status_id", "assigned_to_id"],
151 :fields => ["status_id", "assigned_to_id"],
151 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
152 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
152 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
153 :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
153 :query => {"name" => "test_edit_global_public_query", "is_public" => "1"}
154 :query => {"name" => "test_edit_global_public_query", "is_public" => "1"}
154
155
155 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4
156 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4
156 q = Query.find_by_name('test_edit_global_public_query')
157 q = Query.find_by_name('test_edit_global_public_query')
157 assert q.is_public?
158 assert q.is_public?
158 assert q.has_default_columns?
159 assert q.has_default_columns?
159 assert q.valid?
160 assert q.valid?
160 end
161 end
161
162
162 def test_get_edit_global_private_query
163 def test_get_edit_global_private_query
163 @request.session[:user_id] = 3
164 @request.session[:user_id] = 3
164 get :edit, :id => 3
165 get :edit, :id => 3
165 assert_response :success
166 assert_response :success
166 assert_template 'edit'
167 assert_template 'edit'
167 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
168 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
168 :name => 'query[is_public]' }
169 :name => 'query[is_public]' }
169 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
170 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
170 :name => 'query_is_for_all',
171 :name => 'query_is_for_all',
171 :checked => 'checked',
172 :checked => 'checked',
172 :disabled => 'disabled' }
173 :disabled => 'disabled' }
173 end
174 end
174
175
175 def test_edit_global_private_query
176 def test_edit_global_private_query
176 @request.session[:user_id] = 3
177 @request.session[:user_id] = 3
177 post :edit,
178 post :edit,
178 :id => 3,
179 :id => 3,
179 :confirm => '1',
180 :confirm => '1',
180 :default_columns => '1',
181 :default_columns => '1',
181 :fields => ["status_id", "assigned_to_id"],
182 :fields => ["status_id", "assigned_to_id"],
182 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
183 :operators => {"assigned_to_id" => "=", "status_id" => "o"},
183 :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
184 :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
184 :query => {"name" => "test_edit_global_private_query", "is_public" => "1"}
185 :query => {"name" => "test_edit_global_private_query", "is_public" => "1"}
185
186
186 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3
187 assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3
187 q = Query.find_by_name('test_edit_global_private_query')
188 q = Query.find_by_name('test_edit_global_private_query')
188 assert !q.is_public?
189 assert !q.is_public?
189 assert q.has_default_columns?
190 assert q.has_default_columns?
190 assert q.valid?
191 assert q.valid?
191 end
192 end
192
193
193 def test_get_edit_project_private_query
194 def test_get_edit_project_private_query
194 @request.session[:user_id] = 3
195 @request.session[:user_id] = 3
195 get :edit, :id => 2
196 get :edit, :id => 2
196 assert_response :success
197 assert_response :success
197 assert_template 'edit'
198 assert_template 'edit'
198 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
199 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
199 :name => 'query[is_public]' }
200 :name => 'query[is_public]' }
200 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
201 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
201 :name => 'query_is_for_all',
202 :name => 'query_is_for_all',
202 :checked => nil,
203 :checked => nil,
203 :disabled => nil }
204 :disabled => nil }
204 end
205 end
205
206
206 def test_get_edit_project_public_query
207 def test_get_edit_project_public_query
207 @request.session[:user_id] = 2
208 @request.session[:user_id] = 2
208 get :edit, :id => 1
209 get :edit, :id => 1
209 assert_response :success
210 assert_response :success
210 assert_template 'edit'
211 assert_template 'edit'
211 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
212 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
212 :name => 'query[is_public]',
213 :name => 'query[is_public]',
213 :checked => 'checked'
214 :checked => 'checked'
214 }
215 }
215 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
216 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
216 :name => 'query_is_for_all',
217 :name => 'query_is_for_all',
217 :checked => nil,
218 :checked => nil,
218 :disabled => 'disabled' }
219 :disabled => 'disabled' }
219 end
220 end
220
221
221 def test_get_edit_sort_criteria
222 def test_get_edit_sort_criteria
222 @request.session[:user_id] = 1
223 @request.session[:user_id] = 1
223 get :edit, :id => 5
224 get :edit, :id => 5
224 assert_response :success
225 assert_response :success
225 assert_template 'edit'
226 assert_template 'edit'
226 assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
227 assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
227 :child => { :tag => 'option', :attributes => { :value => 'priority',
228 :child => { :tag => 'option', :attributes => { :value => 'priority',
228 :selected => 'selected' } }
229 :selected => 'selected' } }
229 assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
230 assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
230 :child => { :tag => 'option', :attributes => { :value => 'desc',
231 :child => { :tag => 'option', :attributes => { :value => 'desc',
231 :selected => 'selected' } }
232 :selected => 'selected' } }
232 end
233 end
233
234
234 def test_destroy
235 def test_destroy
235 @request.session[:user_id] = 2
236 @request.session[:user_id] = 2
236 post :destroy, :id => 1
237 post :destroy, :id => 1
237 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil
238 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil
238 assert_nil Query.find_by_id(1)
239 assert_nil Query.find_by_id(1)
239 end
240 end
240 end
241 end
General Comments 0
You need to be logged in to leave comments. Login now