Fix RuboCop offense Rails/HttpStatus (#39889).

git-svn-id: https://svn.redmine.org/redmine/trunk@22837 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2024-05-18 05:56:55 +00:00
parent 58e9cd420a
commit a9518e28b8
83 changed files with 376 additions and 398 deletions

View File

@@ -97,7 +97,7 @@ class AccountTest < Redmine::IntegrationTest
:autologin => 1
}
)
assert_response 302
assert_response :found
end
assert cookies['custom_autologin'].present?
token = cookies['custom_autologin']

View File

@@ -35,7 +35,7 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base
},
:headers => credentials('admin')
)
assert_response 201
assert_response :created
end
ensure
ActionController::Base.allow_forgery_protection = false

View File

@@ -61,7 +61,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
test "GET /attachments/:id.xml should deny access without credentials" do
get '/attachments/7.xml'
assert_response 401
assert_response :unauthorized
end
test "GET /attachments/download/:id/:filename should return the attachment content" do
@@ -72,7 +72,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
test "GET /attachments/download/:id/:filename should deny access without credentials" do
get '/attachments/download/7/archive.zip'
assert_response 401
assert_response :unauthorized
end
test "GET /attachments/thumbnail/:id should return the thumbnail" do
@@ -118,7 +118,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
:params => {:attachment => {:filename => '', :description => 'updated'}},
:headers => credentials('jsmith')
)
assert_response 422
assert_response :unprocessable_entity
assert_equal 'application/json', response.media_type
json = ActiveSupport::JSON.decode(response.body)
assert_include "File cannot be blank", json['errors']
@@ -209,7 +209,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
"CONTENT_TYPE" => 'image/png'
}.merge(credentials('jsmith'))
)
assert_response 406
assert_response :not_acceptable
end
end
@@ -224,7 +224,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
"CONTENT_TYPE" => 'application/octet-stream'
}.merge(credentials('jsmith'))
)
assert_response 422
assert_response :unprocessable_entity
assert_select 'error', :text => /exceeds the maximum allowed file size/
end
end

View File

@@ -28,7 +28,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
def test_api_should_deny_without_credentials
get '/users/current.xml'
assert_response 401
assert_response :unauthorized
assert response.headers.has_key?('WWW-Authenticate')
end
@@ -37,7 +37,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
user.password = 'my_password'
end
get '/users/current.xml', :headers => credentials(user.login, 'my_password')
assert_response 200
assert_response :ok
end
def test_api_should_deny_http_basic_auth_using_username_and_wrong_password
@@ -45,7 +45,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
user.password = 'my_password'
end
get '/users/current.xml', :headers => credentials(user.login, 'wrong_password')
assert_response 401
assert_response :unauthorized
end
def test_api_should_deny_http_basic_auth_if_twofa_is_active
@@ -54,61 +54,61 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
user.update(twofa_scheme: 'totp')
end
get '/users/current.xml', :headers => credentials(user.login, 'my_password')
assert_response 401
assert_response :unauthorized
end
def test_api_should_accept_http_basic_auth_using_api_key
user = User.generate!
token = Token.create!(:user => user, :action => 'api')
get '/users/current.xml', :headers => credentials(token.value, 'X')
assert_response 200
assert_response :ok
end
def test_api_should_deny_http_basic_auth_using_wrong_api_key
user = User.generate!
token = Token.create!(:user => user, :action => 'feeds') # not the API key
get '/users/current.xml', :headers => credentials(token.value, 'X')
assert_response 401
assert_response :unauthorized
end
def test_api_should_accept_auth_using_api_key_as_parameter
user = User.generate!
token = Token.create!(:user => user, :action => 'api')
get "/users/current.xml?key=#{token.value}"
assert_response 200
assert_response :ok
end
def test_api_should_deny_auth_using_wrong_api_key_as_parameter
user = User.generate!
token = Token.create!(:user => user, :action => 'feeds') # not the API key
get "/users/current.xml?key=#{token.value}"
assert_response 401
assert_response :unauthorized
end
def test_api_should_accept_auth_using_api_key_as_request_header
user = User.generate!
token = Token.create!(:user => user, :action => 'api')
get "/users/current.xml", :headers => {'X-Redmine-API-Key' => token.value.to_s}
assert_response 200
assert_response :ok
end
def test_api_should_deny_auth_using_wrong_api_key_as_request_header
user = User.generate!
token = Token.create!(:user => user, :action => 'feeds') # not the API key
get "/users/current.xml", :headers => {'X-Redmine-API-Key' => token.value.to_s}
assert_response 401
assert_response :unauthorized
end
def test_api_should_trigger_basic_http_auth_with_basic_authorization_header
ApplicationController.any_instance.expects(:authenticate_with_http_basic).once
get '/users/current.xml', :headers => credentials('jsmith')
assert_response 401
assert_response :unauthorized
end
def test_api_should_not_trigger_basic_http_auth_with_non_basic_authorization_header
ApplicationController.any_instance.expects(:authenticate_with_http_basic).never
get '/users/current.xml', :headers => {'HTTP_AUTHORIZATION' => 'Digest foo bar'}
assert_response 401
assert_response :unauthorized
end
def test_invalid_utf8_credentials_should_not_trigger_an_error
@@ -126,7 +126,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
assert_response :success
get '/users/current.json'
assert_response 401
assert_response :unauthorized
end
def test_api_should_accept_switch_user_header_for_admin_user
@@ -140,7 +140,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
def test_api_should_respond_with_412_when_trying_to_switch_to_a_invalid_user
get '/users/current', :headers => {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => 'foobar'}
assert_response 412
assert_response :precondition_failed
end
def test_api_should_respond_with_412_when_trying_to_switch_to_a_locked_user
@@ -148,7 +148,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
assert user.locked?
get '/users/current', :headers => {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => user.login}
assert_response 412
assert_response :precondition_failed
end
def test_api_should_not_accept_switch_user_header_for_non_admin_user

