context "/attachments/:id" do
context "GET" do
should "return the attachment" do
- get '/attachments/7.xml', {}, :authorization => credentials('jsmith')
+ get '/attachments/7.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'attachment',
context "/attachments/download/:id/:filename" do
context "GET" do
should "return the attachment content" do
- get '/attachments/download/7/archive.zip',
- {}, :authorization => credentials('jsmith')
+ get '/attachments/download/7/archive.zip', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/octet-stream', @response.content_type
set_tmp_attachments_directory
context "with a valid HTTP authentication" do
setup do
@user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
- get "/news.xml", nil, :authorization => credentials(@user.login, 'my_password')
+ get "/news.xml", nil, credentials(@user.login, 'my_password')
end
should_respond_with :unauthorized
setup do
@user = User.generate_with_protected!
@token = Token.generate!(:user => @user, :action => 'api')
- get "/news.xml", nil, :authorization => credentials(@token.value, 'X')
+ get "/news.xml", nil, credentials(@token.value, 'X')
end
should_respond_with :unauthorized
context "with a valid HTTP authentication" do
setup do
@user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
- get "/news.json", nil, :authorization => credentials(@user.login, 'my_password')
+ get "/news.json", nil, credentials(@user.login, 'my_password')
end
should_respond_with :unauthorized
setup do
@user = User.generate_with_protected!
@token = Token.generate!(:user => @user, :action => 'api')
- get "/news.json", nil, :authorization => credentials(@token.value, 'DoesNotMatter')
+ get "/news.json", nil, credentials(@token.value, 'DoesNotMatter')
end
should_respond_with :unauthorized
context "GET /projects/:project_id/issue_categories.xml" do
should "return issue categories" do
- get '/projects/1/issue_categories.xml', {}, :authorization => credentials('jsmith')
+ get '/projects/1/issue_categories.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'issue_categories',
context "GET /issue_categories/2.xml" do
should "return requested issue category" do
- get '/issue_categories/2.xml', {}, :authorization => credentials('jsmith')
+ get '/issue_categories/2.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'issue_category',
context "POST /projects/:project_id/issue_categories.xml" do
should "return create issue category" do
assert_difference 'IssueCategory.count' do
- post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, :authorization => credentials('jsmith')
+ post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, credentials('jsmith')
end
assert_response :created
assert_equal 'application/xml', @response.content_type
context "with invalid parameters" do
should "return errors" do
assert_no_difference 'IssueCategory.count' do
- post '/projects/1/issue_categories.xml', {:issue_category => {:name => ''}}, :authorization => credentials('jsmith')
+ post '/projects/1/issue_categories.xml', {:issue_category => {:name => ''}}, credentials('jsmith')
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
context "with valid parameters" do
should "update issue category" do
assert_no_difference 'IssueCategory.count' do
- put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, :authorization => credentials('jsmith')
+ put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, credentials('jsmith')
end
assert_response :ok
assert_equal 'API Update', IssueCategory.find(2).name
context "with invalid parameters" do
should "return errors" do
assert_no_difference 'IssueCategory.count' do
- put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, :authorization => credentials('jsmith')
+ put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, credentials('jsmith')
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
context "DELETE /issue_categories/1.xml" do
should "destroy issue categories" do
assert_difference 'IssueCategory.count', -1 do
- delete '/issue_categories/1.xml', {}, :authorization => credentials('jsmith')
+ delete '/issue_categories/1.xml', {}, credentials('jsmith')
end
assert_response :ok
assert_nil IssueCategory.find_by_id(1)
assert_difference 'IssueCategory.count', -1 do
assert_difference 'Issue.count(:conditions => {:category_id => 2})', 3 do
- delete '/issue_categories/1.xml', {:reassign_to_id => 2}, :authorization => credentials('jsmith')
+ delete '/issue_categories/1.xml', {:reassign_to_id => 2}, credentials('jsmith')
end
end
assert_response :ok
context "/issues/:issue_id/relations" do
context "GET" do
should "return issue relations" do
- get '/issues/9/relations.xml', {}, :authorization => credentials('jsmith')
+ get '/issues/9/relations.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
context "POST" do
should "create a relation" do
assert_difference('IssueRelation.count') do
- post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, :authorization => credentials('jsmith')
+ post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith')
end
relation = IssueRelation.first(:order => 'id DESC')
context "with failure" do
should "return the errors" do
assert_no_difference('IssueRelation.count') do
- post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, :authorization => credentials('jsmith')
+ post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith')
end
assert_response :unprocessable_entity
context "/relations/:id" do
context "GET" do
should "return the relation" do
- get '/relations/2.xml', {}, :authorization => credentials('jsmith')
+ get '/relations/2.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
context "DELETE" do
should "delete the relation" do
assert_difference('IssueRelation.count', -1) do
- delete '/relations/2.xml', {}, :authorization => credentials('jsmith')
+ delete '/relations/2.xml', {}, credentials('jsmith')
end
assert_response :ok
should "create an issue with the attributes" do
assert_difference('Issue.count') do
- post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith')
+ post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, credentials('jsmith')
end
issue = Issue.first(:order => 'id DESC')
context "POST /issues.xml with failure" do
should "have an errors tag" do
assert_no_difference('Issue.count') do
- post '/issues.xml', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith')
+ post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
end
assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
should "create an issue with the attributes" do
assert_difference('Issue.count') do
- post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith')
+ post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, credentials('jsmith')
end
issue = Issue.first(:order => 'id DESC')
context "POST /issues.json with failure" do
should "have an errors element" do
assert_no_difference('Issue.count') do
- post '/issues.json', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith')
+ post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')
end
json = ActiveSupport::JSON.decode(response.body)
context "PUT /issues/6.xml" do
setup do
@parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}}
- @headers = { :authorization => credentials('jsmith') }
end
should_allow_api_authentication(:put,
should "not create a new issue" do
assert_no_difference('Issue.count') do
- put '/issues/6.xml', @parameters, @headers
+ put '/issues/6.xml', @parameters, credentials('jsmith')
end
end
should "create a new journal" do
assert_difference('Journal.count') do
- put '/issues/6.xml', @parameters, @headers
+ put '/issues/6.xml', @parameters, credentials('jsmith')
end
end
should "add the note to the journal" do
- put '/issues/6.xml', @parameters, @headers
+ put '/issues/6.xml', @parameters, credentials('jsmith')
journal = Journal.last
assert_equal "A new note", journal.notes
end
should "update the issue" do
- put '/issues/6.xml', @parameters, @headers
+ put '/issues/6.xml', @parameters, credentials('jsmith')
issue = Issue.find(6)
assert_equal "API update", issue.subject
context "PUT /issues/3.xml with custom fields" do
setup do
@parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}}
- @headers = { :authorization => credentials('jsmith') }
end
should "update custom fields" do
assert_no_difference('Issue.count') do
- put '/issues/3.xml', @parameters, @headers
+ put '/issues/3.xml', @parameters, credentials('jsmith')
end
issue = Issue.find(3)
context "PUT /issues/6.xml with failed update" do
setup do
@parameters = {:issue => {:subject => ''}}
- @headers = { :authorization => credentials('jsmith') }
end
should "not create a new issue" do
assert_no_difference('Issue.count') do
- put '/issues/6.xml', @parameters, @headers
+ put '/issues/6.xml', @parameters, credentials('jsmith')
end
end
should "not create a new journal" do
assert_no_difference('Journal.count') do
- put '/issues/6.xml', @parameters, @headers
+ put '/issues/6.xml', @parameters, credentials('jsmith')
end
end
should "have an errors tag" do
- put '/issues/6.xml', @parameters, @headers
+ put '/issues/6.xml', @parameters, credentials('jsmith')
assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
end
context "PUT /issues/6.json" do
setup do
@parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}}
- @headers = { :authorization => credentials('jsmith') }
end
should_allow_api_authentication(:put,
should "not create a new issue" do
assert_no_difference('Issue.count') do
- put '/issues/6.json', @parameters, @headers
+ put '/issues/6.json', @parameters, credentials('jsmith')
end
end
should "create a new journal" do
assert_difference('Journal.count') do
- put '/issues/6.json', @parameters, @headers
+ put '/issues/6.json', @parameters, credentials('jsmith')
end
end
should "add the note to the journal" do
- put '/issues/6.json', @parameters, @headers
+ put '/issues/6.json', @parameters, credentials('jsmith')
journal = Journal.last
assert_equal "A new note", journal.notes
end
should "update the issue" do
- put '/issues/6.json', @parameters, @headers
+ put '/issues/6.json', @parameters, credentials('jsmith')
issue = Issue.find(6)
assert_equal "API update", issue.subject
context "PUT /issues/6.json with failed update" do
setup do
@parameters = {:issue => {:subject => ''}}
- @headers = { :authorization => credentials('jsmith') }
end
should "not create a new issue" do
assert_no_difference('Issue.count') do
- put '/issues/6.json', @parameters, @headers
+ put '/issues/6.json', @parameters, credentials('jsmith')
end
end
should "not create a new journal" do
assert_no_difference('Journal.count') do
- put '/issues/6.json', @parameters, @headers
+ put '/issues/6.json', @parameters, credentials('jsmith')
end
end
should "have an errors attribute" do
- put '/issues/6.json', @parameters, @headers
+ put '/issues/6.json', @parameters, credentials('jsmith')
json = ActiveSupport::JSON.decode(response.body)
assert json['errors'].include?(['subject', "can't be blank"])
should "delete the issue" do
assert_difference('Issue.count',-1) do
- delete '/issues/6.xml', {}, :authorization => credentials('jsmith')
+ delete '/issues/6.xml', {}, credentials('jsmith')
end
assert_nil Issue.find_by_id(6)
should "delete the issue" do
assert_difference('Issue.count',-1) do
- delete '/issues/6.json', {}, :authorization => credentials('jsmith')
+ delete '/issues/6.json', {}, credentials('jsmith')
end
assert_nil Issue.find_by_id(6)
should "create a project with the attributes" do
assert_difference('Project.count') do
- post '/projects.xml', @parameters, :authorization => credentials('admin')
+ post '/projects.xml', @parameters, credentials('admin')
end
project = Project.first(:order => 'id DESC')
@parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
assert_difference('Project.count') do
- post '/projects.xml', @parameters, :authorization => credentials('admin')
+ post '/projects.xml', @parameters, credentials('admin')
end
project = Project.first(:order => 'id DESC')
@parameters[:project].merge!({:tracker_ids => [1, 3]})
assert_difference('Project.count') do
- post '/projects.xml', @parameters, :authorization => credentials('admin')
+ post '/projects.xml', @parameters, credentials('admin')
end
project = Project.first(:order => 'id DESC')
context ".xml" do
should "return errors" do
assert_no_difference('Project.count') do
- post '/projects.xml', @parameters, :authorization => credentials('admin')
+ post '/projects.xml', @parameters, credentials('admin')
end
assert_response :unprocessable_entity
should "update the project" do
assert_no_difference 'Project.count' do
- put '/projects/2.xml', @parameters, :authorization => credentials('jsmith')
+ put '/projects/2.xml', @parameters, credentials('jsmith')
end
assert_response :ok
assert_equal 'application/xml', @response.content_type
@parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
assert_no_difference 'Project.count' do
- put '/projects/2.xml', @parameters, :authorization => credentials('admin')
+ put '/projects/2.xml', @parameters, credentials('admin')
end
assert_response :ok
project = Project.find(2)
@parameters[:project].merge!({:tracker_ids => [1, 3]})
assert_no_difference 'Project.count' do
- put '/projects/2.xml', @parameters, :authorization => credentials('admin')
+ put '/projects/2.xml', @parameters, credentials('admin')
end
assert_response :ok
project = Project.find(2)
context ".xml" do
should "return errors" do
assert_no_difference('Project.count') do
- put '/projects/2.xml', @parameters, :authorization => credentials('admin')
+ put '/projects/2.xml', @parameters, credentials('admin')
end
assert_response :unprocessable_entity
should "delete the project" do
assert_difference('Project.count',-1) do
- delete '/projects/2.xml', {}, :authorization => credentials('admin')
+ delete '/projects/2.xml', {}, credentials('admin')
end
assert_response :ok
assert_nil Project.find_by_id(2)
context "GET /time_entries.xml" do
should "return time entries" do
- get '/time_entries.xml', {}, :authorization => credentials('jsmith')
+ get '/time_entries.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'time_entries',
context "with limit" do
should "return limited results" do
- get '/time_entries.xml?limit=2', {}, :authorization => credentials('jsmith')
+ get '/time_entries.xml?limit=2', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'time_entries',
context "GET /time_entries/2.xml" do
should "return requested time entry" do
- get '/time_entries/2.xml', {}, :authorization => credentials('jsmith')
+ get '/time_entries/2.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'time_entry',
context "with issue_id" do
should "return 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'}}, :authorization => credentials('jsmith')
+ post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
end
assert_response :created
assert_equal 'application/xml', @response.content_type
context "with project_id" do
should "return 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'}}, :authorization => credentials('jsmith')
+ post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
end
assert_response :created
assert_equal 'application/xml', @response.content_type
context "with invalid parameters" do
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'}}, :authorization => credentials('jsmith')
+ post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith')
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
context "with valid parameters" do
should "update time entry" do
assert_no_difference 'TimeEntry.count' do
- put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, :authorization => credentials('jsmith')
+ put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith')
end
assert_response :ok
assert_equal 'API Update', TimeEntry.find(2).comments
context "with invalid parameters" do
should "return errors" do
assert_no_difference 'TimeEntry.count' do
- put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, :authorization => credentials('jsmith')
+ put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith')
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
context "DELETE /time_entries/2.xml" do
should "destroy time entry" do
assert_difference 'TimeEntry.count', -1 do
- delete '/time_entries/2.xml', {}, :authorization => credentials('jsmith')
+ delete '/time_entries/2.xml', {}, credentials('jsmith')
end
assert_response :ok
assert_nil TimeEntry.find_by_id(2)
end
should "return current user" do
- get '/users/current.xml', {}, :authorization => credentials('jsmith')
+ get '/users/current.xml', {}, credentials('jsmith')
assert_tag :tag => 'user',
:child => {:tag => 'id', :content => '2'}
should "create a user with the attributes" do
assert_difference('User.count') do
- post '/users.xml', @parameters, :authorization => credentials('admin')
+ post '/users.xml', @parameters, credentials('admin')
end
user = User.first(:order => 'id DESC')
should "create a user with the attributes" do
assert_difference('User.count') do
- post '/users.json', @parameters, :authorization => credentials('admin')
+ post '/users.json', @parameters, credentials('admin')
end
user = User.first(:order => 'id DESC')
context ".xml" do
should "return errors" do
assert_no_difference('User.count') do
- post '/users.xml', @parameters, :authorization => credentials('admin')
+ post '/users.xml', @parameters, credentials('admin')
end
assert_response :unprocessable_entity
context ".json" do
should "return errors" do
assert_no_difference('User.count') do
- post '/users.json', @parameters, :authorization => credentials('admin')
+ post '/users.json', @parameters, credentials('admin')
end
assert_response :unprocessable_entity
should "update user with the attributes" do
assert_no_difference('User.count') do
- put '/users/2.xml', @parameters, :authorization => credentials('admin')
+ put '/users/2.xml', @parameters, credentials('admin')
end
user = User.find(2)
should "update user with the attributes" do
assert_no_difference('User.count') do
- put '/users/2.json', @parameters, :authorization => credentials('admin')
+ put '/users/2.json', @parameters, credentials('admin')
end
user = User.find(2)
context ".xml" do
should "return errors" do
assert_no_difference('User.count') do
- put '/users/2.xml', @parameters, :authorization => credentials('admin')
+ put '/users/2.xml', @parameters, credentials('admin')
end
assert_response :unprocessable_entity
context ".json" do
should "return errors" do
assert_no_difference('User.count') do
- put '/users/2.json', @parameters, :authorization => credentials('admin')
+ put '/users/2.json', @parameters, credentials('admin')
end
assert_response :unprocessable_entity
should "delete user" do
assert_difference('User.count', -1) do
- delete '/users/2.xml', {}, :authorization => credentials('admin')
+ delete '/users/2.xml', {}, credentials('admin')
end
assert_response :ok
should "delete user" do
assert_difference('User.count', -1) do
- delete '/users/2.json', {}, :authorization => credentials('admin')
+ delete '/users/2.json', {}, credentials('admin')
end
assert_response :ok
context "POST" do
should "create the version" do
assert_difference 'Version.count' do
- post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, :authorization => credentials('jsmith')
+ post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith')
end
version = Version.first(:order => 'id DESC')
context "with failure" do
should "return the errors" do
assert_no_difference('Version.count') do
- post '/projects/1/versions.xml', {:version => {:name => ''}}, :authorization => credentials('jsmith')
+ post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith')
end
assert_response :unprocessable_entity
context "PUT" do
should "update the version" do
- put '/versions/2.xml', {:version => {:name => 'API update'}}, :authorization => credentials('jsmith')
+ put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
assert_response :ok
assert_equal 'API update', Version.find(2).name
context "DELETE" do
should "destroy the version" do
assert_difference 'Version.count', -1 do
- delete '/versions/3.xml', {}, :authorization => credentials('jsmith')
+ delete '/versions/3.xml', {}, credentials('jsmith')
end
assert_response :ok
end
def credentials(user, password=nil)
- ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
+ {:authorization => ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)}
end
# Mock out a file
context "with a valid HTTP authentication" do
setup do
@user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password', :admin => true) # Admin so they can access the project
- send(http_method, url, parameters, {:authorization => credentials(@user.login, 'my_password')})
+ send(http_method, url, parameters, credentials(@user.login, 'my_password'))
end
should_respond_with success_code
context "with an invalid HTTP authentication" do
setup do
@user = User.generate_with_protected!
- send(http_method, url, parameters, {:authorization => credentials(@user.login, 'wrong_password')})
+ send(http_method, url, parameters, credentials(@user.login, 'wrong_password'))
end
should_respond_with failure_code
context "without credentials" do
setup do
- send(http_method, url, parameters, {:authorization => ''})
+ send(http_method, url, parameters)
end
should_respond_with failure_code
setup do
@user = User.generate_with_protected!(:admin => true)
@token = Token.generate!(:user => @user, :action => 'api')
- send(http_method, url, parameters, {:authorization => credentials(@token.value, 'X')})
+ send(http_method, url, parameters, credentials(@token.value, 'X'))
end
should_respond_with success_code
setup do
@user = User.generate_with_protected!
@token = Token.generate!(:user => @user, :action => 'feeds')
- send(http_method, url, parameters, {:authorization => credentials(@token.value, 'X')})
+ send(http_method, url, parameters, credentials(@token.value, 'X'))
end
should_respond_with failure_code