@@ -1,52 +1,52 | |||||
1 | <%= error_messages_for 'query' %> |
|
1 | <%= error_messages_for 'query' %> | |
2 |
|
2 | |||
3 | <div class="box"> |
|
3 | <div class="box"> | |
4 | <div class="tabular"> |
|
4 | <div class="tabular"> | |
5 | <p><label for="query_name"><%=l(:field_name)%></label> |
|
5 | <p><label for="query_name"><%=l(:field_name)%></label> | |
6 | <%= text_field 'query', 'name', :size => 80 %></p> |
|
6 | <%= text_field 'query', 'name', :size => 80 %></p> | |
7 |
|
7 | |||
8 | <% if User.current.admin? || User.current.allowed_to?(:manage_public_queries, @project) %> |
|
8 | <% if User.current.admin? || User.current.allowed_to?(:manage_public_queries, @project) %> | |
9 | <p><label for="query_is_public"><%=l(:field_is_public)%></label> |
|
9 | <p><label for="query_is_public"><%=l(:field_is_public)%></label> | |
10 | <%= check_box 'query', 'is_public', |
|
10 | <%= check_box 'query', 'is_public', | |
11 | :onchange => (User.current.admin? ? nil : 'if (this.checked) {$("query_is_for_all").checked = false; $("query_is_for_all").disabled = true;} else {$("query_is_for_all").disabled = false;}') %></p> |
|
11 | :onchange => (User.current.admin? ? nil : 'if (this.checked) {$("query_is_for_all").checked = false; $("query_is_for_all").disabled = true;} else {$("query_is_for_all").disabled = false;}') %></p> | |
12 | <% end %> |
|
12 | <% end %> | |
13 |
|
13 | |||
14 | <p><label for="query_is_for_all"><%=l(:field_is_for_all)%></label> |
|
14 | <p><label for="query_is_for_all"><%=l(:field_is_for_all)%></label> | |
15 | <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, |
|
15 | <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, | |
16 | :disabled => (!@query.new_record? && (@query.project.nil? || (@query.is_public? && !User.current.admin?))) %></p> |
|
16 | :disabled => (!@query.new_record? && (@query.project.nil? || (@query.is_public? && !User.current.admin?))) %></p> | |
17 |
|
17 | |||
18 | <p><label for="query_default_columns"><%=l(:label_default_columns)%></label> |
|
18 | <p><label for="query_default_columns"><%=l(:label_default_columns)%></label> | |
19 | <%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns', |
|
19 | <%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns', | |
20 | :onclick => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p> |
|
20 | :onclick => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p> | |
21 |
|
21 | |||
22 | <p><label for="query_group_by"><%= l(:field_group_by) %></label> |
|
22 | <p><label for="query_group_by"><%= l(:field_group_by) %></label> | |
23 | <%= select 'query', 'group_by', @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, :include_blank => true %></p> |
|
23 | <%= select 'query', 'group_by', @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, :include_blank => true %></p> | |
24 | </div> |
|
24 | </div> | |
25 |
|
25 | |||
26 | <fieldset><legend><%= l(:label_filter_plural) %></legend> |
|
26 | <fieldset><legend><%= l(:label_filter_plural) %></legend> | |
27 | <%= render :partial => 'queries/filters', :locals => {:query => query}%> |
|
27 | <%= render :partial => 'queries/filters', :locals => {:query => query}%> | |
28 | </fieldset> |
|
28 | </fieldset> | |
29 |
|
29 | |||
30 | <fieldset><legend><%= l(:label_sort) %></legend> |
|
30 | <fieldset><legend><%= l(:label_sort) %></legend> | |
31 | <% 3.times do |i| %> |
|
31 | <% 3.times do |i| %> | |
32 | <%= i+1 %>: |
|
32 | <%= i+1 %>: | |
33 | <%= label_tag "query_sort_criteria_attribute_" + i.to_s, |
|
33 | <%= label_tag "query_sort_criteria_attribute_" + i.to_s, | |
34 | l(:description_query_sort_criteria_attribute), :class => "hidden-for-sighted" %> |
|
34 | l(:description_query_sort_criteria_attribute), :class => "hidden-for-sighted" %> | |
35 | <%= select_tag("query[sort_criteria][#{i}][]", |
|
35 | <%= select_tag("query[sort_criteria][#{i}][]", | |
36 | options_for_select([[]] + query.available_columns.select(&:sortable?).collect {|column| [column.caption, column.name.to_s]}, @query.sort_criteria_key(i)), |
|
36 | options_for_select([[]] + query.available_columns.select(&:sortable?).collect {|column| [column.caption, column.name.to_s]}, @query.sort_criteria_key(i)), | |
37 | :id => "query_sort_criteria_attribute_" + i.to_s)%> |
|
37 | :id => "query_sort_criteria_attribute_" + i.to_s)%> | |
38 | <%= label_tag "query_sort_criteria_direction_" + i.to_s, |
|
38 | <%= label_tag "query_sort_criteria_direction_" + i.to_s, | |
39 | l(:description_query_sort_criteria_direction), :class => "hidden-for-sighted" %> |
|
39 | l(:description_query_sort_criteria_direction), :class => "hidden-for-sighted" %> | |
40 | <%= select_tag("query[sort_criteria][#{i}][]", |
|
40 | <%= select_tag("query[sort_criteria][#{i}][]", | |
41 | options_for_select([[], [l(:label_ascending), 'asc'], [l(:label_descending), 'desc']], @query.sort_criteria_order(i)), |
|
41 | options_for_select([[], [l(:label_ascending), 'asc'], [l(:label_descending), 'desc']], @query.sort_criteria_order(i)), | |
42 | :id => "query_sort_criteria_direction_" + i.to_s) %> |
|
42 | :id => "query_sort_criteria_direction_" + i.to_s) %> | |
43 | <br /> |
|
43 | <br /> | |
44 | <% end %> |
|
44 | <% end %> | |
45 | </fieldset> |
|
45 | </fieldset> | |
46 |
|
46 | |||
47 | <% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %> |
|
47 | <%= content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %> | |
48 | <legend><%= l(:field_column_names) %></legend> |
|
48 | <legend><%= l(:field_column_names) %></legend> | |
49 | <%= render :partial => 'queries/columns', :locals => {:query => query}%> |
|
49 | <%= render :partial => 'queries/columns', :locals => {:query => query}%> | |
50 | <% end %> |
|
50 | <% end %> | |
51 |
|
51 | |||
52 | </div> |
|
52 | </div> |
@@ -1,271 +1,275 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class 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 |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries | |
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_new_project_query |
|
27 | def test_new_project_query | |
28 | @request.session[:user_id] = 2 |
|
28 | @request.session[:user_id] = 2 | |
29 | get :new, :project_id => 1 |
|
29 | get :new, :project_id => 1 | |
30 | assert_response :success |
|
30 | assert_response :success | |
31 | assert_template 'new' |
|
31 | assert_template 'new' | |
32 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
32 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
33 | :name => 'query[is_public]', |
|
33 | :name => 'query[is_public]', | |
34 | :checked => nil } |
|
34 | :checked => nil } | |
35 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
35 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
36 | :name => 'query_is_for_all', |
|
36 | :name => 'query_is_for_all', | |
37 | :checked => nil, |
|
37 | :checked => nil, | |
38 | :disabled => nil } |
|
38 | :disabled => nil } | |
|
39 | assert_select 'select[name=?]', 'c[]' do | |||
|
40 | assert_select 'option[value=tracker]' | |||
|
41 | assert_select 'option[value=subject]' | |||
|
42 | end | |||
39 | end |
|
43 | end | |
40 |
|
44 | |||
41 | def test_new_global_query |
|
45 | def test_new_global_query | |
42 | @request.session[:user_id] = 2 |
|
46 | @request.session[:user_id] = 2 | |
43 | get :new |
|
47 | get :new | |
44 | assert_response :success |
|
48 | assert_response :success | |
45 | assert_template 'new' |
|
49 | assert_template 'new' | |
46 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
50 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
47 | :name => 'query[is_public]' } |
|
51 | :name => 'query[is_public]' } | |
48 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
52 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
49 | :name => 'query_is_for_all', |
|
53 | :name => 'query_is_for_all', | |
50 | :checked => 'checked', |
|
54 | :checked => 'checked', | |
51 | :disabled => nil } |
|
55 | :disabled => nil } | |
52 | end |
|
56 | end | |
53 |
|
57 | |||
54 | def test_new_on_invalid_project |
|
58 | def test_new_on_invalid_project | |
55 | @request.session[:user_id] = 2 |
|
59 | @request.session[:user_id] = 2 | |
56 | get :new, :project_id => 'invalid' |
|
60 | get :new, :project_id => 'invalid' | |
57 | assert_response 404 |
|
61 | assert_response 404 | |
58 | end |
|
62 | end | |
59 |
|
63 | |||
60 | def test_create_project_public_query |
|
64 | def test_create_project_public_query | |
61 | @request.session[:user_id] = 2 |
|
65 | @request.session[:user_id] = 2 | |
62 | post :create, |
|
66 | post :create, | |
63 | :project_id => 'ecookbook', |
|
67 | :project_id => 'ecookbook', | |
64 | :default_columns => '1', |
|
68 | :default_columns => '1', | |
65 | :f => ["status_id", "assigned_to_id"], |
|
69 | :f => ["status_id", "assigned_to_id"], | |
66 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
70 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, | |
67 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
71 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
68 | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} |
|
72 | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} | |
69 |
|
73 | |||
70 | q = Query.find_by_name('test_new_project_public_query') |
|
74 | q = Query.find_by_name('test_new_project_public_query') | |
71 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
75 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q | |
72 | assert q.is_public? |
|
76 | assert q.is_public? | |
73 | assert q.has_default_columns? |
|
77 | assert q.has_default_columns? | |
74 | assert q.valid? |
|
78 | assert q.valid? | |
75 | end |
|
79 | end | |
76 |
|
80 | |||
77 | def test_create_project_private_query |
|
81 | def test_create_project_private_query | |
78 | @request.session[:user_id] = 3 |
|
82 | @request.session[:user_id] = 3 | |
79 | post :create, |
|
83 | post :create, | |
80 | :project_id => 'ecookbook', |
|
84 | :project_id => 'ecookbook', | |
81 | :default_columns => '1', |
|
85 | :default_columns => '1', | |
82 | :fields => ["status_id", "assigned_to_id"], |
|
86 | :fields => ["status_id", "assigned_to_id"], | |
83 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
87 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
84 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
88 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
85 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} |
|
89 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} | |
86 |
|
90 | |||
87 | q = Query.find_by_name('test_new_project_private_query') |
|
91 | q = Query.find_by_name('test_new_project_private_query') | |
88 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
92 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q | |
89 | assert !q.is_public? |
|
93 | assert !q.is_public? | |
90 | assert q.has_default_columns? |
|
94 | assert q.has_default_columns? | |
91 | assert q.valid? |
|
95 | assert q.valid? | |
92 | end |
|
96 | end | |
93 |
|
97 | |||
94 | def test_create_global_private_query_with_custom_columns |
|
98 | def test_create_global_private_query_with_custom_columns | |
95 | @request.session[:user_id] = 3 |
|
99 | @request.session[:user_id] = 3 | |
96 | post :create, |
|
100 | post :create, | |
97 | :fields => ["status_id", "assigned_to_id"], |
|
101 | :fields => ["status_id", "assigned_to_id"], | |
98 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
102 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
99 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
103 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |
100 | :query => {"name" => "test_new_global_private_query", "is_public" => "1"}, |
|
104 | :query => {"name" => "test_new_global_private_query", "is_public" => "1"}, | |
101 | :c => ["", "tracker", "subject", "priority", "category"] |
|
105 | :c => ["", "tracker", "subject", "priority", "category"] | |
102 |
|
106 | |||
103 | q = Query.find_by_name('test_new_global_private_query') |
|
107 | q = Query.find_by_name('test_new_global_private_query') | |
104 | 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 | |
105 | assert !q.is_public? |
|
109 | assert !q.is_public? | |
106 | assert !q.has_default_columns? |
|
110 | assert !q.has_default_columns? | |
107 | 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} | |
108 | assert q.valid? |
|
112 | assert q.valid? | |
109 | end |
|
113 | end | |
110 |
|
114 | |||
111 | def test_create_global_query_with_custom_filters |
|
115 | def test_create_global_query_with_custom_filters | |
112 | @request.session[:user_id] = 3 |
|
116 | @request.session[:user_id] = 3 | |
113 | post :create, |
|
117 | post :create, | |
114 | :fields => ["assigned_to_id"], |
|
118 | :fields => ["assigned_to_id"], | |
115 | :operators => {"assigned_to_id" => "="}, |
|
119 | :operators => {"assigned_to_id" => "="}, | |
116 | :values => { "assigned_to_id" => ["me"]}, |
|
120 | :values => { "assigned_to_id" => ["me"]}, | |
117 | :query => {"name" => "test_new_global_query"} |
|
121 | :query => {"name" => "test_new_global_query"} | |
118 |
|
122 | |||
119 | q = Query.find_by_name('test_new_global_query') |
|
123 | q = Query.find_by_name('test_new_global_query') | |
120 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
124 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q | |
121 | assert !q.has_filter?(:status_id) |
|
125 | assert !q.has_filter?(:status_id) | |
122 | assert_equal ['assigned_to_id'], q.filters.keys |
|
126 | assert_equal ['assigned_to_id'], q.filters.keys | |
123 | assert q.valid? |
|
127 | assert q.valid? | |
124 | end |
|
128 | end | |
125 |
|
129 | |||
126 | def test_create_with_sort |
|
130 | def test_create_with_sort | |
127 | @request.session[:user_id] = 1 |
|
131 | @request.session[:user_id] = 1 | |
128 | post :create, |
|
132 | post :create, | |
129 | :default_columns => '1', |
|
133 | :default_columns => '1', | |
130 | :operators => {"status_id" => "o"}, |
|
134 | :operators => {"status_id" => "o"}, | |
131 | :values => {"status_id" => ["1"]}, |
|
135 | :values => {"status_id" => ["1"]}, | |
132 | :query => {:name => "test_new_with_sort", |
|
136 | :query => {:name => "test_new_with_sort", | |
133 | :is_public => "1", |
|
137 | :is_public => "1", | |
134 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} |
|
138 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} | |
135 |
|
139 | |||
136 | query = Query.find_by_name("test_new_with_sort") |
|
140 | query = Query.find_by_name("test_new_with_sort") | |
137 | assert_not_nil query |
|
141 | assert_not_nil query | |
138 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
|
142 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria | |
139 | end |
|
143 | end | |
140 |
|
144 | |||
141 | def test_create_with_failure |
|
145 | def test_create_with_failure | |
142 | @request.session[:user_id] = 2 |
|
146 | @request.session[:user_id] = 2 | |
143 | assert_no_difference '::Query.count' do |
|
147 | assert_no_difference '::Query.count' do | |
144 | post :create, :project_id => 'ecookbook', :query => {:name => ''} |
|
148 | post :create, :project_id => 'ecookbook', :query => {:name => ''} | |
145 | end |
|
149 | end | |
146 | assert_response :success |
|
150 | assert_response :success | |
147 | assert_template 'new' |
|
151 | assert_template 'new' | |
148 | end |
|
152 | end | |
149 |
|
153 | |||
150 | def test_edit_global_public_query |
|
154 | def test_edit_global_public_query | |
151 | @request.session[:user_id] = 1 |
|
155 | @request.session[:user_id] = 1 | |
152 | get :edit, :id => 4 |
|
156 | get :edit, :id => 4 | |
153 | assert_response :success |
|
157 | assert_response :success | |
154 | assert_template 'edit' |
|
158 | assert_template 'edit' | |
155 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
159 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
156 | :name => 'query[is_public]', |
|
160 | :name => 'query[is_public]', | |
157 | :checked => 'checked' } |
|
161 | :checked => 'checked' } | |
158 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
162 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
159 | :name => 'query_is_for_all', |
|
163 | :name => 'query_is_for_all', | |
160 | :checked => 'checked', |
|
164 | :checked => 'checked', | |
161 | :disabled => 'disabled' } |
|
165 | :disabled => 'disabled' } | |
162 | end |
|
166 | end | |
163 |
|
167 | |||
164 | def test_edit_global_private_query |
|
168 | def test_edit_global_private_query | |
165 | @request.session[:user_id] = 3 |
|
169 | @request.session[:user_id] = 3 | |
166 | get :edit, :id => 3 |
|
170 | get :edit, :id => 3 | |
167 | assert_response :success |
|
171 | assert_response :success | |
168 | assert_template 'edit' |
|
172 | assert_template 'edit' | |
169 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
173 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
170 | :name => 'query[is_public]' } |
|
174 | :name => 'query[is_public]' } | |
171 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
175 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
172 | :name => 'query_is_for_all', |
|
176 | :name => 'query_is_for_all', | |
173 | :checked => 'checked', |
|
177 | :checked => 'checked', | |
174 | :disabled => 'disabled' } |
|
178 | :disabled => 'disabled' } | |
175 | end |
|
179 | end | |
176 |
|
180 | |||
177 | def test_edit_project_private_query |
|
181 | def test_edit_project_private_query | |
178 | @request.session[:user_id] = 3 |
|
182 | @request.session[:user_id] = 3 | |
179 | get :edit, :id => 2 |
|
183 | get :edit, :id => 2 | |
180 | assert_response :success |
|
184 | assert_response :success | |
181 | assert_template 'edit' |
|
185 | assert_template 'edit' | |
182 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
186 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
183 | :name => 'query[is_public]' } |
|
187 | :name => 'query[is_public]' } | |
184 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
188 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
185 | :name => 'query_is_for_all', |
|
189 | :name => 'query_is_for_all', | |
186 | :checked => nil, |
|
190 | :checked => nil, | |
187 | :disabled => nil } |
|
191 | :disabled => nil } | |
188 | end |
|
192 | end | |
189 |
|
193 | |||
190 | def test_edit_project_public_query |
|
194 | def test_edit_project_public_query | |
191 | @request.session[:user_id] = 2 |
|
195 | @request.session[:user_id] = 2 | |
192 | get :edit, :id => 1 |
|
196 | get :edit, :id => 1 | |
193 | assert_response :success |
|
197 | assert_response :success | |
194 | assert_template 'edit' |
|
198 | assert_template 'edit' | |
195 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
199 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
196 | :name => 'query[is_public]', |
|
200 | :name => 'query[is_public]', | |
197 | :checked => 'checked' |
|
201 | :checked => 'checked' | |
198 | } |
|
202 | } | |
199 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
203 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
200 | :name => 'query_is_for_all', |
|
204 | :name => 'query_is_for_all', | |
201 | :checked => nil, |
|
205 | :checked => nil, | |
202 | :disabled => 'disabled' } |
|
206 | :disabled => 'disabled' } | |
203 | end |
|
207 | end | |
204 |
|
208 | |||
205 | def test_edit_sort_criteria |
|
209 | def test_edit_sort_criteria | |
206 | @request.session[:user_id] = 1 |
|
210 | @request.session[:user_id] = 1 | |
207 | get :edit, :id => 5 |
|
211 | get :edit, :id => 5 | |
208 | assert_response :success |
|
212 | assert_response :success | |
209 | assert_template 'edit' |
|
213 | assert_template 'edit' | |
210 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
214 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, | |
211 | :child => { :tag => 'option', :attributes => { :value => 'priority', |
|
215 | :child => { :tag => 'option', :attributes => { :value => 'priority', | |
212 | :selected => 'selected' } } |
|
216 | :selected => 'selected' } } | |
213 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
217 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, | |
214 | :child => { :tag => 'option', :attributes => { :value => 'desc', |
|
218 | :child => { :tag => 'option', :attributes => { :value => 'desc', | |
215 | :selected => 'selected' } } |
|
219 | :selected => 'selected' } } | |
216 | end |
|
220 | end | |
217 |
|
221 | |||
218 | def test_edit_invalid_query |
|
222 | def test_edit_invalid_query | |
219 | @request.session[:user_id] = 2 |
|
223 | @request.session[:user_id] = 2 | |
220 | get :edit, :id => 99 |
|
224 | get :edit, :id => 99 | |
221 | assert_response 404 |
|
225 | assert_response 404 | |
222 | end |
|
226 | end | |
223 |
|
227 | |||
224 | def test_udpate_global_private_query |
|
228 | def test_udpate_global_private_query | |
225 | @request.session[:user_id] = 3 |
|
229 | @request.session[:user_id] = 3 | |
226 | put :update, |
|
230 | put :update, | |
227 | :id => 3, |
|
231 | :id => 3, | |
228 | :default_columns => '1', |
|
232 | :default_columns => '1', | |
229 | :fields => ["status_id", "assigned_to_id"], |
|
233 | :fields => ["status_id", "assigned_to_id"], | |
230 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
234 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
231 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
235 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |
232 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} |
|
236 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} | |
233 |
|
237 | |||
234 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
|
238 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 | |
235 | q = Query.find_by_name('test_edit_global_private_query') |
|
239 | q = Query.find_by_name('test_edit_global_private_query') | |
236 | assert !q.is_public? |
|
240 | assert !q.is_public? | |
237 | assert q.has_default_columns? |
|
241 | assert q.has_default_columns? | |
238 | assert q.valid? |
|
242 | assert q.valid? | |
239 | end |
|
243 | end | |
240 |
|
244 | |||
241 | def test_update_global_public_query |
|
245 | def test_update_global_public_query | |
242 | @request.session[:user_id] = 1 |
|
246 | @request.session[:user_id] = 1 | |
243 | put :update, |
|
247 | put :update, | |
244 | :id => 4, |
|
248 | :id => 4, | |
245 | :default_columns => '1', |
|
249 | :default_columns => '1', | |
246 | :fields => ["status_id", "assigned_to_id"], |
|
250 | :fields => ["status_id", "assigned_to_id"], | |
247 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
251 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
248 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
252 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
249 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} |
|
253 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} | |
250 |
|
254 | |||
251 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
|
255 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 | |
252 | q = Query.find_by_name('test_edit_global_public_query') |
|
256 | q = Query.find_by_name('test_edit_global_public_query') | |
253 | assert q.is_public? |
|
257 | assert q.is_public? | |
254 | assert q.has_default_columns? |
|
258 | assert q.has_default_columns? | |
255 | assert q.valid? |
|
259 | assert q.valid? | |
256 | end |
|
260 | end | |
257 |
|
261 | |||
258 | def test_update_with_failure |
|
262 | def test_update_with_failure | |
259 | @request.session[:user_id] = 1 |
|
263 | @request.session[:user_id] = 1 | |
260 | put :update, :id => 4, :query => {:name => ''} |
|
264 | put :update, :id => 4, :query => {:name => ''} | |
261 | assert_response :success |
|
265 | assert_response :success | |
262 | assert_template 'edit' |
|
266 | assert_template 'edit' | |
263 | end |
|
267 | end | |
264 |
|
268 | |||
265 | def test_destroy |
|
269 | def test_destroy | |
266 | @request.session[:user_id] = 2 |
|
270 | @request.session[:user_id] = 2 | |
267 | delete :destroy, :id => 1 |
|
271 | delete :destroy, :id => 1 | |
268 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
272 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil | |
269 | assert_nil Query.find_by_id(1) |
|
273 | assert_nil Query.find_by_id(1) | |
270 | end |
|
274 | end | |
271 | end |
|
275 | end |
General Comments 0
You need to be logged in to leave comments.
Login now