Test cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8477 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-01-02 19:59:52 +00:00
parent 395fe0d777
commit 131f258f5f
10 changed files with 79 additions and 85 deletions

View File

@ -40,7 +40,7 @@ class ApiTest::AttachmentsTest < ActionController::IntegrationTest
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',
@ -69,8 +69,7 @@ class ApiTest::AttachmentsTest < ActionController::IntegrationTest
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

View File

@ -41,7 +41,7 @@ class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest
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
@ -55,7 +55,7 @@ class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest
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
@ -84,7 +84,7 @@ class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest
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
@ -98,7 +98,7 @@ class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest
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

View File

@ -30,7 +30,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
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',
@ -40,7 +40,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
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',
@ -51,7 +51,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
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
@ -64,7 +64,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
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
@ -78,7 +78,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
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
@ -88,7 +88,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
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
@ -101,7 +101,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
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)
@ -113,7 +113,7 @@ class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest
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

View File

@ -35,7 +35,7 @@ class ApiTest::IssueRelationsTest < ActionController::IntegrationTest
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
@ -55,7 +55,7 @@ class ApiTest::IssueRelationsTest < ActionController::IntegrationTest
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')
@ -71,7 +71,7 @@ class ApiTest::IssueRelationsTest < ActionController::IntegrationTest
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
@ -84,7 +84,7 @@ class ApiTest::IssueRelationsTest < ActionController::IntegrationTest
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
@ -95,7 +95,7 @@ class ApiTest::IssueRelationsTest < ActionController::IntegrationTest
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

View File

@ -344,7 +344,7 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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')
@ -362,7 +362,7 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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"}
@ -377,7 +377,7 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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')
@ -392,7 +392,7 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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)
@ -404,7 +404,6 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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,
@ -414,25 +413,25 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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
@ -443,12 +442,11 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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)
@ -460,23 +458,22 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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
@ -485,7 +482,6 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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,
@ -495,25 +491,25 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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
@ -524,23 +520,22 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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"])
@ -555,7 +550,7 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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)
@ -570,7 +565,7 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
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)

View File

@ -152,7 +152,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
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')
@ -170,7 +170,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
@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')
@ -181,7 +181,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
@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')
@ -198,7 +198,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
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
@ -223,7 +223,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
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
@ -235,7 +235,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
@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)
@ -246,7 +246,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
@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)
@ -263,7 +263,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
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
@ -283,7 +283,7 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
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)

View File

@ -34,7 +34,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
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',
@ -43,7 +43,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
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',
@ -54,7 +54,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
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',
@ -66,7 +66,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
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
@ -84,7 +84,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
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
@ -102,7 +102,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
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
@ -116,7 +116,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
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
@ -126,7 +126,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
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
@ -139,7 +139,7 @@ class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
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)

View File

@ -60,7 +60,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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'}
@ -91,7 +91,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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')
@ -120,7 +120,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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')
@ -148,7 +148,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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
@ -163,7 +163,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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
@ -199,7 +199,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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)
@ -224,7 +224,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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)
@ -252,7 +252,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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
@ -267,7 +267,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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
@ -290,7 +290,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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
@ -305,7 +305,7 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
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

View File

@ -58,7 +58,7 @@ class ApiTest::VersionsTest < ActionController::IntegrationTest
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')
@ -72,7 +72,7 @@ class ApiTest::VersionsTest < ActionController::IntegrationTest
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
@ -103,7 +103,7 @@ class ApiTest::VersionsTest < ActionController::IntegrationTest
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
@ -113,7 +113,7 @@ class ApiTest::VersionsTest < ActionController::IntegrationTest
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

View File

@ -63,7 +63,7 @@ class ActiveSupport::TestCase
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
@ -244,7 +244,7 @@ class ActiveSupport::TestCase
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
@ -257,7 +257,7 @@ class ActiveSupport::TestCase
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
@ -269,7 +269,7 @@ class ActiveSupport::TestCase
context "without credentials" do
setup do
send(http_method, url, parameters, {:authorization => ''})
send(http_method, url, parameters)
end
should_respond_with failure_code
@ -299,7 +299,7 @@ class ActiveSupport::TestCase
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
@ -314,7 +314,7 @@ class ActiveSupport::TestCase
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