Commit c52be151 authored by jplang's avatar jplang

Pass parameters with :params in controller tests.

git-svn-id: https://svn.redmine.org/redmine/trunk@15666 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 04db6049
......@@ -45,7 +45,7 @@ class RolesControllerTest < Redmine::ControllerTest
def test_new_with_copy
copy_from = Role.find(2)
get :new, :copy => copy_from.id.to_s
get :new, :params => {:copy => copy_from.id.to_s}
assert_response :success
assert_template 'new'
......@@ -68,20 +68,26 @@ class RolesControllerTest < Redmine::ControllerTest
end
def test_create_with_validaton_failure
post :create, :role => {:name => '',
:permissions => ['add_issues', 'edit_issues', 'log_time', ''],
:assignable => '0'}
post :create, :params => {
:role => {
:name => '',
:permissions => ['add_issues', 'edit_issues', 'log_time', ''],
:assignable => '0'
}
}
assert_response :success
assert_template 'new'
assert_select 'div#errorExplanation'
end
def test_create_without_workflow_copy
post :create, :role => {:name => 'RoleWithoutWorkflowCopy',
:permissions => ['add_issues', 'edit_issues', 'log_time', ''],
:assignable => '0'}
post :create, :params => {
:role => {
:name => 'RoleWithoutWorkflowCopy',
:permissions => ['add_issues', 'edit_issues', 'log_time', ''],
:assignable => '0'
}
}
assert_redirected_to '/roles'
role = Role.find_by_name('RoleWithoutWorkflowCopy')
assert_not_nil role
......@@ -90,11 +96,14 @@ class RolesControllerTest < Redmine::ControllerTest
end
def test_create_with_workflow_copy
post :create, :role => {:name => 'RoleWithWorkflowCopy',
:permissions => ['add_issues', 'edit_issues', 'log_time', ''],
:assignable => '0'},
:copy_workflow_from => '1'
post :create, :params => {
:role => {
:name => 'RoleWithWorkflowCopy',
:permissions => ['add_issues', 'edit_issues', 'log_time', ''],
:assignable => '0'
},
:copy_workflow_from => '1'
}
assert_redirected_to '/roles'
role = Role.find_by_name('RoleWithWorkflowCopy')
assert_not_nil role
......@@ -102,7 +111,7 @@ class RolesControllerTest < Redmine::ControllerTest
end
def test_edit
get :edit, :id => 1
get :edit, :params => {:id => 1}
assert_response :success
assert_template 'edit'
assert_equal Role.find(1), assigns(:role)
......@@ -110,34 +119,39 @@ class RolesControllerTest < Redmine::ControllerTest
end
def test_edit_anonymous
get :edit, :id => Role.anonymous.id
get :edit, :params => {:id => Role.anonymous.id}
assert_response :success
assert_template 'edit'
assert_select 'select[name=?]', 'role[issues_visibility]', 0
end
def test_edit_invalid_should_respond_with_404
get :edit, :id => 999
get :edit, :params => {:id => 999}
assert_response 404
end
def test_update
put :update, :id => 1,
:role => {:name => 'Manager',
:permissions => ['edit_project', ''],
:assignable => '0'}
put :update, :params => {
:id => 1,
:role => {
:name => 'Manager',
:permissions => ['edit_project', ''],
:assignable => '0'
}
}
assert_redirected_to '/roles'
role = Role.find(1)
assert_equal [:edit_project], role.permissions
end
def test_update_trackers_permissions
put :update, :id => 1, :role => {
:permissions_all_trackers => {'add_issues' => '0'},
:permissions_tracker_ids => {'add_issues' => ['1', '3', '']}
put :update, :params => {
:id => 1,
:role => {
:permissions_all_trackers => {'add_issues' => '0'},
:permissions_tracker_ids => {'add_issues' => ['1', '3', '']}
}
}
assert_redirected_to '/roles'
role = Role.find(1)
......@@ -149,7 +163,7 @@ class RolesControllerTest < Redmine::ControllerTest
end
def test_update_with_failure
put :update, :id => 1, :role => {:name => ''}
put :update, :params => {:id => 1, :role => {:name => ''}}
assert_response :success
assert_template 'edit'
end
......@@ -157,13 +171,13 @@ class RolesControllerTest < Redmine::ControllerTest
def test_destroy
r = Role.create!(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
delete :destroy, :id => r
delete :destroy, :params => {:id => r}
assert_redirected_to '/roles'
assert_nil Role.find_by_id(r.id)
end
def test_destroy_role_in_use
delete :destroy, :id => 1
delete :destroy, :params => {:id => 1}
assert_redirected_to '/roles'
assert_equal 'This role is in use and cannot be deleted.', flash[:error]
assert_not_nil Role.find_by_id(1)
......@@ -182,7 +196,13 @@ class RolesControllerTest < Redmine::ControllerTest
end
def test_post_permissions
post :permissions, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
post :permissions, :params => {
:permissions => {
'0' => '',
'1' => ['edit_issues'],
'3' => ['add_issues', 'delete_issues']
}
}
assert_redirected_to '/roles'
assert_equal [:edit_issues], Role.find(1).permissions
......@@ -191,33 +211,33 @@ class RolesControllerTest < Redmine::ControllerTest
end
def test_clear_all_permissions
post :permissions, :permissions => { '0' => '' }
post :permissions, :params => {:permissions => { '0' => '' }}
assert_redirected_to '/roles'
assert Role.find(1).permissions.empty?
end
def test_move_highest
put :update, :id => 3, :role => {:position => 1}
put :update, :params => {:id => 3, :role => {:position => 1}}
assert_redirected_to '/roles'
assert_equal 1, Role.find(3).position
end
def test_move_higher
position = Role.find(3).position
put :update, :id => 3, :role => {:position => position - 1}
put :update, :params => {:id => 3, :role => {:position => position - 1}}
assert_redirected_to '/roles'
assert_equal position - 1, Role.find(3).position
end
def test_move_lower
position = Role.find(2).position
put :update, :id => 2, :role => {:position => position + 1}
put :update, :params => {:id => 2, :role => {:position => position + 1}}
assert_redirected_to '/roles'
assert_equal position + 1, Role.find(2).position
end
def test_move_lowest
put :update, :id => 2, :role => {:position => Role.givable.count}
put :update, :params => {:id => 2, :role => {:position => Role.givable.count}}
assert_redirected_to '/roles'
assert_equal Role.givable.count, Role.find(2).position
end
......
......@@ -35,7 +35,7 @@ class SearchControllerTest < Redmine::ControllerTest
assert_response :success
assert_template 'index'
get :index, :q => "cook"
get :index, :params => {:q => "cook"}
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Project.find(1))
......@@ -43,30 +43,30 @@ class SearchControllerTest < Redmine::ControllerTest
def test_search_on_archived_project_should_return_404
Project.find(3).archive
get :index, :id => 3
get :index, :params => {:id => 3}
assert_response 404
end
def test_search_on_invisible_project_by_user_should_be_denied
@request.session[:user_id] = 7
get :index, :id => 2
get :index, :params => {:id => 2}
assert_response 403
end
def test_search_on_invisible_project_by_anonymous_user_should_redirect
get :index, :id => 2
get :index, :params => {:id => 2}
assert_response 302
end
def test_search_on_private_project_by_member_should_succeed
@request.session[:user_id] = 2
get :index, :id => 2
get :index, :params => {:id => 2}
assert_response :success
end
def test_search_all_projects
with_settings :default_language => 'en' do
get :index, :q => 'recipe subproject commit', :all_words => ''
get :index, :params => {:q => 'recipe subproject commit', :all_words => ''}
end
assert_response :success
assert_template 'index'
......@@ -83,7 +83,7 @@ class SearchControllerTest < Redmine::ControllerTest
end
def test_search_issues
get :index, :q => 'issue', :issues => 1
get :index, :params => {:q => 'issue', :issues => 1}
assert_response :success
assert_template 'index'
......@@ -97,7 +97,7 @@ class SearchControllerTest < Redmine::ControllerTest
def test_search_issues_should_search_notes
Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
get :index, :q => 'searchkeyword', :issues => 1
get :index, :params => {:q => 'searchkeyword', :issues => 1}
assert_response :success
assert_include Issue.find(2), assigns(:results)
end
......@@ -106,7 +106,7 @@ class SearchControllerTest < Redmine::ControllerTest
Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
get :index, :q => 'searchkeyword', :issues => 1
get :index, :params => {:q => 'searchkeyword', :issues => 1}
assert_response :success
assert_include Issue.find(2), assigns(:results)
assert_equal 1, assigns(:results).size
......@@ -117,18 +117,18 @@ class SearchControllerTest < Redmine::ControllerTest
@request.session[:user_id] = 2
Role.find(1).add_permission! :view_private_notes
get :index, :q => 'searchkeyword', :issues => 1
get :index, :params => {:q => 'searchkeyword', :issues => 1}
assert_response :success
assert_include Issue.find(2), assigns(:results)
Role.find(1).remove_permission! :view_private_notes
get :index, :q => 'searchkeyword', :issues => 1
get :index, :params => {:q => 'searchkeyword', :issues => 1}
assert_response :success
assert_not_include Issue.find(2), assigns(:results)
end
def test_search_all_projects_with_scope_param
get :index, :q => 'issue', :scope => 'all'
get :index, :params => {:q => 'issue', :scope => 'all'}
assert_response :success
assert_template 'index'
assert assigns(:results).present?
......@@ -136,7 +136,7 @@ class SearchControllerTest < Redmine::ControllerTest
def test_search_my_projects
@request.session[:user_id] = 2
get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''}
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Issue.find(1))
......@@ -145,14 +145,14 @@ class SearchControllerTest < Redmine::ControllerTest
def test_search_my_projects_without_memberships
# anonymous user has no memberships
get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''}
assert_response :success
assert_template 'index'
assert assigns(:results).empty?
end
def test_search_project_and_subprojects
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''}
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Issue.find(1))
......@@ -162,18 +162,18 @@ class SearchControllerTest < Redmine::ControllerTest
def test_search_without_searchable_custom_fields
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
get :index, :id => 1
get :index, :params => {:id => 1}
assert_response :success
assert_template 'index'
assert_not_nil assigns(:project)
get :index, :id => 1, :q => "can"
get :index, :params => {:id => 1, :q => "can"}
assert_response :success
assert_template 'index'
end
def test_search_with_searchable_custom_fields
get :index, :id => 1, :q => "stringforcustomfield"
get :index, :params => {:id => 1, :q => "stringforcustomfield"}
assert_response :success
results = assigns(:results)
assert_not_nil results
......@@ -185,7 +185,7 @@ class SearchControllerTest < Redmine::ControllerTest
issue = Issue.generate! :subject => 'search_attachments'
attachment = Attachment.generate! :container => Issue.find(1), :filename => 'search_attachments.patch'
get :index, :id => 1, :q => 'search_attachments', :attachments => '0'
get :index, :params => {:id => 1, :q => 'search_attachments', :attachments => '0'}
results = assigns(:results)
assert_equal 1, results.size
assert_equal issue, results.first
......@@ -195,7 +195,7 @@ class SearchControllerTest < Redmine::ControllerTest
issue = Issue.generate! :subject => 'search_attachments'
attachment = Attachment.generate! :container => Issue.find(1), :filename => 'search_attachments.patch'
get :index, :id => 1, :q => 'search_attachments', :attachments => 'only'
get :index, :params => {:id => 1, :q => 'search_attachments', :attachments => 'only'}
results = assigns(:results)
assert_equal 1, results.size
assert_equal attachment.container, results.first
......@@ -205,7 +205,7 @@ class SearchControllerTest < Redmine::ControllerTest
Issue.generate! :subject => 'search_attachments'
Attachment.generate! :container => Issue.find(1), :filename => 'search_attachments.patch'
get :index, :id => 1, :q => 'search_attachments', :attachments => '1'
get :index, :params => {:id => 1, :q => 'search_attachments', :attachments => '1'}
results = assigns(:results)
assert_equal 2, results.size
end
......@@ -214,14 +214,14 @@ class SearchControllerTest < Redmine::ControllerTest
Issue.generate! :subject => 'search_open'
Issue.generate! :subject => 'search_open', :status_id => 5
get :index, :id => 1, :q => 'search_open', :open_issues => '1'
get :index, :params => {:id => 1, :q => 'search_open', :open_issues => '1'}
results = assigns(:results)
assert_equal 1, results.size
end
def test_search_all_words
# 'all words' is on by default
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1'
get :index, :params => {:id => 1, :q => 'recipe updating saving', :all_words => '1'}
assert_equal true, assigns(:all_words)
results = assigns(:results)
assert_not_nil results
......@@ -230,7 +230,7 @@ class SearchControllerTest < Redmine::ControllerTest
end
def test_search_one_of_the_words
get :index, :id => 1, :q => 'recipe updating saving', :all_words => ''
get :index, :params => {:id => 1, :q => 'recipe updating saving', :all_words => ''}
assert_equal false, assigns(:all_words)
results = assigns(:results)
assert_not_nil results
......@@ -239,14 +239,14 @@ class SearchControllerTest < Redmine::ControllerTest
end
def test_search_titles_only_without_result
get :index, :id => 1, :q => 'recipe updating saving', :titles_only => '1'
get :index, :params => {:id => 1, :q => 'recipe updating saving', :titles_only => '1'}
results = assigns(:results)
assert_not_nil results
assert_equal 0, results.size
end
def test_search_titles_only
get :index, :id => 1, :q => 'recipe', :titles_only => '1'
get :index, :params => {:id => 1, :q => 'recipe', :titles_only => '1'}
assert_equal true, assigns(:titles_only)
results = assigns(:results)
assert_not_nil results
......@@ -255,7 +255,8 @@ class SearchControllerTest < Redmine::ControllerTest
def test_search_content
Issue.where(:id => 1).update_all("description = 'This is a searchkeywordinthecontent'")
get :index, :id => 1, :q => 'searchkeywordinthecontent', :titles_only => ''
get :index, :params => {:id => 1, :q => 'searchkeywordinthecontent', :titles_only => ''}
assert_equal false, assigns(:titles_only)
results = assigns(:results)
assert_not_nil results
......@@ -265,54 +266,54 @@ class SearchControllerTest < Redmine::ControllerTest
def test_search_with_pagination
issue = (0..24).map {Issue.generate! :subject => 'search_with_limited_results'}.reverse
get :index, :q => 'search_with_limited_results'
get :index, :params => {:q => 'search_with_limited_results'}
assert_response :success
assert_equal issue[0..9], assigns(:results)
get :index, :q => 'search_with_limited_results', :page => 2
get :index, :params => {:q => 'search_with_limited_results', :page => 2}
assert_response :success
assert_equal issue[10..19], assigns(:results)
get :index, :q => 'search_with_limited_results', :page => 3
get :index, :params => {:q => 'search_with_limited_results', :page => 3}
assert_response :success
assert_equal issue[20..24], assigns(:results)
get :index, :q => 'search_with_limited_results', :page => 4
get :index, :params => {:q => 'search_with_limited_results', :page => 4}
assert_response :success
assert_equal [], assigns(:results)
end
def test_search_with_invalid_project_id
get :index, :id => 195, :q => 'recipe'
get :index, :params => {:id => 195, :q => 'recipe'}
assert_response 404
assert_nil assigns(:results)
end
def test_quick_jump_to_issue
# issue of a public project
get :index, :q => "3"
get :index, :params => {:q => "3"}
assert_redirected_to '/issues/3'
# issue of a private project
get :index, :q => "4"
get :index, :params => {:q => "4"}
assert_response :success
assert_template 'index'
end
def test_large_integer
get :index, :q => '4615713488'
get :index, :params => {:q => '4615713488'}
assert_response :success
assert_template 'index'
end
def test_tokens_with_quotes
get :index, :id => 1, :q => '"good bye" hello "bye bye"'
get :index, :params => {:id => 1, :q => '"good bye" hello "bye bye"'}
assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
end
def test_results_should_be_escaped_once
assert Issue.find(1).update_attributes(:subject => '<subject> escaped_once', :description => '<description> escaped_once')
get :index, :q => 'escaped_once'
get :index, :params => {:q => 'escaped_once'}
assert_response :success
assert_select '#search-results' do
assert_select 'dt.issue a', :text => /<subject>/
......@@ -322,7 +323,7 @@ class SearchControllerTest < Redmine::ControllerTest
def test_keywords_should_be_highlighted
assert Issue.find(1).update_attributes(:subject => 'subject highlighted', :description => 'description highlighted')
get :index, :q => 'highlighted'
get :index, :params => {:q => 'highlighted'}
assert_response :success
assert_select '#search-results' do
assert_select 'dt.issue a span.highlight', :text => 'highlighted'
......
......@@ -64,7 +64,7 @@ class SearchCustomFieldsVisibilityTest < Redmine::ControllerTest
@users_to_test.each do |user, fields|
@request.session[:user_id] = user.id
@fields.each_with_index do |field, i|
get :index, :q => "value#{i}"
get :index, :params => {:q => "value#{i}"}
assert_response :success
# we should get a result only if the custom field is visible
if fields.include?(field)
......
......@@ -35,7 +35,7 @@ class SessionsControllerTest < Redmine::ControllerTest
token = Token.create!(:user_id => 2, :action => 'session', :created_on => 10.hours.ago, :updated_on => 10.hours.ago)
created = token.reload.created_on
get :index, {}, {:user_id => 2, :tk => token.value}
get :index, :session => {:user_id => 2, :tk => token.value}
assert_response :success
token.reload
assert_equal created.to_i, token.created_on.to_i
......@@ -48,13 +48,13 @@ class SessionsControllerTest < Redmine::ControllerTest
token = Token.create!(:user_id => 2, :action => 'session', :created_on => created, :updated_on => created)
with_settings :session_lifetime => '0', :session_timeout => '0' do
get :index, {}, {:user_id => 2, :tk => token.value}
get :index, :session => {:user_id => 2, :tk => token.value}
assert_response :success
end
end
def test_user_session_without_token_should_be_reset
get :index, {}, {:user_id => 2}
get :index, :session => {:user_id => 2}
assert_redirected_to 'http://test.host/login?back_url=http%3A%2F%2Ftest.host%2F'
end
......@@ -63,7 +63,7 @@ class SessionsControllerTest < Redmine::ControllerTest
token = Token.create!(:user_id => 2, :action => 'session', :created_on => created, :updated_on => created)
with_settings :session_timeout => '720' do
get :index, {}, {:user_id => 2, :tk => token.value}
get :index, :session => {:user_id => 2, :tk => token.value}
assert_redirected_to 'http://test.host/login?back_url=http%3A%2F%2Ftest.host%2F'
end
end
......@@ -73,7 +73,7 @@ class SessionsControllerTest < Redmine::ControllerTest
token = Token.create!(:user_id => 2, :action => 'session', :created_on => created, :updated_on => created)
with_settings :session_timeout => '720' do
get :index, {}, {:user_id => 2, :tk => token.value}
get :index, :session => {:user_id => 2, :tk => token.value}
assert_response :success
end
end
......@@ -83,7 +83,7 @@ class SessionsControllerTest < Redmine::ControllerTest
token = Token.create!(:user_id => 2, :action => 'session', :created_on => created, :updated_on => created)
with_settings :session_timeout => '60' do
get :index, {}, {:user_id => 2, :tk => token.value}
get :index, :session => {:user_id => 2, :tk => token.value}
assert_redirected_to 'http://test.host/login?back_url=http%3A%2F%2Ftest.host%2F'
end
end
......@@ -93,7 +93,7 @@ class SessionsControllerTest < Redmine::ControllerTest
token = Token.create!(:user_id => 2, :action => 'session', :created_on => created, :updated_on => created)
with_settings :session_timeout => '60' do
get :index, {}, {:user_id => 2, :tk => token.value}
get :index, :session => {:user_id => 2, :tk => token.value}
assert_response :success
end
end
......@@ -106,7 +106,7 @@ class SessionsControllerTest < Redmine::ControllerTest
autologin_token = Token.create!(:user_id => 2, :action => 'autologin', :created_on => 1.day.ago)
@request.cookies['autologin'] = autologin_token.value
get :index, {}, {:user_id => 2, :tk => token.value}
get :index, :session => {:user_id => 2, :tk => token.value}
assert_equal 2, session[:user_id]
assert_response :success
assert_not_equal token.value, session[:tk]
......@@ -122,7 +122,7 @@ class SessionsControllerTest < Redmine::ControllerTest
token = Token.create!(:user_id => 2, :action => 'session', :created_on => created, :updated_on => created)
with_settings :session_timeout => '60' do
get :index, {}, {:user_id => user.id, :tk => token.value}
get :index, :session => {:user_id => user.id, :tk => token.value}
assert_redirected_to 'http://test.host/login?back_url=http%3A%2F%2Ftest.host%2F'
assert_include "Veuillez vous reconnecter", flash[:error]
assert_equal :fr, current_language
......
......@@ -73,11 +73,14 @@ class SettingsControllerTest < Redmine::ControllerTest
end
def test_post_edit_notifications
post :edit, :settings => {:mail_from => 'functional@test.foo',
:bcc_recipients => '0',
:notified_events => %w(issue_added issue_updated news_added),
:emails_footer => 'Test footer'
}
post :edit, :params => {
:settings => {
:mail_from => 'functional@test.foo',
:bcc_recipients => '0',
:notified_events => %w(issue_added issue_updated news_added),
:emails_footer => 'Test footer'
}
}
assert_redirected_to '/settings'
assert_equal 'functional@test.foo', Setting.mail_from
assert !Setting.bcc_recipients?
......@@ -125,12 +128,14 @@ class SettingsControllerTest < Redmine::ControllerTest
end