Commit 5fd20eb9 authored by jplang's avatar jplang

Use Rails 5 syntax for functional tests.

git-svn-id: https://svn.redmine.org/redmine/trunk@16585 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 5a21820f
......@@ -41,13 +41,17 @@ class AccountControllerOpenidTest < Redmine::ControllerTest
existing_user.login = 'cool_user'
assert existing_user.save!
post :login, :openid_url => existing_user.identity_url
post :login, :params => {
:openid_url => existing_user.identity_url
}
assert_redirected_to '/my/page'
end
def test_login_with_invalid_openid_provider
Setting.self_registration = '0'
post :login, :openid_url => 'http;//openid.example.com/good_user'
post :login, :params => {
:openid_url => 'http;//openid.example.com/good_user'
}
assert_redirected_to home_url
end
......@@ -61,13 +65,17 @@ class AccountControllerOpenidTest < Redmine::ControllerTest
existing_user.login = 'cool_user'
assert existing_user.save!
post :login, :openid_url => existing_user.identity_url
post :login, :params => {
:openid_url => existing_user.identity_url
}
assert_redirected_to '/login'
end
def test_login_with_openid_with_new_user_created
Setting.self_registration = '3'
post :login, :openid_url => 'http://openid.example.com/good_user'
post :login, :params => {
:openid_url => 'http://openid.example.com/good_user'
}
assert_redirected_to '/my/account'
user = User.find_by_login('cool_user')
assert user
......@@ -77,7 +85,9 @@ class AccountControllerOpenidTest < Redmine::ControllerTest
def test_login_with_openid_with_new_user_and_self_registration_off
Setting.self_registration = '0'
post :login, :openid_url => 'http://openid.example.com/good_user'
post :login, :params => {
:openid_url => 'http://openid.example.com/good_user'
}
assert_redirected_to home_url
user = User.find_by_login('cool_user')
assert_nil user
......@@ -85,7 +95,9 @@ class AccountControllerOpenidTest < Redmine::ControllerTest
def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
Setting.self_registration = '1'
post :login, :openid_url => 'http://openid.example.com/good_user'
post :login, :params => {
:openid_url => 'http://openid.example.com/good_user'
}
assert_redirected_to '/login'
user = User.find_by_login('cool_user')
assert user
......@@ -96,7 +108,9 @@ class AccountControllerOpenidTest < Redmine::ControllerTest
def test_login_with_openid_with_new_user_created_with_manual_activation
Setting.self_registration = '2'
post :login, :openid_url => 'http://openid.example.com/good_user'
post :login, :params => {
:openid_url => 'http://openid.example.com/good_user'
}
assert_redirected_to '/login'
user = User.find_by_login('cool_user')
assert user
......@@ -109,7 +123,9 @@ class AccountControllerOpenidTest < Redmine::ControllerTest
existing_user.login = 'cool_user'
assert existing_user.save!
post :login, :openid_url => 'http://openid.example.com/good_user'
post :login, :params => {
:openid_url => 'http://openid.example.com/good_user'
}
assert_response :success
assert_select 'input[name=?][value=?]', 'user[identity_url]', 'http://openid.example.com/good_user'
......@@ -118,7 +134,9 @@ class AccountControllerOpenidTest < Redmine::ControllerTest
def test_login_with_openid_with_new_user_with_missing_information_should_register
Setting.self_registration = '3'
post :login, :openid_url => 'http://openid.example.com/good_blank_user'
post :login, :params => {
:openid_url => 'http://openid.example.com/good_blank_user'
}
assert_response :success
assert_select 'input[name=?]', 'user[login]'
......@@ -141,15 +159,18 @@ class AccountControllerOpenidTest < Redmine::ControllerTest
Setting.self_registration = '3'
assert_difference 'User.count' do
post :register, :user => {
:login => 'good_blank_user',
:password => '',
:password_confirmation => '',
:firstname => 'Cool',
:lastname => 'User',
:mail => 'user@somedomain.com',
:identity_url => 'http://openid.example.com/good_blank_user'
}
post :register, :params => {
:user => {
:login => 'good_blank_user',
:password => '',
:password_confirmation => '',
:firstname => 'Cool',
:lastname => 'User',
:mail => 'user@somedomain.com',
:identity_url => 'http://openid.example.com/good_blank_user'
}
}
assert_response 302
end
......
......@@ -36,7 +36,9 @@ class AccountControllerTest < Redmine::ControllerTest
@request.session[:user_id] = 2
@request.env["HTTP_REFERER"] = 'http://test.host/issues/show/1'
get :login, :back_url => 'http://test.host/issues/show/1'
get :login, :params => {
:back_url => 'http://test.host/issues/show/1'
}
assert_redirected_to '/issues/show/1'
assert_equal 2, @request.session[:user_id]
end
......@@ -66,7 +68,11 @@ class AccountControllerTest < Redmine::ControllerTest
'/'
]
back_urls.each do |back_url|
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => back_url
post :login, :params => {
:username => 'jsmith',
:password => 'jsmith',
:back_url => back_url
}
assert_redirected_to back_url
end
end
......@@ -80,7 +86,11 @@ class AccountControllerTest < Redmine::ControllerTest
'/redmine'
]
back_urls.each do |back_url|
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => back_url
post :login, :params => {
:username => 'jsmith',
:password => 'jsmith',
:back_url => back_url
}
assert_redirected_to back_url
end
ensure
......@@ -93,7 +103,11 @@ class AccountControllerTest < Redmine::ControllerTest
'//test.foo/fake'
]
back_urls.each do |back_url|
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => back_url
post :login, :params => {
:username => 'jsmith',
:password => 'jsmith',
:back_url => back_url
}
assert_redirected_to '/my/page'
end
end
......@@ -120,7 +134,11 @@ class AccountControllerTest < Redmine::ControllerTest
'.test.foo'
]
back_urls.each do |back_url|
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => back_url
post :login, :params => {
:username => 'jsmith',
:password => 'jsmith',
:back_url => back_url
}
assert_redirected_to '/my/page'
end
ensure
......@@ -128,7 +146,10 @@ class AccountControllerTest < Redmine::ControllerTest
end
def test_login_with_wrong_password
post :login, :username => 'admin', :password => 'bad'
post :login, :params => {
:username => 'admin',
:password => 'bad'
}
assert_response :success
assert_select 'div.flash.error', :text => /Invalid user or password/
......@@ -140,7 +161,10 @@ class AccountControllerTest < Redmine::ControllerTest
def test_login_with_locked_account_should_fail
User.find(2).update_attribute :status, User::STATUS_LOCKED
post :login, :username => 'jsmith', :password => 'jsmith'
post :login, :params => {
:username => 'jsmith',
:password => 'jsmith'
}
assert_redirected_to '/login'
assert_include 'locked', flash[:error]
assert_nil @request.session[:user_id]
......@@ -150,7 +174,10 @@ class AccountControllerTest < Redmine::ControllerTest
User.find(2).update_attribute :status, User::STATUS_REGISTERED
with_settings :self_registration => '2', :default_language => 'en' do
post :login, :username => 'jsmith', :password => 'jsmith'
post :login, :params => {
:username => 'jsmith',
:password => 'jsmith'
}
assert_redirected_to '/login'
assert_include 'pending administrator approval', flash[:error]
end
......@@ -160,7 +187,10 @@ class AccountControllerTest < Redmine::ControllerTest
User.find(2).update_attribute :status, User::STATUS_REGISTERED
with_settings :self_registration => '1', :default_language => 'en' do
post :login, :username => 'jsmith', :password => 'jsmith'
post :login, :params => {
:username => 'jsmith',
:password => 'jsmith'
}
assert_redirected_to '/login'
assert_equal 2, @request.session[:registered_user_id]
assert_include 'new activation email', flash[:error]
......@@ -172,7 +202,10 @@ class AccountControllerTest < Redmine::ControllerTest
User.find(2).update_attribute :auth_source_id, source.id
AuthSource.any_instance.stubs(:authenticate).raises(AuthSourceException.new("Something wrong"))
post :login, :username => 'jsmith', :password => 'jsmith'
post :login, :params => {
:username => 'jsmith',
:password => 'jsmith'
}
assert_response 500
assert_select_error /Something wrong/
end
......@@ -180,7 +213,10 @@ class AccountControllerTest < Redmine::ControllerTest
def test_login_should_reset_session
@controller.expects(:reset_session).once
post :login, :username => 'jsmith', :password => 'jsmith'
post :login, :params => {
:username => 'jsmith',
:password => 'jsmith'
}
assert_response 302
end
......@@ -257,14 +293,17 @@ class AccountControllerTest < Redmine::ControllerTest
def test_post_register_with_registration_on
with_settings :self_registration => '3' do
assert_difference 'User.count' do
post :register, :user => {
:login => 'register',
:password => 'secret123',
:password_confirmation => 'secret123',
:firstname => 'John',
:lastname => 'Doe',
:mail => 'register@example.com'
}
post :register, :params => {
:user => {
:login => 'register',
:password => 'secret123',
:password_confirmation => 'secret123',
:firstname => 'John',
:lastname => 'Doe',
:mail => 'register@example.com'
}
}
assert_redirected_to '/my/account'
end
user = User.order('id DESC').first
......@@ -280,14 +319,17 @@ class AccountControllerTest < Redmine::ControllerTest
def test_post_register_with_registration_off_should_redirect
with_settings :self_registration => '0' do
assert_no_difference 'User.count' do
post :register, :user => {
:login => 'register',
:password => 'test',
:password_confirmation => 'test',
:firstname => 'John',
:lastname => 'Doe',
:mail => 'register@example.com'
}
post :register, :params => {
:user => {
:login => 'register',
:password => 'test',
:password_confirmation => 'test',
:firstname => 'John',
:lastname => 'Doe',
:mail => 'register@example.com'
}
}
assert_redirected_to '/'
end
end
......@@ -296,14 +338,21 @@ class AccountControllerTest < Redmine::ControllerTest
def test_post_register_should_create_user_with_hide_mail_preference
with_settings :default_users_hide_mail => '0' do
user = new_record(User) do
post :register, :user => {
:login => 'register',
:password => 'secret123', :password_confirmation => 'secret123',
:firstname => 'John', :lastname => 'Doe',
:mail => 'register@example.com'
}, :pref => {
:hide_mail => '1'
}
post :register, :params => {
:user => {
:login => 'register',
:password => 'secret123',
:password_confirmation => 'secret123',
:firstname => 'John',
:lastname => 'Doe',
:mail => 'register@example.com'
},
:pref => {
:hide_mail => '1'
}
}
end
assert_equal true, user.pref.hide_mail
end
......@@ -320,7 +369,9 @@ class AccountControllerTest < Redmine::ControllerTest
ActionMailer::Base.deliveries.clear
assert_difference 'ActionMailer::Base.deliveries.size' do
assert_difference 'Token.count' do
post :lost_password, :mail => 'JSmith@somenet.foo'
post :lost_password, :params => {
:mail => 'JSmith@somenet.foo'
}
assert_redirected_to '/login'
end
end
......@@ -340,7 +391,9 @@ class AccountControllerTest < Redmine::ControllerTest
assert_difference 'ActionMailer::Base.deliveries.size' do
assert_difference 'Token.count' do
post :lost_password, :mail => 'ANOTHERaddress@foo.bar'
post :lost_password, :params => {
:mail => 'ANOTHERaddress@foo.bar'
}
assert_redirected_to '/login'
end
end
......@@ -351,7 +404,9 @@ class AccountControllerTest < Redmine::ControllerTest
def test_lost_password_for_unknown_user_should_fail
Token.delete_all
assert_no_difference 'Token.count' do
post :lost_password, :mail => 'invalid@somenet.foo'
post :lost_password, :params => {
:mail => 'invalid@somenet.foo'
}
assert_response :success
end
end
......@@ -361,7 +416,9 @@ class AccountControllerTest < Redmine::ControllerTest
assert User.find(2).lock!
assert_no_difference 'Token.count' do
post :lost_password, :mail => 'JSmith@somenet.foo'
post :lost_password, :params => {
:mail => 'JSmith@somenet.foo'
}
assert_redirected_to '/account/lost_password'
end
end
......@@ -370,7 +427,9 @@ class AccountControllerTest < Redmine::ControllerTest
User.any_instance.stubs(:change_password_allowed?).returns(false)
assert_no_difference 'Token.count' do
post :lost_password, :mail => 'JSmith@somenet.foo'
post :lost_password, :params => {
:mail => 'JSmith@somenet.foo'
}
assert_response :success
end
end
......@@ -379,7 +438,9 @@ class AccountControllerTest < Redmine::ControllerTest
user = User.find(2)
token = Token.create!(:action => 'recovery', :user => user)
get :lost_password, :token => token.value
get :lost_password, :params => {
:token => token.value
}
assert_redirected_to '/account/lost_password'
assert_equal token.value, request.session[:password_recovery_token]
......@@ -397,7 +458,9 @@ class AccountControllerTest < Redmine::ControllerTest
end
def test_get_lost_password_with_invalid_token_should_redirect
get :lost_password, :token => "abcdef"
get :lost_password, :params => {
:token => "abcdef"
}
assert_redirected_to '/'
end
......@@ -406,7 +469,11 @@ class AccountControllerTest < Redmine::ControllerTest
user = User.find(2)
token = Token.create!(:action => 'recovery', :user => user)
post :lost_password, :token => token.value, :new_password => 'newpass123', :new_password_confirmation => 'newpass123'
post :lost_password, :params => {
:token => token.value,
:new_password => 'newpass123',
:new_password_confirmation => 'newpass123'
}
assert_redirected_to '/login'
user.reload
assert user.check_password?('newpass123')
......@@ -422,7 +489,11 @@ class AccountControllerTest < Redmine::ControllerTest
token = Token.create!(:action => 'recovery', :user => user)
user.lock!
post :lost_password, :token => token.value, :new_password => 'newpass123', :new_password_confirmation => 'newpass123'
post :lost_password, :params => {
:token => token.value,
:new_password => 'newpass123',
:new_password_confirmation => 'newpass123'
}
assert_redirected_to '/'
assert ! user.check_password?('newpass123')
end
......@@ -431,7 +502,11 @@ class AccountControllerTest < Redmine::ControllerTest
user = User.find(2)
token = Token.create!(:action => 'recovery', :user => user)
post :lost_password, :token => token.value, :new_password => 'newpass', :new_password_confirmation => 'wrongpass'
post :lost_password, :params => {
:token => token.value,
:new_password => 'newpass',
:new_password_confirmation => 'wrongpass'
}
assert_response :success
assert_not_nil Token.find_by_id(token.id), "Token was deleted"
......@@ -445,7 +520,11 @@ class AccountControllerTest < Redmine::ControllerTest
user.save!
token = Token.create!(:action => 'recovery', :user => user)
post :lost_password, :token => token.value, :new_password => 'originalpassword', :new_password_confirmation => 'originalpassword'
post :lost_password, :params => {
:token => token.value,
:new_password => 'originalpassword',
:new_password_confirmation => 'originalpassword'
}
assert_response :success
assert_not_nil Token.find_by_id(token.id), "Token was deleted"
......@@ -460,14 +539,22 @@ class AccountControllerTest < Redmine::ControllerTest
user.save!
token = Token.create!(:action => 'recovery', :user => user)
post :lost_password, :token => token.value, :new_password => 'newpassword', :new_password_confirmation => 'newpassword'
post :lost_password, :params => {
:token => token.value,
:new_password => 'newpassword',
:new_password_confirmation => 'newpassword'
}
assert_redirected_to '/login'
assert_equal false, user.reload.must_change_passwd
end
def test_post_lost_password_with_invalid_token_should_redirect
post :lost_password, :token => "abcdef", :new_password => 'newpass', :new_password_confirmation => 'newpass'
post :lost_password, :params => {
:token => "abcdef",
:new_password => 'newpass',
:new_password_confirmation => 'newpass'
}
assert_redirected_to '/'
end
......
......@@ -30,7 +30,10 @@ class ActivitiesControllerTest < Redmine::ControllerTest
def test_project_index
get :index, :id => 1, :with_subprojects => 0
get :index, :params => {
:id => 1,
:with_subprojects => 0
}
assert_response :success
assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
......@@ -38,12 +41,17 @@ class ActivitiesControllerTest < Redmine::ControllerTest
end
def test_project_index_with_invalid_project_id_should_respond_404
get :index, :id => 299
get :index, :params => {
:id => 299
}
assert_response 404
end
def test_previous_project_index
get :index, :id => 1, :from => 2.days.ago.to_date
get :index, :params => {
:id => 1,
:from => 2.days.ago.to_date
}
assert_response :success
assert_select 'h3', :text => /#{3.days.ago.to_date.day}/
......@@ -64,7 +72,9 @@ class ActivitiesControllerTest < Redmine::ControllerTest
def test_user_index
@request.session[:user_id] = 1
get :index, :user_id => 2
get :index, :params => {
:user_id => 2
}
assert_response :success
assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
......@@ -77,12 +87,17 @@ class ActivitiesControllerTest < Redmine::ControllerTest
end
def test_user_index_with_invalid_user_id_should_respond_404
get :index, :user_id => 299
get :index, :params => {
:user_id => 299
}
assert_response 404
end
def test_index_atom_feed
get :index, :format => 'atom', :with_subprojects => 0
get :index, :params => {
:format => 'atom',
:with_subprojects => 0
}
assert_response :success
assert_select 'feed' do
......@@ -95,15 +110,18 @@ class ActivitiesControllerTest < Redmine::ControllerTest
end
def test_index_atom_feed_with_explicit_selection
get :index, :format => 'atom', :with_subprojects => 0,
:show_changesets => 1,
:show_documents => 1,
:show_files => 1,
:show_issues => 1,
:show_messages => 1,
:show_news => 1,
:show_time_entries => 1,
:show_wiki_edits => 1
get :index, :params => {
:format => 'atom',
:with_subprojects => 0,
:show_changesets => 1,
:show_documents => 1,
:show_files => 1,
:show_issues => 1,
:show_messages => 1,
:show_news => 1,
:show_time_entries => 1,
:show_wiki_edits => 1
}
assert_response :success
......@@ -118,7 +136,10 @@ class ActivitiesControllerTest < Redmine::ControllerTest
def test_index_atom_feed_with_one_item_type
with_settings :default_language => 'en' do
get :index, :format => 'atom', :show_issues => '1'
get :index, :params => {
:format => 'atom',
:show_issues => '1'
}
assert_response :success
assert_select 'title', :text => /Issues/
......@@ -126,7 +147,10 @@ class ActivitiesControllerTest < Redmine::ControllerTest
end
def test_index_atom_feed_with_user
get :index, :user_id => 2, :format => 'atom'
get :index, :params => {
:user_id => 2,
:format => 'atom'
}
assert_response :success
assert_select 'title', :text => "Redmine: #{User.find(2).name}"
......@@ -149,7 +173,11 @@ class ActivitiesControllerTest < Redmine::ControllerTest
def test_index_with_submitted_scope_should_save_as_preference
@request.session[:user_id] = 2
get :index, :show_issues => '1', :show_messages => '1', :submit => 'Apply'
get :index, :params => {
:show_issues => '1',
:show_messages => '1',
:submit => 'Apply'
}
assert_response :success