Convert tests to shoulda

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3765 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-06-05 03:52:53 +00:00
parent e94c45d548
commit f484fe8556

View File

@ -45,85 +45,140 @@ class IssuesApiTest < ActionController::IntegrationTest
def setup def setup
Setting.rest_api_enabled = '1' Setting.rest_api_enabled = '1'
end end
def test_index context "/index.xml" do
get '/issues.xml' setup do
assert_response :success get '/issues.xml'
assert_equal 'application/xml', @response.content_type end
should_respond_with :success
should_respond_with_content_type 'application/xml'
end end
def test_index_with_filter context "/index.xml with filter" do
get '/issues.xml?status_id=5' setup do
assert_response :success get '/issues.xml?status_id=5'
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'issues',
:children => { :count => Issue.visible.count(:conditions => {:status_id => 5}),
:only => { :tag => 'issue' } }
end
def test_show
get '/issues/1.xml'
assert_response :success
assert_equal 'application/xml', @response.content_type
end
def test_create
attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}
assert_difference 'Issue.count' do
post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith')
end end
assert_response :created
assert_equal 'application/xml', @response.content_type should_respond_with :success
issue = Issue.first(:order => 'id DESC') should_respond_with_content_type 'application/xml'
attributes.each do |attribute, value| should "show only issues with the status_id" do
assert_equal value, issue.send(attribute) assert_tag :tag => 'issues',
:children => { :count => Issue.visible.count(:conditions => {:status_id => 5}),
:only => { :tag => 'issue' } }
end end
end end
def test_create_failure context "/issues/1.xml" do
attributes = {:project_id => 1} setup do
assert_no_difference 'Issue.count' do get '/issues/1.xml'
post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith')
end end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
end
def test_update should_respond_with :success
attributes = {:subject => 'API update'} should_respond_with_content_type 'application/xml'
assert_no_difference 'Issue.count' do end
assert_difference 'Journal.count' do
put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith') context "POST /issues.xml" do
setup do
@issue_count = Issue.count
@attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}
post '/issues.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
end
should_respond_with :created
should_respond_with_content_type 'application/xml'
should "create an issue with the attributes" do
assert_equal Issue.count, @issue_count + 1
issue = Issue.first(:order => 'id DESC')
@attributes.each do |attribute, value|
assert_equal value, issue.send(attribute)
end end
end end
assert_response :ok
assert_equal 'application/xml', @response.content_type
issue = Issue.find(1)
attributes.each do |attribute, value|
assert_equal value, issue.send(attribute)
end
end end
def test_update_failure context "POST /issues.xml with failure" do
attributes = {:subject => ''} setup do
assert_no_difference 'Issue.count' do @attributes = {:project_id => 1}
assert_no_difference 'Journal.count' do post '/issues.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith') end
end
should_respond_with :unprocessable_entity
should_respond_with_content_type 'application/xml'
should "have an errors tag" do
assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
end end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
end end
def test_destroy context "PUT /issues/1.xml" do
assert_difference 'Issue.count', -1 do setup do
@issue_count = Issue.count
@journal_count = Journal.count
@attributes = {:subject => 'API update'}
put '/issues/1.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
end
should_respond_with :ok
should_respond_with_content_type 'application/xml'
should "not create a new issue" do
assert_equal Issue.count, @issue_count
end
should "create a new journal" do
assert_equal Journal.count, @journal_count + 1
end
should "update the issue" do
issue = Issue.find(1)
@attributes.each do |attribute, value|
assert_equal value, issue.send(attribute)
end
end
end
context "PUT /issues/1.xml with failed update" do
setup do
@attributes = {:subject => ''}
@issue_count = Issue.count
@journal_count = Journal.count
put '/issues/1.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
end
should_respond_with :unprocessable_entity
should_respond_with_content_type 'application/xml'
should "not create a new issue" do
assert_equal Issue.count, @issue_count
end
should "not create a new journal" do
assert_equal Journal.count, @journal_count
end
should "have an errors tag" do
assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
end
end
context "DELETE /issues/1.xml" do
setup do
@issue_count = Issue.count
delete '/issues/1.xml', {}, :authorization => credentials('jsmith') delete '/issues/1.xml', {}, :authorization => credentials('jsmith')
end end
assert_response :ok
assert_equal 'application/xml', @response.content_type should_respond_with :ok
assert_nil Issue.find_by_id(1) should_respond_with_content_type 'application/xml'
should "delete the issue" do
assert_equal Issue.count, @issue_count -1
assert_nil Issue.find_by_id(1)
end
end end
def credentials(user, password=nil) def credentials(user, password=nil)