@@ -1,128 +1,129 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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, :create, :index] |
|
20 | before_filter :find_query, :except => [:new, :create, :index] | |
21 | before_filter :find_optional_project, :only => [:new, :create] |
|
21 | before_filter :find_optional_project, :only => [:new, :create] | |
22 |
|
22 | |||
23 | accept_api_auth :index |
|
23 | accept_api_auth :index | |
24 |
|
24 | |||
25 | include QueriesHelper |
|
25 | include QueriesHelper | |
26 |
|
26 | |||
27 | def index |
|
27 | def index | |
28 | case params[:format] |
|
28 | case params[:format] | |
29 | when 'xml', 'json' |
|
29 | when 'xml', 'json' | |
30 | @offset, @limit = api_offset_and_limit |
|
30 | @offset, @limit = api_offset_and_limit | |
31 | else |
|
31 | else | |
32 | @limit = per_page_option |
|
32 | @limit = per_page_option | |
33 | end |
|
33 | end | |
34 | @query_count = IssueQuery.visible.count |
|
34 | @query_count = IssueQuery.visible.count | |
35 | @query_pages = Paginator.new @query_count, @limit, params['page'] |
|
35 | @query_pages = Paginator.new @query_count, @limit, params['page'] | |
36 | @queries = IssueQuery.visible. |
|
36 | @queries = IssueQuery.visible. | |
37 | order("#{Query.table_name}.name"). |
|
37 | order("#{Query.table_name}.name"). | |
38 | limit(@limit). |
|
38 | limit(@limit). | |
39 | offset(@offset). |
|
39 | offset(@offset). | |
40 | to_a |
|
40 | to_a | |
41 | respond_to do |format| |
|
41 | respond_to do |format| | |
42 | format.html {render_error :status => 406} |
|
42 | format.html {render_error :status => 406} | |
43 | format.api |
|
43 | format.api | |
44 | end |
|
44 | end | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def new |
|
47 | def new | |
48 | @query = IssueQuery.new |
|
48 | @query = IssueQuery.new | |
49 | @query.user = User.current |
|
49 | @query.user = User.current | |
50 | @query.project = @project |
|
50 | @query.project = @project | |
51 | @query.build_from_params(params) |
|
51 | @query.build_from_params(params) | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def create |
|
54 | def create | |
55 | @query = IssueQuery.new |
|
55 | @query = IssueQuery.new | |
56 | @query.user = User.current |
|
56 | @query.user = User.current | |
57 | @query.project = @project |
|
57 | @query.project = @project | |
58 | update_query_from_params |
|
58 | update_query_from_params | |
59 |
|
59 | |||
60 | if @query.save |
|
60 | if @query.save | |
61 | flash[:notice] = l(:notice_successful_create) |
|
61 | flash[:notice] = l(:notice_successful_create) | |
62 | redirect_to_issues(:query_id => @query) |
|
62 | redirect_to_issues(:query_id => @query) | |
63 | else |
|
63 | else | |
64 | render :action => 'new', :layout => !request.xhr? |
|
64 | render :action => 'new', :layout => !request.xhr? | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def edit |
|
68 | def edit | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | def update |
|
71 | def update | |
72 | update_query_from_params |
|
72 | update_query_from_params | |
73 |
|
73 | |||
74 | if @query.save |
|
74 | if @query.save | |
75 | flash[:notice] = l(:notice_successful_update) |
|
75 | flash[:notice] = l(:notice_successful_update) | |
76 | redirect_to_issues(:query_id => @query) |
|
76 | redirect_to_issues(:query_id => @query) | |
77 | else |
|
77 | else | |
78 | render :action => 'edit' |
|
78 | render :action => 'edit' | |
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def destroy |
|
82 | def destroy | |
83 | @query.destroy |
|
83 | @query.destroy | |
84 | redirect_to_issues(:set_filter => 1) |
|
84 | redirect_to_issues(:set_filter => 1) | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | private |
|
87 | private | |
88 | def find_query |
|
88 | def find_query | |
89 | @query = IssueQuery.find(params[:id]) |
|
89 | @query = IssueQuery.find(params[:id]) | |
90 | @project = @query.project |
|
90 | @project = @query.project | |
91 | render_403 unless @query.editable_by?(User.current) |
|
91 | render_403 unless @query.editable_by?(User.current) | |
92 | rescue ActiveRecord::RecordNotFound |
|
92 | rescue ActiveRecord::RecordNotFound | |
93 | render_404 |
|
93 | render_404 | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | def find_optional_project |
|
96 | def find_optional_project | |
97 | @project = Project.find(params[:project_id]) if params[:project_id] |
|
97 | @project = Project.find(params[:project_id]) if params[:project_id] | |
98 | render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) |
|
98 | render_403 unless User.current.allowed_to?(:save_queries, @project, :global => true) | |
99 | rescue ActiveRecord::RecordNotFound |
|
99 | rescue ActiveRecord::RecordNotFound | |
100 | render_404 |
|
100 | render_404 | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | def update_query_from_params |
|
103 | def update_query_from_params | |
104 | @query.project = params[:query_is_for_all] ? nil : @project |
|
104 | @query.project = params[:query_is_for_all] ? nil : @project | |
105 | @query.build_from_params(params) |
|
105 | @query.build_from_params(params) | |
106 | @query.column_names = nil if params[:default_columns] |
|
106 | @query.column_names = nil if params[:default_columns] | |
107 | @query.sort_criteria = params[:query] && params[:query][:sort_criteria] |
|
107 | @query.sort_criteria = params[:query] && params[:query][:sort_criteria] | |
108 | @query.name = params[:query] && params[:query][:name] |
|
108 | @query.name = params[:query] && params[:query][:name] | |
109 | if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin? |
|
109 | if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin? | |
110 | @query.visibility = (params[:query] && params[:query][:visibility]) || IssueQuery::VISIBILITY_PRIVATE |
|
110 | @query.visibility = (params[:query] && params[:query][:visibility]) || IssueQuery::VISIBILITY_PRIVATE | |
|
111 | @query.role_ids = params[:query] && params[:query][:role_ids] | |||
111 | else |
|
112 | else | |
112 | @query.visibility = IssueQuery::VISIBILITY_PRIVATE |
|
113 | @query.visibility = IssueQuery::VISIBILITY_PRIVATE | |
113 | end |
|
114 | end | |
114 | @query |
|
115 | @query | |
115 | end |
|
116 | end | |
116 |
|
117 | |||
117 | def redirect_to_issues(options) |
|
118 | def redirect_to_issues(options) | |
118 | if params[:gantt] |
|
119 | if params[:gantt] | |
119 | if @project |
|
120 | if @project | |
120 | redirect_to project_gantt_path(@project, options) |
|
121 | redirect_to project_gantt_path(@project, options) | |
121 | else |
|
122 | else | |
122 | redirect_to issues_gantt_path(options) |
|
123 | redirect_to issues_gantt_path(options) | |
123 | end |
|
124 | end | |
124 | else |
|
125 | else | |
125 | redirect_to _project_issues_path(@project, options) |
|
126 | redirect_to _project_issues_path(@project, options) | |
126 | end |
|
127 | end | |
127 | end |
|
128 | end | |
128 | end |
|
129 | end |
@@ -1,358 +1,374 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class QueriesControllerTest < ActionController::TestCase |
|
20 | class QueriesControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries, :enabled_modules |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries, :enabled_modules | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | User.current = nil |
|
24 | User.current = nil | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def test_index |
|
27 | def test_index | |
28 | get :index |
|
28 | get :index | |
29 | # HTML response not implemented |
|
29 | # HTML response not implemented | |
30 | assert_response 406 |
|
30 | assert_response 406 | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_new_project_query |
|
33 | def test_new_project_query | |
34 | @request.session[:user_id] = 2 |
|
34 | @request.session[:user_id] = 2 | |
35 | get :new, :project_id => 1 |
|
35 | get :new, :project_id => 1 | |
36 | assert_response :success |
|
36 | assert_response :success | |
37 | assert_template 'new' |
|
37 | assert_template 'new' | |
38 | assert_select 'input[name=?][value="0"][checked=checked]', 'query[visibility]' |
|
38 | assert_select 'input[name=?][value="0"][checked=checked]', 'query[visibility]' | |
39 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked]):not([disabled])' |
|
39 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked]):not([disabled])' | |
40 | assert_select 'select[name=?]', 'c[]' do |
|
40 | assert_select 'select[name=?]', 'c[]' do | |
41 | assert_select 'option[value=tracker]' |
|
41 | assert_select 'option[value=tracker]' | |
42 | assert_select 'option[value=subject]' |
|
42 | assert_select 'option[value=subject]' | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_new_global_query |
|
46 | def test_new_global_query | |
47 | @request.session[:user_id] = 2 |
|
47 | @request.session[:user_id] = 2 | |
48 | get :new |
|
48 | get :new | |
49 | assert_response :success |
|
49 | assert_response :success | |
50 | assert_template 'new' |
|
50 | assert_template 'new' | |
51 | assert_select 'input[name=?]', 'query[visibility]', 0 |
|
51 | assert_select 'input[name=?]', 'query[visibility]', 0 | |
52 | assert_select 'input[name=query_is_for_all][type=checkbox][checked]:not([disabled])' |
|
52 | assert_select 'input[name=query_is_for_all][type=checkbox][checked]:not([disabled])' | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_new_on_invalid_project |
|
55 | def test_new_on_invalid_project | |
56 | @request.session[:user_id] = 2 |
|
56 | @request.session[:user_id] = 2 | |
57 | get :new, :project_id => 'invalid' |
|
57 | get :new, :project_id => 'invalid' | |
58 | assert_response 404 |
|
58 | assert_response 404 | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def test_create_project_public_query |
|
61 | def test_create_project_public_query | |
62 | @request.session[:user_id] = 2 |
|
62 | @request.session[:user_id] = 2 | |
63 | post :create, |
|
63 | post :create, | |
64 | :project_id => 'ecookbook', |
|
64 | :project_id => 'ecookbook', | |
65 | :default_columns => '1', |
|
65 | :default_columns => '1', | |
66 | :f => ["status_id", "assigned_to_id"], |
|
66 | :f => ["status_id", "assigned_to_id"], | |
67 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
67 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, | |
68 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
68 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
69 | :query => {"name" => "test_new_project_public_query", "visibility" => "2"} |
|
69 | :query => {"name" => "test_new_project_public_query", "visibility" => "2"} | |
70 |
|
70 | |||
71 | q = Query.find_by_name('test_new_project_public_query') |
|
71 | q = Query.find_by_name('test_new_project_public_query') | |
72 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
72 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q | |
73 | assert q.is_public? |
|
73 | assert q.is_public? | |
74 | assert q.has_default_columns? |
|
74 | assert q.has_default_columns? | |
75 | assert q.valid? |
|
75 | assert q.valid? | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_create_project_private_query |
|
78 | def test_create_project_private_query | |
79 | @request.session[:user_id] = 3 |
|
79 | @request.session[:user_id] = 3 | |
80 | post :create, |
|
80 | post :create, | |
81 | :project_id => 'ecookbook', |
|
81 | :project_id => 'ecookbook', | |
82 | :default_columns => '1', |
|
82 | :default_columns => '1', | |
83 | :fields => ["status_id", "assigned_to_id"], |
|
83 | :fields => ["status_id", "assigned_to_id"], | |
84 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
84 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
85 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
85 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
86 | :query => {"name" => "test_new_project_private_query", "visibility" => "0"} |
|
86 | :query => {"name" => "test_new_project_private_query", "visibility" => "0"} | |
87 |
|
87 | |||
88 | q = Query.find_by_name('test_new_project_private_query') |
|
88 | q = Query.find_by_name('test_new_project_private_query') | |
89 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
89 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q | |
90 | assert !q.is_public? |
|
90 | assert !q.is_public? | |
91 | assert q.has_default_columns? |
|
91 | assert q.has_default_columns? | |
92 | assert q.valid? |
|
92 | assert q.valid? | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
|
95 | def test_create_project_roles_query | |||
|
96 | @request.session[:user_id] = 2 | |||
|
97 | post :create, | |||
|
98 | :project_id => 'ecookbook', | |||
|
99 | :default_columns => '1', | |||
|
100 | :fields => ["status_id", "assigned_to_id"], | |||
|
101 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |||
|
102 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |||
|
103 | :query => {"name" => "test_create_project_roles_query", "visibility" => "1", "role_ids" => ["1", "2", ""]} | |||
|
104 | ||||
|
105 | q = Query.find_by_name('test_create_project_roles_query') | |||
|
106 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q | |||
|
107 | assert_equal Query::VISIBILITY_ROLES, q.visibility | |||
|
108 | assert_equal [1, 2], q.roles.ids.sort | |||
|
109 | end | |||
|
110 | ||||
95 | def test_create_global_private_query_with_custom_columns |
|
111 | def test_create_global_private_query_with_custom_columns | |
96 | @request.session[:user_id] = 3 |
|
112 | @request.session[:user_id] = 3 | |
97 | post :create, |
|
113 | post :create, | |
98 | :fields => ["status_id", "assigned_to_id"], |
|
114 | :fields => ["status_id", "assigned_to_id"], | |
99 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
115 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
100 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
116 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |
101 | :query => {"name" => "test_new_global_private_query", "visibility" => "0"}, |
|
117 | :query => {"name" => "test_new_global_private_query", "visibility" => "0"}, | |
102 | :c => ["", "tracker", "subject", "priority", "category"] |
|
118 | :c => ["", "tracker", "subject", "priority", "category"] | |
103 |
|
119 | |||
104 | q = Query.find_by_name('test_new_global_private_query') |
|
120 | q = Query.find_by_name('test_new_global_private_query') | |
105 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
121 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q | |
106 | assert !q.is_public? |
|
122 | assert !q.is_public? | |
107 | assert !q.has_default_columns? |
|
123 | assert !q.has_default_columns? | |
108 | assert_equal [:id, :tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} |
|
124 | assert_equal [:id, :tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} | |
109 | assert q.valid? |
|
125 | assert q.valid? | |
110 | end |
|
126 | end | |
111 |
|
127 | |||
112 | def test_create_global_query_with_custom_filters |
|
128 | def test_create_global_query_with_custom_filters | |
113 | @request.session[:user_id] = 3 |
|
129 | @request.session[:user_id] = 3 | |
114 | post :create, |
|
130 | post :create, | |
115 | :fields => ["assigned_to_id"], |
|
131 | :fields => ["assigned_to_id"], | |
116 | :operators => {"assigned_to_id" => "="}, |
|
132 | :operators => {"assigned_to_id" => "="}, | |
117 | :values => { "assigned_to_id" => ["me"]}, |
|
133 | :values => { "assigned_to_id" => ["me"]}, | |
118 | :query => {"name" => "test_new_global_query"} |
|
134 | :query => {"name" => "test_new_global_query"} | |
119 |
|
135 | |||
120 | q = Query.find_by_name('test_new_global_query') |
|
136 | q = Query.find_by_name('test_new_global_query') | |
121 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
137 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q | |
122 | assert !q.is_public? |
|
138 | assert !q.is_public? | |
123 | assert !q.has_filter?(:status_id) |
|
139 | assert !q.has_filter?(:status_id) | |
124 | assert_equal ['assigned_to_id'], q.filters.keys |
|
140 | assert_equal ['assigned_to_id'], q.filters.keys | |
125 | assert q.valid? |
|
141 | assert q.valid? | |
126 | end |
|
142 | end | |
127 |
|
143 | |||
128 | def test_create_with_sort |
|
144 | def test_create_with_sort | |
129 | @request.session[:user_id] = 1 |
|
145 | @request.session[:user_id] = 1 | |
130 | post :create, |
|
146 | post :create, | |
131 | :default_columns => '1', |
|
147 | :default_columns => '1', | |
132 | :operators => {"status_id" => "o"}, |
|
148 | :operators => {"status_id" => "o"}, | |
133 | :values => {"status_id" => ["1"]}, |
|
149 | :values => {"status_id" => ["1"]}, | |
134 | :query => {:name => "test_new_with_sort", |
|
150 | :query => {:name => "test_new_with_sort", | |
135 | :visibility => "2", |
|
151 | :visibility => "2", | |
136 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} |
|
152 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} | |
137 |
|
153 | |||
138 | query = Query.find_by_name("test_new_with_sort") |
|
154 | query = Query.find_by_name("test_new_with_sort") | |
139 | assert_not_nil query |
|
155 | assert_not_nil query | |
140 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
|
156 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria | |
141 | end |
|
157 | end | |
142 |
|
158 | |||
143 | def test_create_with_failure |
|
159 | def test_create_with_failure | |
144 | @request.session[:user_id] = 2 |
|
160 | @request.session[:user_id] = 2 | |
145 | assert_no_difference '::Query.count' do |
|
161 | assert_no_difference '::Query.count' do | |
146 | post :create, :project_id => 'ecookbook', :query => {:name => ''} |
|
162 | post :create, :project_id => 'ecookbook', :query => {:name => ''} | |
147 | end |
|
163 | end | |
148 | assert_response :success |
|
164 | assert_response :success | |
149 | assert_template 'new' |
|
165 | assert_template 'new' | |
150 | assert_select 'input[name=?]', 'query[name]' |
|
166 | assert_select 'input[name=?]', 'query[name]' | |
151 | end |
|
167 | end | |
152 |
|
168 | |||
153 | def test_create_global_query_from_gantt |
|
169 | def test_create_global_query_from_gantt | |
154 | @request.session[:user_id] = 1 |
|
170 | @request.session[:user_id] = 1 | |
155 | assert_difference 'IssueQuery.count' do |
|
171 | assert_difference 'IssueQuery.count' do | |
156 | post :create, |
|
172 | post :create, | |
157 | :gantt => 1, |
|
173 | :gantt => 1, | |
158 | :operators => {"status_id" => "o"}, |
|
174 | :operators => {"status_id" => "o"}, | |
159 | :values => {"status_id" => ["1"]}, |
|
175 | :values => {"status_id" => ["1"]}, | |
160 | :query => {:name => "test_create_from_gantt", |
|
176 | :query => {:name => "test_create_from_gantt", | |
161 | :draw_relations => '1', |
|
177 | :draw_relations => '1', | |
162 | :draw_progress_line => '1'} |
|
178 | :draw_progress_line => '1'} | |
163 | assert_response 302 |
|
179 | assert_response 302 | |
164 | end |
|
180 | end | |
165 | query = IssueQuery.order('id DESC').first |
|
181 | query = IssueQuery.order('id DESC').first | |
166 | assert_redirected_to "/issues/gantt?query_id=#{query.id}" |
|
182 | assert_redirected_to "/issues/gantt?query_id=#{query.id}" | |
167 | assert_equal true, query.draw_relations |
|
183 | assert_equal true, query.draw_relations | |
168 | assert_equal true, query.draw_progress_line |
|
184 | assert_equal true, query.draw_progress_line | |
169 | end |
|
185 | end | |
170 |
|
186 | |||
171 | def test_create_project_query_from_gantt |
|
187 | def test_create_project_query_from_gantt | |
172 | @request.session[:user_id] = 1 |
|
188 | @request.session[:user_id] = 1 | |
173 | assert_difference 'IssueQuery.count' do |
|
189 | assert_difference 'IssueQuery.count' do | |
174 | post :create, |
|
190 | post :create, | |
175 | :project_id => 'ecookbook', |
|
191 | :project_id => 'ecookbook', | |
176 | :gantt => 1, |
|
192 | :gantt => 1, | |
177 | :operators => {"status_id" => "o"}, |
|
193 | :operators => {"status_id" => "o"}, | |
178 | :values => {"status_id" => ["1"]}, |
|
194 | :values => {"status_id" => ["1"]}, | |
179 | :query => {:name => "test_create_from_gantt", |
|
195 | :query => {:name => "test_create_from_gantt", | |
180 | :draw_relations => '0', |
|
196 | :draw_relations => '0', | |
181 | :draw_progress_line => '0'} |
|
197 | :draw_progress_line => '0'} | |
182 | assert_response 302 |
|
198 | assert_response 302 | |
183 | end |
|
199 | end | |
184 | query = IssueQuery.order('id DESC').first |
|
200 | query = IssueQuery.order('id DESC').first | |
185 | assert_redirected_to "/projects/ecookbook/issues/gantt?query_id=#{query.id}" |
|
201 | assert_redirected_to "/projects/ecookbook/issues/gantt?query_id=#{query.id}" | |
186 | assert_equal false, query.draw_relations |
|
202 | assert_equal false, query.draw_relations | |
187 | assert_equal false, query.draw_progress_line |
|
203 | assert_equal false, query.draw_progress_line | |
188 | end |
|
204 | end | |
189 |
|
205 | |||
190 | def test_create_project_public_query_should_force_private_without_manage_public_queries_permission |
|
206 | def test_create_project_public_query_should_force_private_without_manage_public_queries_permission | |
191 | @request.session[:user_id] = 3 |
|
207 | @request.session[:user_id] = 3 | |
192 | query = new_record(Query) do |
|
208 | query = new_record(Query) do | |
193 | post :create, |
|
209 | post :create, | |
194 | :project_id => 'ecookbook', |
|
210 | :project_id => 'ecookbook', | |
195 | :query => {"name" => "name", "visibility" => "2"} |
|
211 | :query => {"name" => "name", "visibility" => "2"} | |
196 | assert_response 302 |
|
212 | assert_response 302 | |
197 | end |
|
213 | end | |
198 | assert_not_nil query.project |
|
214 | assert_not_nil query.project | |
199 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility |
|
215 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility | |
200 | end |
|
216 | end | |
201 |
|
217 | |||
202 | def test_create_global_public_query_should_force_private_without_manage_public_queries_permission |
|
218 | def test_create_global_public_query_should_force_private_without_manage_public_queries_permission | |
203 | @request.session[:user_id] = 3 |
|
219 | @request.session[:user_id] = 3 | |
204 | query = new_record(Query) do |
|
220 | query = new_record(Query) do | |
205 | post :create, |
|
221 | post :create, | |
206 | :project_id => 'ecookbook', :query_is_for_all => '1', |
|
222 | :project_id => 'ecookbook', :query_is_for_all => '1', | |
207 | :query => {"name" => "name", "visibility" => "2"} |
|
223 | :query => {"name" => "name", "visibility" => "2"} | |
208 | assert_response 302 |
|
224 | assert_response 302 | |
209 | end |
|
225 | end | |
210 | assert_nil query.project |
|
226 | assert_nil query.project | |
211 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility |
|
227 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility | |
212 | end |
|
228 | end | |
213 |
|
229 | |||
214 | def test_create_project_public_query_with_manage_public_queries_permission |
|
230 | def test_create_project_public_query_with_manage_public_queries_permission | |
215 | @request.session[:user_id] = 2 |
|
231 | @request.session[:user_id] = 2 | |
216 | query = new_record(Query) do |
|
232 | query = new_record(Query) do | |
217 | post :create, |
|
233 | post :create, | |
218 | :project_id => 'ecookbook', |
|
234 | :project_id => 'ecookbook', | |
219 | :query => {"name" => "name", "visibility" => "2"} |
|
235 | :query => {"name" => "name", "visibility" => "2"} | |
220 | assert_response 302 |
|
236 | assert_response 302 | |
221 | end |
|
237 | end | |
222 | assert_not_nil query.project |
|
238 | assert_not_nil query.project | |
223 | assert_equal Query::VISIBILITY_PUBLIC, query.visibility |
|
239 | assert_equal Query::VISIBILITY_PUBLIC, query.visibility | |
224 | end |
|
240 | end | |
225 |
|
241 | |||
226 | def test_create_global_public_query_should_force_private_with_manage_public_queries_permission |
|
242 | def test_create_global_public_query_should_force_private_with_manage_public_queries_permission | |
227 | @request.session[:user_id] = 2 |
|
243 | @request.session[:user_id] = 2 | |
228 | query = new_record(Query) do |
|
244 | query = new_record(Query) do | |
229 | post :create, |
|
245 | post :create, | |
230 | :project_id => 'ecookbook', :query_is_for_all => '1', |
|
246 | :project_id => 'ecookbook', :query_is_for_all => '1', | |
231 | :query => {"name" => "name", "visibility" => "2"} |
|
247 | :query => {"name" => "name", "visibility" => "2"} | |
232 | assert_response 302 |
|
248 | assert_response 302 | |
233 | end |
|
249 | end | |
234 | assert_nil query.project |
|
250 | assert_nil query.project | |
235 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility |
|
251 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility | |
236 | end |
|
252 | end | |
237 |
|
253 | |||
238 | def test_create_global_public_query_by_admin |
|
254 | def test_create_global_public_query_by_admin | |
239 | @request.session[:user_id] = 1 |
|
255 | @request.session[:user_id] = 1 | |
240 | query = new_record(Query) do |
|
256 | query = new_record(Query) do | |
241 | post :create, |
|
257 | post :create, | |
242 | :project_id => 'ecookbook', :query_is_for_all => '1', |
|
258 | :project_id => 'ecookbook', :query_is_for_all => '1', | |
243 | :query => {"name" => "name", "visibility" => "2"} |
|
259 | :query => {"name" => "name", "visibility" => "2"} | |
244 | assert_response 302 |
|
260 | assert_response 302 | |
245 | end |
|
261 | end | |
246 | assert_nil query.project |
|
262 | assert_nil query.project | |
247 | assert_equal Query::VISIBILITY_PUBLIC, query.visibility |
|
263 | assert_equal Query::VISIBILITY_PUBLIC, query.visibility | |
248 | end |
|
264 | end | |
249 |
|
265 | |||
250 | def test_edit_global_public_query |
|
266 | def test_edit_global_public_query | |
251 | @request.session[:user_id] = 1 |
|
267 | @request.session[:user_id] = 1 | |
252 | get :edit, :id => 4 |
|
268 | get :edit, :id => 4 | |
253 | assert_response :success |
|
269 | assert_response :success | |
254 | assert_template 'edit' |
|
270 | assert_template 'edit' | |
255 | assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' |
|
271 | assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' | |
256 | assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]' |
|
272 | assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]' | |
257 | end |
|
273 | end | |
258 |
|
274 | |||
259 | def test_edit_global_private_query |
|
275 | def test_edit_global_private_query | |
260 | @request.session[:user_id] = 3 |
|
276 | @request.session[:user_id] = 3 | |
261 | get :edit, :id => 3 |
|
277 | get :edit, :id => 3 | |
262 | assert_response :success |
|
278 | assert_response :success | |
263 | assert_template 'edit' |
|
279 | assert_template 'edit' | |
264 | assert_select 'input[name=?]', 'query[visibility]', 0 |
|
280 | assert_select 'input[name=?]', 'query[visibility]', 0 | |
265 | assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]' |
|
281 | assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]' | |
266 | end |
|
282 | end | |
267 |
|
283 | |||
268 | def test_edit_project_private_query |
|
284 | def test_edit_project_private_query | |
269 | @request.session[:user_id] = 3 |
|
285 | @request.session[:user_id] = 3 | |
270 | get :edit, :id => 2 |
|
286 | get :edit, :id => 2 | |
271 | assert_response :success |
|
287 | assert_response :success | |
272 | assert_template 'edit' |
|
288 | assert_template 'edit' | |
273 | assert_select 'input[name=?]', 'query[visibility]', 0 |
|
289 | assert_select 'input[name=?]', 'query[visibility]', 0 | |
274 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])' |
|
290 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])' | |
275 | end |
|
291 | end | |
276 |
|
292 | |||
277 | def test_edit_project_public_query |
|
293 | def test_edit_project_public_query | |
278 | @request.session[:user_id] = 2 |
|
294 | @request.session[:user_id] = 2 | |
279 | get :edit, :id => 1 |
|
295 | get :edit, :id => 1 | |
280 | assert_response :success |
|
296 | assert_response :success | |
281 | assert_template 'edit' |
|
297 | assert_template 'edit' | |
282 | assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' |
|
298 | assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' | |
283 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])' |
|
299 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])' | |
284 | end |
|
300 | end | |
285 |
|
301 | |||
286 | def test_edit_sort_criteria |
|
302 | def test_edit_sort_criteria | |
287 | @request.session[:user_id] = 1 |
|
303 | @request.session[:user_id] = 1 | |
288 | get :edit, :id => 5 |
|
304 | get :edit, :id => 5 | |
289 | assert_response :success |
|
305 | assert_response :success | |
290 | assert_template 'edit' |
|
306 | assert_template 'edit' | |
291 | assert_select 'select[name=?]', 'query[sort_criteria][0][]' do |
|
307 | assert_select 'select[name=?]', 'query[sort_criteria][0][]' do | |
292 | assert_select 'option[value=priority][selected=selected]' |
|
308 | assert_select 'option[value=priority][selected=selected]' | |
293 | assert_select 'option[value=desc][selected=selected]' |
|
309 | assert_select 'option[value=desc][selected=selected]' | |
294 | end |
|
310 | end | |
295 | end |
|
311 | end | |
296 |
|
312 | |||
297 | def test_edit_invalid_query |
|
313 | def test_edit_invalid_query | |
298 | @request.session[:user_id] = 2 |
|
314 | @request.session[:user_id] = 2 | |
299 | get :edit, :id => 99 |
|
315 | get :edit, :id => 99 | |
300 | assert_response 404 |
|
316 | assert_response 404 | |
301 | end |
|
317 | end | |
302 |
|
318 | |||
303 | def test_udpate_global_private_query |
|
319 | def test_udpate_global_private_query | |
304 | @request.session[:user_id] = 3 |
|
320 | @request.session[:user_id] = 3 | |
305 | put :update, |
|
321 | put :update, | |
306 | :id => 3, |
|
322 | :id => 3, | |
307 | :default_columns => '1', |
|
323 | :default_columns => '1', | |
308 | :fields => ["status_id", "assigned_to_id"], |
|
324 | :fields => ["status_id", "assigned_to_id"], | |
309 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
325 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
310 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
326 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |
311 | :query => {"name" => "test_edit_global_private_query", "visibility" => "2"} |
|
327 | :query => {"name" => "test_edit_global_private_query", "visibility" => "2"} | |
312 |
|
328 | |||
313 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
|
329 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 | |
314 | q = Query.find_by_name('test_edit_global_private_query') |
|
330 | q = Query.find_by_name('test_edit_global_private_query') | |
315 | assert !q.is_public? |
|
331 | assert !q.is_public? | |
316 | assert q.has_default_columns? |
|
332 | assert q.has_default_columns? | |
317 | assert q.valid? |
|
333 | assert q.valid? | |
318 | end |
|
334 | end | |
319 |
|
335 | |||
320 | def test_update_global_public_query |
|
336 | def test_update_global_public_query | |
321 | @request.session[:user_id] = 1 |
|
337 | @request.session[:user_id] = 1 | |
322 | put :update, |
|
338 | put :update, | |
323 | :id => 4, |
|
339 | :id => 4, | |
324 | :default_columns => '1', |
|
340 | :default_columns => '1', | |
325 | :fields => ["status_id", "assigned_to_id"], |
|
341 | :fields => ["status_id", "assigned_to_id"], | |
326 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
342 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
327 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
343 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
328 | :query => {"name" => "test_edit_global_public_query", "visibility" => "2"} |
|
344 | :query => {"name" => "test_edit_global_public_query", "visibility" => "2"} | |
329 |
|
345 | |||
330 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
|
346 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 | |
331 | q = Query.find_by_name('test_edit_global_public_query') |
|
347 | q = Query.find_by_name('test_edit_global_public_query') | |
332 | assert q.is_public? |
|
348 | assert q.is_public? | |
333 | assert q.has_default_columns? |
|
349 | assert q.has_default_columns? | |
334 | assert q.valid? |
|
350 | assert q.valid? | |
335 | end |
|
351 | end | |
336 |
|
352 | |||
337 | def test_update_with_failure |
|
353 | def test_update_with_failure | |
338 | @request.session[:user_id] = 1 |
|
354 | @request.session[:user_id] = 1 | |
339 | put :update, :id => 4, :query => {:name => ''} |
|
355 | put :update, :id => 4, :query => {:name => ''} | |
340 | assert_response :success |
|
356 | assert_response :success | |
341 | assert_template 'edit' |
|
357 | assert_template 'edit' | |
342 | end |
|
358 | end | |
343 |
|
359 | |||
344 | def test_destroy |
|
360 | def test_destroy | |
345 | @request.session[:user_id] = 2 |
|
361 | @request.session[:user_id] = 2 | |
346 | delete :destroy, :id => 1 |
|
362 | delete :destroy, :id => 1 | |
347 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
363 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil | |
348 | assert_nil Query.find_by_id(1) |
|
364 | assert_nil Query.find_by_id(1) | |
349 | end |
|
365 | end | |
350 |
|
366 | |||
351 | def test_backslash_should_be_escaped_in_filters |
|
367 | def test_backslash_should_be_escaped_in_filters | |
352 | @request.session[:user_id] = 2 |
|
368 | @request.session[:user_id] = 2 | |
353 | get :new, :subject => 'foo/bar' |
|
369 | get :new, :subject => 'foo/bar' | |
354 | assert_response :success |
|
370 | assert_response :success | |
355 | assert_template 'new' |
|
371 | assert_template 'new' | |
356 | assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body |
|
372 | assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body | |
357 | end |
|
373 | end | |
358 | end |
|
374 | end |
General Comments 0
You need to be logged in to leave comments.
Login now