summaryrefslogtreecommitdiffstats
path: root/test/functional/queries_controller_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-12-17 17:54:52 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-12-17 17:54:52 +0000
commit199eaff14ea3217efd0ee2592abb88798e465338 (patch)
tree2c2ef0e6a293f758da2a40dbf28f83c035231751 /test/functional/queries_controller_test.rb
parent92e4708ee36891179cf7ac39bf692b65989b8654 (diff)
downloadredmine-199eaff14ea3217efd0ee2592abb88798e465338.tar.gz
redmine-199eaff14ea3217efd0ee2592abb88798e465338.zip
Additional tests for QueriesController.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8265 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional/queries_controller_test.rb')
-rw-r--r--test/functional/queries_controller_test.rb127
1 files changed, 74 insertions, 53 deletions
diff --git a/test/functional/queries_controller_test.rb b/test/functional/queries_controller_test.rb
index dfa5d6153..5fc454388 100644
--- a/test/functional/queries_controller_test.rb
+++ b/test/functional/queries_controller_test.rb
@@ -16,22 +16,15 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../test_helper', __FILE__)
-require 'queries_controller'
-
-# Re-raise errors caught by the controller.
-class QueriesController; def rescue_action(e) raise e end; end
class QueriesControllerTest < ActionController::TestCase
fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries
def setup
- @controller = QueriesController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
User.current = nil
end
- def test_get_new_project_query
+ def test_new_project_query
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
@@ -45,7 +38,7 @@ class QueriesControllerTest < ActionController::TestCase
:disabled => nil }
end
- def test_get_new_global_query
+ def test_new_global_query
@request.session[:user_id] = 2
get :new
assert_response :success
@@ -58,7 +51,13 @@ class QueriesControllerTest < ActionController::TestCase
:disabled => nil }
end
- def test_new_project_public_query
+ def test_new_on_invalid_project
+ @request.session[:user_id] = 2
+ get :new, :project_id => 'invalid'
+ assert_response 404
+ end
+
+ def test_create_project_public_query
@request.session[:user_id] = 2
post :create,
:project_id => 'ecookbook',
@@ -75,7 +74,7 @@ class QueriesControllerTest < ActionController::TestCase
assert q.valid?
end
- def test_new_project_private_query
+ def test_create_project_private_query
@request.session[:user_id] = 3
post :create,
:project_id => 'ecookbook',
@@ -92,7 +91,7 @@ class QueriesControllerTest < ActionController::TestCase
assert q.valid?
end
- def test_new_global_private_query_with_custom_columns
+ def test_create_global_private_query_with_custom_columns
@request.session[:user_id] = 3
post :create,
:fields => ["status_id", "assigned_to_id"],
@@ -109,7 +108,7 @@ class QueriesControllerTest < ActionController::TestCase
assert q.valid?
end
- def test_new_global_query_with_custom_filters
+ def test_create_global_query_with_custom_filters
@request.session[:user_id] = 3
post :create,
:fields => ["assigned_to_id"],
@@ -124,7 +123,7 @@ class QueriesControllerTest < ActionController::TestCase
assert q.valid?
end
- def test_new_with_sort
+ def test_create_with_sort
@request.session[:user_id] = 1
post :create,
:default_columns => '1',
@@ -139,7 +138,16 @@ class QueriesControllerTest < ActionController::TestCase
assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria
end
- def test_get_edit_global_public_query
+ def test_create_with_failure
+ @request.session[:user_id] = 2
+ assert_no_difference 'Query.count' do
+ post :create, :project_id => 'ecookbook', :query => {:name => ''}
+ end
+ assert_response :success
+ assert_template 'new'
+ end
+
+ def test_edit_global_public_query
@request.session[:user_id] = 1
get :edit, :id => 4
assert_response :success
@@ -153,24 +161,7 @@ class QueriesControllerTest < ActionController::TestCase
:disabled => 'disabled' }
end
- def test_edit_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", "is_public" => "1"}
-
- assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4
- q = Query.find_by_name('test_edit_global_public_query')
- assert q.is_public?
- assert q.has_default_columns?
- assert q.valid?
- end
-
- def test_get_edit_global_private_query
+ def test_edit_global_private_query
@request.session[:user_id] = 3
get :edit, :id => 3
assert_response :success
@@ -183,24 +174,7 @@ class QueriesControllerTest < ActionController::TestCase
:disabled => 'disabled' }
end
- def test_edit_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", "is_public" => "1"}
-
- assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3
- q = Query.find_by_name('test_edit_global_private_query')
- assert !q.is_public?
- assert q.has_default_columns?
- assert q.valid?
- end
-
- def test_get_edit_project_private_query
+ def test_edit_project_private_query
@request.session[:user_id] = 3
get :edit, :id => 2
assert_response :success
@@ -213,7 +187,7 @@ class QueriesControllerTest < ActionController::TestCase
:disabled => nil }
end
- def test_get_edit_project_public_query
+ def test_edit_project_public_query
@request.session[:user_id] = 2
get :edit, :id => 1
assert_response :success
@@ -228,7 +202,7 @@ class QueriesControllerTest < ActionController::TestCase
:disabled => 'disabled' }
end
- def test_get_edit_sort_criteria
+ def test_edit_sort_criteria
@request.session[:user_id] = 1
get :edit, :id => 5
assert_response :success
@@ -241,6 +215,53 @@ class QueriesControllerTest < ActionController::TestCase
:selected => 'selected' } }
end
+ def test_edit_invalid_query
+ @request.session[:user_id] = 2
+ get :edit, :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", "is_public" => "1"}
+
+ assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3
+ q = Query.find_by_name('test_edit_global_private_query')
+ assert !q.is_public?
+ assert q.has_default_columns?
+ assert q.valid?
+ end
+
+ 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", "is_public" => "1"}
+
+ assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4
+ q = Query.find_by_name('test_edit_global_public_query')
+ assert q.is_public?
+ assert q.has_default_columns?
+ assert q.valid?
+ end
+
+ def test_update_with_failure
+ @request.session[:user_id] = 1
+ put :update, :id => 4, :query => {:name => ''}
+ assert_response :success
+ assert_template 'edit'
+ end
+
def test_destroy
@request.session[:user_id] = 2
delete :destroy, :id => 1