View File

@@ -42,7 +42,7 @@ class Redmine::ApiTest::EnumerationsTest < Redmine::ApiTest::Base
test "GET /enumerations/invalid_subclass.xml should return 404" do
get '/enumerations/invalid_subclass.xml'
assert_response 404
assert_response :not_found
assert_equal 'application/xml', response.media_type
end
end

View File

@@ -24,7 +24,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
test "GET /groups.xml should require authentication" do
get '/groups.xml'
assert_response 401
assert_response :unauthorized
end
test "GET /groups.xml should return givable groups" do
@@ -61,7 +61,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
test "GET /groups.json should require authentication" do
get '/groups.json'
assert_response 401
assert_response :unauthorized
end
test "GET /groups.json should return groups" do

View File

@@ -723,7 +723,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
'/issues.json',
:params => {:issue => {:project_id => 999, :subject => "API"}},
:headers => credentials('jsmith'))
assert_response 422
assert_response :unprocessable_entity
end
test "POST /issues.json with invalid project_id and any assigned_to_id should respond with 422" do
@@ -737,7 +737,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
}
},
:headers => credentials('jsmith'))
assert_response 422
assert_response :unprocessable_entity
end
test "POST /issues.json with invalid project_id and any fixed_version_id should respond with 422" do
@@ -751,7 +751,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
}
},
:headers => credentials('jsmith'))
assert_response 422
assert_response :unprocessable_entity
end
test "PUT /issues/:id.xml" do

View File

@@ -63,7 +63,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
test "GET /time_entries/:id.xml with invalid id should 404" do
get '/time_entries/999.xml', :headers => credentials('jsmith')
assert_response 404
assert_response :not_found
end
test "POST /time_entries.xml with issue_id should create time entry" do
@@ -211,7 +211,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
'/time_entries/2.xml',
:params => {:time_entry => {:hours => '2.3', :comments => 'API Update'}},
:headers => credentials('dlopper'))
assert_response 403
assert_response :forbidden
end
test "DELETE /time_entries/:id.xml should destroy time entry" do

View File

@@ -261,7 +261,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
test "GET /users/current.xml should require authentication" do
get '/users/current.xml'
assert_response 401
assert_response :unauthorized
end
test "GET /users/current.xml should return current user" do

View File

