code layout cleanup test/integration/api_test/issues_test.rb

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10574 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2012-10-09 11:03:20 +00:00
parent 178f64950f
commit 92f9280352
1 changed files with 57 additions and 27 deletions

View File

@ -114,7 +114,8 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
:children => {:count => 1}, :children => {:count => 1},
:child => { :child => {
:tag => 'relation', :tag => 'relation',
:attributes => {:id => '2', :issue_id => '2', :issue_to_id => '3', :relation_type => 'relates'} :attributes => {:id => '2', :issue_id => '2', :issue_to_id => '3',
:relation_type => 'relates'}
} }
assert_tag 'relations', assert_tag 'relations',
:parent => {:tag => 'issue', :child => {:tag => 'id', :content => '1'}}, :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '1'}},
@ -134,12 +135,12 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
context "with custom field filter" do context "with custom field filter" do
should "show only issues with the custom field value" do should "show only issues with the custom field value" do
get '/issues.xml', { :set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}} get '/issues.xml',
{:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='},
:v => {:cf_1 => ['MySQL']}}
expected_ids = Issue.visible.all( expected_ids = Issue.visible.all(
:include => :custom_values, :include => :custom_values,
:conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id) :conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id)
assert_select 'issues > issue > id', :count => expected_ids.count do |ids| assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
end end
@ -388,9 +389,21 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
context "with subtasks" do context "with subtasks" do
setup do setup do
@c1 = Issue.create!(:status_id => 1, :subject => "child c1", :tracker_id => 1, :project_id => 1, :author_id => 1, :parent_issue_id => 1) @c1 = Issue.create!(
@c2 = Issue.create!(:status_id => 1, :subject => "child c2", :tracker_id => 1, :project_id => 1, :author_id => 1, :parent_issue_id => 1) :status_id => 1, :subject => "child c1",
@c3 = Issue.create!(:status_id => 1, :subject => "child c3", :tracker_id => 1, :project_id => 1, :author_id => 1, :parent_issue_id => @c1.id) :tracker_id => 1, :project_id => 1, :author_id => 1,
:parent_issue_id => 1
)
@c2 = Issue.create!(
:status_id => 1, :subject => "child c2",
:tracker_id => 1, :project_id => 1, :author_id => 1,
:parent_issue_id => 1
)
@c3 = Issue.create!(
:status_id => 1, :subject => "child c3",
:tracker_id => 1, :project_id => 1, :author_id => 1,
:parent_issue_id => @c1.id
)
end end
context ".xml" do context ".xml" do
@ -428,7 +441,8 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
assert_equal([ assert_equal([
{ {
'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'}, 'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'},
'children' => [{ 'id' => @c3.id, 'subject' => 'child c3', 'tracker' => {'id' => 1, 'name' => 'Bug'} }] 'children' => [{'id' => @c3.id, 'subject' => 'child c3',
'tracker' => {'id' => 1, 'name' => 'Bug'} }]
}, },
{ 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} } { 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} }
], ],
@ -440,16 +454,18 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
end end
context "POST /issues.xml" do context "POST /issues.xml" do
should_allow_api_authentication(:post, should_allow_api_authentication(
'/issues.xml', :post,
{:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, '/issues.xml',
{:success_code => :created}) {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
{:success_code => :created}
)
should "create an issue with the attributes" do should "create an issue with the attributes" do
assert_difference('Issue.count') do assert_difference('Issue.count') do
post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, credentials('jsmith') post '/issues.xml',
{:issue => {:project_id => 1, :subject => 'API test',
:tracker_id => 2, :status_id => 3}}, credentials('jsmith')
end end
issue = Issue.first(:order => 'id DESC') issue = Issue.first(:order => 'id DESC')
assert_equal 1, issue.project_id assert_equal 1, issue.project_id
assert_equal 2, issue.tracker_id assert_equal 2, issue.tracker_id
@ -475,12 +491,16 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
context "POST /issues.json" do context "POST /issues.json" do
should_allow_api_authentication(:post, should_allow_api_authentication(:post,
'/issues.json', '/issues.json',
{:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, {:issue => {:project_id => 1, :subject => 'API test',
:tracker_id => 2, :status_id => 3}},
{:success_code => :created}) {:success_code => :created})
should "create an issue with the attributes" do should "create an issue with the attributes" do
assert_difference('Issue.count') do assert_difference('Issue.count') do
post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, credentials('jsmith') post '/issues.json',
{:issue => {:project_id => 1, :subject => 'API test',
:tracker_id => 2, :status_id => 3}},
credentials('jsmith')
end end
issue = Issue.first(:order => 'id DESC') issue = Issue.first(:order => 'id DESC')
@ -544,7 +564,10 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
context "PUT /issues/3.xml with custom fields" do context "PUT /issues/3.xml with custom fields" do
setup do setup do
@parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}} @parameters = {
:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' },
{'id' => '2', 'value' => '150'}]}
}
end end
should "update custom fields" do should "update custom fields" do
@ -562,7 +585,10 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
setup do setup do
field = CustomField.find(1) field = CustomField.find(1)
field.update_attribute :multiple, true field.update_attribute :multiple, true
@parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, {'id' => '2', 'value' => '150'}]}} @parameters = {
:issue => {:custom_fields => [{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] },
{'id' => '2', 'value' => '150'}]}
}
end end
should "update custom fields" do should "update custom fields" do
@ -696,10 +722,10 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
def test_create_issue_with_uploaded_file def test_create_issue_with_uploaded_file
set_tmp_attachments_directory set_tmp_attachments_directory
# upload the file # upload the file
assert_difference 'Attachment.count' do assert_difference 'Attachment.count' do
post '/uploads.xml', 'test_create_with_upload', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) post '/uploads.xml', 'test_create_with_upload',
{"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
assert_response :created assert_response :created
end end
xml = Hash.from_xml(response.body) xml = Hash.from_xml(response.body)
@ -709,8 +735,10 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
# create the issue with the upload's token # create the issue with the upload's token
assert_difference 'Issue.count' do assert_difference 'Issue.count' do
post '/issues.xml', post '/issues.xml',
{:issue => {:project_id => 1, :subject => 'Uploaded file', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}}, {:issue => {:project_id => 1, :subject => 'Uploaded file',
credentials('jsmith') :uploads => [{:token => token, :filename => 'test.txt',
:content_type => 'text/plain'}]}},
credentials('jsmith')
assert_response :created assert_response :created
end end
issue = Issue.first(:order => 'id DESC') issue = Issue.first(:order => 'id DESC')
@ -740,10 +768,10 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
def test_update_issue_with_uploaded_file def test_update_issue_with_uploaded_file
set_tmp_attachments_directory set_tmp_attachments_directory
# upload the file # upload the file
assert_difference 'Attachment.count' do assert_difference 'Attachment.count' do
post '/uploads.xml', 'test_upload_with_upload', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) post '/uploads.xml', 'test_upload_with_upload',
{"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
assert_response :created assert_response :created
end end
xml = Hash.from_xml(response.body) xml = Hash.from_xml(response.body)
@ -753,8 +781,10 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
# update the issue with the upload's token # update the issue with the upload's token
assert_difference 'Journal.count' do assert_difference 'Journal.count' do
put '/issues/1.xml', put '/issues/1.xml',
{:issue => {:notes => 'Attachment added', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}}, {:issue => {:notes => 'Attachment added',
credentials('jsmith') :uploads => [{:token => token, :filename => 'test.txt',
:content_type => 'text/plain'}]}},
credentials('jsmith')
assert_response :ok assert_response :ok
assert_equal '', @response.body assert_equal '', @response.body
end end