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
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?
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
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!
assert_select 'input[name=new_password]'
assert_select 'input[name=new_password_confirmation]'
- post "/account/lost_password",
- :token => token.value, :new_password => 'newpass123',
- :new_password_confirmation => 'newpass123'
+ 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]
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'
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'
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
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'
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
get '/account/register'
assert_response :success
- post '/account/register',
- :user => {:login => "newuser", :language => "en",
- :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
- :password => "newpass123", :password_confirmation => "newpass123"}
+ post '/account/register', :params => {
+ :user => {
+ :login => "newuser", :language => "en",
+ :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
+ :password => "newpass123", :password_confirmation => "newpass123"
+ }
+ }
assert_redirected_to '/my/account'
follow_redirect!
assert_response :success
def test_register_with_manual_activation
Setting.self_registration = '2'
- post '/account/register',
- :user => {:login => "newuser", :language => "en",
- :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
- :password => "newpass123", :password_confirmation => "newpass123"}
+ post '/account/register', :params => {
+ :user => {
+ :login => "newuser", :language => "en",
+ :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
+ :password => "newpass123", :password_confirmation => "newpass123"
+ }
+ }
assert_redirected_to '/login'
assert !User.find_by_login('newuser').active?
end
Setting.self_registration = '1'
Token.delete_all
- post '/account/register',
- :user => {:login => "newuser", :language => "en",
- :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
- :password => "newpass123", :password_confirmation => "newpass123"}
+ post '/account/register', :params => {
+ :user => {
+ :login => "newuser", :language => "en",
+ :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
+ :password => "newpass123", :password_confirmation => "newpass123"
+ }
+ }
assert_redirected_to '/login'
assert !User.find_by_login('newuser').active?
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
{: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')
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')
# register a new account
assert_difference 'User.count' do
assert_difference 'Token.count' do
- post '/account/register',
- :user => {:login => "newuser", :language => "en",
- :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
- :password => "newpass123", :password_confirmation => "newpass123"}
+ post '/account/register', :params => {
+ :user => {
+ :login => "newuser", :language => "en",
+ :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
+ :password => "newpass123", :password_confirmation => "newpass123"
+ }
+ }
end
end
user = User.order('id desc').first
# 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!
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
get "/users/new"
assert_response :success
- post "/users",
- :user => { :login => "psmith", :firstname => "Paul",
- :lastname => "Smith", :mail => "psmith@somenet.foo",
- :language => "en", :password => "psmith09",
- :password_confirmation => "psmith09" }
+ post "/users", :params => {
+ :user => {
+ :login => "psmith", :firstname => "Paul",
+ :lastname => "Smith", :mail => "psmith@somenet.foo",
+ :language => "en", :password => "psmith09",
+ :password_confirmation => "psmith09"
+ }
+ }
user = User.find_by_login("psmith")
assert_kind_of User, user
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'},
- :password => "psmith09", :password_confirmation => "psmith09"
+ 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
def test_api_should_work_with_protect_from_forgery
ActionController::Base.allow_forgery_protection = true
assert_difference('User.count') do
- post '/users.xml', {
- :user => {
- :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
- :mail => 'foo@example.net', :password => 'secret123'}
- },
- credentials('admin')
+ post '/users.xml',
+ :params => {
+ :user => {
+ :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
+ :mail => 'foo@example.net', :password => 'secret123'}
+ },
+ :headers => credentials('admin')
assert_response 201
end
ensure
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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')
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
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
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
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
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
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
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
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
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
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
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
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
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)
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)
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)
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)
}
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
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
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
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
@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
: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": {
}
}
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
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
}
}
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": {
}
}
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
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": {
}
}
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
: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'
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
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
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
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
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
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
: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
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
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
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
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
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
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
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).
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).
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
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
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
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
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
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)
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
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
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"
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
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
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
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
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)
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)
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
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
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
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
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)
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)
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
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
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"
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"
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
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)
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
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
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
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
# 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
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']
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
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
# 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
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
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
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"]'
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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']
: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'
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'
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
field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string')
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', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}]
- }}, credentials('jsmith')
+ post '/time_entries.xml',
+ :params => {:time_entry => {
+ :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}]
+ }},
+ :headers => credentials('jsmith')
end
assert_response :created
assert_equal 'application/xml', @response.content_type
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
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
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
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
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
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
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
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', {
- :user => {
- :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
- :mail => 'foo@example.net', :password => 'secret123',
- :mail_notification => 'only_assigned'}
+ post '/users.xml',
+ :params => {
+ :user => {
+ :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
+ :mail => 'foo@example.net', :password => 'secret123',
+ :mail_notification => 'only_assigned'
+ }
},
- credentials('admin')
+ :headers => credentials('admin')
end
user = User.order('id DESC').first
test "POST /users.json with valid parameters should create the user" do
assert_difference('User.count') do
- post '/users.json', {
- :user => {
- :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
- :mail => 'foo@example.net', :password => 'secret123',
- :mail_notification => 'only_assigned'}
+ post '/users.json',
+ :params => {
+ :user => {
+ :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
+ :mail => 'foo@example.net', :password => 'secret123',
+ :mail_notification => 'only_assigned'
+ }
},
- credentials('admin')
+ :headers => credentials('admin')
end
user = User.order('id DESC').first
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
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
test "PUT /users/:id.xml with valid parameters should update the user" do
assert_no_difference('User.count') do
- put '/users/2.xml', {
- :user => {
- :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
- :mail => 'jsmith@somenet.foo'}
+ put '/users/2.xml',
+ :params => {
+ :user => {
+ :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
+ :mail => 'jsmith@somenet.foo'
+ }
},
- credentials('admin')
+ :headers => credentials('admin')
end
user = User.find(2)
test "PUT /users/:id.json with valid parameters should update the user" do
assert_no_difference('User.count') do
- put '/users/2.json', {
- :user => {
- :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
- :mail => 'jsmith@somenet.foo'}
+ put '/users/2.json',
+ :params => {
+ :user => {
+ :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
+ :mail => 'jsmith@somenet.foo'
+ }
},
- credentials('admin')
+ :headers => credentials('admin')
end
user = User.find(2)
test "PUT /users/:id.xml with invalid parameters" do
assert_no_difference('User.count') do
- put '/users/2.xml', {
- :user => {
- :login => 'jsmith', :firstname => '', :lastname => 'Lastname',
- :mail => 'foo'}
+ put '/users/2.xml',
+ :params => {
+ :user => {
+ :login => 'jsmith', :firstname => '', :lastname => 'Lastname',
+ :mail => 'foo'
+ }
},
- credentials('admin')
+ :headers => credentials('admin')
end
assert_response :unprocessable_entity
test "PUT /users/:id.json with invalid parameters" do
assert_no_difference('User.count') do
- put '/users/2.json', {
- :user => {
- :login => 'jsmith', :firstname => '', :lastname => 'Lastname',
- :mail => 'foo'}
+ put '/users/2.json',
+ :params => {
+ :user => {
+ :login => 'jsmith', :firstname => '', :lastname => 'Lastname',
+ :mail => 'foo'
+ }
},
- credentials('admin')
+ :headers => credentials('admin')
end
assert_response :unprocessable_entity
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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"
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"
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
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
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}}
}
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}}
}
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}}
}
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}}
}
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
assert_response :success
issue = new_record(Issue) do
- post '/projects/ecookbook/issues',
- :issue => { :tracker_id => "1",
- :start_date => "2006-12-26",
- :priority_id => "4",
- :subject => "new test issue",
- :category_id => "",
- :description => "new issue",
- :done_ratio => "0",
- :due_date => "",
- :assigned_to_id => "" },
- :custom_fields => {'2' => 'Value for field 2'}
+ post '/projects/ecookbook/issues', :params => {
+ :issue => {
+ :tracker_id => "1",
+ :start_date => "2006-12-26",
+ :priority_id => "4",
+ :subject => "new test issue",
+ :category_id => "",
+ :description => "new issue",
+ :done_ratio => "0",
+ :due_date => "",
+ :assigned_to_id => "",
+ :custom_field_values => {'2' => 'Value for field 2'}
+ }
+ }
end
# check redirection
assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
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
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
set_tmp_attachments_directory
attachment = new_record(Attachment) do
- put '/issues/1',
- :notes => 'Some notes',
- :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
+ 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
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
# Create issue
issue = new_record(Issue) do
- post '/projects/ecookbook/issues',
- :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}
+ 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
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 => {
- :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
- }
+ :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
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
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 => {
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 => {
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 => {
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 => {
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 => {
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 => {
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]
: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)
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
get '/my/password'
assert_response 200
- post '/my/password', :password => 'jsmith',
- :new_password => 'secret123',
- :new_password_confirmation => 'secret123'
+ post '/my/password', :params => {
+ :password => 'jsmith',
+ :new_password => 'secret123',
+ :new_password_confirmation => 'secret123'
+ }
assert_response 302
assert_not_equal token, session[:tk]
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'
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")
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")
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
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'
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"]'
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
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"]'
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"]'
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
def test_sudo_mode_should_skip_api_requests
with_settings :rest_api_enabled => '1' do
assert_difference('User.count') do
- post '/users.json', {
- :user => {
- :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
- :mail => 'foo@example.net', :password => 'secret123',
- :mail_notification => 'only_assigned'}
+ post '/users.json', :params => {
+ :user => {
+ :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
+ :mail => 'foo@example.net', :password => 'secret123',
+ :mail_notification => 'only_assigned'
+ }
},
- credentials('admin')
+ :headers => credentials('admin')
assert_response :created
end
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
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