@@ -26,7 +26,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
get '/projects/ecookbook/wiki/index.xml'
assert_response 200
assert_response :ok
assert_equal 'application/xml', response.media_type
assert_select 'wiki_pages[type=array]' do
assert_select 'wiki_page', :count => Wiki.find(1).pages.count
@@ -45,7 +45,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
get '/projects/ecookbook/wiki/CookBook_documentation.xml'
assert_response 200
assert_response :ok
assert_equal 'application/xml', response.media_type
assert_select 'wiki_page' do
assert_select 'title', :text => 'CookBook_documentation'
@@ -60,7 +60,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
test "GET /projects/:project_id/wiki/:title.xml?include=attachments should include attachments" do
get '/projects/ecookbook/wiki/Page_with_an_inline_image.xml?include=attachments'
assert_response 200
assert_response :ok
assert_equal 'application/xml', response.media_type
assert_select 'wiki_page' do
assert_select 'title', :text => 'Page_with_an_inline_image'
@@ -75,13 +75,13 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
get '/projects/ecookbook/wiki/Invalid_Page.xml', :headers => credentials('jsmith')
assert_response 404
assert_response :not_found
assert_equal 'application/xml', response.media_type
end
test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
assert_response 200
assert_response :ok
assert_equal 'application/xml', response.media_type
assert_select 'wiki_page' do
assert_select 'title', :text => 'CookBook_documentation'
@@ -98,7 +98,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
Role.anonymous.remove_permission! :view_wiki_edits
get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
assert_response 401
assert_response :unauthorized
assert_equal 'application/xml', response.media_type
end
@@ -130,7 +130,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
WikiContentVersion.find_by_id(2).update(author_id: nil)
get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
assert_response 200
assert_response :ok
assert_equal 'application/xml', response.media_type
assert_select 'wiki_page' do
assert_select 'author', 0
@@ -176,7 +176,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
},
:headers => credentials('jsmith')
)
assert_response 409
assert_response :conflict
end
end
end
@@ -194,7 +194,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
},
:headers => credentials('jsmith')
)
assert_response 201
assert_response :created
end
end
@@ -227,7 +227,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
},
:headers => credentials('jsmith')
)
assert_response 201
assert_response :created
end
end
@@ -251,7 +251,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
},
:headers => credentials('jsmith')
)
assert_response 201
assert_response :created
end
end

View File

@@ -57,23 +57,23 @@ class ApplicationTest < Redmine::IntegrationTest
def test_token_based_access_should_not_start_session
# issue of a private project
get '/issues/4.atom'
assert_response 302
assert_response :found
atom_key = User.find(2).atom_key
get "/issues/4.atom?key=#{atom_key}"
assert_response 200
assert_response :ok
assert_nil session[:user_id]
end
def test_missing_template_should_respond_with_4xx
get '/login.png'
assert_response 406
assert_response :not_acceptable
end
def test_invalid_token_should_call_custom_handler
ActionController::Base.allow_forgery_protection = true
post '/issues'
assert_response 422
assert_response :unprocessable_entity
assert_include "Invalid form authenticity token.", response.body
ensure
ActionController::Base.allow_forgery_protection = false
@@ -83,7 +83,7 @@ class ApplicationTest < Redmine::IntegrationTest
ActionController::Base.allow_forgery_protection = true
Setting.default_language = 'en'
post '/issues', :headers => {'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'}
assert_response 422
assert_response :unprocessable_entity
assert_equal :fr, current_language
assert_select "html[lang=?]", "fr"
ensure
@@ -93,7 +93,7 @@ class ApplicationTest < Redmine::IntegrationTest
def test_require_login_with_pdf_format_should_not_error
with_settings :login_required => '1' do
get '/issues/1.pdf'
assert_response 302
assert_response :found
end
end
@@ -101,7 +101,7 @@ class ApplicationTest < Redmine::IntegrationTest
Role.anonymous.remove_permission! :view_gantt
with_settings :login_required => '0' do
get '/projects/nonexistingproject/issues/gantt'
assert_response 302
assert_response :found
end
end
@@ -109,6 +109,6 @@ class ApplicationTest < Redmine::IntegrationTest
log_user('jsmith', 'jsmith')
get '/projects/nonexistingproject/issues/gantt'
assert_response 404
assert_response :not_found
end
end

View File

@@ -75,7 +75,7 @@ class AttachmentsTest < Redmine::IntegrationTest
}
}
)
assert_response 302
assert_response :found
end
issue = Issue.order('id DESC').first
@@ -159,7 +159,7 @@ class AttachmentsTest < Redmine::IntegrationTest
}
}
)
assert_response 302
assert_response :found
end
issue = Issue.order('id DESC').first
@@ -185,7 +185,7 @@ class AttachmentsTest < Redmine::IntegrationTest
:attachments => {'p0' => {:filename => filename, :token => token}}
}
)
assert_response 302
assert_response :found
end
issue = Issue.order('id DESC').first
assert_equal 'Issue with upload', issue.subject
@@ -258,7 +258,7 @@ class AttachmentsTest < Redmine::IntegrationTest
with_settings :login_required => '0' do
get "/attachments/journals/3/download"
assert_response 403
assert_response :forbidden
end
with_settings :login_required => '1' do
get "/attachments/journals/3/download"

