diff options
Diffstat (limited to 'test/functional/queries_controller_test.rb')
-rw-r--r-- | test/functional/queries_controller_test.rb | 346 |
1 files changed, 240 insertions, 106 deletions
diff --git a/test/functional/queries_controller_test.rb b/test/functional/queries_controller_test.rb index cabdab968..8bc42e890 100644 --- a/test/functional/queries_controller_test.rb +++ b/test/functional/queries_controller_test.rb @@ -37,7 +37,9 @@ class QueriesControllerTest < Redmine::ControllerTest def test_new_project_query @request.session[:user_id] = 2 - get :new, :project_id => 1 + get :new, :params => { + :project_id => 1 + } assert_response :success assert_select 'input[name=?][value="0"][checked=checked]', 'query[visibility]' @@ -59,26 +61,38 @@ class QueriesControllerTest < Redmine::ControllerTest def test_new_on_invalid_project @request.session[:user_id] = 2 - get :new, :project_id => 'invalid' + get :new, :params => { + :project_id => 'invalid' + } assert_response 404 end def test_new_time_entry_query @request.session[:user_id] = 2 - get :new, :project_id => 1, :type => 'TimeEntryQuery' + get :new, :params => { + :project_id => 1, + :type => 'TimeEntryQuery' + } assert_response :success assert_select 'input[name=type][value=?]', 'TimeEntryQuery' end def test_create_project_public_query @request.session[:user_id] = 2 - post :create, - :project_id => 'ecookbook', - :default_columns => '1', - :f => ["status_id", "assigned_to_id"], - :op => {"assigned_to_id" => "=", "status_id" => "o"}, - :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, - :query => {"name" => "test_new_project_public_query", "visibility" => "2"} + post :create, :params => { + :project_id => 'ecookbook', + :default_columns => '1', + :f => ["status_id", "assigned_to_id"], + :op => { + "assigned_to_id" => "=", "status_id" => "o" + }, + :v => { + "assigned_to_id" => ["1"], "status_id" => ["1"] + }, + :query => { + "name" => "test_new_project_public_query", "visibility" => "2" + } + } q = Query.find_by_name('test_new_project_public_query') assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q @@ -89,13 +103,20 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_project_private_query @request.session[:user_id] = 3 - post :create, - :project_id => 'ecookbook', - :default_columns => '1', - :fields => ["status_id", "assigned_to_id"], - :operators => {"assigned_to_id" => "=", "status_id" => "o"}, - :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, - :query => {"name" => "test_new_project_private_query", "visibility" => "0"} + post :create, :params => { + :project_id => 'ecookbook', + :default_columns => '1', + :fields => ["status_id", "assigned_to_id"], + :operators => { + "assigned_to_id" => "=", "status_id" => "o" + }, + :values => { + "assigned_to_id" => ["1"], "status_id" => ["1"] + }, + :query => { + "name" => "test_new_project_private_query", "visibility" => "0" + } + } q = Query.find_by_name('test_new_project_private_query') assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q @@ -106,13 +127,20 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_project_roles_query @request.session[:user_id] = 2 - post :create, - :project_id => 'ecookbook', - :default_columns => '1', - :fields => ["status_id", "assigned_to_id"], - :operators => {"assigned_to_id" => "=", "status_id" => "o"}, - :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, - :query => {"name" => "test_create_project_roles_query", "visibility" => "1", "role_ids" => ["1", "2", ""]} + post :create, :params => { + :project_id => 'ecookbook', + :default_columns => '1', + :fields => ["status_id", "assigned_to_id"], + :operators => { + "assigned_to_id" => "=", "status_id" => "o" + }, + :values => { + "assigned_to_id" => ["1"], "status_id" => ["1"] + }, + :query => { + "name" => "test_create_project_roles_query", "visibility" => "1", "role_ids" => ["1", "2", ""] + } + } q = Query.find_by_name('test_create_project_roles_query') assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q @@ -122,12 +150,19 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_global_private_query_with_custom_columns @request.session[:user_id] = 3 - post :create, - :fields => ["status_id", "assigned_to_id"], - :operators => {"assigned_to_id" => "=", "status_id" => "o"}, - :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, - :query => {"name" => "test_new_global_private_query", "visibility" => "0"}, - :c => ["", "tracker", "subject", "priority", "category"] + post :create, :params => { + :fields => ["status_id", "assigned_to_id"], + :operators => { + "assigned_to_id" => "=", "status_id" => "o" + }, + :values => { + "assigned_to_id" => ["me"], "status_id" => ["1"] + }, + :query => { + "name" => "test_new_global_private_query", "visibility" => "0" + }, + :c => ["", "tracker", "subject", "priority", "category"] + } q = Query.find_by_name('test_new_global_private_query') assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q @@ -139,11 +174,18 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_global_query_with_custom_filters @request.session[:user_id] = 3 - post :create, - :fields => ["assigned_to_id"], - :operators => {"assigned_to_id" => "="}, - :values => { "assigned_to_id" => ["me"]}, - :query => {"name" => "test_new_global_query"} + post :create, :params => { + :fields => ["assigned_to_id"], + :operators => { + "assigned_to_id" => "=" + }, + :values => { + "assigned_to_id" => ["me"] + }, + :query => { + "name" => "test_new_global_query" + } + } q = Query.find_by_name('test_new_global_query') assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q @@ -155,13 +197,21 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_with_sort @request.session[:user_id] = 1 - post :create, - :default_columns => '1', - :operators => {"status_id" => "o"}, - :values => {"status_id" => ["1"]}, - :query => {:name => "test_new_with_sort", - :visibility => "2", - :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} + post :create, :params => { + :default_columns => '1', + :operators => { + "status_id" => "o" + }, + :values => { + "status_id" => ["1"] + }, + :query => { + :name => "test_new_with_sort", + :visibility => "2", + :sort_criteria => { + "0" => ["due_date", "desc"], "1" => ["tracker", ""]} + } + } query = Query.find_by_name("test_new_with_sort") assert_not_nil query @@ -171,7 +221,12 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_with_failure @request.session[:user_id] = 2 assert_no_difference '::Query.count' do - post :create, :project_id => 'ecookbook', :query => {:name => ''} + post :create, :params => { + :project_id => 'ecookbook', + :query => { + :name => '' + } + } end assert_response :success @@ -181,13 +236,20 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_global_query_from_gantt @request.session[:user_id] = 1 assert_difference 'IssueQuery.count' do - post :create, - :gantt => 1, - :operators => {"status_id" => "o"}, - :values => {"status_id" => ["1"]}, - :query => {:name => "test_create_from_gantt", - :draw_relations => '1', - :draw_progress_line => '1'} + post :create, :params => { + :gantt => 1, + :operators => { + "status_id" => "o" + }, + :values => { + "status_id" => ["1"] + }, + :query => { + :name => "test_create_from_gantt", + :draw_relations => '1', + :draw_progress_line => '1' + } + } assert_response 302 end query = IssueQuery.order('id DESC').first @@ -199,14 +261,21 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_project_query_from_gantt @request.session[:user_id] = 1 assert_difference 'IssueQuery.count' do - post :create, - :project_id => 'ecookbook', - :gantt => 1, - :operators => {"status_id" => "o"}, - :values => {"status_id" => ["1"]}, - :query => {:name => "test_create_from_gantt", - :draw_relations => '0', - :draw_progress_line => '0'} + post :create, :params => { + :project_id => 'ecookbook', + :gantt => 1, + :operators => { + "status_id" => "o" + }, + :values => { + "status_id" => ["1"] + }, + :query => { + :name => "test_create_from_gantt", + :draw_relations => '0', + :draw_progress_line => '0' + } + } assert_response 302 end query = IssueQuery.order('id DESC').first @@ -218,9 +287,12 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_project_public_query_should_force_private_without_manage_public_queries_permission @request.session[:user_id] = 3 query = new_record(Query) do - post :create, - :project_id => 'ecookbook', - :query => {"name" => "name", "visibility" => "2"} + post :create, :params => { + :project_id => 'ecookbook', + :query => { + "name" => "name", "visibility" => "2" + } + } assert_response 302 end assert_not_nil query.project @@ -230,9 +302,13 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_global_public_query_should_force_private_without_manage_public_queries_permission @request.session[:user_id] = 3 query = new_record(Query) do - post :create, - :project_id => 'ecookbook', :query_is_for_all => '1', - :query => {"name" => "name", "visibility" => "2"} + post :create, :params => { + :project_id => 'ecookbook', + :query_is_for_all => '1', + :query => { + "name" => "name", "visibility" => "2" + } + } assert_response 302 end assert_nil query.project @@ -242,9 +318,12 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_project_public_query_with_manage_public_queries_permission @request.session[:user_id] = 2 query = new_record(Query) do - post :create, - :project_id => 'ecookbook', - :query => {"name" => "name", "visibility" => "2"} + post :create, :params => { + :project_id => 'ecookbook', + :query => { + "name" => "name", "visibility" => "2" + } + } assert_response 302 end assert_not_nil query.project @@ -254,9 +333,13 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_global_public_query_should_force_private_with_manage_public_queries_permission @request.session[:user_id] = 2 query = new_record(Query) do - post :create, - :project_id => 'ecookbook', :query_is_for_all => '1', - :query => {"name" => "name", "visibility" => "2"} + post :create, :params => { + :project_id => 'ecookbook', + :query_is_for_all => '1', + :query => { + "name" => "name", "visibility" => "2" + } + } assert_response 302 end assert_nil query.project @@ -266,9 +349,13 @@ class QueriesControllerTest < Redmine::ControllerTest def test_create_global_public_query_by_admin @request.session[:user_id] = 1 query = new_record(Query) do - post :create, - :project_id => 'ecookbook', :query_is_for_all => '1', - :query => {"name" => "name", "visibility" => "2"} + post :create, :params => { + :project_id => 'ecookbook', + :query_is_for_all => '1', + :query => { + "name" => "name", "visibility" => "2" + } + } assert_response 302 end assert_nil query.project @@ -279,14 +366,21 @@ class QueriesControllerTest < Redmine::ControllerTest @request.session[:user_id] = 2 q = new_record(TimeEntryQuery) do - post :create, - :project_id => 'ecookbook', - :type => 'TimeEntryQuery', - :default_columns => '1', - :f => ["spent_on"], - :op => {"spent_on" => "="}, - :v => { "spent_on" => ["2016-07-14"]}, - :query => {"name" => "test_new_project_public_query", "visibility" => "2"} + post :create, :params => { + :project_id => 'ecookbook', + :type => 'TimeEntryQuery', + :default_columns => '1', + :f => ["spent_on"], + :op => { + "spent_on" => "=" + }, + :v => { + "spent_on" => ["2016-07-14"] + }, + :query => { + "name" => "test_new_project_public_query", "visibility" => "2" + } + } end assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => 'ecookbook', :query_id => q.id @@ -297,7 +391,9 @@ class QueriesControllerTest < Redmine::ControllerTest def test_edit_global_public_query @request.session[:user_id] = 1 - get :edit, :id => 4 + get :edit, :params => { + :id => 4 + } assert_response :success assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' @@ -306,7 +402,9 @@ class QueriesControllerTest < Redmine::ControllerTest def test_edit_global_private_query @request.session[:user_id] = 3 - get :edit, :id => 3 + get :edit, :params => { + :id => 3 + } assert_response :success assert_select 'input[name=?]', 'query[visibility]', 0 @@ -315,7 +413,9 @@ class QueriesControllerTest < Redmine::ControllerTest def test_edit_project_private_query @request.session[:user_id] = 3 - get :edit, :id => 2 + get :edit, :params => { + :id => 2 + } assert_response :success assert_select 'input[name=?]', 'query[visibility]', 0 @@ -324,7 +424,9 @@ class QueriesControllerTest < Redmine::ControllerTest def test_edit_project_public_query @request.session[:user_id] = 2 - get :edit, :id => 1 + get :edit, :params => { + :id => 1 + } assert_response :success assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' @@ -333,7 +435,9 @@ class QueriesControllerTest < Redmine::ControllerTest def test_edit_sort_criteria @request.session[:user_id] = 1 - get :edit, :id => 5 + get :edit, :params => { + :id => 5 + } assert_response :success assert_select 'select[name=?]', 'query[sort_criteria][0][]' do @@ -344,19 +448,28 @@ class QueriesControllerTest < Redmine::ControllerTest def test_edit_invalid_query @request.session[:user_id] = 2 - get :edit, :id => 99 + get :edit, :params => { + :id => 99 + } assert_response 404 end def test_udpate_global_private_query @request.session[:user_id] = 3 - put :update, - :id => 3, - :default_columns => '1', - :fields => ["status_id", "assigned_to_id"], - :operators => {"assigned_to_id" => "=", "status_id" => "o"}, - :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, - :query => {"name" => "test_edit_global_private_query", "visibility" => "2"} + put :update, :params => { + :id => 3, + :default_columns => '1', + :fields => ["status_id", "assigned_to_id"], + :operators => { + "assigned_to_id" => "=", "status_id" => "o" + }, + :values => { + "assigned_to_id" => ["me"], "status_id" => ["1"] + }, + :query => { + "name" => "test_edit_global_private_query", "visibility" => "2" + } + } assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 q = Query.find_by_name('test_edit_global_private_query') @@ -367,13 +480,20 @@ class QueriesControllerTest < Redmine::ControllerTest def test_update_global_public_query @request.session[:user_id] = 1 - put :update, - :id => 4, - :default_columns => '1', - :fields => ["status_id", "assigned_to_id"], - :operators => {"assigned_to_id" => "=", "status_id" => "o"}, - :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, - :query => {"name" => "test_edit_global_public_query", "visibility" => "2"} + put :update, :params => { + :id => 4, + :default_columns => '1', + :fields => ["status_id", "assigned_to_id"], + :operators => { + "assigned_to_id" => "=", "status_id" => "o" + }, + :values => { + "assigned_to_id" => ["1"], "status_id" => ["1"] + }, + :query => { + "name" => "test_edit_global_public_query", "visibility" => "2" + } + } assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 q = Query.find_by_name('test_edit_global_public_query') @@ -384,28 +504,40 @@ class QueriesControllerTest < Redmine::ControllerTest def test_update_with_failure @request.session[:user_id] = 1 - put :update, :id => 4, :query => {:name => ''} + put :update, :params => { + :id => 4, + :query => { + :name => '' + } + } assert_response :success assert_select_error /Name cannot be blank/ end def test_destroy @request.session[:user_id] = 2 - delete :destroy, :id => 1 + delete :destroy, :params => { + :id => 1 + } assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil assert_nil Query.find_by_id(1) end def test_backslash_should_be_escaped_in_filters @request.session[:user_id] = 2 - get :new, :subject => 'foo/bar' + get :new, :params => { + :subject => 'foo/bar' + } assert_response :success assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body end def test_filter_with_project_id_should_return_filter_values @request.session[:user_id] = 2 - get :filter, :project_id => 1, :name => 'fixed_version_id' + get :filter, :params => { + :project_id => 1, + :name => 'fixed_version_id' + } assert_response :success assert_equal 'application/json', response.content_type @@ -415,7 +547,9 @@ class QueriesControllerTest < Redmine::ControllerTest def test_filter_without_project_id_should_return_filter_values @request.session[:user_id] = 2 - get :filter, :name => 'fixed_version_id' + get :filter, :params => { + :name => 'fixed_version_id' + } assert_response :success assert_equal 'application/json', response.content_type |