mirror of
https://github.com/redmine/redmine.git
synced 2025-11-12 00:06:01 +01:00
Use Rails 5 syntax for integration tests.
git-svn-id: http://svn.redmine.org/redmine/trunk@16586 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -45,7 +45,11 @@ class AccountTest < Redmine::IntegrationTest
|
||||
with_settings :autologin => '7' do
|
||||
assert_difference 'Token.count', 2 do
|
||||
# User logs in with 'autologin' checked
|
||||
post '/login', :username => user.login, :password => 'admin', :autologin => 1
|
||||
post '/login', :params => {
|
||||
:username => user.login,
|
||||
:password => 'admin',
|
||||
:autologin => 1
|
||||
}
|
||||
assert_redirected_to '/my/page'
|
||||
end
|
||||
token = Token.where(:action => 'autologin').order(:id => :desc).first
|
||||
@@ -80,7 +84,11 @@ class AccountTest < Redmine::IntegrationTest
|
||||
|
||||
with_settings :autologin => '7' do
|
||||
assert_difference 'Token.count', 2 do
|
||||
post '/login', :username => 'admin', :password => 'admin', :autologin => 1
|
||||
post '/login', :params => {
|
||||
:username => 'admin',
|
||||
:password => 'admin',
|
||||
:autologin => 1
|
||||
}
|
||||
assert_response 302
|
||||
end
|
||||
assert cookies['custom_autologin'].present?
|
||||
@@ -106,7 +114,9 @@ class AccountTest < Redmine::IntegrationTest
|
||||
assert_response :success
|
||||
assert_select 'input[name=mail]'
|
||||
|
||||
post "/account/lost_password", :mail => 'jSmith@somenet.foo'
|
||||
post "/account/lost_password", :params => {
|
||||
:mail => 'jSmith@somenet.foo'
|
||||
}
|
||||
assert_redirected_to "/login"
|
||||
|
||||
token = Token.first
|
||||
@@ -114,7 +124,9 @@ class AccountTest < Redmine::IntegrationTest
|
||||
assert_equal 'jsmith@somenet.foo', token.user.mail
|
||||
assert !token.expired?
|
||||
|
||||
get "/account/lost_password", :token => token.value
|
||||
get "/account/lost_password", :params => {
|
||||
:token => token.value
|
||||
}
|
||||
assert_redirected_to '/account/lost_password'
|
||||
|
||||
follow_redirect!
|
||||
@@ -123,9 +135,10 @@ class AccountTest < Redmine::IntegrationTest
|
||||
assert_select 'input[name=new_password]'
|
||||
assert_select 'input[name=new_password_confirmation]'
|
||||
|
||||
post "/account/lost_password",
|
||||
post "/account/lost_password", :params => {
|
||||
:token => token.value, :new_password => 'newpass123',
|
||||
:new_password_confirmation => 'newpass123'
|
||||
}
|
||||
assert_redirected_to "/login"
|
||||
assert_equal 'Password was successfully updated.', flash[:notice]
|
||||
|
||||
@@ -136,7 +149,10 @@ class AccountTest < Redmine::IntegrationTest
|
||||
def test_user_with_must_change_passwd_should_be_forced_to_change_its_password
|
||||
User.find_by_login('jsmith').update_attribute :must_change_passwd, true
|
||||
|
||||
post '/login', :username => 'jsmith', :password => 'jsmith'
|
||||
post '/login', :params => {
|
||||
:username => 'jsmith',
|
||||
:password => 'jsmith'
|
||||
}
|
||||
assert_redirected_to '/my/page'
|
||||
follow_redirect!
|
||||
assert_redirected_to '/my/password'
|
||||
@@ -151,7 +167,10 @@ class AccountTest < Redmine::IntegrationTest
|
||||
user.language = 'it'
|
||||
user.save!
|
||||
|
||||
post '/login', :username => 'jsmith', :password => 'jsmith'
|
||||
post '/login', :params => {
|
||||
:username => 'jsmith',
|
||||
:password => 'jsmith'
|
||||
}
|
||||
assert_redirected_to '/my/page'
|
||||
follow_redirect!
|
||||
assert_redirected_to '/my/password'
|
||||
@@ -163,13 +182,20 @@ class AccountTest < Redmine::IntegrationTest
|
||||
def test_user_with_must_change_passwd_should_be_able_to_change_its_password
|
||||
User.find_by_login('jsmith').update_attribute :must_change_passwd, true
|
||||
|
||||
post '/login', :username => 'jsmith', :password => 'jsmith'
|
||||
post '/login', :params => {
|
||||
:username => 'jsmith',
|
||||
:password => 'jsmith'
|
||||
}
|
||||
assert_redirected_to '/my/page'
|
||||
follow_redirect!
|
||||
assert_redirected_to '/my/password'
|
||||
follow_redirect!
|
||||
assert_response :success
|
||||
post '/my/password', :password => 'jsmith', :new_password => 'newpassword', :new_password_confirmation => 'newpassword'
|
||||
post '/my/password', :params => {
|
||||
:password => 'jsmith',
|
||||
:new_password => 'newpassword',
|
||||
:new_password_confirmation => 'newpassword'
|
||||
}
|
||||
assert_redirected_to '/my/account'
|
||||
follow_redirect!
|
||||
assert_response :success
|
||||
@@ -181,7 +207,10 @@ class AccountTest < Redmine::IntegrationTest
|
||||
User.find_by_login('jsmith').update_attribute :passwd_changed_on, 14.days.ago
|
||||
|
||||
with_settings :password_max_age => 7 do
|
||||
post '/login', :username => 'jsmith', :password => 'jsmith'
|
||||
post '/login', :params => {
|
||||
:username => 'jsmith',
|
||||
:password => 'jsmith'
|
||||
}
|
||||
assert_redirected_to '/my/page'
|
||||
follow_redirect!
|
||||
assert_redirected_to '/my/password'
|
||||
@@ -195,13 +224,20 @@ class AccountTest < Redmine::IntegrationTest
|
||||
User.find_by_login('jsmith').update_attribute :passwd_changed_on, 14.days.ago
|
||||
|
||||
with_settings :password_max_age => 7 do
|
||||
post '/login', :username => 'jsmith', :password => 'jsmith'
|
||||
post '/login', :params => {
|
||||
:username => 'jsmith',
|
||||
:password => 'jsmith'
|
||||
}
|
||||
assert_redirected_to '/my/page'
|
||||
follow_redirect!
|
||||
assert_redirected_to '/my/password'
|
||||
follow_redirect!
|
||||
assert_response :success
|
||||
post '/my/password', :password => 'jsmith', :new_password => 'newpassword', :new_password_confirmation => 'newpassword'
|
||||
post '/my/password', :params => {
|
||||
:password => 'jsmith',
|
||||
:new_password => 'newpassword',
|
||||
:new_password_confirmation => 'newpassword'
|
||||
}
|
||||
assert_redirected_to '/my/account'
|
||||
follow_redirect!
|
||||
assert_response :success
|
||||
@@ -217,10 +253,13 @@ class AccountTest < Redmine::IntegrationTest
|
||||
get '/account/register'
|
||||
assert_response :success
|
||||
|
||||
post '/account/register',
|
||||
:user => {:login => "newuser", :language => "en",
|
||||
post '/account/register', :params => {
|
||||
:user => {
|
||||
:login => "newuser", :language => "en",
|
||||
:firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
|
||||
:password => "newpass123", :password_confirmation => "newpass123"}
|
||||
:password => "newpass123", :password_confirmation => "newpass123"
|
||||
}
|
||||
}
|
||||
assert_redirected_to '/my/account'
|
||||
follow_redirect!
|
||||
assert_response :success
|
||||
@@ -234,10 +273,13 @@ class AccountTest < Redmine::IntegrationTest
|
||||
def test_register_with_manual_activation
|
||||
Setting.self_registration = '2'
|
||||
|
||||
post '/account/register',
|
||||
:user => {:login => "newuser", :language => "en",
|
||||
post '/account/register', :params => {
|
||||
:user => {
|
||||
:login => "newuser", :language => "en",
|
||||
:firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
|
||||
:password => "newpass123", :password_confirmation => "newpass123"}
|
||||
:password => "newpass123", :password_confirmation => "newpass123"
|
||||
}
|
||||
}
|
||||
assert_redirected_to '/login'
|
||||
assert !User.find_by_login('newuser').active?
|
||||
end
|
||||
@@ -246,10 +288,13 @@ class AccountTest < Redmine::IntegrationTest
|
||||
Setting.self_registration = '1'
|
||||
Token.delete_all
|
||||
|
||||
post '/account/register',
|
||||
:user => {:login => "newuser", :language => "en",
|
||||
post '/account/register', :params => {
|
||||
:user => {
|
||||
:login => "newuser", :language => "en",
|
||||
:firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
|
||||
:password => "newpass123", :password_confirmation => "newpass123"}
|
||||
:password => "newpass123", :password_confirmation => "newpass123"
|
||||
}
|
||||
}
|
||||
assert_redirected_to '/login'
|
||||
assert !User.find_by_login('newuser').active?
|
||||
|
||||
@@ -258,7 +303,9 @@ class AccountTest < Redmine::IntegrationTest
|
||||
assert_equal 'newuser@foo.bar', token.user.mail
|
||||
assert !token.expired?
|
||||
|
||||
get '/account/activate', :token => token.value
|
||||
get '/account/activate', :params => {
|
||||
:token => token.value
|
||||
}
|
||||
assert_redirected_to '/login'
|
||||
log_user('newuser', 'newpass123')
|
||||
end
|
||||
@@ -270,7 +317,10 @@ class AccountTest < Redmine::IntegrationTest
|
||||
{:login => 'foo', :firstname => 'Foo', :lastname => 'Smith',
|
||||
:mail => 'foo@bar.com', :auth_source_id => 66})
|
||||
|
||||
post '/login', :username => 'foo', :password => 'bar'
|
||||
post '/login', :params => {
|
||||
:username => 'foo',
|
||||
:password => 'bar'
|
||||
}
|
||||
assert_redirected_to '/my/page'
|
||||
|
||||
user = User.find_by_login('foo')
|
||||
@@ -285,15 +335,21 @@ class AccountTest < Redmine::IntegrationTest
|
||||
AuthSource.expects(:authenticate).returns(
|
||||
{:login => 'foo', :lastname => 'Smith', :auth_source_id => 66})
|
||||
|
||||
post '/login', :username => 'foo', :password => 'bar'
|
||||
post '/login', :params => {
|
||||
:username => 'foo',
|
||||
:password => 'bar'
|
||||
}
|
||||
assert_response :success
|
||||
assert_select 'input[name=?][value=""]', 'user[firstname]'
|
||||
assert_select 'input[name=?][value=Smith]', 'user[lastname]'
|
||||
assert_select 'input[name=?]', 'user[login]', 0
|
||||
assert_select 'input[name=?]', 'user[password]', 0
|
||||
|
||||
post '/account/register',
|
||||
:user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'}
|
||||
post '/account/register', :params => {
|
||||
:user => {
|
||||
:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'
|
||||
}
|
||||
}
|
||||
assert_redirected_to '/my/account'
|
||||
|
||||
user = User.find_by_login('foo')
|
||||
@@ -309,10 +365,13 @@ class AccountTest < Redmine::IntegrationTest
|
||||
# register a new account
|
||||
assert_difference 'User.count' do
|
||||
assert_difference 'Token.count' do
|
||||
post '/account/register',
|
||||
:user => {:login => "newuser", :language => "en",
|
||||
post '/account/register', :params => {
|
||||
:user => {
|
||||
:login => "newuser", :language => "en",
|
||||
:firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
|
||||
:password => "newpass123", :password_confirmation => "newpass123"}
|
||||
:password => "newpass123", :password_confirmation => "newpass123"
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
user = User.order('id desc').first
|
||||
@@ -321,7 +380,9 @@ class AccountTest < Redmine::IntegrationTest
|
||||
|
||||
# try to use "lost password"
|
||||
assert_no_difference 'ActionMailer::Base.deliveries.size' do
|
||||
post '/account/lost_password', :mail => 'newuser@foo.bar'
|
||||
post '/account/lost_password', :params => {
|
||||
:mail => 'newuser@foo.bar'
|
||||
}
|
||||
end
|
||||
assert_redirected_to '/account/lost_password'
|
||||
follow_redirect!
|
||||
@@ -342,7 +403,10 @@ class AccountTest < Redmine::IntegrationTest
|
||||
get activation_path
|
||||
assert_redirected_to '/login'
|
||||
|
||||
post '/login', :username => 'newuser', :password => 'newpass123'
|
||||
post '/login', :params => {
|
||||
:username => 'newuser',
|
||||
:password => 'newpass123'
|
||||
}
|
||||
assert_redirected_to '/my/page'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,11 +31,14 @@ class AdminTest < Redmine::IntegrationTest
|
||||
get "/users/new"
|
||||
assert_response :success
|
||||
|
||||
post "/users",
|
||||
:user => { :login => "psmith", :firstname => "Paul",
|
||||
post "/users", :params => {
|
||||
:user => {
|
||||
:login => "psmith", :firstname => "Paul",
|
||||
:lastname => "Smith", :mail => "psmith@somenet.foo",
|
||||
:language => "en", :password => "psmith09",
|
||||
:password_confirmation => "psmith09" }
|
||||
:password_confirmation => "psmith09"
|
||||
}
|
||||
}
|
||||
|
||||
user = User.find_by_login("psmith")
|
||||
assert_kind_of User, user
|
||||
@@ -45,16 +48,24 @@ class AdminTest < Redmine::IntegrationTest
|
||||
assert_kind_of User, logged_user
|
||||
assert_equal "Paul", logged_user.firstname
|
||||
|
||||
put "/users/#{user.id}", :id => user.id, :user => { :status => User::STATUS_LOCKED }
|
||||
put "/users/#{user.id}", :params => {
|
||||
:id => user.id,
|
||||
:user => {
|
||||
:status => User::STATUS_LOCKED
|
||||
}
|
||||
}
|
||||
assert_redirected_to "/users/#{ user.id }/edit"
|
||||
locked_user = User.try_to_login("psmith", "psmith09")
|
||||
assert_nil locked_user
|
||||
end
|
||||
|
||||
test "Add a user as an anonymous user should fail" do
|
||||
post '/users',
|
||||
:user => { :login => 'psmith', :firstname => 'Paul'},
|
||||
post '/users', :params => {
|
||||
:user => {
|
||||
:login => 'psmith', :firstname => 'Paul',
|
||||
:password => "psmith09", :password_confirmation => "psmith09"
|
||||
}
|
||||
}
|
||||
assert_response :redirect
|
||||
assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fusers"
|
||||
end
|
||||
|
||||
@@ -23,12 +23,13 @@ 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'}
|
||||
},
|
||||
credentials('admin')
|
||||
:headers => credentials('admin')
|
||||
assert_response 201
|
||||
end
|
||||
ensure
|
||||
@@ -36,17 +37,17 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
def test_json_datetime_format
|
||||
get '/users/1.json', {}, credentials('admin')
|
||||
get '/users/1.json', :headers => credentials('admin')
|
||||
assert_include '"created_on":"2006-07-19T17:12:21Z"', response.body
|
||||
end
|
||||
|
||||
def test_xml_datetime_format
|
||||
get '/users/1.xml', {}, credentials('admin')
|
||||
get '/users/1.xml', :headers => credentials('admin')
|
||||
assert_include '<created_on>2006-07-19T17:12:21Z</created_on>', response.body
|
||||
end
|
||||
|
||||
def test_head_response_should_have_empty_body
|
||||
put '/users/7.xml', {:user => {:login => 'foo'}}, credentials('admin')
|
||||
put '/users/7.xml', :params => {:user => {:login => 'foo'}}, :headers => credentials('admin')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
|
||||
@@ -38,7 +38,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /attachments/:id.xml should return the attachment" do
|
||||
get '/attachments/7.xml', {}, credentials('jsmith')
|
||||
get '/attachments/7.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'attachment id', :text => '7' do
|
||||
@@ -48,7 +48,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /attachments/:id.xml for image should include thumbnail_url" do
|
||||
get '/attachments/16.xml', {}, credentials('jsmith')
|
||||
get '/attachments/16.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'attachment id:contains(16)' do
|
||||
@@ -63,7 +63,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /attachments/download/:id/:filename should return the attachment content" do
|
||||
get '/attachments/download/7/archive.zip', {}, credentials('jsmith')
|
||||
get '/attachments/download/7/archive.zip', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_equal 'application/zip', @response.content_type
|
||||
set_tmp_attachments_directory
|
||||
@@ -77,13 +77,13 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /attachments/thumbnail/:id should return the thumbnail" do
|
||||
skip unless convert_installed?
|
||||
get '/attachments/thumbnail/16', {}, credentials('jsmith')
|
||||
get '/attachments/thumbnail/16', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "DELETE /attachments/:id.xml should return ok and delete Attachment" do
|
||||
assert_difference 'Attachment.count', -1 do
|
||||
delete '/attachments/7.xml', {}, credentials('jsmith')
|
||||
delete '/attachments/7.xml', :headers => credentials('jsmith')
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
end
|
||||
@@ -92,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', {}, credentials('jsmith')
|
||||
delete '/attachments/7.json', :headers => credentials('jsmith')
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
end
|
||||
@@ -101,8 +101,8 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PATCH /attachments/:id.json should update the attachment" do
|
||||
patch '/attachments/7.json',
|
||||
{:attachment => {:filename => 'renamed.zip', :description => 'updated'}},
|
||||
credentials('jsmith')
|
||||
:params => {:attachment => {:filename => 'renamed.zip', :description => 'updated'}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 'application/json', response.content_type
|
||||
@@ -113,8 +113,8 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PATCH /attachments/:id.json with failure should return the errors" do
|
||||
patch '/attachments/7.json',
|
||||
{:attachment => {:filename => '', :description => 'updated'}},
|
||||
credentials('jsmith')
|
||||
:params => {:attachment => {:filename => '', :description => 'updated'}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response 422
|
||||
assert_equal 'application/json', response.content_type
|
||||
@@ -125,7 +125,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
test "POST /uploads.xml should return the token" do
|
||||
set_tmp_attachments_directory
|
||||
assert_difference 'Attachment.count' do
|
||||
post '/uploads.xml', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
post '/uploads.xml', :headers => {
|
||||
"RAW_POST_DATA" => 'File content',
|
||||
"CONTENT_TYPE" => 'application/octet-stream'
|
||||
}.merge(credentials('jsmith'))
|
||||
assert_response :created
|
||||
assert_equal 'application/xml', response.content_type
|
||||
end
|
||||
@@ -145,7 +148,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
assert_equal 'File content'.size, attachment.filesize
|
||||
assert attachment.content_type.blank?
|
||||
assert attachment.filename.present?
|
||||
assert_match /\d+_[0-9a-z]+/, attachment.diskfile
|
||||
assert_match %r{\d+_[0-9a-z]+}, attachment.diskfile
|
||||
assert File.exist?(attachment.diskfile)
|
||||
assert_equal 'File content', File.read(attachment.diskfile)
|
||||
end
|
||||
@@ -153,7 +156,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
test "POST /uploads.json should return the token" do
|
||||
set_tmp_attachments_directory
|
||||
assert_difference 'Attachment.count' do
|
||||
post '/uploads.json', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
post '/uploads.json', :headers => {
|
||||
"RAW_POST_DATA" => 'File content',
|
||||
"CONTENT_TYPE" => 'application/octet-stream'
|
||||
}.merge(credentials('jsmith'))
|
||||
assert_response :created
|
||||
assert_equal 'application/json', response.content_type
|
||||
end
|
||||
@@ -170,7 +176,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
test "POST /uploads.xml should accept :filename param as the attachment filename" do
|
||||
set_tmp_attachments_directory
|
||||
assert_difference 'Attachment.count' do
|
||||
post '/uploads.xml?filename=test.txt', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
post '/uploads.xml?filename=test.txt', :headers => {
|
||||
"RAW_POST_DATA" => 'File content',
|
||||
"CONTENT_TYPE" => 'application/octet-stream'
|
||||
}.merge(credentials('jsmith'))
|
||||
assert_response :created
|
||||
end
|
||||
|
||||
@@ -182,7 +191,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
test "POST /uploads.xml should not accept other content types" do
|
||||
set_tmp_attachments_directory
|
||||
assert_no_difference 'Attachment.count' do
|
||||
post '/uploads.xml', 'PNG DATA', {"CONTENT_TYPE" => 'image/png'}.merge(credentials('jsmith'))
|
||||
post '/uploads.xml', :headers => {
|
||||
"RAW_POST_DATA" => 'PNG DATA',
|
||||
"CONTENT_TYPE" => 'image/png'
|
||||
}.merge(credentials('jsmith'))
|
||||
assert_response 406
|
||||
end
|
||||
end
|
||||
@@ -191,7 +203,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
set_tmp_attachments_directory
|
||||
with_settings :attachment_max_size => 1 do
|
||||
assert_no_difference 'Attachment.count' do
|
||||
post '/uploads.xml', ('x' * 2048), {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
post '/uploads.xml', :headers => {
|
||||
"RAW_POST_DATA" => ('x' * 2048),
|
||||
"CONTENT_TYPE" => 'application/octet-stream'
|
||||
}.merge(credentials('jsmith'))
|
||||
assert_response 422
|
||||
assert_select 'error', :text => /exceeds the maximum allowed file size/
|
||||
end
|
||||
@@ -201,7 +216,9 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
test "POST /uploads.json should create an empty file and return a valid token" do
|
||||
set_tmp_attachments_directory
|
||||
assert_difference 'Attachment.count' do
|
||||
post '/uploads.json', '', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
post '/uploads.json', :headers => {
|
||||
"CONTENT_TYPE" => 'application/octet-stream'
|
||||
}.merge(credentials('jsmith'))
|
||||
assert_response :created
|
||||
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
fixtures :users
|
||||
|
||||
def test_api_should_deny_without_credentials
|
||||
get '/users/current.xml', {}
|
||||
get '/users/current.xml'
|
||||
assert_response 401
|
||||
assert_equal User.anonymous, User.current
|
||||
assert response.headers.has_key?('WWW-Authenticate')
|
||||
@@ -31,7 +31,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
user = User.generate! do |user|
|
||||
user.password = 'my_password'
|
||||
end
|
||||
get '/users/current.xml', {}, credentials(user.login, 'my_password')
|
||||
get '/users/current.xml', :headers => credentials(user.login, 'my_password')
|
||||
assert_response 200
|
||||
assert_equal user, User.current
|
||||
end
|
||||
@@ -40,7 +40,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
user = User.generate! do |user|
|
||||
user.password = 'my_password'
|
||||
end
|
||||
get '/users/current.xml', {}, credentials(user.login, 'wrong_password')
|
||||
get '/users/current.xml', :headers => credentials(user.login, 'wrong_password')
|
||||
assert_response 401
|
||||
assert_equal User.anonymous, User.current
|
||||
end
|
||||
@@ -48,7 +48,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
def test_api_should_accept_http_basic_auth_using_api_key
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'api')
|
||||
get '/users/current.xml', {}, credentials(token.value, 'X')
|
||||
get '/users/current.xml', :headers => credentials(token.value, 'X')
|
||||
assert_response 200
|
||||
assert_equal user, User.current
|
||||
end
|
||||
@@ -56,7 +56,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
def test_api_should_deny_http_basic_auth_using_wrong_api_key
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'feeds') # not the API key
|
||||
get '/users/current.xml', {}, credentials(token.value, 'X')
|
||||
get '/users/current.xml', :headers => credentials(token.value, 'X')
|
||||
assert_response 401
|
||||
assert_equal User.anonymous, User.current
|
||||
end
|
||||
@@ -64,7 +64,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
def test_api_should_accept_auth_using_api_key_as_parameter
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'api')
|
||||
get "/users/current.xml?key=#{token.value}", {}
|
||||
get "/users/current.xml?key=#{token.value}"
|
||||
assert_response 200
|
||||
assert_equal user, User.current
|
||||
end
|
||||
@@ -72,7 +72,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
def test_api_should_deny_auth_using_wrong_api_key_as_parameter
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'feeds') # not the API key
|
||||
get "/users/current.xml?key=#{token.value}", {}
|
||||
get "/users/current.xml?key=#{token.value}"
|
||||
assert_response 401
|
||||
assert_equal User.anonymous, User.current
|
||||
end
|
||||
@@ -80,7 +80,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
def test_api_should_accept_auth_using_api_key_as_request_header
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'api')
|
||||
get "/users/current.xml", {}, {'X-Redmine-API-Key' => token.value.to_s}
|
||||
get "/users/current.xml", :headers => {'X-Redmine-API-Key' => token.value.to_s}
|
||||
assert_response 200
|
||||
assert_equal user, User.current
|
||||
end
|
||||
@@ -88,20 +88,20 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
def test_api_should_deny_auth_using_wrong_api_key_as_request_header
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'feeds') # not the API key
|
||||
get "/users/current.xml", {}, {'X-Redmine-API-Key' => token.value.to_s}
|
||||
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
|
||||
ApplicationController.any_instance.expects(:authenticate_with_http_basic).once
|
||||
get '/users/current.xml', {}, credentials('jsmith')
|
||||
get '/users/current.xml', :headers => credentials('jsmith')
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
def test_api_should_not_trigger_basic_http_auth_with_non_basic_authorization_header
|
||||
ApplicationController.any_instance.expects(:authenticate_with_http_basic).never
|
||||
get '/users/current.xml', {}, 'HTTP_AUTHORIZATION' => 'Digest foo bar'
|
||||
get '/users/current.xml', :headers => {'HTTP_AUTHORIZATION' => 'Digest foo bar'}
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
@@ -109,7 +109,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
invalid_utf8 = "\x82".force_encoding('UTF-8')
|
||||
assert !invalid_utf8.valid_encoding?
|
||||
assert_nothing_raised do
|
||||
get '/users/current.xml', {}, credentials(invalid_utf8, "foo")
|
||||
get '/users/current.xml', :headers => credentials(invalid_utf8, "foo")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -127,14 +127,14 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
user = User.find(1)
|
||||
su = User.find(4)
|
||||
|
||||
get '/users/current', {}, {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login}
|
||||
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
|
||||
get '/users/current', {}, {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => 'foobar'}
|
||||
get '/users/current', :headers => {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => 'foobar'}
|
||||
assert_response 412
|
||||
end
|
||||
|
||||
@@ -142,7 +142,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
user = User.find(5)
|
||||
assert user.locked?
|
||||
|
||||
get '/users/current', {}, {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => user.login}
|
||||
get '/users/current', :headers => {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => user.login}
|
||||
assert_response 412
|
||||
end
|
||||
|
||||
@@ -150,7 +150,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
user = User.find(2)
|
||||
su = User.find(4)
|
||||
|
||||
get '/users/current', {}, {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login}
|
||||
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
|
||||
|
||||
@@ -23,8 +23,11 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
|
||||
def test_integer_custom_fields_should_accept_strings
|
||||
field = GroupCustomField.generate!(:field_format => 'int')
|
||||
|
||||
post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}),
|
||||
{'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
|
||||
post '/groups.json',
|
||||
:params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}),
|
||||
:headers => {
|
||||
'CONTENT_TYPE' => 'application/json'
|
||||
}.merge(credentials('admin'))
|
||||
assert_response :created
|
||||
group = Group.order('id DESC').first
|
||||
assert_equal "52", group.custom_field_value(field)
|
||||
@@ -33,8 +36,11 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
|
||||
def test_integer_custom_fields_should_accept_integers
|
||||
field = GroupCustomField.generate!(:field_format => 'int')
|
||||
|
||||
post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}),
|
||||
{'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
|
||||
post '/groups.json',
|
||||
:params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}),
|
||||
:headers => {
|
||||
'CONTENT_TYPE' => 'application/json'
|
||||
}.merge(credentials('admin'))
|
||||
assert_response :created
|
||||
group = Group.order('id DESC').first
|
||||
assert_equal "52", group.custom_field_value(field)
|
||||
@@ -43,8 +49,11 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
|
||||
def test_boolean_custom_fields_should_accept_strings
|
||||
field = GroupCustomField.generate!(:field_format => 'bool')
|
||||
|
||||
post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": "1"}}}),
|
||||
{'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
|
||||
post '/groups.json',
|
||||
:params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": "1"}}}),
|
||||
:headers => {
|
||||
'CONTENT_TYPE' => 'application/json'
|
||||
}.merge(credentials('admin'))
|
||||
assert_response :created
|
||||
group = Group.order('id DESC').first
|
||||
assert_equal "1", group.custom_field_value(field)
|
||||
@@ -53,8 +62,11 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
|
||||
def test_boolean_custom_fields_should_accept_integers
|
||||
field = GroupCustomField.generate!(:field_format => 'bool')
|
||||
|
||||
post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": 1}}}),
|
||||
{'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
|
||||
post '/groups.json',
|
||||
:params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": 1}}}),
|
||||
:headers => {
|
||||
'CONTENT_TYPE' => 'application/json'
|
||||
}.merge(credentials('admin'))
|
||||
assert_response :created
|
||||
group = Group.order('id DESC').first
|
||||
assert_equal "1", group.custom_field_value(field)
|
||||
@@ -75,7 +87,11 @@ payload = <<-JSON
|
||||
}
|
||||
JSON
|
||||
|
||||
post '/groups.json', payload, {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
|
||||
post '/groups.json',
|
||||
:params => payload,
|
||||
:headers => {
|
||||
'CONTENT_TYPE' => 'application/json'
|
||||
}.merge(credentials('admin'))
|
||||
assert_response :created
|
||||
group = Group.order('id DESC').first
|
||||
assert_equal ["V1", "V3"], group.custom_field_value(field).sort
|
||||
|
||||
@@ -21,7 +21,7 @@ class Redmine::ApiTest::CustomFieldsTest < Redmine::ApiTest::Base
|
||||
fixtures :users, :custom_fields
|
||||
|
||||
test "GET /custom_fields.xml should return custom fields" do
|
||||
get '/custom_fields.xml', {}, credentials('admin')
|
||||
get '/custom_fields.xml', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', response.content_type
|
||||
|
||||
@@ -45,7 +45,7 @@ class Redmine::ApiTest::CustomFieldsTest < Redmine::ApiTest::Base
|
||||
foo = field.enumerations.create!(:name => 'Foo')
|
||||
bar = field.enumerations.create!(:name => 'Bar')
|
||||
|
||||
get '/custom_fields.xml', {}, credentials('admin')
|
||||
get '/custom_fields.xml', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
|
||||
assert_select 'possible_value' do
|
||||
|
||||
@@ -54,11 +54,11 @@ class Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base
|
||||
user.password = 'my_password'
|
||||
end
|
||||
|
||||
get "/news.xml", nil, credentials(@user.login, 'my_password')
|
||||
get "/news.xml", :headers => credentials(@user.login, 'my_password')
|
||||
assert_response :unauthorized
|
||||
assert_equal User.anonymous, User.current
|
||||
|
||||
get "/news.json", nil, credentials(@user.login, 'my_password')
|
||||
get "/news.json", :headers => credentials(@user.login, 'my_password')
|
||||
assert_response :unauthorized
|
||||
assert_equal User.anonymous, User.current
|
||||
end
|
||||
@@ -67,11 +67,11 @@ class Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base
|
||||
@user = User.generate!
|
||||
@token = Token.create!(:user => @user, :action => 'api')
|
||||
|
||||
get "/news.xml", nil, credentials(@token.value, 'X')
|
||||
get "/news.xml", :headers => credentials(@token.value, 'X')
|
||||
assert_response :unauthorized
|
||||
assert_equal User.anonymous, User.current
|
||||
|
||||
get "/news.json", nil, credentials(@token.value, 'X')
|
||||
get "/news.json", :headers => credentials(@token.value, 'X')
|
||||
assert_response :unauthorized
|
||||
assert_equal User.anonymous, User.current
|
||||
end
|
||||
|
||||
@@ -28,14 +28,16 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base
|
||||
:versions
|
||||
|
||||
test "GET /projects/:project_id/files.xml should return the list of uploaded files" do
|
||||
get '/projects/1/files.xml', {}, credentials('jsmith')
|
||||
get '/projects/1/files.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_select 'files>file>id', :text => '8'
|
||||
end
|
||||
|
||||
test "POST /projects/:project_id/files.json should create a file" do
|
||||
set_tmp_attachments_directory
|
||||
post '/uploads.xml', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
post '/uploads.xml',
|
||||
:params => 'File content',
|
||||
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
token = Attachment.last.token
|
||||
payload = <<-JSON
|
||||
{ "file": {
|
||||
@@ -43,7 +45,9 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base
|
||||
}
|
||||
}
|
||||
JSON
|
||||
post '/projects/1/files.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
post '/projects/1/files.json',
|
||||
:params => payload,
|
||||
: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
|
||||
@@ -51,14 +55,18 @@ 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', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
post '/uploads.xml',
|
||||
:params => 'File content',
|
||||
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
token = Attachment.last.token
|
||||
payload = <<-XML
|
||||
<file>
|
||||
<token>#{token}</token>
|
||||
</file>
|
||||
XML
|
||||
post '/projects/1/files.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
|
||||
post '/projects/1/files.xml',
|
||||
:params => payload,
|
||||
: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
|
||||
@@ -71,13 +79,17 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base
|
||||
}
|
||||
}
|
||||
JSON
|
||||
post '/projects/1/files.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
post '/projects/1/files.json',
|
||||
:params => payload,
|
||||
: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', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
post '/uploads.xml',
|
||||
:params => 'File content',
|
||||
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
token = Attachment.last.token
|
||||
payload = <<-JSON
|
||||
{ "file": {
|
||||
@@ -88,7 +100,9 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base
|
||||
}
|
||||
}
|
||||
JSON
|
||||
post '/projects/1/files.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
post '/projects/1/files.json',
|
||||
:params => payload,
|
||||
: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
|
||||
@@ -97,7 +111,9 @@ 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', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
post '/uploads.xml',
|
||||
:params => 'File content',
|
||||
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
|
||||
token = Attachment.last.token
|
||||
payload = <<-JSON
|
||||
{ "file": {
|
||||
@@ -108,7 +124,9 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base
|
||||
}
|
||||
}
|
||||
JSON
|
||||
post '/projects/1/files.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
post '/projects/1/files.json',
|
||||
:params => payload,
|
||||
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
assert_equal 3, Attachment.last.container_id
|
||||
assert_equal "Version", Attachment.last.container_type
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /groups.xml should return givable groups" do
|
||||
get '/groups.xml', {}, credentials('admin')
|
||||
get '/groups.xml', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', response.content_type
|
||||
|
||||
@@ -40,7 +40,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /groups.xml?builtin=1 should return all groups" do
|
||||
get '/groups.xml?builtin=1', {}, credentials('admin')
|
||||
get '/groups.xml?builtin=1', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', response.content_type
|
||||
|
||||
@@ -63,7 +63,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /groups.json should return groups" do
|
||||
get '/groups.json', {}, credentials('admin')
|
||||
get '/groups.json', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
assert_equal 'application/json', response.content_type
|
||||
|
||||
@@ -76,7 +76,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /groups/:id.xml should return the group" do
|
||||
get '/groups/10.xml', {}, credentials('admin')
|
||||
get '/groups/10.xml', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', response.content_type
|
||||
|
||||
@@ -87,7 +87,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /groups/:id.xml should return the builtin group" do
|
||||
get '/groups/12.xml', {}, credentials('admin')
|
||||
get '/groups/12.xml', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', response.content_type
|
||||
|
||||
@@ -98,7 +98,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /groups/:id.xml should include users if requested" do
|
||||
get '/groups/10.xml?include=users', {}, credentials('admin')
|
||||
get '/groups/10.xml?include=users', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', response.content_type
|
||||
|
||||
@@ -111,7 +111,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /groups/:id.xml include memberships if requested" do
|
||||
get '/groups/10.xml?include=memberships', {}, credentials('admin')
|
||||
get '/groups/10.xml?include=memberships', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', response.content_type
|
||||
|
||||
@@ -122,7 +122,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "POST /groups.xml with valid parameters should create the group" do
|
||||
assert_difference('Group.count') do
|
||||
post '/groups.xml', {:group => {:name => 'Test', :user_ids => [2, 3]}}, credentials('admin')
|
||||
post '/groups.xml',
|
||||
:params => {:group => {:name => 'Test', :user_ids => [2, 3]}},
|
||||
:headers => credentials('admin')
|
||||
assert_response :created
|
||||
assert_equal 'application/xml', response.content_type
|
||||
end
|
||||
@@ -138,7 +140,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "POST /groups.xml with invalid parameters should return errors" do
|
||||
assert_no_difference('Group.count') do
|
||||
post '/groups.xml', {:group => {:name => ''}}, credentials('admin')
|
||||
post '/groups.xml',
|
||||
:params => {:group => {:name => ''}},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', response.content_type
|
||||
@@ -150,7 +154,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PUT /groups/:id.xml with valid parameters should update the group" do
|
||||
group = Group.generate!
|
||||
put "/groups/#{group.id}.xml", {:group => {:name => 'New name', :user_ids => [2, 3]}}, credentials('admin')
|
||||
put "/groups/#{group.id}.xml",
|
||||
:params => {:group => {:name => 'New name', :user_ids => [2, 3]}},
|
||||
:headers => credentials('admin')
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
|
||||
@@ -160,7 +166,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PUT /groups/:id.xml with invalid parameters should return errors" do
|
||||
group = Group.generate!
|
||||
put "/groups/#{group.id}.xml", {:group => {:name => ''}}, credentials('admin')
|
||||
put "/groups/#{group.id}.xml",
|
||||
:params => {:group => {:name => ''}},
|
||||
:headers => credentials('admin')
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', response.content_type
|
||||
|
||||
@@ -172,7 +180,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
test "DELETE /groups/:id.xml should delete the group" do
|
||||
group = Group.generate!
|
||||
assert_difference 'Group.count', -1 do
|
||||
delete "/groups/#{group.id}.xml", {}, credentials('admin')
|
||||
delete "/groups/#{group.id}.xml", :headers => credentials('admin')
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
end
|
||||
@@ -181,7 +189,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
test "POST /groups/:id/users.xml should add user to the group" do
|
||||
group = Group.generate!
|
||||
assert_difference 'group.reload.users.count' do
|
||||
post "/groups/#{group.id}/users.xml", {:user_id => 5}, credentials('admin')
|
||||
post "/groups/#{group.id}/users.xml",
|
||||
:params => {:user_id => 5},
|
||||
:headers => credentials('admin')
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
end
|
||||
@@ -193,7 +203,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
group.users << User.find(5)
|
||||
|
||||
assert_no_difference 'group.reload.users.count' do
|
||||
post "/groups/#{group.id}/users.xml", {:user_id => 5}, credentials('admin')
|
||||
post "/groups/#{group.id}/users.xml",
|
||||
:params => {:user_id => 5},
|
||||
:headers => credentials('admin')
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
@@ -207,7 +219,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
group.users << User.find(8)
|
||||
|
||||
assert_difference 'group.reload.users.count', -1 do
|
||||
delete "/groups/#{group.id}/users/8.xml", {}, credentials('admin')
|
||||
delete "/groups/#{group.id}/users/8.xml", :headers => credentials('admin')
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
end
|
||||
|
||||
@@ -25,14 +25,14 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
|
||||
:enabled_modules
|
||||
|
||||
test "GET /projects/:project_id/issue_categories.xml should return the issue categories" do
|
||||
get '/projects/1/issue_categories.xml', {}, credentials('jsmith')
|
||||
get '/projects/1/issue_categories.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'issue_categories issue_category id', :text => '2'
|
||||
end
|
||||
|
||||
test "GET /issue_categories/:id.xml should return the issue category" do
|
||||
get '/issue_categories/2.xml', {}, credentials('jsmith')
|
||||
get '/issue_categories/2.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'issue_category id', :text => '2'
|
||||
@@ -40,7 +40,9 @@ 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', {:issue_category => {:name => 'API'}}, credentials('jsmith')
|
||||
post '/projects/1/issue_categories.xml',
|
||||
:params => {:issue_category => {:name => 'API'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :created
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -52,7 +54,9 @@ 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', {:issue_category => {:name => ''}}, credentials('jsmith')
|
||||
post '/projects/1/issue_categories.xml',
|
||||
:params => {:issue_category => {:name => ''}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -62,7 +66,9 @@ 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', {:issue_category => {:name => 'API Update'}}, credentials('jsmith')
|
||||
put '/issue_categories/2.xml',
|
||||
:params => {:issue_category => {:name => 'API Update'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
@@ -71,7 +77,9 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PUT /issue_categories/:id.xml with invalid parameters should return errors" do
|
||||
assert_no_difference 'IssueCategory.count' do
|
||||
put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, credentials('jsmith')
|
||||
put '/issue_categories/2.xml',
|
||||
:params => {:issue_category => {:name => ''}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -81,7 +89,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "DELETE /issue_categories/:id.xml should destroy the issue category" do
|
||||
assert_difference 'IssueCategory.count', -1 do
|
||||
delete '/issue_categories/1.xml', {}, credentials('jsmith')
|
||||
delete '/issue_categories/1.xml', :headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
@@ -94,7 +102,9 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
|
||||
|
||||
assert_difference 'IssueCategory.count', -1 do
|
||||
assert_difference 'Issue.where(:category_id => 2).count', 3 do
|
||||
delete '/issue_categories/1.xml', {:reassign_to_id => 2}, credentials('jsmith')
|
||||
delete '/issue_categories/1.xml',
|
||||
:params => {:reassign_to_id => 2},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
end
|
||||
assert_response :ok
|
||||
|
||||
@@ -28,7 +28,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
|
||||
:issue_relations
|
||||
|
||||
test "GET /issues/:issue_id/relations.xml should return issue relations" do
|
||||
get '/issues/9/relations.xml', {}, credentials('jsmith')
|
||||
get '/issues/9/relations.xml', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -38,7 +38,9 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "POST /issues/:issue_id/relations.xml should create the relation" do
|
||||
assert_difference('IssueRelation.count') do
|
||||
post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith')
|
||||
post '/issues/2/relations.xml',
|
||||
:params => {:relation => {:issue_to_id => 7, :relation_type => 'relates'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
relation = IssueRelation.order('id DESC').first
|
||||
@@ -53,7 +55,9 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "POST /issues/:issue_id/relations.xml with failure should return errors" do
|
||||
assert_no_difference('IssueRelation.count') do
|
||||
post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith')
|
||||
post '/issues/2/relations.xml',
|
||||
:params => {:relation => {:issue_to_id => 7, :relation_type => 'foo'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
@@ -61,7 +65,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /relations/:id.xml should return the relation" do
|
||||
get '/relations/2.xml', {}, credentials('jsmith')
|
||||
get '/relations/2.xml', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -70,7 +74,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "DELETE /relations/:id.xml should delete the relation" do
|
||||
assert_difference('IssueRelation.count', -1) do
|
||||
delete '/relations/2.xml', {}, credentials('jsmith')
|
||||
delete '/relations/2.xml', :headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_response :ok
|
||||
|
||||
@@ -55,7 +55,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /issues.xml with nometa header should not contain metadata" do
|
||||
get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'}
|
||||
get '/issues.xml', :headers => {'X-Redmine-Nometa' => '1'}
|
||||
assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
|
||||
end
|
||||
|
||||
@@ -99,7 +99,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /issues.xml with invalid query params" do
|
||||
get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}}
|
||||
get '/issues.xml', :params => {:f => ['start_date'], :op => {:start_date => '='}}
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -108,7 +108,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /issues.xml with custom field filter" do
|
||||
get '/issues.xml',
|
||||
{:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}}
|
||||
:params => {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}}
|
||||
|
||||
expected_ids = Issue.visible.
|
||||
joins(:custom_values).
|
||||
@@ -121,7 +121,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /issues.xml with custom field filter (shorthand method)" do
|
||||
get '/issues.xml', {:cf_1 => 'MySQL'}
|
||||
get '/issues.xml', :params => {:cf_1 => 'MySQL'}
|
||||
|
||||
expected_ids = Issue.visible.
|
||||
joins(:custom_values).
|
||||
@@ -143,21 +143,24 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
Issue.generate!(:subject => '1').update_column(:updated_on, Time.parse("2014-01-02T10:25:00Z"))
|
||||
Issue.generate!(:subject => '2').update_column(:updated_on, Time.parse("2014-01-02T12:13:00Z"))
|
||||
|
||||
get '/issues.xml',
|
||||
{:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '<='},
|
||||
:v => {:updated_on => ['2014-01-02T12:00:00Z']}}
|
||||
get '/issues.xml', :params => {
|
||||
:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '<='},
|
||||
:v => {:updated_on => ['2014-01-02T12:00:00Z']}
|
||||
}
|
||||
assert_select 'issues>issue', :count => 1
|
||||
assert_select 'issues>issue>subject', :text => '1'
|
||||
|
||||
get '/issues.xml',
|
||||
{:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='},
|
||||
:v => {:updated_on => ['2014-01-02T12:00:00Z']}}
|
||||
get '/issues.xml', :params => {
|
||||
:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='},
|
||||
:v => {:updated_on => ['2014-01-02T12:00:00Z']}
|
||||
}
|
||||
assert_select 'issues>issue', :count => 1
|
||||
assert_select 'issues>issue>subject', :text => '2'
|
||||
|
||||
get '/issues.xml',
|
||||
{:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='},
|
||||
:v => {:updated_on => ['2014-01-02T08:00:00Z']}}
|
||||
get '/issues.xml', :params => {
|
||||
:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='},
|
||||
:v => {:updated_on => ['2014-01-02T08:00:00Z']}
|
||||
}
|
||||
assert_select 'issues>issue', :count => 2
|
||||
end
|
||||
|
||||
@@ -184,7 +187,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
test "GET /issues/:id.xml with journals" do
|
||||
Journal.find(2).update_attribute(:private_notes, true)
|
||||
|
||||
get '/issues/1.xml?include=journals', {}, credentials('jsmith')
|
||||
get '/issues/1.xml?include=journals', :headers => credentials('jsmith')
|
||||
|
||||
assert_select 'issue journals[type=array]' do
|
||||
assert_select 'journal[id="1"]' do
|
||||
@@ -353,7 +356,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
test "GET /issues/:id.xml?include=watchers should include watchers" do
|
||||
Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
|
||||
|
||||
get '/issues/1.xml?include=watchers', {}, credentials('jsmith')
|
||||
get '/issues/1.xml?include=watchers', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 'application/xml', response.content_type
|
||||
@@ -371,7 +374,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
Issue.find(1).changesets << Changeset.generate!(:repository => repository)
|
||||
assert Issue.find(1).changesets.any?
|
||||
|
||||
get '/issues/1.xml?include=changesets', {}, credentials('jsmith')
|
||||
get '/issues/1.xml?include=changesets', :headers => credentials('jsmith')
|
||||
|
||||
# the user jsmith has no permission to view the associated changeset
|
||||
assert_select 'issue changesets[type=array]' do
|
||||
@@ -422,7 +425,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
TimeEntry.generate!(:user => user, :hours => 5.5, :issue_id => parent.id)
|
||||
TimeEntry.generate!(:user => user, :hours => 2, :issue_id => child.id)
|
||||
TimeEntry.generate!(:user => User.find(1), :hours => 100, :issue_id => child.id)
|
||||
get '/issues/3.xml', {} , credentials(user.login)
|
||||
get '/issues/3.xml', :headers => credentials(user.login)
|
||||
|
||||
assert_equal 'application/xml', response.content_type
|
||||
assert_select 'issue' do
|
||||
@@ -472,7 +475,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
TimeEntry.generate!(:user => user, :hours => 5.5, :issue_id => parent.id)
|
||||
TimeEntry.generate!(:user => user, :hours => 2, :issue_id => child.id)
|
||||
TimeEntry.generate!(:user => User.find(1), :hours => 100, :issue_id => child.id)
|
||||
get '/issues/3.json', {} , credentials(user.login)
|
||||
get '/issues/3.json', :headers => credentials(user.login)
|
||||
|
||||
assert_equal 'application/json', response.content_type
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
@@ -493,7 +496,9 @@ payload = <<-XML
|
||||
XML
|
||||
|
||||
assert_difference('Issue.count') do
|
||||
post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
|
||||
post '/issues.xml',
|
||||
:params => payload,
|
||||
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
|
||||
end
|
||||
issue = Issue.order('id DESC').first
|
||||
assert_equal 1, issue.project_id
|
||||
@@ -509,8 +514,13 @@ XML
|
||||
test "POST /issues.xml with watcher_user_ids should create issue with watchers" do
|
||||
assert_difference('Issue.count') do
|
||||
post '/issues.xml',
|
||||
{:issue => {:project_id => 1, :subject => 'Watchers',
|
||||
:tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]}}, credentials('jsmith')
|
||||
:params => {
|
||||
:issue => {
|
||||
:project_id => 1, :subject => 'Watchers',
|
||||
:tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]
|
||||
}
|
||||
},
|
||||
:headers => credentials('jsmith')
|
||||
assert_response :created
|
||||
end
|
||||
issue = Issue.order('id desc').first
|
||||
@@ -520,7 +530,9 @@ XML
|
||||
|
||||
test "POST /issues.xml with failure should return errors" do
|
||||
assert_no_difference('Issue.count') do
|
||||
post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
|
||||
post '/issues.xml',
|
||||
:params => {:issue => {:project_id => 1}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_select 'errors error', :text => "Subject cannot be blank"
|
||||
@@ -540,7 +552,9 @@ payload = <<-JSON
|
||||
JSON
|
||||
|
||||
assert_difference('Issue.count') do
|
||||
post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
post '/issues.json',
|
||||
:params => payload,
|
||||
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
end
|
||||
|
||||
issue = Issue.order('id DESC').first
|
||||
@@ -553,8 +567,8 @@ JSON
|
||||
test "POST /issues.json should accept project identifier as project_id" do
|
||||
assert_difference('Issue.count') do
|
||||
post '/issues.json',
|
||||
{:issue => {:project_id => 'subproject1', :tracker_id => 2, :subject => 'Foo'}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:project_id => 'subproject1', :tracker_id => 2, :subject => 'Foo'}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :created
|
||||
end
|
||||
@@ -581,7 +595,9 @@ payload = <<-JSON
|
||||
JSON
|
||||
|
||||
assert_difference('Issue.count') do
|
||||
post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
post '/issues.json',
|
||||
:params => payload,
|
||||
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
end
|
||||
|
||||
assert_response :created
|
||||
@@ -594,8 +610,8 @@ JSON
|
||||
|
||||
issue = new_record(Issue) do
|
||||
post '/issues.json',
|
||||
{:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {}}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {}}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_equal "Default", issue.custom_field_value(field)
|
||||
end
|
||||
@@ -605,15 +621,17 @@ JSON
|
||||
|
||||
issue = new_record(Issue) do
|
||||
post '/issues.json',
|
||||
{:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {field.id.to_s => ""}}},
|
||||
credentials('jsmith')
|
||||
: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', {:issue => {:project_id => 1}}, credentials('jsmith')
|
||||
post '/issues.json',
|
||||
:params => {:issue => {:project_id => 1}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
@@ -621,15 +639,17 @@ JSON
|
||||
end
|
||||
|
||||
test "POST /issues.json with invalid project_id should respond with 422" do
|
||||
post '/issues.json', {:issue => {:project_id => 999, :subject => "API"}}, credentials('jsmith')
|
||||
post '/issues.json',
|
||||
:params => {:issue => {:project_id => 999, :subject => "API"}},
|
||||
:headers => credentials('jsmith')
|
||||
assert_response 422
|
||||
end
|
||||
|
||||
test "PUT /issues/:id.xml" do
|
||||
assert_difference('Journal.count') do
|
||||
put '/issues/6.xml',
|
||||
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
issue = Issue.find(6)
|
||||
@@ -640,11 +660,12 @@ JSON
|
||||
|
||||
test "PUT /issues/:id.xml with custom fields" do
|
||||
put '/issues/3.xml',
|
||||
{:issue => {:custom_fields => [
|
||||
:params => {:issue => {:custom_fields => [
|
||||
{'id' => '1', 'value' => 'PostgreSQL' },
|
||||
{'id' => '2', 'value' => '150'}
|
||||
]}},
|
||||
credentials('jsmith')
|
||||
]}
|
||||
},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
issue = Issue.find(3)
|
||||
assert_equal '150', issue.custom_value_for(2).value
|
||||
@@ -656,11 +677,12 @@ JSON
|
||||
field.update_attribute :multiple, true
|
||||
|
||||
put '/issues/3.xml',
|
||||
{:issue => {:custom_fields => [
|
||||
:params => {:issue => {:custom_fields => [
|
||||
{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] },
|
||||
{'id' => '2', 'value' => '150'}
|
||||
]}},
|
||||
credentials('jsmith')
|
||||
]}
|
||||
},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
issue = Issue.find(3)
|
||||
assert_equal '150', issue.custom_value_for(2).value
|
||||
@@ -669,8 +691,8 @@ JSON
|
||||
|
||||
test "PUT /issues/:id.xml with project change" do
|
||||
put '/issues/3.xml',
|
||||
{:issue => {:project_id => 2, :subject => 'Project changed'}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:project_id => 2, :subject => 'Project changed'}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
issue = Issue.find(3)
|
||||
assert_equal 2, issue.project_id
|
||||
@@ -680,8 +702,8 @@ JSON
|
||||
test "PUT /issues/:id.xml with notes only" do
|
||||
assert_difference('Journal.count') do
|
||||
put '/issues/6.xml',
|
||||
{:issue => {:notes => 'Notes only'}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:notes => 'Notes only'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
journal = Journal.last
|
||||
@@ -695,8 +717,8 @@ JSON
|
||||
|
||||
assert_difference('Journal.count') do
|
||||
put "/issues/#{issue.id}.json",
|
||||
{:issue => {:custom_field_values => {}, :notes => 'API'}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:custom_field_values => {}, :notes => 'API'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_equal "", issue.reload.custom_field_value(field)
|
||||
@@ -709,8 +731,8 @@ JSON
|
||||
|
||||
assert_difference('Journal.count') do
|
||||
put "/issues/#{issue.id}.json",
|
||||
{:issue => {:custom_field_values => {field.id.to_s => ""}, :notes => 'API'}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:custom_field_values => {field.id.to_s => ""}, :notes => 'API'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_equal "", issue.reload.custom_field_value(field)
|
||||
@@ -722,8 +744,8 @@ JSON
|
||||
|
||||
assert_difference('Journal.count') do
|
||||
put "/issues/#{issue.id}.json",
|
||||
{:issue => {:tracker_id => 2, :custom_field_values => {}, :notes => 'API'}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:tracker_id => 2, :custom_field_values => {}, :notes => 'API'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_equal 2, issue.reload.tracker_id
|
||||
@@ -736,8 +758,8 @@ JSON
|
||||
|
||||
assert_difference('Journal.count') do
|
||||
put "/issues/#{issue.id}.json",
|
||||
{:issue => {:tracker_id => 2, :custom_field_values => {field.id.to_s => ""}, :notes => 'API'}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:tracker_id => 2, :custom_field_values => {field.id.to_s => ""}, :notes => 'API'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_equal 2, issue.reload.tracker_id
|
||||
@@ -745,7 +767,9 @@ JSON
|
||||
end
|
||||
|
||||
test "PUT /issues/:id.xml with failed update" do
|
||||
put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith')
|
||||
put '/issues/6.xml',
|
||||
:params => {:issue => {:subject => ''}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
assert_select 'errors error', :text => "Subject cannot be blank"
|
||||
@@ -753,7 +777,9 @@ JSON
|
||||
|
||||
test "PUT /issues/:id.xml with invalid assignee should return error" do
|
||||
user = User.generate!
|
||||
put '/issues/6.xml', {:issue => {:assigned_to_id => user.id}}, credentials('jsmith')
|
||||
put '/issues/6.xml',
|
||||
:params => {:issue => {:assigned_to_id => user.id}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
assert_select 'errors error', :text => "Assignee is invalid"
|
||||
@@ -762,8 +788,8 @@ JSON
|
||||
test "PUT /issues/:id.json" do
|
||||
assert_difference('Journal.count') do
|
||||
put '/issues/6.json',
|
||||
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
credentials('jsmith')
|
||||
:params => {:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
@@ -776,7 +802,9 @@ JSON
|
||||
end
|
||||
|
||||
test "PUT /issues/:id.json with failed update" do
|
||||
put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
|
||||
put '/issues/6.json',
|
||||
:params => {:issue => {:subject => ''}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
@@ -785,7 +813,7 @@ JSON
|
||||
|
||||
test "DELETE /issues/:id.xml" do
|
||||
assert_difference('Issue.count', -1) do
|
||||
delete '/issues/6.xml', {}, credentials('jsmith')
|
||||
delete '/issues/6.xml', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
@@ -795,7 +823,7 @@ JSON
|
||||
|
||||
test "DELETE /issues/:id.json" do
|
||||
assert_difference('Issue.count', -1) do
|
||||
delete '/issues/6.json', {}, credentials('jsmith')
|
||||
delete '/issues/6.json', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
@@ -805,7 +833,9 @@ JSON
|
||||
|
||||
test "POST /issues/:id/watchers.xml should add watcher" do
|
||||
assert_difference 'Watcher.count' do
|
||||
post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith')
|
||||
post '/issues/1/watchers.xml',
|
||||
:params => {:user_id => 3},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
@@ -819,7 +849,7 @@ JSON
|
||||
Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
|
||||
|
||||
assert_difference 'Watcher.count', -1 do
|
||||
delete '/issues/1/watchers/3.xml', {}, credentials('jsmith')
|
||||
delete '/issues/1/watchers/3.xml', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
@@ -834,10 +864,10 @@ JSON
|
||||
# create the issue with the upload's token
|
||||
assert_difference 'Issue.count' do
|
||||
post '/issues.xml',
|
||||
{:issue => {:project_id => 1, :subject => 'Uploaded file',
|
||||
:params => {:issue => {:project_id => 1, :subject => 'Uploaded file',
|
||||
:uploads => [{:token => token, :filename => 'test.txt',
|
||||
:content_type => 'text/plain'}]}},
|
||||
credentials('jsmith')
|
||||
:headers => credentials('jsmith')
|
||||
assert_response :created
|
||||
end
|
||||
issue = Issue.order('id DESC').first
|
||||
@@ -851,7 +881,7 @@ JSON
|
||||
assert_equal 2, attachment.author_id
|
||||
|
||||
# get the issue with its attachments
|
||||
get "/issues/#{issue.id}.xml", :include => 'attachments'
|
||||
get "/issues/#{issue.id}.xml?include=attachments"
|
||||
assert_response :success
|
||||
xml = Hash.from_xml(response.body)
|
||||
attachments = xml['issue']['attachments']
|
||||
@@ -890,7 +920,9 @@ JSON
|
||||
XML
|
||||
|
||||
assert_difference 'Issue.count' do
|
||||
post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
|
||||
post '/issues.xml',
|
||||
:params => payload,
|
||||
:headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
|
||||
assert_response :created
|
||||
end
|
||||
issue = Issue.order('id DESC').first
|
||||
@@ -916,7 +948,9 @@ XML
|
||||
JSON
|
||||
|
||||
assert_difference 'Issue.count' do
|
||||
post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
post '/issues.json',
|
||||
:params => payload,
|
||||
:headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
|
||||
assert_response :created
|
||||
end
|
||||
issue = Issue.order('id DESC').first
|
||||
@@ -930,10 +964,10 @@ JSON
|
||||
# update the issue with the upload's token
|
||||
assert_difference 'Journal.count' do
|
||||
put '/issues/1.xml',
|
||||
{:issue => {:notes => 'Attachment added',
|
||||
:params => {:issue => {:notes => 'Attachment added',
|
||||
:uploads => [{:token => token, :filename => 'test.txt',
|
||||
:content_type => 'text/plain'}]}},
|
||||
credentials('jsmith')
|
||||
:headers => credentials('jsmith')
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
fixtures :projects, :users, :roles, :members, :member_roles
|
||||
|
||||
test "GET /projects/:project_id/memberships.xml should return memberships" do
|
||||
get '/projects/1/memberships.xml', {}, credentials('jsmith')
|
||||
get '/projects/1/memberships.xml', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -32,7 +32,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /projects/:project_id/memberships.json should return memberships" do
|
||||
get '/projects/1/memberships.json', {}, credentials('jsmith')
|
||||
get '/projects/1/memberships.json', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/json', @response.content_type
|
||||
@@ -54,13 +54,13 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
project = Project.find(1)
|
||||
project.close
|
||||
assert !project.reload.active?
|
||||
get '/projects/1/memberships.json', {}, credentials('jsmith')
|
||||
get '/projects/1/memberships.json', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "GET /projects/:project_id/memberships.xml should include locked users" do
|
||||
assert User.find(3).lock!
|
||||
get '/projects/ecookbook/memberships.xml', {}, credentials('jsmith')
|
||||
get '/projects/ecookbook/memberships.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_select 'memberships[type=array] membership id', :text => '2' do
|
||||
assert_select '~ user[id="3"][name="Dave Lopper"]'
|
||||
@@ -69,7 +69,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "POST /projects/:project_id/memberships.xml should create the membership" do
|
||||
assert_difference 'Member.count' do
|
||||
post '/projects/1/memberships.xml', {:membership => {:user_id => 7, :role_ids => [2,3]}}, credentials('jsmith')
|
||||
post '/projects/1/memberships.xml',
|
||||
:params => {:membership => {:user_id => 7, :role_ids => [2,3]}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :created
|
||||
end
|
||||
@@ -79,7 +81,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
group = Group.find(11)
|
||||
|
||||
assert_difference 'Member.count', 1 + group.users.count do
|
||||
post '/projects/1/memberships.xml', {:membership => {:user_id => 11, :role_ids => [2,3]}}, credentials('jsmith')
|
||||
post '/projects/1/memberships.xml',
|
||||
:params => {:membership => {:user_id => 11, :role_ids => [2,3]}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :created
|
||||
end
|
||||
@@ -87,7 +91,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "POST /projects/:project_id/memberships.xml with invalid parameters should return errors" do
|
||||
assert_no_difference 'Member.count' do
|
||||
post '/projects/1/memberships.xml', {:membership => {:role_ids => [2,3]}}, credentials('jsmith')
|
||||
post '/projects/1/memberships.xml',
|
||||
:params => {:membership => {:role_ids => [2,3]}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -96,7 +102,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /memberships/:id.xml should return the membership" do
|
||||
get '/memberships/2.xml', {}, credentials('jsmith')
|
||||
get '/memberships/2.xml', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -107,7 +113,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /memberships/:id.json should return the membership" do
|
||||
get '/memberships/2.json', {}, credentials('jsmith')
|
||||
get '/memberships/2.json', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/json', @response.content_type
|
||||
@@ -125,7 +131,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
test "PUT /memberships/:id.xml should update the membership" do
|
||||
assert_not_equal [1,2], Member.find(2).role_ids.sort
|
||||
assert_no_difference 'Member.count' do
|
||||
put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [1,2]}}, credentials('jsmith')
|
||||
put '/memberships/2.xml',
|
||||
:params => {:membership => {:user_id => 3, :role_ids => [1,2]}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
@@ -135,7 +143,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "PUT /memberships/:id.xml with invalid parameters should return errors" do
|
||||
put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [99]}}, credentials('jsmith')
|
||||
put '/memberships/2.xml',
|
||||
:params => {:membership => {:user_id => 3, :role_ids => [99]}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -144,7 +154,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "DELETE /memberships/:id.xml should destroy the membership" do
|
||||
assert_difference 'Member.count', -1 do
|
||||
delete '/memberships/2.xml', {}, credentials('jsmith')
|
||||
delete '/memberships/2.xml', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
@@ -156,7 +166,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
|
||||
assert_no_difference 'Member.count' do
|
||||
# A membership with an inherited role cannot be deleted
|
||||
Member.find(2).member_roles.first.update_attribute :inherited_from, 99
|
||||
delete '/memberships/2.xml', {}, credentials('jsmith')
|
||||
delete '/memberships/2.xml', :headers => credentials('jsmith')
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
@@ -142,8 +142,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
|
||||
with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
|
||||
assert_difference('Project.count') do
|
||||
post '/projects.xml',
|
||||
{:project => {:name => 'API test', :identifier => 'api-test'}},
|
||||
credentials('admin')
|
||||
:params => {:project => {:name => 'API test', :identifier => 'api-test'}},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -161,8 +161,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
|
||||
test "POST /projects.xml should accept enabled_module_names attribute" do
|
||||
assert_difference('Project.count') do
|
||||
post '/projects.xml',
|
||||
{:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
|
||||
credentials('admin')
|
||||
:params => {:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
project = Project.order('id DESC').first
|
||||
@@ -172,8 +172,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
|
||||
test "POST /projects.xml should accept tracker_ids attribute" do
|
||||
assert_difference('Project.count') do
|
||||
post '/projects.xml',
|
||||
{:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}},
|
||||
credentials('admin')
|
||||
:params => {:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
project = Project.order('id DESC').first
|
||||
@@ -182,7 +182,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "POST /projects.xml with invalid parameters should return errors" do
|
||||
assert_no_difference('Project.count') do
|
||||
post '/projects.xml', {:project => {:name => 'API test'}}, credentials('admin')
|
||||
post '/projects.xml',
|
||||
:params => {:project => {:name => 'API test'}},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
@@ -192,7 +194,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PUT /projects/:id.xml with valid parameters should update the project" do
|
||||
assert_no_difference 'Project.count' do
|
||||
put '/projects/2.xml', {:project => {:name => 'API update'}}, credentials('jsmith')
|
||||
put '/projects/2.xml',
|
||||
:params => {:project => {:name => 'API update'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
@@ -203,7 +207,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PUT /projects/:id.xml should accept enabled_module_names attribute" do
|
||||
assert_no_difference 'Project.count' do
|
||||
put '/projects/2.xml', {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, credentials('admin')
|
||||
put '/projects/2.xml',
|
||||
:params => {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
@@ -213,7 +219,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PUT /projects/:id.xml should accept tracker_ids attribute" do
|
||||
assert_no_difference 'Project.count' do
|
||||
put '/projects/2.xml', {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, credentials('admin')
|
||||
put '/projects/2.xml',
|
||||
:params => {:project => {:name => 'API update', :tracker_ids => [1, 3]}},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
@@ -223,7 +231,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PUT /projects/:id.xml with invalid parameters should return errors" do
|
||||
assert_no_difference('Project.count') do
|
||||
put '/projects/2.xml', {:project => {:name => ''}}, credentials('admin')
|
||||
put '/projects/2.xml',
|
||||
:params => {:project => {:name => ''}},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
@@ -233,7 +243,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "DELETE /projects/:id.xml should delete the project" do
|
||||
assert_difference('Project.count',-1) do
|
||||
delete '/projects/2.xml', {}, credentials('admin')
|
||||
delete '/projects/2.xml', :headers => credentials('admin')
|
||||
end
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
|
||||
@@ -45,7 +45,7 @@ class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /search.xml without query strings should return empty results" do
|
||||
get '/search.xml', :q => '', :all_words => ''
|
||||
get '/search.xml', :params => {:q => '', :all_words => ''}
|
||||
|
||||
assert_response :success
|
||||
assert_select 'result', 0
|
||||
@@ -54,7 +54,7 @@ class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base
|
||||
test "GET /search.xml with query strings should return results" do
|
||||
issue = Issue.generate!(:subject => 'searchapi')
|
||||
|
||||
get '/search.xml', :q => 'searchapi', :all_words => ''
|
||||
get '/search.xml', :params => {:q => 'searchapi', :all_words => ''}
|
||||
|
||||
assert_response :success
|
||||
|
||||
@@ -75,14 +75,14 @@ class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base
|
||||
test "GET /search.xml should paginate" do
|
||||
issue = (0..10).map {Issue.generate! :subject => 'search_with_limited_results'}.reverse.map(&:id)
|
||||
|
||||
get '/search.json', :q => 'search_with_limited_results', :limit => 4
|
||||
get '/search.json', :params => {:q => 'search_with_limited_results', :limit => 4}
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_equal 11, json['total_count']
|
||||
assert_equal 0, json['offset']
|
||||
assert_equal 4, json['limit']
|
||||
assert_equal issue[0..3], json['results'].map {|r| r['id']}
|
||||
|
||||
get '/search.json', :q => 'search_with_limited_results', :offset => 8, :limit => 4
|
||||
get '/search.json', :params => {:q => 'search_with_limited_results', :offset => 8, :limit => 4}
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_equal 11, json['total_count']
|
||||
assert_equal 8, json['offset']
|
||||
|
||||
@@ -28,21 +28,21 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
|
||||
:time_entries
|
||||
|
||||
test "GET /time_entries.xml should return time entries" do
|
||||
get '/time_entries.xml', {}, credentials('jsmith')
|
||||
get '/time_entries.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'time_entries[type=array] time_entry id', :text => '2'
|
||||
end
|
||||
|
||||
test "GET /time_entries.xml with limit should return limited results" do
|
||||
get '/time_entries.xml?limit=2', {}, credentials('jsmith')
|
||||
get '/time_entries.xml?limit=2', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'time_entries[type=array] time_entry', 2
|
||||
end
|
||||
|
||||
test "GET /time_entries/:id.xml should return the time entry" do
|
||||
get '/time_entries/2.xml', {}, credentials('jsmith')
|
||||
get '/time_entries/2.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'time_entry id', :text => '2'
|
||||
@@ -53,7 +53,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
|
||||
project.close
|
||||
project.save!
|
||||
|
||||
get '/time_entries/2.xml', {}, credentials('jsmith')
|
||||
get '/time_entries/2.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'time_entry id', :text => '2'
|
||||
@@ -61,7 +61,9 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "POST /time_entries.xml with issue_id should create time entry" do
|
||||
assert_difference 'TimeEntry.count' do
|
||||
post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, 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
|
||||
@@ -79,9 +81,11 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
|
||||
field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string')
|
||||
|
||||
assert_difference 'TimeEntry.count' do
|
||||
post '/time_entries.xml', {:time_entry => {
|
||||
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'}]
|
||||
}}, credentials('jsmith')
|
||||
}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :created
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -92,7 +96,9 @@ 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', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, 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
|
||||
@@ -108,7 +114,9 @@ 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', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith')
|
||||
post '/time_entries.xml',
|
||||
:params => {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -118,7 +126,9 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
|
||||
|
||||
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', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith')
|
||||
put '/time_entries/2.xml',
|
||||
:params => {:time_entry => {:comments => 'API Update'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
@@ -127,7 +137,9 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "PUT /time_entries/:id.xml with invalid parameters should return errors" do
|
||||
assert_no_difference 'TimeEntry.count' do
|
||||
put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith')
|
||||
put '/time_entries/2.xml',
|
||||
:params => {:time_entry => {:hours => '', :comments => 'API Update'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
@@ -137,7 +149,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "DELETE /time_entries/:id.xml should destroy time entry" do
|
||||
assert_difference 'TimeEntry.count', -1 do
|
||||
delete '/time_entries/2.xml', {}, credentials('jsmith')
|
||||
delete '/time_entries/2.xml', :headers => credentials('jsmith')
|
||||
end
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
|
||||
@@ -21,7 +21,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
|
||||
fixtures :users, :email_addresses, :members, :member_roles, :roles, :projects
|
||||
|
||||
test "GET /users.xml should return users" do
|
||||
get '/users.xml', {}, credentials('admin')
|
||||
get '/users.xml', :headers => credentials('admin')
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', response.content_type
|
||||
@@ -31,7 +31,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /users.json should return users" do
|
||||
get '/users.json', {}, credentials('admin')
|
||||
get '/users.json', :headers => credentials('admin')
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/json', response.content_type
|
||||
@@ -84,56 +84,58 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /users/current.xml should return current user" do
|
||||
get '/users/current.xml', {}, credentials('jsmith')
|
||||
get '/users/current.xml', :headers => credentials('jsmith')
|
||||
|
||||
assert_select 'user id', :text => '2'
|
||||
end
|
||||
|
||||
test "GET /users/:id should not return login for other user" do
|
||||
get '/users/3.xml', {}, credentials('jsmith')
|
||||
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', {}, credentials('jsmith')
|
||||
get '/users/2.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_select 'user login', :text => 'jsmith'
|
||||
end
|
||||
|
||||
test "GET /users/:id should not return api_key for other user" do
|
||||
get '/users/3.xml', {}, credentials('jsmith')
|
||||
get '/users/3.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_select 'user api_key', 0
|
||||
end
|
||||
|
||||
test "GET /users/:id should return api_key for current user" do
|
||||
get '/users/2.xml', {}, credentials('jsmith')
|
||||
get '/users/2.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_select 'user api_key', :text => User.find(2).api_key
|
||||
end
|
||||
|
||||
test "GET /users/:id should not return status for standard user" do
|
||||
get '/users/3.xml', {}, credentials('jsmith')
|
||||
get '/users/3.xml', :headers => credentials('jsmith')
|
||||
assert_response :success
|
||||
assert_select 'user status', 0
|
||||
end
|
||||
|
||||
test "GET /users/:id should return status for administrators" do
|
||||
get '/users/2.xml', {}, credentials('admin')
|
||||
get '/users/2.xml', :headers => credentials('admin')
|
||||
assert_response :success
|
||||
assert_select 'user status', :text => User.find(1).status.to_s
|
||||
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',
|
||||
:mail => 'foo@example.net', :password => 'secret123',
|
||||
:mail_notification => 'only_assigned'}
|
||||
:mail_notification => 'only_assigned'
|
||||
}
|
||||
},
|
||||
credentials('admin')
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
user = User.order('id DESC').first
|
||||
@@ -152,13 +154,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
|
||||
|
||||
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',
|
||||
:mail => 'foo@example.net', :password => 'secret123',
|
||||
:mail_notification => 'only_assigned'}
|
||||
:mail_notification => 'only_assigned'
|
||||
}
|
||||
},
|
||||
credentials('admin')
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
user = User.order('id DESC').first
|
||||
@@ -178,7 +182,13 @@ 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', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin')
|
||||
post '/users.xml',
|
||||
:params => {
|
||||
:user =>{
|
||||
:login => 'foo', :lastname => 'Lastname', :mail => 'foo'
|
||||
}
|
||||
},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
@@ -188,7 +198,13 @@ 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', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin')
|
||||
post '/users.json',
|
||||
:params => {
|
||||
:user => {
|
||||
:login => 'foo', :lastname => 'Lastname', :mail => 'foo'
|
||||
}
|
||||
},
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
@@ -201,12 +217,14 @@ 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'}
|
||||
:mail => 'jsmith@somenet.foo'
|
||||
}
|
||||
},
|
||||
credentials('admin')
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
user = User.find(2)
|
||||
@@ -222,12 +240,14 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
|
||||
|
||||
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'}
|
||||
:mail => 'jsmith@somenet.foo'
|
||||
}
|
||||
},
|
||||
credentials('admin')
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
user = User.find(2)
|
||||
@@ -243,12 +263,14 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
|
||||
|
||||
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'}
|
||||
:mail => 'foo'
|
||||
}
|
||||
},
|
||||
credentials('admin')
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
@@ -258,12 +280,14 @@ 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'}
|
||||
:mail => 'foo'
|
||||
}
|
||||
},
|
||||
credentials('admin')
|
||||
:headers => credentials('admin')
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
@@ -276,7 +300,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
|
||||
|
||||
test "DELETE /users/:id.xml should delete the user" do
|
||||
assert_difference('User.count', -1) do
|
||||
delete '/users/2.xml', {}, credentials('admin')
|
||||
delete '/users/2.xml', :headers => credentials('admin')
|
||||
end
|
||||
|
||||
assert_response :ok
|
||||
@@ -285,7 +309,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
|
||||
|
||||
test "DELETE /users/:id.json should delete the user" do
|
||||
assert_difference('User.count', -1) do
|
||||
delete '/users/2.json', {}, credentials('admin')
|
||||
delete '/users/2.json', :headers => credentials('admin')
|
||||
end
|
||||
|
||||
assert_response :ok
|
||||
|
||||
@@ -40,7 +40,9 @@ 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', {:version => {:name => 'API test'}}, credentials('jsmith')
|
||||
post '/projects/1/versions.xml',
|
||||
:params => {:version => {:name => 'API test'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
version = Version.order('id DESC').first
|
||||
@@ -53,7 +55,9 @@ 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', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith')
|
||||
post '/projects/1/versions.xml',
|
||||
:params => {:version => {:name => 'API test', :due_date => '2012-01-24'}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
version = Version.order('id DESC').first
|
||||
@@ -69,14 +73,16 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
|
||||
field = VersionCustomField.generate!
|
||||
|
||||
assert_difference 'Version.count' do
|
||||
post '/projects/1/versions.xml', {
|
||||
post '/projects/1/versions.xml',
|
||||
:params => {
|
||||
:version => {
|
||||
:name => 'API test',
|
||||
:custom_fields => [
|
||||
{'id' => field.id.to_s, 'value' => 'Some value'}
|
||||
]
|
||||
}
|
||||
}, credentials('jsmith')
|
||||
},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
version = Version.order('id DESC').first
|
||||
@@ -90,7 +96,9 @@ 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', {:version => {:name => ''}}, credentials('jsmith')
|
||||
post '/projects/1/versions.xml',
|
||||
:params => {:version => {:name => ''}},
|
||||
:headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
@@ -110,7 +118,9 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "PUT /versions/:id.xml should update the version" do
|
||||
put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
|
||||
put '/versions/2.xml',
|
||||
:params => {:version => {:name => 'API update'}},
|
||||
:headers => credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
@@ -119,7 +129,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "DELETE /versions/:id.xml should destroy the version" do
|
||||
assert_difference 'Version.count', -1 do
|
||||
delete '/versions/3.xml', {}, credentials('jsmith')
|
||||
delete '/versions/3.xml', :headers => credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_response :ok
|
||||
|
||||
@@ -72,7 +72,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
end
|
||||
|
||||
test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
|
||||
get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith')
|
||||
get '/projects/ecookbook/wiki/Invalid_Page.xml', :headers => credentials('jsmith')
|
||||
assert_response 404
|
||||
assert_equal 'application/xml', response.content_type
|
||||
end
|
||||
@@ -104,8 +104,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
assert_no_difference 'WikiPage.count' do
|
||||
assert_difference 'WikiContent::Version.count' do
|
||||
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
|
||||
{:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
|
||||
credentials('jsmith')
|
||||
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
|
||||
:headers => credentials('jsmith')
|
||||
assert_response 200
|
||||
end
|
||||
end
|
||||
@@ -121,8 +121,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
assert_no_difference 'WikiPage.count' do
|
||||
assert_difference 'WikiContent::Version.count' do
|
||||
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
|
||||
{:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
|
||||
credentials('jsmith')
|
||||
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
|
||||
:headers => credentials('jsmith')
|
||||
assert_response 200
|
||||
end
|
||||
end
|
||||
@@ -138,8 +138,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
assert_no_difference 'WikiPage.count' do
|
||||
assert_no_difference 'WikiContent::Version.count' do
|
||||
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
|
||||
{:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
|
||||
credentials('jsmith')
|
||||
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
|
||||
:headers => credentials('jsmith')
|
||||
assert_response 409
|
||||
end
|
||||
end
|
||||
@@ -149,8 +149,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
assert_difference 'WikiPage.count' do
|
||||
assert_difference 'WikiContent::Version.count' do
|
||||
put '/projects/ecookbook/wiki/New_page_from_API.xml',
|
||||
{:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
|
||||
credentials('jsmith')
|
||||
:params => {:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
|
||||
:headers => credentials('jsmith')
|
||||
assert_response 201
|
||||
end
|
||||
end
|
||||
@@ -170,9 +170,9 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
assert_difference 'WikiPage.count' do
|
||||
assert_difference 'WikiContent::Version.count' do
|
||||
put '/projects/ecookbook/wiki/New_page_from_API.xml',
|
||||
{:wiki_page => {:text => 'New content from API with Attachments', :comments => 'API create with Attachments',
|
||||
:params => {:wiki_page => {:text => 'New content from API with Attachments', :comments => 'API create with Attachments',
|
||||
:uploads => [:token => attachment.token, :filename => 'testfile.txt', :content_type => "text/plain"]}},
|
||||
credentials('jsmith')
|
||||
:headers => credentials('jsmith')
|
||||
assert_response 201
|
||||
end
|
||||
end
|
||||
@@ -187,8 +187,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
assert_difference 'WikiPage.count' do
|
||||
assert_difference 'WikiContent::Version.count' do
|
||||
put '/projects/ecookbook/wiki/New_subpage_from_API.xml',
|
||||
{:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
|
||||
credentials('jsmith')
|
||||
:params => {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
|
||||
:headers => credentials('jsmith')
|
||||
assert_response 201
|
||||
end
|
||||
end
|
||||
@@ -200,7 +200,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', {}, credentials('jsmith')
|
||||
delete '/projects/ecookbook/wiki/CookBook_documentation.xml', :headers => credentials('jsmith')
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
|
||||
@@ -32,21 +32,21 @@ class ApplicationTest < Redmine::IntegrationTest
|
||||
Setting.default_language = 'en'
|
||||
|
||||
# a french user
|
||||
get '/projects', { }, 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
|
||||
get '/projects', :headers => {'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'}
|
||||
assert_response :success
|
||||
assert_select 'h2', :text => 'Projets'
|
||||
assert_equal :fr, current_language
|
||||
assert_select "html[lang=?]", "fr"
|
||||
|
||||
# then an italien user
|
||||
get '/projects', { }, 'HTTP_ACCEPT_LANGUAGE' => 'it;q=0.8,en-us;q=0.5,en;q=0.3'
|
||||
get '/projects', :headers => {'HTTP_ACCEPT_LANGUAGE' => 'it;q=0.8,en-us;q=0.5,en;q=0.3'}
|
||||
assert_response :success
|
||||
assert_select 'h2', :text => 'Progetti'
|
||||
assert_equal :it, current_language
|
||||
assert_select "html[lang=?]", "it"
|
||||
|
||||
# not a supported language: default language should be used
|
||||
get '/projects', { }, 'HTTP_ACCEPT_LANGUAGE' => 'zz'
|
||||
get '/projects', :headers => {'HTTP_ACCEPT_LANGUAGE' => 'zz'}
|
||||
assert_response :success
|
||||
assert_select 'h2', :text => 'Projects'
|
||||
assert_select "html[lang=?]", "en"
|
||||
@@ -80,7 +80,7 @@ class ApplicationTest < Redmine::IntegrationTest
|
||||
def test_localization_should_be_set_correctly_on_invalid_token
|
||||
ActionController::Base.allow_forgery_protection = true
|
||||
Setting.default_language = 'en'
|
||||
post '/issues', { }, 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
|
||||
post '/issues', :headers => {'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'}
|
||||
assert_response 422
|
||||
assert_equal :fr, current_language
|
||||
assert_select "html[lang=?]", "fr"
|
||||
|
||||
@@ -28,7 +28,9 @@ class AttachmentsTest < Redmine::IntegrationTest
|
||||
def test_upload_should_set_default_content_type
|
||||
log_user('jsmith', 'jsmith')
|
||||
assert_difference 'Attachment.count' do
|
||||
post "/uploads.js?attachment_id=1&filename=foo.txt", "File content", {"CONTENT_TYPE" => 'application/octet-stream'}
|
||||
post "/uploads.js?attachment_id=1&filename=foo.txt",
|
||||
:params => "File content",
|
||||
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}
|
||||
assert_response :success
|
||||
end
|
||||
attachment = Attachment.order(:id => :desc).first
|
||||
@@ -38,7 +40,9 @@ class AttachmentsTest < Redmine::IntegrationTest
|
||||
def test_upload_should_accept_content_type_param
|
||||
log_user('jsmith', 'jsmith')
|
||||
assert_difference 'Attachment.count' do
|
||||
post "/uploads.js?attachment_id=1&filename=foo&content_type=image/jpeg", "File content", {"CONTENT_TYPE" => 'application/octet-stream'}
|
||||
post "/uploads.js?attachment_id=1&filename=foo&content_type=image/jpeg",
|
||||
:params => "File content",
|
||||
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}
|
||||
assert_response :success
|
||||
end
|
||||
attachment = Attachment.order(:id => :desc).first
|
||||
@@ -51,7 +55,7 @@ class AttachmentsTest < Redmine::IntegrationTest
|
||||
token = ajax_upload('myupload.txt', 'File content')
|
||||
|
||||
assert_difference 'Issue.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {:tracker_id => 1, :subject => 'Issue with upload'},
|
||||
:attachments => {'1' => {:filename => 'myupload.txt', :description => 'My uploaded file', :token => token}}
|
||||
}
|
||||
@@ -73,7 +77,7 @@ class AttachmentsTest < Redmine::IntegrationTest
|
||||
|
||||
token = ajax_upload('myupload.jpg', 'JPEG content')
|
||||
|
||||
post '/issues/preview/new/ecookbook', {
|
||||
post '/issues/preview/new/ecookbook', :params => {
|
||||
:issue => {:tracker_id => 1, :description => 'Inline upload: !myupload.jpg!'},
|
||||
:attachments => {'1' => {:filename => 'myupload.jpg', :description => 'My uploaded file', :token => token}}
|
||||
}
|
||||
@@ -93,7 +97,7 @@ class AttachmentsTest < Redmine::IntegrationTest
|
||||
token = ajax_upload('myupload.txt', 'File content')
|
||||
|
||||
assert_no_difference 'Issue.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {:tracker_id => 1, :subject => ''},
|
||||
:attachments => {'1' => {:filename => 'myupload.txt', :description => 'My uploaded file', :token => token}}
|
||||
}
|
||||
@@ -104,7 +108,7 @@ class AttachmentsTest < Redmine::IntegrationTest
|
||||
assert_select 'input[name=?][value=?]', 'attachments[p0][description]', 'My uploaded file'
|
||||
|
||||
assert_difference 'Issue.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {:tracker_id => 1, :subject => 'Issue with upload'},
|
||||
:attachments => {'p0' => {:filename => 'myupload.txt', :description => 'My uploaded file', :token => token}}
|
||||
}
|
||||
@@ -154,7 +158,9 @@ class AttachmentsTest < Redmine::IntegrationTest
|
||||
|
||||
def ajax_upload(filename, content, attachment_id=1)
|
||||
assert_difference 'Attachment.count' do
|
||||
post "/uploads.js?attachment_id=#{attachment_id}&filename=#{filename}", content, {"CONTENT_TYPE" => 'application/octet-stream'}
|
||||
post "/uploads.js?attachment_id=#{attachment_id}&filename=#{filename}",
|
||||
:params => content,
|
||||
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}
|
||||
assert_response :success
|
||||
assert_equal 'text/javascript', response.content_type
|
||||
end
|
||||
|
||||
@@ -42,8 +42,9 @@ class IssuesTest < Redmine::IntegrationTest
|
||||
assert_response :success
|
||||
|
||||
issue = new_record(Issue) do
|
||||
post '/projects/ecookbook/issues',
|
||||
:issue => { :tracker_id => "1",
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {
|
||||
:tracker_id => "1",
|
||||
:start_date => "2006-12-26",
|
||||
:priority_id => "4",
|
||||
:subject => "new test issue",
|
||||
@@ -51,8 +52,10 @@ class IssuesTest < Redmine::IntegrationTest
|
||||
:description => "new issue",
|
||||
:done_ratio => "0",
|
||||
:due_date => "",
|
||||
:assigned_to_id => "" },
|
||||
:custom_fields => {'2' => 'Value for field 2'}
|
||||
:assigned_to_id => "",
|
||||
:custom_field_values => {'2' => 'Value for field 2'}
|
||||
}
|
||||
}
|
||||
end
|
||||
# check redirection
|
||||
assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
|
||||
@@ -68,7 +71,12 @@ class IssuesTest < Redmine::IntegrationTest
|
||||
Role.anonymous.remove_permission! :add_issues
|
||||
|
||||
assert_no_difference 'Issue.count' do
|
||||
post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
|
||||
post '/projects/1/issues', :params => {
|
||||
:issue => {
|
||||
:tracker_id => "1",
|
||||
:subject => "new test issue"
|
||||
}
|
||||
}
|
||||
end
|
||||
assert_response 302
|
||||
end
|
||||
@@ -78,7 +86,12 @@ class IssuesTest < Redmine::IntegrationTest
|
||||
Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [3])
|
||||
|
||||
issue = new_record(Issue) do
|
||||
post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
|
||||
post '/projects/1/issues', :params => {
|
||||
:issue => {
|
||||
:tracker_id => "1",
|
||||
:subject => "new test issue"
|
||||
}
|
||||
}
|
||||
assert_response 302
|
||||
end
|
||||
assert_equal User.anonymous, issue.author
|
||||
@@ -90,9 +103,10 @@ class IssuesTest < Redmine::IntegrationTest
|
||||
set_tmp_attachments_directory
|
||||
|
||||
attachment = new_record(Attachment) do
|
||||
put '/issues/1',
|
||||
:notes => 'Some notes',
|
||||
put '/issues/1', :params => {
|
||||
:issue => {:notes => 'Some notes'},
|
||||
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
|
||||
}
|
||||
assert_redirected_to "/issues/1"
|
||||
end
|
||||
|
||||
@@ -160,7 +174,9 @@ class IssuesTest < Redmine::IntegrationTest
|
||||
end
|
||||
|
||||
def test_other_formats_links_on_index_without_project_id_in_url
|
||||
get '/issues', :project_id => 'ecookbook'
|
||||
get '/issues', :params => {
|
||||
:project_id => 'ecookbook'
|
||||
}
|
||||
|
||||
%w(Atom PDF CSV).each do |format|
|
||||
assert_select 'a[rel=nofollow][href=?]', "/issues.#{format.downcase}?project_id=ecookbook", :text => format
|
||||
@@ -225,13 +241,14 @@ class IssuesTest < Redmine::IntegrationTest
|
||||
|
||||
# Create issue
|
||||
issue = new_record(Issue) do
|
||||
post '/projects/ecookbook/issues',
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {
|
||||
:tracker_id => '1',
|
||||
:priority_id => '4',
|
||||
:subject => 'Issue with user custom field',
|
||||
:custom_field_values => {@field.id.to_s => users.first.id.to_s}
|
||||
}
|
||||
}
|
||||
assert_response 302
|
||||
end
|
||||
|
||||
@@ -250,11 +267,12 @@ class IssuesTest < Redmine::IntegrationTest
|
||||
with_settings :default_language => 'en' do
|
||||
# Update issue
|
||||
assert_difference 'Journal.count' do
|
||||
put "/issues/#{issue.id}",
|
||||
:notes => 'Updating custom field',
|
||||
put "/issues/#{issue.id}", :params => {
|
||||
:issue => {
|
||||
:notes => 'Updating custom field',
|
||||
:custom_field_values => {@field.id.to_s => new_tester.id.to_s}
|
||||
}
|
||||
}
|
||||
assert_redirected_to "/issues/#{issue.id}"
|
||||
end
|
||||
# Issue view
|
||||
@@ -264,20 +282,23 @@ class IssuesTest < Redmine::IntegrationTest
|
||||
end
|
||||
|
||||
def test_update_using_invalid_http_verbs
|
||||
log_user('jsmith', 'jsmith')
|
||||
subject = 'Updated by an invalid http verb'
|
||||
|
||||
get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
|
||||
get '/issues/update/1', :params => {:issue => {:subject => subject}}
|
||||
assert_response 404
|
||||
assert_not_equal subject, Issue.find(1).subject
|
||||
|
||||
post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
|
||||
post '/issues/1', :params => {:issue => {:subject => subject}}
|
||||
assert_response 404
|
||||
assert_not_equal subject, Issue.find(1).subject
|
||||
end
|
||||
|
||||
def test_get_watch_should_be_invalid
|
||||
log_user('jsmith', 'jsmith')
|
||||
|
||||
assert_no_difference 'Watcher.count' do
|
||||
get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
|
||||
get '/watchers/watch?object_type=issue&object_id=1'
|
||||
assert_response 404
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,7 +51,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
|
||||
def test_create_with_attachment
|
||||
issue = new_record(Issue) do
|
||||
assert_difference 'Attachment.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {
|
||||
:subject => "Subject",
|
||||
:custom_field_values => {
|
||||
@@ -91,7 +91,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
|
||||
def test_create_without_attachment
|
||||
issue = new_record(Issue) do
|
||||
assert_no_difference 'Attachment.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {
|
||||
:subject => "Subject",
|
||||
:custom_field_values => {
|
||||
@@ -117,7 +117,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
|
||||
def test_failure_on_create_should_preserve_attachment
|
||||
attachment = new_record(Attachment) do
|
||||
assert_no_difference 'Issue.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {
|
||||
:subject => "",
|
||||
:custom_field_values => {
|
||||
@@ -136,7 +136,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
|
||||
|
||||
issue = new_record(Issue) do
|
||||
assert_no_difference 'Attachment.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {
|
||||
:subject => "Subject",
|
||||
:custom_field_values => {
|
||||
@@ -160,7 +160,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
|
||||
|
||||
attachment = new_record(Attachment) do
|
||||
assert_difference 'Issue.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {
|
||||
:subject => "Blank",
|
||||
:custom_field_values => {
|
||||
@@ -179,7 +179,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
|
||||
|
||||
attachment = new_record(Attachment) do
|
||||
assert_no_difference 'Issue.count' do
|
||||
post '/projects/ecookbook/issues', {
|
||||
post '/projects/ecookbook/issues', :params => {
|
||||
:issue => {
|
||||
:subject => "Blank",
|
||||
:custom_field_values => {
|
||||
|
||||
@@ -107,7 +107,7 @@ VIEW
|
||||
|
||||
def test_controller_hook_context_should_include_request
|
||||
Redmine::Hook.add_listener(ContextTestHook)
|
||||
post '/login', :username => 'admin', :password => 'admin'
|
||||
post '/login', :params => {:username => 'admin', :password => 'admin'}
|
||||
assert_not_nil ContextTestHook.context
|
||||
context = ContextTestHook.context
|
||||
assert_kind_of ActionDispatch::Request, context[:request]
|
||||
|
||||
@@ -29,7 +29,8 @@ class MenuManagerTest < Redmine::IntegrationTest
|
||||
:enabled_modules
|
||||
|
||||
def test_project_menu_with_specific_locale
|
||||
get '/projects/ecookbook/issues', { }, 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
|
||||
get '/projects/ecookbook/issues',
|
||||
:headers => {'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'}
|
||||
|
||||
assert_select 'div#main-menu' do
|
||||
assert_select 'li a.activity[href=?]', '/projects/ecookbook/activity', :text => ll('fr', :label_activity)
|
||||
|
||||
@@ -43,8 +43,10 @@ class ProjectsTest < Redmine::IntegrationTest
|
||||
end
|
||||
|
||||
def test_modules_should_not_allow_get
|
||||
log_user("admin", "admin")
|
||||
|
||||
assert_no_difference 'EnabledModule.count' do
|
||||
get '/projects/1/modules', {:enabled_module_names => ['']}, credentials('jsmith')
|
||||
get '/projects/1/modules', :params => {:enabled_module_names => ['']}
|
||||
assert_response 404
|
||||
end
|
||||
end
|
||||
|
||||
@@ -69,9 +69,11 @@ class SessionsTest < Redmine::IntegrationTest
|
||||
|
||||
get '/my/password'
|
||||
assert_response 200
|
||||
post '/my/password', :password => 'jsmith',
|
||||
post '/my/password', :params => {
|
||||
:password => 'jsmith',
|
||||
:new_password => 'secret123',
|
||||
:new_password_confirmation => 'secret123'
|
||||
}
|
||||
assert_response 302
|
||||
assert_not_equal token, session[:tk]
|
||||
|
||||
@@ -81,10 +83,10 @@ class SessionsTest < Redmine::IntegrationTest
|
||||
|
||||
def test_simultaneous_sessions_should_be_valid
|
||||
first = open_session do |session|
|
||||
session.post "/login", :username => 'jsmith', :password => 'jsmith'
|
||||
session.post "/login", :params => {:username => 'jsmith', :password => 'jsmith'}
|
||||
end
|
||||
other = open_session do |session|
|
||||
session.post "/login", :username => 'jsmith', :password => 'jsmith'
|
||||
session.post "/login", :params => {:username => 'jsmith', :password => 'jsmith'}
|
||||
end
|
||||
|
||||
first.get '/my/account'
|
||||
|
||||
@@ -15,11 +15,12 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
log_user("admin", "admin")
|
||||
get "/users/new"
|
||||
assert_response :success
|
||||
post "/users",
|
||||
post "/users", :params => {
|
||||
:user => { :login => "psmith", :firstname => "Paul",
|
||||
:lastname => "Smith", :mail => "psmith@somenet.foo",
|
||||
:language => "en", :password => "psmith09",
|
||||
:password_confirmation => "psmith09" }
|
||||
}
|
||||
assert_response 302
|
||||
|
||||
user = User.find_by_login("psmith")
|
||||
@@ -31,23 +32,25 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
expire_sudo_mode!
|
||||
get "/users/new"
|
||||
assert_response :success
|
||||
post "/users",
|
||||
post "/users", :params => {
|
||||
:user => { :login => "psmith", :firstname => "Paul",
|
||||
:lastname => "Smith", :mail => "psmith@somenet.foo",
|
||||
:language => "en", :password => "psmith09",
|
||||
:password_confirmation => "psmith09" }
|
||||
}
|
||||
assert_response :success
|
||||
assert_nil User.find_by_login("psmith")
|
||||
|
||||
assert_select 'input[name=?][value=?]', 'user[login]', 'psmith'
|
||||
assert_select 'input[name=?][value=?]', 'user[firstname]', 'Paul'
|
||||
|
||||
post "/users",
|
||||
post "/users", :params => {
|
||||
:user => { :login => "psmith", :firstname => "Paul",
|
||||
:lastname => "Smith", :mail => "psmith@somenet.foo",
|
||||
:language => "en", :password => "psmith09",
|
||||
:password_confirmation => "psmith09" },
|
||||
:sudo_password => 'admin'
|
||||
}
|
||||
assert_response 302
|
||||
|
||||
user = User.find_by_login("psmith")
|
||||
@@ -61,19 +64,19 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
assert_response :success
|
||||
|
||||
assert_no_difference 'Member.count' do
|
||||
xhr :post, '/projects/ecookbook/memberships', membership: {role_ids: [1], user_id: 7}
|
||||
post '/projects/ecookbook/memberships', :params => {membership: {role_ids: [1], user_id: 7}}, :xhr => true
|
||||
end
|
||||
|
||||
assert_no_difference 'Member.count' do
|
||||
xhr :post, '/projects/ecookbook/memberships', membership: {role_ids: [1], user_id: 7}, sudo_password: ''
|
||||
post '/projects/ecookbook/memberships', :params => {membership: {role_ids: [1], user_id: 7}, sudo_password: ''}, :xhr => true
|
||||
end
|
||||
|
||||
assert_no_difference 'Member.count' do
|
||||
xhr :post, '/projects/ecookbook/memberships', membership: {role_ids: [1], user_id: 7}, sudo_password: 'wrong'
|
||||
post '/projects/ecookbook/memberships', :params => {membership: {role_ids: [1], user_id: 7}, sudo_password: 'wrong'}, :xhr => true
|
||||
end
|
||||
|
||||
assert_difference 'Member.count' do
|
||||
xhr :post, '/projects/ecookbook/memberships', membership: {role_ids: [1], user_id: 7}, sudo_password: 'admin'
|
||||
post '/projects/ecookbook/memberships', :params => {membership: {role_ids: [1], user_id: 7}, sudo_password: 'admin'}, :xhr => true
|
||||
end
|
||||
assert User.find(7).member_of?(Project.find(1))
|
||||
end
|
||||
@@ -85,19 +88,19 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
assert_response :success
|
||||
|
||||
assert_no_difference 'Member.count' do
|
||||
post '/projects/ecookbook/memberships', membership: {role_ids: [1], user_id: 7}
|
||||
post '/projects/ecookbook/memberships', :params => {membership: {role_ids: [1], user_id: 7}}
|
||||
end
|
||||
|
||||
assert_no_difference 'Member.count' do
|
||||
post '/projects/ecookbook/memberships', membership: {role_ids: [1], user_id: 7}, sudo_password: ''
|
||||
post '/projects/ecookbook/memberships', :params => {membership: {role_ids: [1], user_id: 7}, sudo_password: ''}
|
||||
end
|
||||
|
||||
assert_no_difference 'Member.count' do
|
||||
post '/projects/ecookbook/memberships', membership: {role_ids: [1], user_id: 7}, sudo_password: 'wrong'
|
||||
post '/projects/ecookbook/memberships', :params => {membership: {role_ids: [1], user_id: 7}, sudo_password: 'wrong'}
|
||||
end
|
||||
|
||||
assert_difference 'Member.count' do
|
||||
post '/projects/ecookbook/memberships', membership: {role_ids: [1], user_id: 7}, sudo_password: 'admin'
|
||||
post '/projects/ecookbook/memberships', :params => {membership: {role_ids: [1], user_id: 7}, sudo_password: 'admin'}
|
||||
end
|
||||
|
||||
assert_redirected_to '/projects/ecookbook/settings/members'
|
||||
@@ -113,20 +116,20 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
get '/roles/new'
|
||||
assert_response :success
|
||||
|
||||
post '/roles', role: { }
|
||||
post '/roles', :params => {role: { }}
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Confirm your password to continue'
|
||||
assert_select 'form[action="/roles"]'
|
||||
assert_select '#flash_error', 0
|
||||
|
||||
post '/roles', role: { name: 'new role', issues_visibility: 'all' }
|
||||
post '/roles', :params => {role: { name: 'new role', issues_visibility: 'all' }}
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Confirm your password to continue'
|
||||
assert_select 'form[action="/roles"]'
|
||||
assert_select 'input[type=hidden][name=?][value=?]', 'role[name]', 'new role'
|
||||
assert_select '#flash_error', 0
|
||||
|
||||
post '/roles', role: { name: 'new role', issues_visibility: 'all' }, sudo_password: 'wrong'
|
||||
post '/roles', :params => {role: { name: 'new role', issues_visibility: 'all' }, sudo_password: 'wrong'}
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Confirm your password to continue'
|
||||
assert_select 'form[action="/roles"]'
|
||||
@@ -134,7 +137,7 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
assert_select '#flash_error'
|
||||
|
||||
assert_difference 'Role.count' do
|
||||
post '/roles', role: { name: 'new role', issues_visibility: 'all', assignable: '1', permissions: %w(view_calendar) }, sudo_password: 'admin'
|
||||
post '/roles', :params => {role: { name: 'new role', issues_visibility: 'all', assignable: '1', permissions: %w(view_calendar) }, sudo_password: 'admin'}
|
||||
end
|
||||
assert_redirected_to '/roles'
|
||||
end
|
||||
@@ -144,7 +147,7 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
expire_sudo_mode!
|
||||
get '/my/account'
|
||||
assert_response :success
|
||||
post '/my/account', user: { mail: 'newmail@test.com' }
|
||||
post '/my/account', :params => {user: { mail: 'newmail@test.com' }}
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Confirm your password to continue'
|
||||
assert_select 'form[action="/my/account"]'
|
||||
@@ -152,7 +155,7 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
assert_select '#flash_error', 0
|
||||
|
||||
# wrong password
|
||||
post '/my/account', user: { mail: 'newmail@test.com' }, sudo_password: 'wrong'
|
||||
post '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'wrong'}
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Confirm your password to continue'
|
||||
assert_select 'form[action="/my/account"]'
|
||||
@@ -160,12 +163,12 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
assert_select '#flash_error'
|
||||
|
||||
# correct password
|
||||
post '/my/account', user: { mail: 'newmail@test.com' }, sudo_password: 'jsmith'
|
||||
post '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'jsmith'}
|
||||
assert_redirected_to '/my/account'
|
||||
assert_equal 'newmail@test.com', User.find_by_login('jsmith').mail
|
||||
|
||||
# sudo mode should now be active and not require password again
|
||||
post '/my/account', user: { mail: 'even.newer.mail@test.com' }
|
||||
post '/my/account', :params => {user: { mail: 'even.newer.mail@test.com' }}
|
||||
assert_redirected_to '/my/account'
|
||||
assert_equal 'even.newer.mail@test.com', User.find_by_login('jsmith').mail
|
||||
end
|
||||
@@ -173,13 +176,14 @@ class SudoModeTest < Redmine::IntegrationTest
|
||||
def test_sudo_mode_should_skip_api_requests
|
||||
with_settings :rest_api_enabled => '1' do
|
||||
assert_difference('User.count') do
|
||||
post '/users.json', {
|
||||
post '/users.json', :params => {
|
||||
:user => {
|
||||
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
|
||||
:mail => 'foo@example.net', :password => 'secret123',
|
||||
:mail_notification => 'only_assigned'}
|
||||
:mail_notification => 'only_assigned'
|
||||
}
|
||||
},
|
||||
credentials('admin')
|
||||
:headers => credentials('admin')
|
||||
|
||||
assert_response :created
|
||||
end
|
||||
|
||||
@@ -21,8 +21,10 @@ class UsersTest < Redmine::IntegrationTest
|
||||
fixtures :users, :email_addresses
|
||||
|
||||
def test_destroy_should_not_accept_get_requests
|
||||
log_user('admin', 'admin')
|
||||
|
||||
assert_no_difference 'User.count' do
|
||||
get '/users/destroy/2', {}, credentials('admin')
|
||||
get '/users/destroy/2'
|
||||
assert_response 404
|
||||
end
|
||||
end
|
||||
|
||||
@@ -343,6 +343,17 @@ module Redmine
|
||||
assert_equal login, User.find(session[:user_id]).login
|
||||
end
|
||||
|
||||
%w(get post patch put delete head).each do |http_method|
|
||||
class_eval %Q"
|
||||
def #{http_method}(path, parameters = nil, headers_or_env = nil)
|
||||
if headers_or_env.nil? && parameters.is_a?(Hash) && (parameters.key?(:params) || parameters.key?(:headers))
|
||||
super path, parameters[:params], parameters[:headers]
|
||||
else
|
||||
super
|
||||
end
|
||||
end"
|
||||
end
|
||||
|
||||
def credentials(user, password=nil)
|
||||
{'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user