Redmine 4.1.1

This commit is contained in:
Manuel Cillero 2020-11-22 21:20:06 +01:00
parent 33e7b881a5
commit 3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -58,14 +60,14 @@ class AccountTest < Redmine::IntegrationTest
assert_equal 'autologin', token.action
assert_equal user.id, session[:user_id]
assert_equal token.value, cookies['autologin']
# Session is cleared
reset!
User.current = nil
# Clears user's last login timestamp
user.update_attribute :last_login_on, nil
assert_nil user.reload.last_login_on
# User comes back with user's autologin cookie
cookies[:autologin] = token.value
get '/my/page'
@ -146,6 +148,61 @@ class AccountTest < Redmine::IntegrationTest
assert_equal false, Token.exists?(token.id), "Password recovery token was not deleted"
end
def test_lost_password_expired_token
Token.delete_all
get "/account/lost_password"
assert_response :success
assert_select 'input[name=mail]'
post "/account/lost_password", :params => {
:mail => 'jSmith@somenet.foo'
}
assert_redirected_to "/login"
token = Token.first
assert_equal 'recovery', token.action
assert_equal 'jsmith@somenet.foo', token.user.mail
refute token.expired?
get "/account/lost_password", :params => {
:token => token.value
}
assert_redirected_to '/account/lost_password'
follow_redirect!
assert_response :success
# suppose the user forgets to continue the process and the token expires.
token.update_column :created_on, 1.week.ago
assert token.expired?
assert_select 'input[type=hidden][name=token][value=?]', token.value
assert_select 'input[name=new_password]'
assert_select 'input[name=new_password_confirmation]'
post "/account/lost_password", :params => {
:token => token.value, :new_password => 'newpass123',
:new_password_confirmation => 'newpass123'
}
assert_redirected_to "/account/lost_password"
assert_equal 'This password recovery link has expired, please try again.', flash[:error]
follow_redirect!
assert_response :success
post "/account/lost_password", :params => {
:mail => 'jSmith@somenet.foo'
}
assert_redirected_to "/login"
# should have a new token now
token = Token.last
assert_equal 'recovery', token.action
assert_equal 'jsmith@somenet.foo', token.user.mail
refute token.expired?
end
def test_user_with_must_change_passwd_should_be_forced_to_change_its_password
User.find_by_login('jsmith').update_attribute :must_change_passwd, true

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -51,7 +53,7 @@ class AdminTest < Redmine::IntegrationTest
put "/users/#{user.id}", :params => {
:id => user.id,
:user => {
:status => User::STATUS_LOCKED
:status => User::STATUS_LOCKED
}
}
assert_redirected_to "/users/#{ user.id }/edit"

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -23,13 +25,14 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base
def test_api_should_work_with_protect_from_forgery
ActionController::Base.allow_forgery_protection = true
assert_difference('User.count') do
post '/users.xml',
post(
'/users.xml',
:params => {
:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
:mail => 'foo@example.net', :password => 'secret123'}
},
:headers => credentials('admin')
:headers => credentials('admin'))
assert_response 201
end
ensure
@ -38,18 +41,18 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base
def test_json_datetime_format
get '/users/1.json', :headers => credentials('admin')
assert_include '"created_on":"2006-07-19T17:12:21Z"', response.body
assert_include %Q|"created_on":"#{Time.zone.parse('2006-07-19T17:12:21Z').iso8601}"|, response.body
end
def test_xml_datetime_format
get '/users/1.xml', :headers => credentials('admin')
assert_include '<created_on>2006-07-19T17:12:21Z</created_on>', response.body
assert_include "<created_on>#{Time.zone.parse('2006-07-19T17:12:21Z').iso8601}</created_on>", response.body
end
def test_head_response_should_have_empty_body
put '/users/7.xml', :params => {:user => {:login => 'foo'}}, :headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -59,20 +61,17 @@ 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
set_tmp_attachments_directory
end
test "GET /attachments/download/:id/:filename should return the attachment content" do
get '/attachments/download/7/archive.zip', :headers => credentials('jsmith')
assert_response :success
assert_equal 'application/zip', @response.content_type
set_tmp_attachments_directory
end
test "GET /attachments/download/:id/:filename should deny access without credentials" do
get '/attachments/download/7/archive.zip'
assert_response 302
set_tmp_attachments_directory
assert_response 401
end
test "GET /attachments/thumbnail/:id should return the thumbnail" do
@ -84,7 +83,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
test "DELETE /attachments/:id.xml should return ok and delete Attachment" do
assert_difference 'Attachment.count', -1 do
delete '/attachments/7.xml', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_nil Attachment.find_by_id(7)
@ -93,7 +92,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
test "DELETE /attachments/:id.json should return ok and delete Attachment" do
assert_difference 'Attachment.count', -1 do
delete '/attachments/7.json', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_nil Attachment.find_by_id(7)
@ -104,8 +103,8 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
:params => {:attachment => {:filename => 'renamed.zip', :description => 'updated'}},
:headers => credentials('jsmith')
assert_response :ok
assert_equal 'application/json', response.content_type
assert_response :no_content
assert_nil response.content_type
attachment = Attachment.find(7)
assert_equal 'renamed.zip', attachment.filename
assert_equal 'updated', attachment.description
@ -220,14 +219,11 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
"CONTENT_TYPE" => 'application/octet-stream'
}.merge(credentials('jsmith'))
assert_response :created
end
json = ActiveSupport::JSON.decode(response.body)
assert_kind_of Hash, json['upload']
token = json['upload']['token']
assert token.present?
assert attachment = Attachment.find_by_token(token)
assert_equal 0, attachment.filesize
assert attachment.digest.present?

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -20,10 +22,13 @@ require File.expand_path('../../../test_helper', __FILE__)
class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
fixtures :users
def teardown
User.current = nil
end
def test_api_should_deny_without_credentials
get '/users/current.xml'
assert_response 401
assert_equal User.anonymous, User.current
assert response.headers.has_key?('WWW-Authenticate')
end
@ -33,7 +38,6 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
end
get '/users/current.xml', :headers => credentials(user.login, 'my_password')
assert_response 200
assert_equal user, User.current
end
def test_api_should_deny_http_basic_auth_using_username_and_wrong_password
@ -42,7 +46,6 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
end
get '/users/current.xml', :headers => credentials(user.login, 'wrong_password')
assert_response 401
assert_equal User.anonymous, User.current
end
def test_api_should_accept_http_basic_auth_using_api_key
@ -50,7 +53,6 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
token = Token.create!(:user => user, :action => 'api')
get '/users/current.xml', :headers => credentials(token.value, 'X')
assert_response 200
assert_equal user, User.current
end
def test_api_should_deny_http_basic_auth_using_wrong_api_key
@ -58,7 +60,6 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
token = Token.create!(:user => user, :action => 'feeds') # not the API key
get '/users/current.xml', :headers => credentials(token.value, 'X')
assert_response 401
assert_equal User.anonymous, User.current
end
def test_api_should_accept_auth_using_api_key_as_parameter
@ -66,7 +67,6 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
token = Token.create!(:user => user, :action => 'api')
get "/users/current.xml?key=#{token.value}"
assert_response 200
assert_equal user, User.current
end
def test_api_should_deny_auth_using_wrong_api_key_as_parameter
@ -74,7 +74,6 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
token = Token.create!(:user => user, :action => 'feeds') # not the API key
get "/users/current.xml?key=#{token.value}"
assert_response 401
assert_equal User.anonymous, User.current
end
def test_api_should_accept_auth_using_api_key_as_request_header
@ -82,7 +81,6 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
token = Token.create!(:user => user, :action => 'api')
get "/users/current.xml", :headers => {'X-Redmine-API-Key' => token.value.to_s}
assert_response 200
assert_equal user, User.current
end
def test_api_should_deny_auth_using_wrong_api_key_as_request_header
@ -90,7 +88,6 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
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_equal User.anonymous, User.current
end
def test_api_should_trigger_basic_http_auth_with_basic_authorization_header
@ -106,7 +103,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
end
def test_invalid_utf8_credentials_should_not_trigger_an_error
invalid_utf8 = "\x82".force_encoding('UTF-8')
invalid_utf8 = "\x82"
assert !invalid_utf8.valid_encoding?
assert_nothing_raised do
get '/users/current.xml', :headers => credentials(invalid_utf8, "foo")
@ -130,7 +127,6 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
get '/users/current', :headers => {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login}
assert_response :success
assert_select 'h2', :text => su.name
assert_equal su, User.current
end
def test_api_should_respond_with_412_when_trying_to_switch_to_a_invalid_user
@ -153,6 +149,5 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
get '/users/current', :headers => {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login}
assert_response :success
assert_select 'h2', :text => user.name
assert_equal user, User.current
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -22,12 +24,12 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
def test_integer_custom_fields_should_accept_strings
field = GroupCustomField.generate!(:field_format => 'int')
post '/groups.json',
post(
'/groups.json',
:params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}),
:headers => {
'CONTENT_TYPE' => 'application/json'
}.merge(credentials('admin'))
}.merge(credentials('admin')))
assert_response :created
group = Group.order('id DESC').first
assert_equal "52", group.custom_field_value(field)
@ -35,12 +37,12 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
def test_integer_custom_fields_should_accept_integers
field = GroupCustomField.generate!(:field_format => 'int')
post '/groups.json',
post(
'/groups.json',
:params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}),
:headers => {
'CONTENT_TYPE' => 'application/json'
}.merge(credentials('admin'))
}.merge(credentials('admin')))
assert_response :created
group = Group.order('id DESC').first
assert_equal "52", group.custom_field_value(field)
@ -48,12 +50,12 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
def test_boolean_custom_fields_should_accept_strings
field = GroupCustomField.generate!(:field_format => 'bool')
post '/groups.json',
post(
'/groups.json',
:params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": "1"}}}),
:headers => {
'CONTENT_TYPE' => 'application/json'
}.merge(credentials('admin'))
}.merge(credentials('admin')))
assert_response :created
group = Group.order('id DESC').first
assert_equal "1", group.custom_field_value(field)
@ -61,12 +63,12 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
def test_boolean_custom_fields_should_accept_integers
field = GroupCustomField.generate!(:field_format => 'bool')
post '/groups.json',
post(
'/groups.json',
:params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": 1}}}),
:headers => {
'CONTENT_TYPE' => 'application/json'
}.merge(credentials('admin'))
}.merge(credentials('admin')))
assert_response :created
group = Group.order('id DESC').first
assert_equal "1", group.custom_field_value(field)
@ -79,19 +81,18 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
:possible_values => ["V1", "V2", "V3"],
:default_value => "V2"
)
payload = <<-JSON
{"group": {"name":"Foooo",
"custom_field_values":{"#{field.id}":["V1","V3"]}
}
}
JSON
post '/groups.json',
payload = <<~JSON
{"group": {"name":"Foooo",
"custom_field_values":{"#{field.id}":["V1","V3"]}
}
}
JSON
post(
'/groups.json',
:params => payload,
:headers => {
'CONTENT_TYPE' => 'application/json'
}.merge(credentials('admin'))
}.merge(credentials('admin')))
assert_response :created
group = Group.order('id DESC').first
assert_equal ["V1", "V3"], group.custom_field_value(field).sort

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -41,12 +43,10 @@ class Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base
@token = Token.create!(:user => @user, :action => 'api')
get "/news.xml?key=#{@token.value}"
assert_response :unauthorized
assert_equal User.anonymous, User.current
assert_response :forbidden
get "/news.json?key=#{@token.value}"
assert_response :unauthorized
assert_equal User.anonymous, User.current
assert_response :forbidden
end
def test_with_valid_username_password_http_authentication
@ -55,12 +55,10 @@ class Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base
end
get "/news.xml", :headers => credentials(@user.login, 'my_password')
assert_response :unauthorized
assert_equal User.anonymous, User.current
assert_response :forbidden
get "/news.json", :headers => credentials(@user.login, 'my_password')
assert_response :unauthorized
assert_equal User.anonymous, User.current
assert_response :forbidden
end
def test_with_valid_token_http_authentication
@ -68,11 +66,9 @@ class Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base
@token = Token.create!(:user => @user, :action => 'api')
get "/news.xml", :headers => credentials(@token.value, 'X')
assert_response :unauthorized
assert_equal User.anonymous, User.current
assert_response :forbidden
get "/news.json", :headers => credentials(@token.value, 'X')
assert_response :unauthorized
assert_equal User.anonymous, User.current
assert_response :forbidden
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -25,9 +27,15 @@ class Redmine::ApiTest::EnumerationsTest < Redmine::ApiTest::Base
assert_response :success
assert_equal 'application/xml', response.content_type
assert_select 'issue_priorities[type=array]' do
assert_select 'issue_priority' do
assert_select 'issue_priority:nth-of-type(3)' do
assert_select 'id', :text => '6'
assert_select 'name', :text => 'High'
assert_select 'active', :text => 'true'
end
assert_select 'issue_priority:nth-of-type(6)' do
assert_select 'id', :text => '15'
assert_select 'name', :text => 'Inactive Priority'
assert_select 'active', :text => 'false'
end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -35,19 +37,21 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base
test "POST /projects/:project_id/files.json should create a file" do
set_tmp_attachments_directory
post '/uploads.xml',
post(
'/uploads.xml',
:params => 'File content',
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')))
token = Attachment.last.token
payload = <<-JSON
{ "file": {
"token": "#{token}"
}
}
payload = <<~JSON
{ "file": {
"token": "#{token}"
}
}
JSON
post '/projects/1/files.json',
post(
'/projects/1/files.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
assert_response :success
assert_equal 1, Attachment.last.container_id
assert_equal "Project", Attachment.last.container_type
@ -55,54 +59,59 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base
test "POST /projects/:project_id/files.xml should create a file" do
set_tmp_attachments_directory
post '/uploads.xml',
post(
'/uploads.xml',
:params => 'File content',
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')))
token = Attachment.last.token
payload = <<-XML
<file>
<token>#{token}</token>
</file>
payload = <<~XML
<file>
<token>#{token}</token>
</file>
XML
post '/projects/1/files.xml',
post(
'/projects/1/files.xml',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')))
assert_response :success
assert_equal 1, Attachment.last.container_id
assert_equal "Project", Attachment.last.container_type
end
test "POST /projects/:project_id/files.json should refuse requests without the :token parameter" do
payload = <<-JSON
{ "file": {
"filename": "project_file.zip",
}
}
payload = <<~JSON
{ "file": {
"filename": "project_file.zip",
}
}
JSON
post '/projects/1/files.json',
post(
'/projects/1/files.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
assert_response :bad_request
end
test "POST /projects/:project_id/files.json should accept :filename, :description, :content_type as optional parameters" do
set_tmp_attachments_directory
post '/uploads.xml',
post(
'/uploads.xml',
:params => 'File content',
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')))
token = Attachment.last.token
payload = <<-JSON
{ "file": {
"filename": "New filename",
"description": "New description",
"content_type": "application/txt",
"token": "#{token}"
}
}
payload = <<~JSON
{ "file": {
"filename": "New filename",
"description": "New description",
"content_type": "application/txt",
"token": "#{token}"
}
}
JSON
post '/projects/1/files.json',
post(
'/projects/1/files.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
assert_response :success
assert_equal "New filename", Attachment.last.filename
assert_equal "New description", Attachment.last.description
@ -111,22 +120,24 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base
test "POST /projects/:project_id/files.json should accept :version_id to attach the files to a version" do
set_tmp_attachments_directory
post '/uploads.xml',
post(
'/uploads.xml',
:params => 'File content',
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')))
token = Attachment.last.token
payload = <<-JSON
{ "file": {
"version_id": 3,
"filename": "New filename",
"description": "New description",
"token": "#{token}"
}
}
payload = <<~JSON
{ "file": {
"version_id": 3,
"filename": "New filename",
"description": "New description",
"token": "#{token}"
}
}
JSON
post '/projects/1/files.json',
post(
'/projects/1/files.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
assert_equal 3, Attachment.last.container_id
assert_equal "Version", Attachment.last.container_type
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -157,7 +159,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
put "/groups/#{group.id}.xml",
:params => {:group => {:name => 'New name', :user_ids => [2, 3]}},
:headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_equal 'New name', group.reload.name
@ -181,7 +183,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
group = Group.generate!
assert_difference 'Group.count', -1 do
delete "/groups/#{group.id}.xml", :headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
end
@ -192,7 +194,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
post "/groups/#{group.id}/users.xml",
:params => {:user_id => 5},
:headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
assert_include User.find(5), group.reload.users
@ -220,7 +222,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_difference 'group.reload.users.count', -1 do
delete "/groups/#{group.id}/users/8.xml", :headers => credentials('admin')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
assert_not_include User.find(8), group.reload.users

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -40,9 +42,10 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
test "POST /projects/:project_id/issue_categories.xml should return create issue category" do
assert_difference 'IssueCategory.count' do
post '/projects/1/issue_categories.xml',
post(
'/projects/1/issue_categories.xml',
:params => {:issue_category => {:name => 'API'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_response :created
assert_equal 'application/xml', @response.content_type
@ -54,9 +57,10 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
test "POST /projects/:project_id/issue_categories.xml with invalid parameters should return errors" do
assert_no_difference 'IssueCategory.count' do
post '/projects/1/issue_categories.xml',
post(
'/projects/1/issue_categories.xml',
:params => {:issue_category => {:name => ''}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
@ -66,20 +70,22 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
test "PUT /issue_categories/:id.xml with valid parameters should update the issue category" do
assert_no_difference 'IssueCategory.count' do
put '/issue_categories/2.xml',
put(
'/issue_categories/2.xml',
:params => {:issue_category => {:name => 'API Update'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_equal 'API Update', IssueCategory.find(2).name
end
test "PUT /issue_categories/:id.xml with invalid parameters should return errors" do
assert_no_difference 'IssueCategory.count' do
put '/issue_categories/2.xml',
put(
'/issue_categories/2.xml',
:params => {:issue_category => {:name => ''}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
@ -91,23 +97,24 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
assert_difference 'IssueCategory.count', -1 do
delete '/issue_categories/1.xml', :headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil IssueCategory.find_by_id(1)
end
test "DELETE /issue_categories/:id.xml should reassign issues with :reassign_to_id param" do
issue_count = Issue.where(:category_id => 1).count
assert issue_count > 0
assert_difference 'IssueCategory.count', -1 do
assert_difference 'Issue.where(:category_id => 2).count', 3 do
delete '/issue_categories/1.xml',
delete(
'/issue_categories/1.xml',
:params => {:reassign_to_id => 2},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil IssueCategory.find_by_id(1)
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -77,7 +79,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
delete '/relations/2.xml', :headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil IssueRelation.find_by_id(2)
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -18,7 +20,8 @@
require File.expand_path('../../../test_helper', __FILE__)
class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
fixtures :projects,
fixtures(
:projects,
:users,
:roles,
:members,
@ -42,7 +45,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
:journals,
:journal_details,
:queries,
:attachments
:attachments)
test "GET /issues.xml should contain metadata" do
get '/issues.xml'
@ -107,14 +110,14 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
end
test "GET /issues.xml with custom field filter" do
get '/issues.xml',
:params => {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}}
get(
'/issues.xml',
:params => {:set_filter => 1, :f => ['cf_1'],
:op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}})
expected_ids = Issue.visible.
joins(:custom_values).
where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
assert expected_ids.any?
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
end
@ -209,10 +212,10 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
test "GET /issues/:id.xml with journals should format timestamps in ISO 8601" do
get '/issues/1.xml?include=journals'
iso_date = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
assert_select 'issue>created_on', :text => iso_date
assert_select 'issue>updated_on', :text => iso_date
assert_select 'issue journal>created_on', :text => iso_date
issue = Issue.find(1)
assert_select 'issue>created_on', :text => issue.created_on.iso8601
assert_select 'issue>updated_on', :text => issue.updated_on.iso8601
assert_select 'issue journal>created_on', :text => issue.journals[0].created_on.iso8601
end
test "GET /issues/:id.xml with custom fields" do
@ -336,7 +339,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
json = ActiveSupport::JSON.decode(response.body)
assert_equal 2, json['issue']['children'].size
assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size
assert_equal 1, json['issue']['children'].count {|child| child.key?('children')}
end
test "GET /issues/:id.json with no spent time should return floats" do
@ -403,9 +406,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
parent = Issue.find(3)
parent.update_columns :estimated_hours => 2.0
child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
# remove permission!
Role.anonymous.remove_permission! :view_time_entries
#Role.all.each { |role| role.remove_permission! :view_time_entries }
get '/issues/3.xml'
assert_equal 'application/xml', response.content_type
@ -454,9 +455,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
parent = Issue.find(3)
parent.update_columns :estimated_hours => 2.0
child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
# remove permission!
Role.anonymous.remove_permission! :view_time_entries
#Role.all.each { |role| role.remove_permission! :view_time_entries }
get '/issues/3.json'
assert_equal 'application/json', response.content_type
@ -484,26 +483,27 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
end
test "POST /issues.xml should create an issue with the attributes" do
payload = <<-XML
<?xml version="1.0" encoding="UTF-8" ?>
<issue>
<project_id>1</project_id>
<tracker_id>2</tracker_id>
<status_id>3</status_id>
<subject>API test</subject>
</issue>
XML
payload = <<~XML
<?xml version="1.0" encoding="UTF-8" ?>
<issue>
<project_id>1</project_id>
<tracker_id>2</tracker_id>
<status_id>3</status_id>
<category_id>2</category_id>
<subject>API test</subject>
</issue>
XML
assert_difference('Issue.count') do
post '/issues.xml',
post(
'/issues.xml',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')))
end
issue = Issue.order('id DESC').first
assert_equal 1, issue.project_id
assert_equal 2, issue.tracker_id
assert_equal 3, issue.status_id
assert_equal 2, issue.category_id
assert_equal 'API test', issue.subject
assert_response :created
@ -513,14 +513,15 @@ XML
test "POST /issues.xml with watcher_user_ids should create issue with watchers" do
assert_difference('Issue.count') do
post '/issues.xml',
post(
'/issues.xml',
:params => {
:issue => {
:project_id => 1, :subject => 'Watchers',
:tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]
}
},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
assert_response :created
end
issue = Issue.order('id desc').first
@ -530,46 +531,48 @@ XML
test "POST /issues.xml with failure should return errors" do
assert_no_difference('Issue.count') do
post '/issues.xml',
post(
'/issues.xml',
:params => {:issue => {:project_id => 1}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_select 'errors error', :text => "Subject cannot be blank"
end
test "POST /issues.json should create an issue with the attributes" do
payload = <<-JSON
{
"issue": {
"project_id": "1",
"tracker_id": "2",
"status_id": "3",
"subject": "API test"
}
}
JSON
payload = <<~JSON
{
"issue": {
"project_id": "1",
"tracker_id": "2",
"status_id": "3",
"category_id": "2",
"subject": "API test"
}
}
JSON
assert_difference('Issue.count') do
post '/issues.json',
post(
'/issues.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
end
issue = Issue.order('id DESC').first
assert_equal 1, issue.project_id
assert_equal 2, issue.tracker_id
assert_equal 3, issue.status_id
assert_equal 2, issue.category_id
assert_equal 'API test', issue.subject
end
test "POST /issues.json should accept project identifier as project_id" do
assert_difference('Issue.count') do
post '/issues.json',
post(
'/issues.json',
:params => {:issue => {:project_id => 'subproject1', :tracker_id => 2, :subject => 'Foo'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
assert_response :created
end
end
@ -583,23 +586,21 @@ JSON
:is_for_all => true,
:trackers => Tracker.all.to_a
)
payload = <<-JSON
{
"issue": {
"project_id": "1",
"subject": "Multivalued custom field",
"custom_field_values":{"#{field.id}":["V1","V3"]}
}
}
JSON
payload = <<~JSON
{
"issue": {
"project_id": "1",
"subject": "Multivalued custom field",
"custom_field_values":{"#{field.id}":["V1","V3"]}
}
}
JSON
assert_difference('Issue.count') do
post '/issues.json',
post(
'/issues.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
end
assert_response :created
issue = Issue.order('id DESC').first
assert_equal ["V1", "V3"], issue.custom_field_value(field).sort
@ -607,51 +608,58 @@ JSON
test "POST /issues.json with omitted custom field should set default value" do
field = IssueCustomField.generate!(:default_value => "Default")
issue = new_record(Issue) do
post '/issues.json',
:params => {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {}}},
:headers => credentials('jsmith')
post(
'/issues.json',
:params => {
:issue => {:project_id => 1, :subject => 'API',
:custom_field_values => {}}
},
:headers => credentials('jsmith'))
end
assert_equal "Default", issue.custom_field_value(field)
end
test "POST /issues.json with custom field set to blank should not set default value" do
field = IssueCustomField.generate!(:default_value => "Default")
issue = new_record(Issue) do
post '/issues.json',
:params => {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {field.id.to_s => ""}}},
:headers => credentials('jsmith')
post(
'/issues.json',
:params => {
:issue => {:project_id => 1, :subject => 'API',
:custom_field_values => {field.id.to_s => ""}}
},
:headers => credentials('jsmith'))
end
assert_equal "", issue.custom_field_value(field)
end
test "POST /issues.json with failure should return errors" do
assert_no_difference('Issue.count') do
post '/issues.json',
post(
'/issues.json',
:params => {:issue => {:project_id => 1}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
json = ActiveSupport::JSON.decode(response.body)
assert json['errors'].include?("Subject cannot be blank")
end
test "POST /issues.json with invalid project_id should respond with 422" do
post '/issues.json',
post(
'/issues.json',
:params => {:issue => {:project_id => 999, :subject => "API"}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
assert_response 422
end
test "PUT /issues/:id.xml" do
assert_difference('Journal.count') do
put '/issues/6.xml',
put(
'/issues/6.xml',
:params => {:issue => {:subject => 'API update', :notes => 'A new note'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
issue = Issue.find(6)
assert_equal "API update", issue.subject
journal = Journal.last
@ -659,14 +667,18 @@ JSON
end
test "PUT /issues/:id.xml with custom fields" do
put '/issues/3.xml',
:params => {:issue => {:custom_fields => [
{'id' => '1', 'value' => 'PostgreSQL' },
{'id' => '2', 'value' => '150'}
]}
},
:headers => credentials('jsmith')
put(
'/issues/3.xml',
:params =>
{
:issue => {
:custom_fields => [
{'id' => '1', 'value' => 'PostgreSQL' },
{'id' => '2', 'value' => '150'}
]
}
},
:headers => credentials('jsmith'))
issue = Issue.find(3)
assert_equal '150', issue.custom_value_for(2).value
assert_equal 'PostgreSQL', issue.custom_value_for(1).value
@ -675,25 +687,28 @@ JSON
test "PUT /issues/:id.xml with multi custom fields" do
field = CustomField.find(1)
field.update_attribute :multiple, true
put '/issues/3.xml',
:params => {:issue => {:custom_fields => [
{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] },
{'id' => '2', 'value' => '150'}
]}
},
:headers => credentials('jsmith')
put(
'/issues/3.xml',
:params =>
{
:issue => {
:custom_fields => [
{'id' => '1', 'value' => ['MySQL', 'PostgreSQL']},
{'id' => '2', 'value' => '150'}
]
}
},
:headers => credentials('jsmith'))
issue = Issue.find(3)
assert_equal '150', issue.custom_value_for(2).value
assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
end
test "PUT /issues/:id.xml with project change" do
put '/issues/3.xml',
put(
'/issues/3.xml',
:params => {:issue => {:project_id => 2, :subject => 'Project changed'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
issue = Issue.find(3)
assert_equal 2, issue.project_id
assert_equal 'Project changed', issue.subject
@ -701,11 +716,11 @@ JSON
test "PUT /issues/:id.xml with notes only" do
assert_difference('Journal.count') do
put '/issues/6.xml',
put(
'/issues/6.xml',
:params => {:issue => {:notes => 'Notes only'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
journal = Journal.last
assert_equal "Notes only", journal.notes
end
@ -714,13 +729,12 @@ JSON
field = IssueCustomField.generate!(:default_value => "Default")
issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""})
assert_equal "", issue.reload.custom_field_value(field)
assert_difference('Journal.count') do
put "/issues/#{issue.id}.json",
put(
"/issues/#{issue.id}.json",
:params => {:issue => {:custom_field_values => {}, :notes => 'API'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_equal "", issue.reload.custom_field_value(field)
end
@ -728,26 +742,24 @@ JSON
field = IssueCustomField.generate!(:default_value => "Default")
issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""})
assert_equal "", issue.reload.custom_field_value(field)
assert_difference('Journal.count') do
put "/issues/#{issue.id}.json",
put(
"/issues/#{issue.id}.json",
:params => {:issue => {:custom_field_values => {field.id.to_s => ""}, :notes => 'API'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_equal "", issue.reload.custom_field_value(field)
end
test "PUT /issues/:id.json with tracker change and omitted custom field specific to that tracker should set default value" do
field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2])
issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
assert_difference('Journal.count') do
put "/issues/#{issue.id}.json",
put(
"/issues/#{issue.id}.json",
:params => {:issue => {:tracker_id => 2, :custom_field_values => {}, :notes => 'API'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_equal 2, issue.reload.tracker_id
assert_equal "Default", issue.reload.custom_field_value(field)
end
@ -755,43 +767,42 @@ JSON
test "PUT /issues/:id.json with tracker change and custom field specific to that tracker set to blank should not set default value" do
field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2])
issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
assert_difference('Journal.count') do
put "/issues/#{issue.id}.json",
put(
"/issues/#{issue.id}.json",
:params => {:issue => {:tracker_id => 2, :custom_field_values => {field.id.to_s => ""}, :notes => 'API'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_equal 2, issue.reload.tracker_id
assert_equal "", issue.reload.custom_field_value(field)
end
test "PUT /issues/:id.xml with failed update" do
put '/issues/6.xml',
put(
'/issues/6.xml',
:params => {:issue => {:subject => ''}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
assert_response :unprocessable_entity
assert_select 'errors error', :text => "Subject cannot be blank"
end
test "PUT /issues/:id.xml with invalid assignee should return error" do
user = User.generate!
put '/issues/6.xml',
put(
'/issues/6.xml',
:params => {:issue => {:assigned_to_id => user.id}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
assert_response :unprocessable_entity
assert_select 'errors error', :text => "Assignee is invalid"
end
test "PUT /issues/:id.json" do
assert_difference('Journal.count') do
put '/issues/6.json',
put(
'/issues/6.json',
:params => {:issue => {:subject => 'API update', :notes => 'A new note'}},
:headers => credentials('jsmith')
assert_response :ok
:headers => credentials('jsmith'))
assert_response :no_content
assert_equal '', response.body
end
@ -802,10 +813,10 @@ JSON
end
test "PUT /issues/:id.json with failed update" do
put '/issues/6.json',
put(
'/issues/6.json',
:params => {:issue => {:subject => ''}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
assert_response :unprocessable_entity
json = ActiveSupport::JSON.decode(response.body)
assert json['errors'].include?("Subject cannot be blank")
@ -815,7 +826,7 @@ JSON
assert_difference('Issue.count', -1) do
delete '/issues/6.xml', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_nil Issue.find_by_id(6)
@ -825,7 +836,7 @@ JSON
assert_difference('Issue.count', -1) do
delete '/issues/6.json', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_nil Issue.find_by_id(6)
@ -833,11 +844,11 @@ JSON
test "POST /issues/:id/watchers.xml should add watcher" do
assert_difference 'Watcher.count' do
post '/issues/1/watchers.xml',
post(
'/issues/1/watchers.xml',
:params => {:user_id => 3},
:headers => credentials('jsmith')
assert_response :ok
:headers => credentials('jsmith'))
assert_response :no_content
assert_equal '', response.body
end
watcher = Watcher.order('id desc').first
@ -851,7 +862,7 @@ JSON
assert_difference 'Watcher.count', -1 do
delete '/issues/1/watchers/3.xml', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', response.body
end
assert_equal false, Issue.find(1).watched_by?(User.find(3))
@ -863,11 +874,14 @@ JSON
# create the issue with the upload's token
assert_difference 'Issue.count' do
post '/issues.xml',
:params => {:issue => {:project_id => 1, :subject => 'Uploaded file',
:uploads => [{:token => token, :filename => 'test.txt',
:content_type => 'text/plain'}]}},
:headers => credentials('jsmith')
post(
'/issues.xml',
:params =>
{:issue =>
{:project_id => 1, :subject => 'Uploaded file',
:uploads => [{:token => token, :filename => 'test.txt',
:content_type => 'text/plain'}]}},
:headers => credentials('jsmith'))
assert_response :created
end
issue = Issue.order('id DESC').first
@ -899,30 +913,29 @@ JSON
def test_create_issue_with_multiple_uploaded_files_as_xml
token1 = xml_upload('File content 1', credentials('jsmith'))
token2 = xml_upload('File content 2', credentials('jsmith'))
payload = <<-XML
<?xml version="1.0" encoding="UTF-8" ?>
<issue>
<project_id>1</project_id>
<tracker_id>1</tracker_id>
<subject>Issue with multiple attachments</subject>
<uploads type="array">
<upload>
<token>#{token1}</token>
<filename>test1.txt</filename>
</upload>
<upload>
<token>#{token2}</token>
<filename>test1.txt</filename>
</upload>
</uploads>
</issue>
XML
payload = <<~XML
<?xml version="1.0" encoding="UTF-8" ?>
<issue>
<project_id>1</project_id>
<tracker_id>1</tracker_id>
<subject>Issue with multiple attachments</subject>
<uploads type="array">
<upload>
<token>#{token1}</token>
<filename>test1.txt</filename>
</upload>
<upload>
<token>#{token2}</token>
<filename>test1.txt</filename>
</upload>
</uploads>
</issue>
XML
assert_difference 'Issue.count' do
post '/issues.xml',
post(
'/issues.xml',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')))
assert_response :created
end
issue = Issue.order('id DESC').first
@ -932,25 +945,24 @@ XML
def test_create_issue_with_multiple_uploaded_files_as_json
token1 = json_upload('File content 1', credentials('jsmith'))
token2 = json_upload('File content 2', credentials('jsmith'))
payload = <<-JSON
{
"issue": {
"project_id": "1",
"tracker_id": "1",
"subject": "Issue with multiple attachments",
"uploads": [
{"token": "#{token1}", "filename": "test1.txt"},
{"token": "#{token2}", "filename": "test2.txt"}
]
}
}
JSON
payload = <<~JSON
{
"issue": {
"project_id": "1",
"tracker_id": "1",
"subject": "Issue with multiple attachments",
"uploads": [
{"token": "#{token1}", "filename": "test1.txt"},
{"token": "#{token2}", "filename": "test2.txt"}
]
}
}
JSON
assert_difference 'Issue.count' do
post '/issues.json',
post(
'/issues.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
assert_response :created
end
issue = Issue.order('id DESC').first
@ -963,12 +975,16 @@ JSON
# update the issue with the upload's token
assert_difference 'Journal.count' do
put '/issues/1.xml',
:params => {:issue => {:notes => 'Attachment added',
:uploads => [{:token => token, :filename => 'test.txt',
:content_type => 'text/plain'}]}},
:headers => credentials('jsmith')
assert_response :ok
put(
'/issues/1.xml',
:params =>
{:issue =>
{:notes => 'Attachment added',
:uploads =>
[{:token => token, :filename => 'test.txt',
:content_type => 'text/plain'}]}},
:headers => credentials('jsmith'))
assert_response :no_content
assert_equal '', @response.body
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -135,7 +137,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
:params => {:membership => {:user_id => 3, :role_ids => [1,2]}},
:headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
member = Member.find(2)
@ -156,7 +158,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
assert_difference 'Member.count', -1 do
delete '/memberships/2.xml', :headers => credentials('jsmith')
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
assert_nil Member.find_by_id(2)

View file

@ -0,0 +1,105 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../test_helper', __FILE__)
class Redmine::ApiTest::MyTest < Redmine::ApiTest::Base
fixtures :users, :email_addresses, :members, :member_roles, :roles, :projects
test "GET /my/account.json should return user" do
assert Setting.rest_api_enabled?
get '/my/account.json', :headers => credentials('dlopper', 'foo')
assert_response :success
assert_equal 'application/json', response.content_type
json = ActiveSupport::JSON.decode(response.body)
assert json.key?('user')
assert_equal 'dlopper', json['user']['login']
end
test "PUT /my/account.xml with valid parameters should update the user" do
put(
'/my/account.xml',
:params => {
:user => {
:firstname => 'Dave', :lastname => 'Renamed',
:mail => 'dave@somenet.foo'
}
},
:headers => credentials('dlopper', 'foo'))
assert_response :no_content
assert_equal '', @response.body
assert user = User.find_by_lastname('Renamed')
assert_equal 'Dave', user.firstname
assert_equal 'Renamed', user.lastname
assert_equal 'dave@somenet.foo', user.mail
refute user.admin?
end
test "PUT /my/account.json with valid parameters should update the user" do
put(
'/my/account.xml',
:params => {
:user => {
:firstname => 'Dave', :lastname => 'Renamed',
:mail => 'dave@somenet.foo'
}
},
:headers => credentials('dlopper', 'foo'))
assert_response :no_content
assert_equal '', @response.body
assert user = User.find_by_lastname('Renamed')
assert_equal 'Dave', user.firstname
assert_equal 'Renamed', user.lastname
assert_equal 'dave@somenet.foo', user.mail
refute user.admin?
end
test "PUT /my/account.xml with invalid parameters" do
put(
'/my/account.xml',
:params => {
:user => {
:login => 'dlopper', :firstname => '', :lastname => 'Lastname'
}
},
:headers => credentials('dlopper', 'foo'))
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
assert_select 'errors error', :text => "First name cannot be blank"
end
test "PUT /my/account.json with invalid parameters" do
put(
'/my/account.json',
:params => {
:user => {
:login => 'dlopper', :firstname => '', :lastname => 'Lastname'
}
},
:headers => credentials('dlopper', 'foo'))
assert_response :unprocessable_entity
assert_equal 'application/json', @response.content_type
json = ActiveSupport::JSON.decode(response.body)
assert_kind_of Hash, json
assert json.has_key?('errors')
assert_kind_of Array, json['errors']
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -25,7 +27,9 @@ class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
:member_roles,
:members,
:enabled_modules,
:news
:news,
:comments,
:attachments
test "GET /news.xml should return news" do
get '/news.xml'
@ -58,4 +62,336 @@ class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
assert_kind_of Hash, json['news'].first
assert_equal 2, json['news'].first['id']
end
test "GET /news/:id.xml" do
get "/news/1.xml"
assert_response :success
assert_equal 'application/xml', response.content_type
assert_select 'news' do
assert_select 'id', 1
assert_select "project[id=1][name=\"eCookbook\"]"
assert_select "author[id=2][name=\"John Smith\"]"
assert_select 'title', 'eCookbook first release !'
assert_select 'summary', 'First version was released...'
assert_select 'description', "eCookbook 1.0 has been released.\n\nVisit http://ecookbook.somenet.foo/"
assert_select 'created_on', News.find(1).created_on.iso8601
end
end
test "GET /news/:id.json" do
get "/news/1.json"
assert_response :success
assert_equal 'application/json', response.content_type
json = ActiveSupport::JSON.decode(response.body)
assert_equal 1, json['news']['id']
end
test "GET /news/:id.xml with attachments" do
news = News.find(1)
attachment = Attachment.first
attachment.container = news
attachment.save!
get "/news/1.xml?include=attachments"
assert_select 'news attachments[type=array]' do
assert_select 'attachment id', :text => '1' do
assert_select '~ filename', :text => 'error281.txt'
assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/1/error281.txt'
end
end
end
test "GET /news/:id.xml with comments" do
get "/news/1.xml?include=comments"
assert_select 'news comments[type=array]' do
assert_select 'comment', 2
assert_select 'comment[id=1]' do
assert_select 'author[id=1][name="Redmine Admin"]'
assert_select 'content', :text => 'my first comment'
end
assert_select 'comment[id=2]' do
assert_select 'author[id=2][name="John Smith"]'
assert_select 'content', :text => 'This is an other comment'
end
end
end
test "POST /project/:project_id/news.xml should create a news with the attributes" do
payload = <<~XML
<?xml version="1.0" encoding="UTF-8" ?>
<news>
<title>NewsXmlApiTest</title>
<summary>News XML-API Test</summary>
<description>This is the description</description>
</news>
XML
assert_difference('News.count') do
post(
'/projects/1/news.xml',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')))
end
news = News.find_by(:title => 'NewsXmlApiTest')
assert_not_nil news
assert_equal 'News XML-API Test', news.summary
assert_equal 'This is the description', news.description
assert_equal User.find_by_login('jsmith'), news.author
assert_equal Project.find(1), news.project
assert_response :no_content
end
test "POST /project/:project_id/news.xml with failure should return errors" do
assert_no_difference('News.count') do
post(
'/projects/1/news.xml',
:params => {:news => {:title => ''}},
:headers => credentials('jsmith'))
end
assert_select 'errors error', :text => "Title cannot be blank"
end
test "POST /project/:project_id/news.json should create a news with the attributes" do
payload = <<~JSON
{
"news": {
"title": "NewsJsonApiTest",
"summary": "News JSON-API Test",
"description": "This is the description"
}
}
JSON
assert_difference('News.count') do
post(
'/projects/1/news.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
end
news = News.find_by(:title => 'NewsJsonApiTest')
assert_not_nil news
assert_equal 'News JSON-API Test', news.summary
assert_equal 'This is the description', news.description
assert_equal User.find_by_login('jsmith'), news.author
assert_equal Project.find(1), news.project
assert_response :no_content
end
test "POST /project/:project_id/news.json with failure should return errors" do
assert_no_difference('News.count') do
post(
'/projects/1/news.json',
:params => {:news => {:title => ''}},
:headers => credentials('jsmith'))
end
json = ActiveSupport::JSON.decode(response.body)
assert json['errors'].include?("Title cannot be blank")
end
test "POST /project/:project_id/news.xml with attachment should create a news with attachment" do
token = xml_upload('test_create_with_attachment', credentials('jsmith'))
attachment = Attachment.find_by_token(token)
assert_difference 'News.count' do
post(
'/projects/1/news.xml',
:params => {:news => {:title => 'News XML-API with Attachment',
:description => 'desc'},
:attachments => [{:token => token, :filename => 'test.txt',
:content_type => 'text/plain'}]},
:headers => credentials('jsmith'))
assert_response :no_content
end
news = News.find_by(:title => 'News XML-API with Attachment')
assert_equal attachment, news.attachments.first
attachment.reload
assert_equal 'test.txt', attachment.filename
assert_equal 'text/plain', attachment.content_type
assert_equal 'test_create_with_attachment'.size, attachment.filesize
assert_equal 2, attachment.author_id
end
test "POST /project/:project_id/news.xml with multiple attachment should create a news with attachments" do
token1 = xml_upload('File content 1', credentials('jsmith'))
token2 = xml_upload('File content 2', credentials('jsmith'))
payload = <<~XML
<?xml version="1.0" encoding="UTF-8" ?>
<news>
<title>News XML-API with attachments</title>
<description>News with multiple attachments</description>
<uploads type="array">
<upload>
<token>#{token1}</token>
<filename>test1.txt</filename>
</upload>
<upload>
<token>#{token2}</token>
<filename>test2.txt</filename>
</upload>
</uploads>
</news>
XML
assert_difference('News.count') do
post(
'/projects/1/news.xml',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')))
assert_response :no_content
end
news = News.find_by(:title => 'News XML-API with attachments')
assert_equal 2, news.attachments.count
end
test "POST /project/:project_id/news.json with multiple attachment should create a news with attachments" do
token1 = json_upload('File content 1', credentials('jsmith'))
token2 = json_upload('File content 2', credentials('jsmith'))
payload = <<~JSON
{
"news": {
"title": "News JSON-API with attachments",
"description": "News with multiple attachments",
"uploads": [
{"token": "#{token1}", "filename": "test1.txt"},
{"token": "#{token2}", "filename": "test2.txt"}
]
}
}
JSON
assert_difference('News.count') do
post(
'/projects/1/news.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
assert_response :no_content
end
news = News.find_by(:title => 'News JSON-API with attachments')
assert_equal 2, news.attachments.count
end
test "PUT /news/:id.xml" do
payload = <<~XML
<?xml version="1.0" encoding="UTF-8" ?>
<news>
<title>NewsUpdateXmlApiTest</title>
<summary>News Update XML-API Test</summary>
<description>update description via xml api</description>
</news>
XML
put(
'/news/1.xml',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')))
news = News.find(1)
assert_equal 'NewsUpdateXmlApiTest', news.title
assert_equal 'News Update XML-API Test', news.summary
assert_equal 'update description via xml api', news.description
end
test "PUT /news/:id.json" do
payload = <<~JSON
{
"news": {
"title": "NewsUpdateJsonApiTest",
"summary": "News Update JSON-API Test",
"description": "update description via json api"
}
}
JSON
put(
'/news/1.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
news = News.find(1)
assert_equal 'NewsUpdateJsonApiTest', news.title
assert_equal 'News Update JSON-API Test', news.summary
assert_equal 'update description via json api', news.description
end
test "PUT /news/:id.xml with failed update" do
put(
'/news/1.xml',
:params => {:news => {:title => ''}},
:headers => credentials('jsmith'))
assert_response :unprocessable_entity
assert_select 'errors error', :text => "Title cannot be blank"
end
test "PUT /news/:id.json with failed update" do
put(
'/news/1.json',
:params => {:news => {:title => ''}},
:headers => credentials('jsmith'))
assert_response :unprocessable_entity
json = ActiveSupport::JSON.decode(response.body)
assert json['errors'].include?("Title cannot be blank")
end
test "PUT /news/:id.xml with multiple attachment should update a news with attachments" do
token1 = xml_upload('File content 1', credentials('jsmith'))
token2 = xml_upload('File content 2', credentials('jsmith'))
payload = <<~XML
<?xml version="1.0" encoding="UTF-8" ?>
<news>
<title>News Update XML-API with attachments</title>
<uploads type="array">
<upload>
<token>#{token1}</token>
<filename>test1.txt</filename>
</upload>
<upload>
<token>#{token2}</token>
<filename>test2.txt</filename>
</upload>
</uploads>
</news>
XML
put(
'/news/1.xml',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')))
assert_response :no_content
news = News.find_by(:title => 'News Update XML-API with attachments')
assert_equal 2, news.attachments.count
end
test "PUT /news/:id.json with multiple attachment should update a news with attachments" do
token1 = json_upload('File content 1', credentials('jsmith'))
token2 = json_upload('File content 2', credentials('jsmith'))
payload = <<~JSON
{
"news": {
"title": "News Update JSON-API with attachments",
"uploads": [
{"token": "#{token1}", "filename": "test1.txt"},
{"token": "#{token2}", "filename": "test2.txt"}
]
}
}
JSON
put(
'/news/1.json',
:params => payload,
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')))
assert_response :no_content
news = News.find_by(:title => 'News Update JSON-API with attachments')
assert_equal 2, news.attachments.count
end
test "DELETE /news/:id.xml" do
assert_difference('News.count', -1) do
delete '/news/1.xml', :headers => credentials('jsmith')
assert_response :no_content
assert_equal '', response.body
end
assert_nil News.find_by_id(1)
end
test "DELETE /news/:id.json" do
assert_difference('News.count', -1) do
delete '/news/1.json', :headers => credentials('jsmith')
assert_response :no_content
assert_equal '', response.body
end
assert_nil News.find_by_id(6)
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -28,13 +30,20 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
end
test "GET /projects.xml should return projects" do
project = Project.find(1)
project.inherit_members = '1'
project.save!
get '/projects.xml'
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_select 'projects>project>id', :text => '1'
assert_select 'projects>project>status', :text => '1'
assert_select 'projects>project>is_public', :text => 'true'
assert_select 'projects>project:first-child' do
assert_select '>id', :text => '1'
assert_select '>status', :text => '1'
assert_select '>is_public', :text => 'true'
assert_select '>inherit_members', :text => 'true'
end
end
test "GET /projects.json should return projects" do
@ -47,6 +56,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_kind_of Array, json['projects']
assert_kind_of Hash, json['projects'].first
assert json['projects'].first.has_key?('id')
assert json['projects'].first.has_key?('inherit_members')
end
test "GET /projects.xml with include=issue_categories should return categories" do
@ -74,6 +84,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
end
test "GET /projects/:id.xml should return the project" do
Project.find(1).update!(:inherit_members => '1')
get '/projects/1.xml'
assert_response :success
assert_equal 'application/xml', @response.content_type
@ -81,6 +93,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_select 'project>id', :text => '1'
assert_select 'project>status', :text => '1'
assert_select 'project>is_public', :text => 'true'
assert_select 'project>inherit_members', :text => 'true'
assert_select 'custom_field[name="Development status"]', :text => 'Stable'
assert_select 'trackers', 0
@ -94,6 +107,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_kind_of Hash, json
assert_kind_of Hash, json['project']
assert_equal 1, json['project']['id']
assert_equal false, json['project']['inherit_members']
assert_equal false, json['project'].has_key?('default_version')
assert_equal false, json['project'].has_key?('default_assignee')
end
test "GET /projects/:id.xml with hidden custom fields should not display hidden custom fields" do
@ -138,6 +154,29 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_select 'enabled_modules[type=array] enabled_module[name=issue_tracking]'
end
def test_get_project_with_default_version_and_assignee
user = User.find(3)
version = Version.find(1)
Project.find(1).update!(default_assigned_to_id: user.id, default_version_id: version.id)
get '/projects/1.json'
json = ActiveSupport::JSON.decode(response.body)
assert_kind_of Hash, json
assert_kind_of Hash, json['project']
assert_equal 1, json['project']['id']
assert json['project'].has_key?('default_assignee')
assert_equal 2, json['project']['default_assignee'].length
assert_equal user.id, json['project']['default_assignee']['id']
assert_equal user.name, json['project']['default_assignee']['name']
assert json['project'].has_key?('default_version')
assert_equal 2, json['project']['default_version'].length
assert_equal version.id, json['project']['default_version']['id']
assert_equal version.name, json['project']['default_version']['name']
end
test "POST /projects.xml with valid parameters should create the project" do
with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
assert_difference('Project.count') do
@ -198,9 +237,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
:params => {:project => {:name => 'API update'}},
:headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_equal 'application/xml', @response.content_type
assert_nil @response.content_type
project = Project.find(2)
assert_equal 'API update', project.name
end
@ -211,7 +250,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
:params => {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
:headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
project = Project.find(2)
assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
@ -223,7 +262,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
:params => {:project => {:name => 'API update', :tracker_ids => [1, 3]}},
:headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
project = Project.find(2)
assert_equal [1, 3], project.trackers.map(&:id).sort
@ -245,7 +284,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_difference('Project.count',-1) do
delete '/projects/2.xml', :headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil Project.find_by_id(2)
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -53,6 +55,11 @@ class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base
assert_select 'role' do
assert_select 'name', :text => 'Manager'
assert_select 'assignable', :text => 'true'
assert_select 'issues_visibility', :text => 'all'
assert_select 'time_entries_visibility', :text => 'all'
assert_select 'users_visibility', :text => 'all'
assert_select 'role permissions[type=array]' do
assert_select 'permission', Role.find(1).permissions.size
assert_select 'permission', :text => 'view_issues'

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -89,7 +91,7 @@ class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base
assert_equal 4, json['limit']
assert_equal issue[8..10], json['results'].map {|r| r['id']}
end
test "GET /search.xml should not quick jump to the issue with given id" do
get '/search.xml', :params => {:q => '3'}
assert_response :success

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -59,11 +61,20 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_select 'time_entry id', :text => '2'
end
test "GET /time_entries/:id.xml with invalid id should 404" do
get '/time_entries/999.xml', :headers => credentials('jsmith')
assert_response 404
end
test "POST /time_entries.xml with issue_id should create time entry" do
assert_difference 'TimeEntry.count' do
post '/time_entries.xml',
:params => {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}},
:headers => credentials('jsmith')
post(
'/time_entries.xml',
:params =>
{:time_entry =>
{:issue_id => '1', :spent_on => '2010-12-02',
:hours => '3.5', :activity_id => '11'}},
:headers => credentials('jsmith'))
end
assert_response :created
assert_equal 'application/xml', @response.content_type
@ -81,11 +92,15 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string')
assert_difference 'TimeEntry.count' do
post '/time_entries.xml',
:params => {:time_entry => {
:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}]
post(
'/time_entries.xml',
:params =>
{:time_entry =>
{:issue_id => '1', :spent_on => '2010-12-02',
:hours => '3.5', :activity_id => '11',
:custom_fields => [{:id => field.id.to_s, :value => 'accepted'}]
}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_response :created
assert_equal 'application/xml', @response.content_type
@ -96,9 +111,13 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
test "POST /time_entries.xml with project_id should create time entry" do
assert_difference 'TimeEntry.count' do
post '/time_entries.xml',
:params => {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}},
:headers => credentials('jsmith')
post(
'/time_entries.xml',
:params =>
{:time_entry =>
{:project_id => '1', :spent_on => '2010-12-02',
:hours => '3.5', :activity_id => '11'}},
:headers => credentials('jsmith'))
end
assert_response :created
assert_equal 'application/xml', @response.content_type
@ -114,9 +133,10 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
test "POST /time_entries.xml with invalid parameters should return errors" do
assert_no_difference 'TimeEntry.count' do
post '/time_entries.xml',
post(
'/time_entries.xml',
:params => {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
@ -124,22 +144,58 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_select 'errors error', :text => "Hours cannot be blank"
end
test "POST /time_entries.xml with :project_id for other user" do
Role.find_by_name('Manager').add_permission! :log_time_for_other_users
entry = new_record(TimeEntry) do
post(
'/time_entries.xml',
:params =>
{:time_entry =>
{:project_id => '1', :spent_on => '2010-12-02', :user_id => '3',
:hours => '3.5', :activity_id => '11'}},
:headers => credentials('jsmith'))
end
assert_response :created
assert_equal 3, entry.user_id
assert_equal 2, entry.author_id
end
test "POST /time_entries.xml with :issue_id for other user" do
Role.find_by_name('Manager').add_permission! :log_time_for_other_users
entry = new_record(TimeEntry) do
post(
'/time_entries.xml',
:params =>
{:time_entry =>
{:issue_id => '1', :spent_on => '2010-12-02', :user_id => '3',
:hours => '3.5', :activity_id => '11'}},
:headers => credentials('jsmith'))
end
assert_response :created
assert_equal 3, entry.user_id
assert_equal 2, entry.author_id
end
test "PUT /time_entries/:id.xml with valid parameters should update time entry" do
assert_no_difference 'TimeEntry.count' do
put '/time_entries/2.xml',
put(
'/time_entries/2.xml',
:params => {:time_entry => {:comments => 'API Update'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_equal 'API Update', TimeEntry.find(2).comments
end
test "PUT /time_entries/:id.xml with invalid parameters should return errors" do
assert_no_difference 'TimeEntry.count' do
put '/time_entries/2.xml',
put(
'/time_entries/2.xml',
:params => {:time_entry => {:hours => '', :comments => 'API Update'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
@ -147,12 +203,31 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_select 'errors error', :text => "Hours cannot be blank"
end
test "PUT /time_entries/:id.xml without permissions should fail" do
put(
'/time_entries/2.xml',
:params => {:time_entry => {:hours => '2.3', :comments => 'API Update'}},
:headers => credentials('dlopper'))
assert_response 403
end
test "DELETE /time_entries/:id.xml should destroy time entry" do
assert_difference 'TimeEntry.count', -1 do
delete '/time_entries/2.xml', :headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil TimeEntry.find_by_id(2)
end
test "DELETE /time_entries/:id.xml with failure should return errors" do
TimeEntry.any_instance.stubs(:destroy).returns(false)
assert_no_difference 'TimeEntry.count' do
delete '/time_entries/2.xml', :headers => credentials('jsmith')
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
assert_select 'errors'
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -28,6 +30,7 @@ class Redmine::ApiTest::TrackersTest < Redmine::ApiTest::Base
assert_select 'trackers[type=array] tracker id', :text => '2' do
assert_select '~ name', :text => 'Feature request'
assert_select '~ description', :text => 'Description for Feature request tracker'
end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -89,16 +91,10 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_select 'user id', :text => '2'
end
test "GET /users/:id should not return login for other user" do
test "GET /users/:id should return login for visible user" do
get '/users/3.xml', :headers => credentials('jsmith')
assert_response :success
assert_select 'user login', 0
end
test "GET /users/:id should return login for current user" do
get '/users/2.xml', :headers => credentials('jsmith')
assert_response :success
assert_select 'user login', :text => 'jsmith'
assert_select 'user login', :text => 'dlopper'
end
test "GET /users/:id should not return api_key for other user" do
@ -125,9 +121,22 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_select 'user status', :text => User.find(1).status.to_s
end
test "GET /users/:id should return admin status for current user" do
get '/users/2.xml', :headers => credentials('jsmith')
assert_response :success
assert_select 'user admin', :text => 'false'
end
test "GET /users/:id should not return admin status for other user" do
get '/users/3.xml', :headers => credentials('jsmith')
assert_response :success
assert_select 'user admin', 0
end
test "POST /users.xml with valid parameters should create the user" do
assert_difference('User.count') do
post '/users.xml',
post(
'/users.xml',
:params => {
:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
@ -135,7 +144,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
:mail_notification => 'only_assigned'
}
},
:headers => credentials('admin')
:headers => credentials('admin'))
end
user = User.order('id DESC').first
@ -152,9 +161,27 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_select 'user id', :text => user.id.to_s
end
test "POST /users.xml with generate_password should generate password" do
assert_difference('User.count') do
post(
'/users.xml',
:params => {
:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
:mail => 'foo@example.net', :generate_password => 'true'
}
},
:headers => credentials('admin'))
end
user = User.order('id DESC').first
assert user.hashed_password.present?
end
test "POST /users.json with valid parameters should create the user" do
assert_difference('User.count') do
post '/users.json',
post(
'/users.json',
:params => {
:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
@ -162,7 +189,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
:mail_notification => 'only_assigned'
}
},
:headers => credentials('admin')
:headers => credentials('admin'))
end
user = User.order('id DESC').first
@ -182,13 +209,14 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
test "POST /users.xml with with invalid parameters should return errors" do
assert_no_difference('User.count') do
post '/users.xml',
post(
'/users.xml',
:params => {
:user =>{
:login => 'foo', :lastname => 'Lastname', :mail => 'foo'
}
},
:headers => credentials('admin')
:headers => credentials('admin'))
end
assert_response :unprocessable_entity
@ -198,13 +226,14 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
test "POST /users.json with with invalid parameters should return errors" do
assert_no_difference('User.count') do
post '/users.json',
post(
'/users.json',
:params => {
:user => {
:login => 'foo', :lastname => 'Lastname', :mail => 'foo'
}
},
:headers => credentials('admin')
:headers => credentials('admin'))
end
assert_response :unprocessable_entity
@ -217,14 +246,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
test "PUT /users/:id.xml with valid parameters should update the user" do
assert_no_difference('User.count') do
put '/users/2.xml',
put(
'/users/2.xml',
:params => {
:user => {
:login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
:mail => 'jsmith@somenet.foo'
}
},
:headers => credentials('admin')
:headers => credentials('admin'))
end
user = User.find(2)
@ -234,20 +264,21 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_equal 'jsmith@somenet.foo', user.mail
assert !user.admin?
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
test "PUT /users/:id.json with valid parameters should update the user" do
assert_no_difference('User.count') do
put '/users/2.json',
put(
'/users/2.json',
:params => {
:user => {
:login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
:mail => 'jsmith@somenet.foo'
}
},
:headers => credentials('admin')
:headers => credentials('admin'))
end
user = User.find(2)
@ -257,20 +288,21 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_equal 'jsmith@somenet.foo', user.mail
assert !user.admin?
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
test "PUT /users/:id.xml with invalid parameters" do
assert_no_difference('User.count') do
put '/users/2.xml',
put(
'/users/2.xml',
:params => {
:user => {
:login => 'jsmith', :firstname => '', :lastname => 'Lastname',
:mail => 'foo'
}
},
:headers => credentials('admin')
:headers => credentials('admin'))
end
assert_response :unprocessable_entity
@ -280,14 +312,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
test "PUT /users/:id.json with invalid parameters" do
assert_no_difference('User.count') do
put '/users/2.json',
put(
'/users/2.json',
:params => {
:user => {
:login => 'jsmith', :firstname => '', :lastname => 'Lastname',
:mail => 'foo'
}
},
:headers => credentials('admin')
:headers => credentials('admin'))
end
assert_response :unprocessable_entity
@ -303,7 +336,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
delete '/users/2.xml', :headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
@ -312,7 +345,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
delete '/users/2.json', :headers => credentials('admin')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -25,7 +27,9 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
:member_roles,
:members,
:enabled_modules,
:versions
:versions,
:wikis, :wiki_pages,
:time_entries
test "GET /projects/:project_id/versions.xml should return project versions" do
get '/projects/1/versions.xml'
@ -40,11 +44,11 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
test "POST /projects/:project_id/versions.xml should create the version" do
assert_difference 'Version.count' do
post '/projects/1/versions.xml',
post(
'/projects/1/versions.xml',
:params => {:version => {:name => 'API test'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
version = Version.order('id DESC').first
assert_equal 'API test', version.name
@ -55,11 +59,11 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
test "POST /projects/:project_id/versions.xml should create the version with due date" do
assert_difference 'Version.count' do
post '/projects/1/versions.xml',
post(
'/projects/1/versions.xml',
:params => {:version => {:name => 'API test', :due_date => '2012-01-24'}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
version = Version.order('id DESC').first
assert_equal 'API test', version.name
assert_equal Date.parse('2012-01-24'), version.due_date
@ -69,11 +73,27 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
assert_select 'version id', :text => version.id.to_s
end
test "POST /projects/:project_id/versions.xml should create the version with wiki page title" do
assert_difference 'Version.count' do
post(
'/projects/1/versions.xml',
:params => {:version => {:name => 'API test', :wiki_page_title => WikiPage.first.title}},
:headers => credentials('jsmith'))
end
version = Version.order('id DESC').first
assert_equal 'API test', version.name
assert_equal WikiPage.first, version.wiki_page
assert_response :created
assert_equal 'application/xml', @response.content_type
assert_select 'version id', :text => version.id.to_s
end
test "POST /projects/:project_id/versions.xml should create the version with custom fields" do
field = VersionCustomField.generate!
assert_difference 'Version.count' do
post '/projects/1/versions.xml',
post(
'/projects/1/versions.xml',
:params => {
:version => {
:name => 'API test',
@ -82,9 +102,8 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
]
}
},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
version = Version.order('id DESC').first
assert_equal 'API test', version.name
assert_equal 'Some value', version.custom_field_value(field)
@ -96,16 +115,20 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
test "POST /projects/:project_id/versions.xml with failure should return the errors" do
assert_no_difference('Version.count') do
post '/projects/1/versions.xml',
post(
'/projects/1/versions.xml',
:params => {:version => {:name => ''}},
:headers => credentials('jsmith')
:headers => credentials('jsmith'))
end
assert_response :unprocessable_entity
assert_select 'errors error', :text => "Name cannot be blank"
end
test "GET /versions/:id.xml should return the version" do
assert_equal [2, 12], Version.find(2).visible_fixed_issues.pluck(:id).sort
TimeEntry.generate!(:issue_id => 2, :hours => 1.0)
TimeEntry.generate!(:issue_id => 12, :hours => 1.5)
get '/versions/2.xml'
assert_response :success
@ -114,17 +137,21 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
assert_select 'id', :text => '2'
assert_select 'name', :text => '1.0'
assert_select 'sharing', :text => 'none'
assert_select 'wiki_page_title', :text => 'ECookBookV1'
assert_select 'estimated_hours', :text => '0.5'
assert_select 'spent_hours', :text => '2.5'
end
end
test "PUT /versions/:id.xml should update the version" do
put '/versions/2.xml',
:params => {:version => {:name => 'API update'}},
:headers => credentials('jsmith')
assert_response :ok
put(
'/versions/2.xml',
:params => {:version => {:name => 'API update', :wiki_page_title => WikiPage.first.title}},
:headers => credentials('jsmith'))
assert_response :no_content
assert_equal '', @response.body
assert_equal 'API update', Version.find(2).name
assert_equal WikiPage.first, Version.find(2).wiki_page
end
test "DELETE /versions/:id.xml should destroy the version" do
@ -132,7 +159,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
delete '/versions/3.xml', :headers => credentials('jsmith')
end
assert_response :ok
assert_response :no_content
assert_equal '', @response.body
assert_nil Version.find_by_id(3)
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -106,7 +108,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
:headers => credentials('jsmith')
assert_response 200
assert_response :no_content
end
end
@ -123,7 +125,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
:headers => credentials('jsmith')
assert_response 200
assert_response :no_content
end
end
@ -201,7 +203,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do
assert_difference 'WikiPage.count', -1 do
delete '/projects/ecookbook/wiki/CookBook_documentation.xml', :headers => credentials('jsmith')
assert_response 200
assert_response :no_content
end
assert_nil WikiPage.find_by_id(1)

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -63,9 +65,9 @@ class ApplicationTest < Redmine::IntegrationTest
assert_nil session[:user_id]
end
def test_missing_template_should_respond_with_404
def test_missing_template_should_respond_with_4xx
get '/login.png'
assert_response 404
assert_response 406
end
def test_invalid_token_should_call_custom_handler

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -28,9 +30,10 @@ class AttachmentsTest < Redmine::IntegrationTest
def test_upload_should_set_default_content_type
log_user('jsmith', 'jsmith')
assert_difference 'Attachment.count' do
post "/uploads.js?attachment_id=1&filename=foo.txt",
post(
"/uploads.js?attachment_id=1&filename=foo.txt",
:params => "File content",
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}
:headers => {"CONTENT_TYPE" => 'application/octet-stream'})
assert_response :success
end
attachment = Attachment.order(:id => :desc).first
@ -40,9 +43,10 @@ class AttachmentsTest < Redmine::IntegrationTest
def test_upload_should_accept_content_type_param
log_user('jsmith', 'jsmith')
assert_difference 'Attachment.count' do
post "/uploads.js?attachment_id=1&filename=foo&content_type=image/jpeg",
post(
"/uploads.js?attachment_id=1&filename=foo&content_type=image/jpeg",
:params => "File content",
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}
:headers => {"CONTENT_TYPE" => 'application/octet-stream'})
assert_response :success
end
attachment = Attachment.order(:id => :desc).first
@ -77,8 +81,9 @@ class AttachmentsTest < Redmine::IntegrationTest
token = ajax_upload('myupload.jpg', 'JPEG content')
post '/issues/preview/new/ecookbook', :params => {
:issue => {:tracker_id => 1, :description => 'Inline upload: !myupload.jpg!'},
post '/issues/preview', :params => {
:issue => {:tracker_id => 1, :project_id => 'ecookbook'},
:text => 'Inline upload: !myupload.jpg!',
:attachments => {'1' => {:filename => 'myupload.jpg', :description => 'My uploaded file', :token => token}}
}
assert_response :success
@ -149,7 +154,6 @@ class AttachmentsTest < Redmine::IntegrationTest
get "/attachments/download/4"
assert_response :success
assert_not_nil response.headers["X-Sendfile"]
ensure
set_tmp_attachments_directory
end
@ -158,9 +162,10 @@ class AttachmentsTest < Redmine::IntegrationTest
def ajax_upload(filename, content, attachment_id=1)
assert_difference 'Attachment.count' do
post "/uploads.js?attachment_id=#{attachment_id}&filename=#{filename}",
post(
"/uploads.js?attachment_id=#{attachment_id}&filename=#{filename}",
:params => content,
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}
:headers => {"CONTENT_TYPE" => 'application/octet-stream'})
assert_response :success
assert_equal 'text/javascript', response.content_type
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -101,23 +103,23 @@ class IssuesTest < Redmine::IntegrationTest
def test_issue_attachments
log_user('jsmith', 'jsmith')
set_tmp_attachments_directory
attachment = new_record(Attachment) do
put '/issues/1', :params => {
:issue => {:notes => 'Some notes'},
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
:attachments => {
'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
'description' => 'This is an attachment'}
}
}
assert_redirected_to "/issues/1"
end
assert_equal Issue.find(1), attachment.container
assert_equal 'testfile.txt', attachment.filename
assert_equal 'This is an attachment', attachment.description
# verify the size of the attachment stored in db
#assert_equal file_data_1.length, attachment.filesize
assert_equal 59, attachment.filesize
# verify that the attachment was written to disk
assert File.exist?(attachment.diskfile)
# remove the attachments
Issue.find(1).attachments.each(&:destroy)
assert_equal 0, Issue.find(1).attachments.length
@ -128,7 +130,7 @@ class IssuesTest < Redmine::IntegrationTest
get '/projects/ecookbook/issues?set_filter=1&group_by=fixed_version&sort=priority:desc,fixed_version,id'
assert_response :success
assert_select 'td.id', :text => '5'
get '/issues/5'
assert_response :success
assert_select '.next-prev-links .position', :text => '5 of 6'
@ -140,7 +142,7 @@ class IssuesTest < Redmine::IntegrationTest
get '/projects/ecookbook/issues?set_filter=1&tracker_id=1'
assert_response :success
assert_select 'td.id', :text => '5'
get '/issues/5'
assert_response :success
assert_select '.next-prev-links .position', :text => '3 of 5'
@ -158,7 +160,7 @@ class IssuesTest < Redmine::IntegrationTest
get "/projects/ecookbook/issues?set_filter=1&query_id=#{query.id}"
assert_response :success
assert_select 'td.id', :text => '5'
get '/issues/5'
assert_response :success
assert_select '.next-prev-links .position', :text => '6 of 8'

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -63,7 +65,7 @@ class LayoutTest < Redmine::IntegrationTest
Role.anonymous.add_permission! :add_issues
get '/projects/ecookbook/issues/new'
assert_select 'head script[src^=?]', '/javascripts/jstoolbar/jstoolbar-textile.min.js?'
assert_select 'head script[src^=?]', '/javascripts/jstoolbar/jstoolbar.js?'
end
def test_calendar_header_tags

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -35,6 +37,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
:attachments
def setup
User.current = nil
set_tmp_attachments_directory
@field = IssueCustomField.generate!(:name => "File", :field_format => "attachment")
log_user "jsmith", "jsmith"
@ -85,7 +88,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
# preview the attachment
get link.attr('href')
assert_response :success
assert_template :file
assert_select 'h2', :text => "#{issue.tracker} ##{issue.id} » testfile.txt"
end
def test_create_without_attachment

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -37,14 +39,14 @@ class HookTest < Redmine::IntegrationTest
Redmine::Hook.clear_listeners
class ContentForInsideHook < Redmine::Hook::ViewListener
render_on :view_welcome_index_left, :inline => <<-VIEW
<% content_for :header_tags do %>
<%= javascript_include_tag 'test_plugin.js', :plugin => 'test_plugin' %>
<%= stylesheet_link_tag 'test_plugin.css', :plugin => 'test_plugin' %>
<% end %>
render_on :view_welcome_index_left, :inline => <<~VIEW
<% content_for :header_tags do %>
<%= javascript_include_tag 'test_plugin.js', :plugin => 'test_plugin' %>
<%= stylesheet_link_tag 'test_plugin.css', :plugin => 'test_plugin' %>
<% end %>
<p>ContentForInsideHook content</p>
VIEW
<p>ContentForInsideHook content</p>
VIEW
end
class SingleRenderOn < Redmine::Hook::ViewListener

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -30,7 +32,7 @@ class MenuManagerTest < Redmine::IntegrationTest
def test_project_menu_with_specific_locale
get '/projects/ecookbook/issues',
:headers => {'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'}
:headers => {'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'}
assert_select 'div#main-menu' do
assert_select 'li a.activity[href=?]', '/projects/ecookbook/activity', :text => ll('fr', :label_activity)
@ -77,4 +79,37 @@ class MenuManagerTest < Redmine::IntegrationTest
get '/login'
assert_select '#main-menu', 0
end
def test_body_should_have_main_menu_css_class_if_main_menu_is_present
get '/projects'
assert_select 'body.has-main-menu'
get '/'
assert_select 'body.has-main-menu', 0
end
def test_cross_project_menu_should_hide_item_if_module_is_not_enabled_for_any_project
user = User.find_by_login('dlopper')
assert_equal [1, 3, 4, 6], Project.visible(user).ids
# gantt and news are not enabled for any visible project
Project.find(1).enabled_module_names = %w(issue_tracking calendar)
Project.find(3).enabled_module_names = %w(time_tracking)
EnabledModule.where(:project_id => [4, 6]).delete_all
log_user('dlopper', 'foo')
get '/projects'
assert_select '#main-menu' do
assert_select 'a.projects', :count => 1
assert_select 'a.activity', :count => 1
assert_select 'a.issues', :count => 1 # issue_tracking
assert_select 'a.time-entries', :count => 1 # time_tracking
assert_select 'a.gantt', :count => 0 # gantt
assert_select 'a.calendar', :count => 1 # calendar
assert_select 'a.news', :count => 0 # news
end
assert_select '#projects-index' do
assert_select 'a.project', :count => 4
end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -57,6 +59,7 @@ class ThemesTest < Redmine::IntegrationTest
end
def test_use_default_favicon_if_theme_provides_none
@theme.favicons.clear
get '/'
assert_response :success
@ -65,7 +68,7 @@ class ThemesTest < Redmine::IntegrationTest
def test_use_theme_favicon_if_theme_provides_one
# Simulate a theme favicon
@theme.favicons << 'a.ico'
@theme.favicons.unshift('a.ico')
get '/'
assert_response :success
@ -75,7 +78,7 @@ class ThemesTest < Redmine::IntegrationTest
end
def test_use_only_one_theme_favicon_if_theme_provides_many
@theme.favicons.concat %w{b.ico a.png}
@theme.favicons.unshift('b.ico', 'a.png')
get '/'
assert_response :success
@ -88,8 +91,8 @@ class ThemesTest < Redmine::IntegrationTest
def test_with_sub_uri
Redmine::Utils.relative_url_root = '/foo'
@theme.javascripts << 'theme'
@theme.favicons << 'a.ico'
@theme.javascripts.unshift('theme')
@theme.favicons.unshift('a.ico')
get '/'
assert_response :success

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -24,6 +26,7 @@ class RepositoriesGitTest < Redmine::IntegrationTest
REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
PRJ_ID = 3
NUM_REV = 28
def setup
User.current = nil
@ -43,8 +46,65 @@ class RepositoriesGitTest < Redmine::IntegrationTest
end
def test_diff_two_revs
get '/projects/subproject1/repository/diff?rev=61b685fbe&rev_to=2f9c0091'
get "/projects/subproject1/repository/#{@repository.id}/diff?rev=61b685fbe&rev_to=2f9c0091"
assert_response :success
end
def test_get_raw_diff_of_a_whole_revision
@repository.fetch_changesets
assert_equal NUM_REV, @repository.changesets.count
get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/diff"
assert_response :success
assert a = css_select("a.diff").first
assert_equal 'Unified diff', a.text
get a['href']
assert_response :success
assert_match /\Acommit deff712f05a90d96edbd70facc47d944be5897e3/, response.body
end
def test_get_raw_diff_of_a_single_file_change
@repository.fetch_changesets
assert_equal NUM_REV, @repository.changesets.count
get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/diff/sources/watchers_controller.rb"
assert_response :success
assert a = css_select("a.diff").first
assert_equal 'Unified diff', a.text
get a['href']
assert_response :success
assert_match /\Acommit deff712f05a90d96edbd70facc47d944be5897e3/, response.body
end
def test_get_diff_with_format_text_should_return_html
@repository.fetch_changesets
assert_equal NUM_REV, @repository.changesets.count
get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/diff/sources/watchers_controller.rb", :params => { :format => 'txt' }
assert_response :success
assert a = css_select("a.diff").first
assert_equal 'Unified diff', a.text
get a['href']
assert_response :success
assert_match /\Acommit deff712f05a90d96edbd70facc47d944be5897e3/, response.body
end
def test_entry_txt_should_return_html
@repository.fetch_changesets
assert_equal NUM_REV, @repository.changesets.count
get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/entry/new_file.txt"
assert_response :success
assert l1 = css_select("#L1").first
assert l1_code = css_select(l1, "td.line-code").first
assert_match 'This is a brand new file', l1_code.text
end
else
puts "Git test repository NOT FOUND. Skipping integration tests !!!"
def test_fake; assert true end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -20,7 +22,8 @@ require File.expand_path('../../../test_helper', __FILE__)
class RoutingAttachmentsTest < Redmine::RoutingTest
def test_attachments
should_route 'GET /attachments/1' => 'attachments#show', :id => '1'
should_route 'GET /attachments/1/filename.ext' => 'attachments#show', :id => '1', :filename => 'filename.ext'
should_route 'GET /attachments/1/filename.ext' => 'attachments#show', :id => '1', :filename => 'filename.ext', :format => 'html'
should_route 'GET /attachments/1/filename.txt' => 'attachments#show', :id => '1', :filename => 'filename.txt', :format => 'html'
should_route 'GET /attachments/download/1' => 'attachments#download', :id => '1'
should_route 'GET /attachments/download/1/filename.ext' => 'attachments#download', :id => '1', :filename => 'filename.ext'

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,7 +21,8 @@ require File.expand_path('../../../test_helper', __FILE__)
class RoutingImportsTest < Redmine::RoutingTest
def test_imports
should_route 'GET /issues/imports/new' => 'imports#new'
should_route 'GET /issues/imports/new' => 'imports#new', :type => 'IssueImport'
should_route 'POST /imports' => 'imports#create'
should_route 'GET /imports/4ae6bc' => 'imports#show', :id => '4ae6bc'

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -33,6 +35,8 @@ class RoutingIssuesTest < Redmine::RoutingTest
should_route 'GET /issues/64/edit' => 'issues#edit', :id => '64'
should_route 'PUT /issues/64' => 'issues#update', :id => '64'
should_route 'DELETE /issues/64' => 'issues#destroy', :id => '64'
should_route "GET /issues/3/tab/time_entries" => 'issues#issue_tab', :id => '3', :name => 'time_entries'
end
def test_issues_bulk_edit

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -20,7 +22,7 @@ require File.expand_path('../../../test_helper', __FILE__)
class RoutingMyTest < Redmine::RoutingTest
def test_my
should_route 'GET /my/account' => 'my#account'
should_route 'POST /my/account' => 'my#account'
should_route 'PUT /my/account' => 'my#account'
should_route 'GET /my/account/destroy' => 'my#destroy'
should_route 'POST /my/account/destroy' => 'my#destroy'

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,14 +21,14 @@ require File.expand_path('../../../test_helper', __FILE__)
class RoutingPreviewsTest < Redmine::RoutingTest
def test_previews
should_route 'GET /issues/preview/new/foo' => 'previews#issue', :project_id => 'foo'
should_route 'PUT /issues/preview/new/foo' => 'previews#issue', :project_id => 'foo'
should_route 'POST /issues/preview/new/foo' => 'previews#issue', :project_id => 'foo'
should_route 'GET /issues/preview/edit/321' => 'previews#issue', :id => '321'
should_route 'PUT /issues/preview/edit/321' => 'previews#issue', :id => '321'
should_route 'POST /issues/preview/edit/321' => 'previews#issue', :id => '321'
should_route 'GET /issues/preview' => 'previews#issue'
should_route 'PUT /issues/preview' => 'previews#issue'
should_route 'POST /issues/preview' => 'previews#issue'
should_route 'GET /news/preview' => 'previews#news'
should_route 'GET /preview/text' => 'previews#text'
should_route 'PUT /preview/text' => 'previews#text'
should_route 'POST /preview/text' => 'previews#text'
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -18,15 +20,17 @@
require File.expand_path('../../../test_helper', __FILE__)
class RoutingRepositoriesTest < Redmine::RoutingTest
def setup
@path_hash = repository_path_hash(%w[path to file.c])
assert_equal "path/to/file.c", @path_hash[:path]
assert_equal "path/to/file.c", @path_hash[:param]
@paths = ['path/to/index.html',
'path/to/file.c', 'path/to/file.yaml', 'path/to/file.txt',
'raw/file.c']
end
def test_repositories_resources
should_route 'GET /projects/foo/repositories/new' => 'repositories#new', :project_id => 'foo'
should_route 'POST /projects/foo/repositories' => 'repositories#create', :project_id => 'foo'
should_route 'GET /repositories/1/edit' => 'repositories#edit', :id => '1'
should_route 'PUT /repositories/1' => 'repositories#update', :id => '1'
should_route 'DELETE /repositories/1' => 'repositories#destroy', :id => '1'
@ -37,8 +41,6 @@ class RoutingRepositoriesTest < Redmine::RoutingTest
def test_repositories
should_route 'GET /projects/foo/repository' => 'repositories#show', :id => 'foo'
should_route 'GET /projects/foo/repository/statistics' => 'repositories#stats', :id => 'foo'
should_route 'GET /projects/foo/repository/graph' => 'repositories#graph', :id => 'foo'
end
def test_repositories_with_repository_id
@ -47,87 +49,40 @@ class RoutingRepositoriesTest < Redmine::RoutingTest
should_route 'GET /projects/foo/repository/svn/graph' => 'repositories#graph', :id => 'foo', :repository_id => 'svn'
end
def test_repositories_revisions
should_route 'GET /projects/foo/repository/revision' => 'repositories#revision', :id => 'foo'
should_route 'GET /projects/foo/repository/revisions' => 'repositories#revisions', :id => 'foo'
should_route 'GET /projects/foo/repository/revisions.atom' => 'repositories#revisions', :id => 'foo', :format => 'atom'
should_route 'GET /projects/foo/repository/revisions/2457' => 'repositories#revision', :id => 'foo', :rev => '2457'
should_route 'GET /projects/foo/repository/revisions/2457/show' => 'repositories#show', :id => 'foo', :rev => '2457'
should_route 'GET /projects/foo/repository/revisions/2457/diff' => 'repositories#diff', :id => 'foo', :rev => '2457'
should_route "GET /projects/foo/repository/revisions/2457/show/#{@path_hash[:path]}" => 'repositories#show',
:id => 'foo', :rev => '2457', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/revisions/2457/diff/#{@path_hash[:path]}" => 'repositories#diff',
:id => 'foo', :rev => '2457', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/revisions/2457/entry/#{@path_hash[:path]}" => 'repositories#entry',
:id => 'foo', :rev => '2457', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/revisions/2457/raw/#{@path_hash[:path]}" => 'repositories#raw',
:id => 'foo', :rev => '2457', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/revisions/2457/annotate/#{@path_hash[:path]}" => 'repositories#annotate',
:id => 'foo', :rev => '2457', :path => @path_hash[:param]
end
def test_repositories_revisions_with_repository_id
should_route 'GET /projects/foo/repository/foo/revision' => 'repositories#revision', :id => 'foo', :repository_id => 'foo'
should_route 'GET /projects/foo/repository/foo/revisions' => 'repositories#revisions', :id => 'foo', :repository_id => 'foo'
should_route 'GET /projects/foo/repository/foo/revisions.atom' => 'repositories#revisions', :id => 'foo', :repository_id => 'foo', :format => 'atom'
should_route 'GET /projects/foo/repository/foo/revisions/2457' => 'repositories#revision', :id => 'foo', :repository_id => 'foo', :rev => '2457'
should_route 'GET /projects/foo/repository/foo/revisions/2457/show' => 'repositories#show', :id => 'foo', :repository_id => 'foo', :rev => '2457'
should_route 'GET /projects/foo/repository/foo/revisions/2457/show' => 'repositories#show', :id => 'foo', :repository_id => 'foo', :rev => '2457', :format => 'html'
should_route 'GET /projects/foo/repository/foo/revisions/2457/diff' => 'repositories#diff', :id => 'foo', :repository_id => 'foo', :rev => '2457'
should_route "GET /projects/foo/repository/foo/revisions/2457/show/#{@path_hash[:path]}" => 'repositories#show',
:id => 'foo', :repository_id => 'foo', :rev => '2457', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/foo/revisions/2457/diff/#{@path_hash[:path]}" => 'repositories#diff',
:id => 'foo', :repository_id => 'foo', :rev => '2457', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/foo/revisions/2457/entry/#{@path_hash[:path]}" => 'repositories#entry',
:id => 'foo', :repository_id => 'foo', :rev => '2457', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/foo/revisions/2457/raw/#{@path_hash[:path]}" => 'repositories#raw',
:id => 'foo', :repository_id => 'foo', :rev => '2457', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/foo/revisions/2457/annotate/#{@path_hash[:path]}" => 'repositories#annotate',
:id => 'foo', :repository_id => 'foo', :rev => '2457', :path => @path_hash[:param]
end
def test_repositories_non_revisions_path
should_route 'GET /projects/foo/repository/changes' => 'repositories#changes', :id => 'foo'
should_route "GET /projects/foo/repository/changes/#{@path_hash[:path]}" => 'repositories#changes',
:id => 'foo', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/diff/#{@path_hash[:path]}" => 'repositories#diff',
:id => 'foo', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/browse/#{@path_hash[:path]}" => 'repositories#browse',
:id => 'foo', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/entry/#{@path_hash[:path]}" => 'repositories#entry',
:id => 'foo', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/raw/#{@path_hash[:path]}" => 'repositories#raw',
:id => 'foo', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/annotate/#{@path_hash[:path]}" => 'repositories#annotate',
:id => 'foo', :path => @path_hash[:param]
%w(show entry raw annotate).each do |action|
@paths.each do |path|
should_route "GET /projects/foo/repository/foo/revisions/2457/#{action}/#{path}" => "repositories##{action}",
:id => 'foo', :repository_id => 'foo', :rev => '2457', :path => path, :format => 'html'
end
end
@paths.each do |path|
should_route "GET /projects/foo/repository/foo/revisions/2457/diff/#{path}" => "repositories#diff",
:id => 'foo', :repository_id => 'foo', :rev => '2457', :path => path
end
end
def test_repositories_non_revisions_path_with_repository_id
should_route 'GET /projects/foo/repository/svn/changes' => 'repositories#changes', :id => 'foo', :repository_id => 'svn'
should_route 'GET /projects/foo/repository/svn/changes' => 'repositories#changes', :id => 'foo', :repository_id => 'svn', :format => 'html'
should_route "GET /projects/foo/repository/svn/changes/#{@path_hash[:path]}" => 'repositories#changes',
:id => 'foo', :repository_id => 'svn', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/svn/diff/#{@path_hash[:path]}" => 'repositories#diff',
:id => 'foo', :repository_id => 'svn', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/svn/browse/#{@path_hash[:path]}" => 'repositories#browse',
:id => 'foo', :repository_id => 'svn', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/svn/entry/#{@path_hash[:path]}" => 'repositories#entry',
:id => 'foo', :repository_id => 'svn', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/svn/raw/#{@path_hash[:path]}" => 'repositories#raw',
:id => 'foo', :repository_id => 'svn', :path => @path_hash[:param]
should_route "GET /projects/foo/repository/svn/annotate/#{@path_hash[:path]}" => 'repositories#annotate',
:id => 'foo', :repository_id => 'svn', :path => @path_hash[:param]
end
def test_repositories_related_issues
should_route 'POST /projects/foo/repository/revisions/123/issues' => 'repositories#add_related_issue',
:id => 'foo', :rev => '123'
should_route 'DELETE /projects/foo/repository/revisions/123/issues/25' => 'repositories#remove_related_issue',
:id => 'foo', :rev => '123', :issue_id => '25'
%w(changes browse entry raw annotate).each do |action|
@paths.each do |path|
should_route "GET /projects/foo/repository/svn/#{action}/#{path}" => "repositories##{action}",
:id => 'foo', :repository_id => 'svn', :path => path, :format => 'html'
end
end
@paths.each do |path|
should_route "GET /projects/foo/repository/svn/diff/#{path}" => "repositories#diff",
:id => 'foo', :repository_id => 'svn', :path => path
end
end
def test_repositories_related_issues_with_repository_id

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -28,6 +30,6 @@ class RoutingRolesTest < Redmine::RoutingTest
should_route 'DELETE /roles/2' => 'roles#destroy', :id => '2'
should_route 'GET /roles/permissions' => 'roles#permissions'
should_route 'POST /roles/permissions' => 'roles#permissions'
should_route 'POST /roles/permissions' => 'roles#update_permissions'
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -55,6 +57,7 @@ class RoutingTimelogsTest < Redmine::RoutingTest
def test_timelogs_bulk_edit
should_route 'GET /time_entries/bulk_edit' => 'timelog#bulk_edit'
should_route 'POST /time_entries/bulk_edit' => 'timelog#bulk_edit'
should_route 'POST /time_entries/bulk_update' => 'timelog#bulk_update'
should_route 'DELETE /time_entries/destroy' => 'timelog#destroy'
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -20,6 +22,6 @@ require File.expand_path('../../../test_helper', __FILE__)
class RoutingWelcomeTest < Redmine::RoutingTest
def test_welcome
should_route 'GET /' => 'welcome#index'
should_route 'GET /robots.txt' => 'welcome#robots'
should_route 'GET /robots.txt' => 'welcome#robots', :format => 'txt'
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,8 +21,6 @@ require File.expand_path('../../../test_helper', __FILE__)
class RoutingWikisTest < Redmine::RoutingTest
def test_wikis
should_route 'POST /projects/foo/wiki' => 'wikis#edit', :id => 'foo'
should_route 'GET /projects/foo/wiki/destroy' => 'wikis#destroy', :id => 'foo'
should_route 'POST /projects/foo/wiki/destroy' => 'wikis#destroy', :id => 'foo'
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path('../../test_helper', __FILE__)
class SudoModeTest < Redmine::IntegrationTest
@ -147,7 +149,7 @@ class SudoModeTest < Redmine::IntegrationTest
expire_sudo_mode!
get '/my/account'
assert_response :success
post '/my/account', :params => {user: { mail: 'newmail@test.com' }}
put '/my/account', :params => {user: { mail: 'newmail@test.com' }}
assert_response :success
assert_select 'h2', 'Confirm your password to continue'
assert_select 'form[action="/my/account"]'
@ -155,7 +157,7 @@ class SudoModeTest < Redmine::IntegrationTest
assert_select '#flash_error', 0
# wrong password
post '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'wrong'}
put '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'wrong'}
assert_response :success
assert_select 'h2', 'Confirm your password to continue'
assert_select 'form[action="/my/account"]'
@ -163,12 +165,12 @@ class SudoModeTest < Redmine::IntegrationTest
assert_select '#flash_error'
# correct password
post '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'jsmith'}
put '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'jsmith'}
assert_redirected_to '/my/account'
assert_equal 'newmail@test.com', User.find_by_login('jsmith').mail
# sudo mode should now be active and not require password again
post '/my/account', :params => {user: { mail: 'even.newer.mail@test.com' }}
put '/my/account', :params => {user: { mail: 'even.newer.mail@test.com' }}
assert_redirected_to '/my/account'
assert_equal 'even.newer.mail@test.com', User.find_by_login('jsmith').mail
end
@ -184,7 +186,7 @@ class SudoModeTest < Redmine::IntegrationTest
}
},
:headers => credentials('admin')
assert_response :created
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -0,0 +1,33 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../test_helper', __FILE__)
class WelcomeTest < Redmine::IntegrationTest
fixtures :users, :email_addresses,
:projects, :enabled_modules, :members, :member_roles, :roles
def test_robots
get '/robots.txt'
assert_response :success
assert_equal 'text/plain', @response.content_type
# Redmine::Utils.relative_url_root does not effect on Rails 5.1.4.
assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
end
end

View file

@ -1,3 +1,22 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../test_helper', __FILE__)
class WikiIntegrationTest < Redmine::IntegrationTest
@ -25,7 +44,7 @@ class WikiIntegrationTest < Redmine::IntegrationTest
# this update should not end up with a loss of content
put '/projects/ecookbook/wiki/Wiki', params: {
content: {
text: "# Wiki\r\n\r\ncontent", comments:""
text: "# Wiki\r\n\r\ncontent", comments: ""
},
wiki_page: { parent_id: "" }
}
@ -42,7 +61,7 @@ class WikiIntegrationTest < Redmine::IntegrationTest
# this update should not end up with a loss of content
put '/projects/ecookbook/wiki/Wiki', params: {
content: {
version: content.version, text: "# Wiki\r\n\r\nnew content", comments:""
version: content.version, text: "# Wiki\r\n\r\nnew content", comments: ""
},
wiki_page: { parent_id: "" }
}
@ -51,6 +70,4 @@ class WikiIntegrationTest < Redmine::IntegrationTest
follow_redirect!
assert_select 'div', /new content/
end
end