View File

@@ -87,7 +87,7 @@ class IssuesTest < Redmine::IntegrationTest
}
)
end
assert_response 302
assert_response :found
end
def test_create_issue_by_anonymous_with_custom_permission_should_succeed
@@ -104,7 +104,7 @@ class IssuesTest < Redmine::IntegrationTest
}
}
)
assert_response 302
assert_response :found
end
assert_equal User.anonymous, issue.author
end
@@ -341,7 +341,7 @@ class IssuesTest < Redmine::IntegrationTest
}
}
)
assert_response 302
assert_response :found
end
# Issue view
@@ -381,11 +381,11 @@ class IssuesTest < Redmine::IntegrationTest
subject = 'Updated by an invalid http verb'
get '/issues/update/1', :params => {:issue => {:subject => subject}}
assert_response 404
assert_response :not_found
assert_not_equal subject, Issue.find(1).subject
post '/issues/1', :params => {:issue => {:subject => subject}}
assert_response 404
assert_response :not_found
assert_not_equal subject, Issue.find(1).subject
end
@@ -394,7 +394,7 @@ class IssuesTest < Redmine::IntegrationTest
assert_no_difference 'Watcher.count' do
get '/watchers/watch?object_type=issue&object_id=1'
assert_response 404
assert_response :not_found
end
end
@@ -406,6 +406,6 @@ class IssuesTest < Redmine::IntegrationTest
'v' => {'cf_9' => ['2021-05-25']}
}
assert_response 404
assert_response :not_found
end
end

View File

@@ -68,7 +68,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
}
}
)
assert_response 302
assert_response :found
end
end
@@ -108,7 +108,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
}
}
)
assert_response 302
assert_response :found
end
end
@@ -166,7 +166,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
}
}
)
assert_response 302
assert_response :found
end
end
@@ -193,7 +193,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
}
}
)
assert_response 302
assert_response :found
end
end
end

View File

@@ -33,9 +33,9 @@ class ProjectsTest < Redmine::IntegrationTest
assert !Project.find(1).active?
get '/projects/1'
assert_response 403
assert_response :forbidden
get "/projects/#{subproject.id}"
assert_response 403
assert_response :forbidden
post "/projects/1/unarchive"
assert_redirected_to "/admin/projects"
@@ -49,7 +49,7 @@ class ProjectsTest < Redmine::IntegrationTest
assert_no_difference 'EnabledModule.count' do
get '/projects/1/modules', :params => {:enabled_module_names => ['']}
assert_response 404
assert_response :not_found
end
end
end

View File

@@ -38,7 +38,7 @@ class SessionsTest < Redmine::IntegrationTest
jsmith.save!
get '/my/account'
assert_response 302
assert_response :found
assert flash[:error].include?('Your session has expired')
end
@@ -50,7 +50,7 @@ class SessionsTest < Redmine::IntegrationTest
assert jsmith.activate!
get '/my/account'
assert_response 302
assert_response :found
assert flash[:error].include?('Your session has expired')
end
@@ -62,7 +62,7 @@ class SessionsTest < Redmine::IntegrationTest
jsmith.save!
get '/my/account'
assert_response 200
assert_response :ok
end
def test_change_password_generates_a_new_token_for_current_session
@@ -70,7 +70,7 @@ class SessionsTest < Redmine::IntegrationTest
assert_not_nil token = session[:tk]
get '/my/password'
assert_response 200
assert_response :ok
post(
'/my/password',
:params => {
@@ -79,11 +79,11 @@ class SessionsTest < Redmine::IntegrationTest
:new_password_confirmation => 'secret123'
}
)
assert_response 302
assert_response :found
assert_not_equal token, session[:tk]
get '/my/account'
assert_response 200
assert_response :ok
end
def test_simultaneous_sessions_should_be_valid

View File

@@ -28,7 +28,7 @@ class SudoModeTest < Redmine::IntegrationTest
}
}
)
assert_response 302
assert_response :found
user = User.find_by_login("psmith")
assert_kind_of User, user
@@ -68,7 +68,7 @@ class SudoModeTest < Redmine::IntegrationTest
:sudo_password => 'admin'
}
)
assert_response 302
assert_response :found
user = User.find_by_login("psmith")
assert_kind_of User, user

View File

@@ -27,7 +27,7 @@ class UsersTest < Redmine::IntegrationTest
assert_no_difference 'User.count' do
get '/users/destroy/2'
assert_response 404
assert_response :not_found
end
end
end