Redmine 4.1.1
This commit is contained in:
parent
33e7b881a5
commit
3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
105
test/integration/api_test/my_test.rb
Normal file
105
test/integration/api_test/my_test.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue