##// END OF EJS Templates
Attachments should be available to the text formatter when previewing an existing news....
Attachments should be available to the text formatter when previewing an existing news. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10400 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r9793:54d55a360a21
r10217:ca4f2c59b647
Show More
issues_test.rb
764 lines | 24.1 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 # Redmine - project management software
Jean-Philippe Lang
Copyright update....
r9453 # Copyright (C) 2006-2012 Jean-Philippe Lang
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825 #
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825 #
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jean-Baptiste Barth
Use absolute paths in test/**/* requires for Ruby 1.9.2 compatibility. #4050...
r4395 require File.expand_path('../../../test_helper', __FILE__)
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196
Eric Davis
Move all API tests into the ApiTest module to make management easier...
r4243 class ApiTest::IssuesTest < ActionController::IntegrationTest
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 fixtures :projects,
:users,
:roles,
:members,
:member_roles,
:issues,
:issue_statuses,
:versions,
:trackers,
:projects_trackers,
:issue_categories,
:enabled_modules,
:enumerations,
:attachments,
:workflows,
:custom_fields,
:custom_values,
:custom_fields_projects,
:custom_fields_trackers,
:time_entries,
:journals,
:journal_details,
Jean-Philippe Lang
REST API for reading attachments (#7671)....
r6175 :queries,
:attachments
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196
def setup
Setting.rest_api_enabled = '1'
end
Eric Davis
Convert tests to shoulda...
r3651
Jean-Philippe Lang
Ability to load relations on /issues API (#7366)....
r6193 context "/issues" do
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 # Use a private project to make sure auth is really working and not just
# only showing public issues.
Eric Davis
Refactor: Convert the tests for Issues#index and #show APIs to shoulda. #6447...
r4250 should_allow_api_authentication(:get, "/projects/private-child/issues.xml")
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 should "contain metadata" do
get '/issues.xml'
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 assert_tag :tag => 'issues',
:attributes => {
:type => 'array',
:total_count => assigns(:issue_count),
:limit => 25,
:offset => 0
}
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 context "with offset and limit" do
should "use the params" do
get '/issues.xml?offset=2&limit=3'
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 assert_equal 3, assigns(:limit)
assert_equal 2, assigns(:offset)
assert_tag :tag => 'issues', :children => {:count => 3, :only => {:tag => 'issue'}}
end
end
context "with nometa param" do
should "not contain metadata" do
get '/issues.xml?nometa=1'
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 assert_tag :tag => 'issues',
:attributes => {
:type => 'array',
:total_count => nil,
:limit => nil,
:offset => nil
}
end
end
context "with nometa header" do
should "not contain metadata" do
get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'}
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 assert_tag :tag => 'issues',
:attributes => {
:type => 'array',
:total_count => nil,
:limit => nil,
:offset => nil
}
end
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Ability to load relations on /issues API (#7366)....
r6193 context "with relations" do
should "display relations" do
get '/issues.xml?include=relations'
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Ability to load relations on /issues API (#7366)....
r6193 assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag 'relations',
:parent => {:tag => 'issue', :child => {:tag => 'id', :content => '3'}},
:children => {:count => 1},
:child => {
:tag => 'relation',
:attributes => {:id => '2', :issue_id => '2', :issue_to_id => '3', :relation_type => 'relates'}
}
assert_tag 'relations',
:parent => {:tag => 'issue', :child => {:tag => 'id', :content => '1'}},
:children => {:count => 0}
end
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Respond with errors and appropriate content type on /issues API calls with invalid query params (#8883)....
r6189 context "with invalid query params" do
should "return errors" do
get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}}
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Respond with errors and appropriate content type on /issues API calls with invalid query params (#8883)....
r6189 assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
assert_tag 'errors', :child => {:tag => 'error', :content => "Start date can't be blank"}
end
end
Etienne Massip
Added 2 tests about passing custom field filter to /issues.xml...
r7461
context "with custom field filter" 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']}}
expected_ids = Issue.visible.all(
:include => :custom_values,
:conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id)
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
end
end
end
context "with custom field filter (shorthand method)" do
should "show only issues with the custom field value" do
get '/issues.xml', { :cf_1 => 'MySQL' }
expected_ids = Issue.visible.all(
:include => :custom_values,
:conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id)
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
end
end
end
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Eric Davis
Added JSON support to the issues API. #1214...
r3652
context "/index.json" do
Eric Davis
Refactor: Convert the tests for Issues#index and #show APIs to shoulda. #6447...
r4250 should_allow_api_authentication(:get, "/projects/private-child/issues.json")
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
Eric Davis
Convert tests to shoulda...
r3651 context "/index.xml with filter" do
should "show only issues with the status_id" do
Eric Davis
Refactor: Convert the tests for Issues#index and #show APIs to shoulda. #6447...
r4250 get '/issues.xml?status_id=5'
Etienne Massip
Added 2 tests about passing custom field filter to /issues.xml...
r7461
expected_ids = Issue.visible.all(:conditions => {:status_id => 5}).map(&:id)
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
end
Eric Davis
Convert tests to shoulda...
r3651 end
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Eric Davis
Convert tests to shoulda...
r3651
Eric Davis
Added JSON support to the issues API. #1214...
r3652 context "/index.json with filter" do
should "show only issues with the status_id" do
Eric Davis
Refactor: Convert the tests for Issues#index and #show APIs to shoulda. #6447...
r4250 get '/issues.json?status_id=5'
Eric Davis
Added JSON support to the issues API. #1214...
r3652 json = ActiveSupport::JSON.decode(response.body)
Jean-Philippe Lang
Converts IssuesController to use the new API template system and makes xml/json responses consistent (#6136)....
r4344 status_ids_used = json['issues'].collect {|j| j['status']['id'] }
Eric Davis
Added JSON support to the issues API. #1214...
r3652 assert_equal 3, status_ids_used.length
assert status_ids_used.all? {|id| id == 5 }
end
end
Eric Davis
Refactor: Convert the tests for Issues#index and #show APIs to shoulda. #6447...
r4250 # Issue 6 is on a private project
context "/issues/6.xml" do
should_allow_api_authentication(:get, "/issues/6.xml")
Eric Davis
Convert tests to shoulda...
r3651 end
Eric Davis
Refactor: Convert the tests for Issues#index and #show APIs to shoulda. #6447...
r4250 context "/issues/6.json" do
should_allow_api_authentication(:get, "/issues/6.json")
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Adds subtasks to GET /issues/:id API (#5338)....
r4351 context "GET /issues/:id" do
Jean-Philippe Lang
Changes the representation of journal details in issue API....
r4369 context "with journals" do
context ".xml" do
should "display journals" do
Jean-Philippe Lang
Makes some attributes optional in API response to get faster/lightweight responses....
r4372 get '/issues/1.xml?include=journals'
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Changes the representation of journal details in issue API....
r4369 assert_tag :tag => 'issue',
:child => {
:tag => 'journals',
:attributes => { :type => 'array' },
:child => {
:tag => 'journal',
:attributes => { :id => '1'},
:child => {
:tag => 'details',
:attributes => { :type => 'array' },
:child => {
:tag => 'detail',
:attributes => { :name => 'status_id' },
:child => {
:tag => 'old_value',
:content => '1',
:sibling => {
:tag => 'new_value',
:content => '2'
}
}
}
}
}
}
end
end
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Fixed: error when serializing back objects with custom fields using ActiveResource (#6403)....
r4366 context "with custom fields" do
context ".xml" do
should "display custom fields" do
get '/issues/3.xml'
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
assert_tag :tag => 'issue',
Jean-Philippe Lang
Fixed: error when serializing back objects with custom fields using ActiveResource (#6403)....
r4366 :child => {
:tag => 'custom_fields',
:attributes => { :type => 'array' },
:child => {
:tag => 'custom_field',
:attributes => { :id => '1'},
:child => {
:tag => 'value',
:content => 'MySQL'
}
}
}
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Fixed: error when serializing back objects with custom fields using ActiveResource (#6403)....
r4366 assert_nothing_raised do
Hash.from_xml(response.body).to_xml
end
end
end
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Adds support for multiselect custom fields (#1189)....
r8601 context "with multi custom fields" do
setup do
field = CustomField.find(1)
field.update_attribute :multiple, true
issue = Issue.find(3)
issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
issue.save!
end
context ".xml" do
should "display custom fields" do
get '/issues/3.xml'
assert_response :success
assert_tag :tag => 'issue',
:child => {
:tag => 'custom_fields',
:attributes => { :type => 'array' },
:child => {
:tag => 'custom_field',
:attributes => { :id => '1'},
:child => {
:tag => 'value',
:attributes => { :type => 'array' },
:children => { :count => 2 }
}
}
}
xml = Hash.from_xml(response.body)
custom_fields = xml['issue']['custom_fields']
assert_kind_of Array, custom_fields
field = custom_fields.detect {|f| f['id'] == '1'}
assert_kind_of Hash, field
assert_equal ['MySQL', 'Oracle'], field['value'].sort
end
end
context ".json" do
should "display custom fields" do
get '/issues/3.json'
assert_response :success
json = ActiveSupport::JSON.decode(response.body)
custom_fields = json['issue']['custom_fields']
assert_kind_of Array, custom_fields
field = custom_fields.detect {|f| f['id'] == 1}
assert_kind_of Hash, field
assert_equal ['MySQL', 'Oracle'], field['value'].sort
end
end
end
context "with empty value for multi custom field" do
setup do
field = CustomField.find(1)
field.update_attribute :multiple, true
issue = Issue.find(3)
issue.custom_field_values = {1 => ['']}
issue.save!
end
context ".xml" do
should "display custom fields" do
get '/issues/3.xml'
assert_response :success
assert_tag :tag => 'issue',
:child => {
:tag => 'custom_fields',
:attributes => { :type => 'array' },
:child => {
:tag => 'custom_field',
:attributes => { :id => '1'},
:child => {
:tag => 'value',
:attributes => { :type => 'array' },
:children => { :count => 0 }
}
}
}
xml = Hash.from_xml(response.body)
custom_fields = xml['issue']['custom_fields']
assert_kind_of Array, custom_fields
field = custom_fields.detect {|f| f['id'] == '1'}
assert_kind_of Hash, field
assert_equal [], field['value']
end
end
context ".json" do
should "display custom fields" do
get '/issues/3.json'
assert_response :success
json = ActiveSupport::JSON.decode(response.body)
custom_fields = json['issue']['custom_fields']
assert_kind_of Array, custom_fields
field = custom_fields.detect {|f| f['id'] == 1}
assert_kind_of Hash, field
assert_equal [], field['value'].sort
end
end
end
Jean-Philippe Lang
REST API for reading attachments (#7671)....
r6175 context "with attachments" do
context ".xml" do
should "display attachments" do
get '/issues/3.xml?include=attachments'
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
REST API for reading attachments (#7671)....
r6175 assert_tag :tag => 'issue',
:child => {
:tag => 'attachments',
:children => {:count => 5},
:child => {
:tag => 'attachment',
:child => {
:tag => 'filename',
:content => 'source.rb',
:sibling => {
:tag => 'content_url',
:content => 'http://www.example.com/attachments/download/4/source.rb'
}
}
}
}
end
end
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Adds subtasks to GET /issues/:id API (#5338)....
r4351 context "with subtasks" do
setup do
Jean-Philippe Lang
Removed some generate! calls....
r8959 @c1 = Issue.create!(:status_id => 1, :subject => "child c1", :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)
Jean-Philippe Lang
Adds subtasks to GET /issues/:id API (#5338)....
r4351 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Adds subtasks to GET /issues/:id API (#5338)....
r4351 context ".xml" do
should "display children" do
Jean-Philippe Lang
Makes some attributes optional in API response to get faster/lightweight responses....
r4372 get '/issues/1.xml?include=children'
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
assert_tag :tag => 'issue',
Jean-Philippe Lang
Adds subtasks to GET /issues/:id API (#5338)....
r4351 :child => {
:tag => 'children',
:children => {:count => 2},
:child => {
:tag => 'issue',
:attributes => {:id => @c1.id.to_s},
:child => {
:tag => 'subject',
:content => 'child c1',
:sibling => {
:tag => 'children',
:children => {:count => 1},
:child => {
:tag => 'issue',
:attributes => {:id => @c3.id.to_s}
}
}
}
}
}
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Adds subtasks to GET /issues/:id API (#5338)....
r4351 context ".json" do
should "display children" do
Jean-Philippe Lang
Makes some attributes optional in API response to get faster/lightweight responses....
r4372 get '/issues/1.json?include=children'
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Adds subtasks to GET /issues/:id API (#5338)....
r4351 json = ActiveSupport::JSON.decode(response.body)
assert_equal([
{
'id' => @c1.id, 'subject' => 'child c1', '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'} }
],
json['issue']['children'])
end
end
end
end
end
Eric Davis
Added JSON support to the issues API. #1214...
r3652
Eric Davis
Convert tests to shoulda...
r3651 context "POST /issues.xml" do
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 should_allow_api_authentication(:post,
'/issues.xml',
{:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
{:success_code => :created})
Eric Davis
Convert tests to shoulda...
r3651
should "create an issue with the attributes" do
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 assert_difference('Issue.count') do
Jean-Philippe Lang
Test cleanup....
r8357 post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, credentials('jsmith')
Eric Davis
Convert tests to shoulda...
r3651 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 issue = Issue.first(:order => 'id DESC')
assert_equal 1, issue.project_id
assert_equal 2, issue.tracker_id
assert_equal 3, issue.status_id
assert_equal 'API test', issue.subject
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Makes projects API return XML description when creating a project (#6874)....
r4283 assert_response :created
assert_equal 'application/xml', @response.content_type
assert_tag 'issue', :child => {:tag => 'id', :content => issue.id.to_s}
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Convert tests to shoulda...
r3651 context "POST /issues.xml with failure" do
should "have an errors tag" do
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 assert_no_difference('Issue.count') do
Jean-Philippe Lang
Test cleanup....
r8357 post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 end
Eric Davis
Convert tests to shoulda...
r3651 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
end
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Eric Davis
Added JSON support to the issues API. #1214...
r3652
context "POST /issues.json" do
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 should_allow_api_authentication(:post,
'/issues.json',
{:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
{:success_code => :created})
Eric Davis
Added JSON support to the issues API. #1214...
r3652
should "create an issue with the attributes" do
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 assert_difference('Issue.count') do
Jean-Philippe Lang
Test cleanup....
r8357 post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, credentials('jsmith')
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 issue = Issue.first(:order => 'id DESC')
assert_equal 1, issue.project_id
assert_equal 2, issue.tracker_id
assert_equal 3, issue.status_id
assert_equal 'API test', issue.subject
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Added JSON support to the issues API. #1214...
r3652 context "POST /issues.json with failure" do
should "have an errors element" do
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 assert_no_difference('Issue.count') do
Jean-Philippe Lang
Test cleanup....
r8357 post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')
Eric Davis
Allow key authentication when creating issues (with tests) #6447...
r4251 end
Eric Davis
Added JSON support to the issues API. #1214...
r3652 json = ActiveSupport::JSON.decode(response.body)
Jean-Philippe Lang
Adds a template for API error messages so that it does not depend on AR::Errors serialization....
r8974 assert json['errors'].include?("Subject can't be blank")
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
end
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 # Issue 6 is on a private project
context "PUT /issues/6.xml" do
Eric Davis
Convert tests to shoulda...
r3651 setup do
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}}
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 should_allow_api_authentication(:put,
'/issues/6.xml',
{:issue => {:subject => 'API update', :notes => 'A new note'}},
{:success_code => :ok})
Eric Davis
Convert tests to shoulda...
r3651
should "not create a new issue" do
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 assert_no_difference('Issue.count') do
Jean-Philippe Lang
Test cleanup....
r8357 put '/issues/6.xml', @parameters, credentials('jsmith')
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 end
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Eric Davis
Convert tests to shoulda...
r3651
should "create a new journal" do
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 assert_difference('Journal.count') do
Jean-Philippe Lang
Test cleanup....
r8357 put '/issues/6.xml', @parameters, credentials('jsmith')
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 end
Eric Davis
Convert tests to shoulda...
r3651 end
Eric Davis
Allow setting an issue's notes via params[:issue][:notes]. (XML API)...
r3934 should "add the note to the journal" do
Jean-Philippe Lang
Test cleanup....
r8357 put '/issues/6.xml', @parameters, credentials('jsmith')
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow setting an issue's notes via params[:issue][:notes]. (XML API)...
r3934 journal = Journal.last
assert_equal "A new note", journal.notes
end
Eric Davis
Convert tests to shoulda...
r3651 should "update the issue" do
Jean-Philippe Lang
Test cleanup....
r8357 put '/issues/6.xml', @parameters, credentials('jsmith')
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 issue = Issue.find(6)
assert_equal "API update", issue.subject
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Support for updating custom fields using the received custom_fields array (#6345, #6403)....
r4367 context "PUT /issues/3.xml with custom fields" do
setup do
@parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}}
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Support for updating custom fields using the received custom_fields array (#6345, #6403)....
r4367 should "update custom fields" do
assert_no_difference('Issue.count') do
Jean-Philippe Lang
Test cleanup....
r8357 put '/issues/3.xml', @parameters, credentials('jsmith')
Jean-Philippe Lang
Support for updating custom fields using the received custom_fields array (#6345, #6403)....
r4367 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Support for updating custom fields using the received custom_fields array (#6345, #6403)....
r4367 issue = Issue.find(3)
assert_equal '150', issue.custom_value_for(2).value
assert_equal 'PostgreSQL', issue.custom_value_for(1).value
end
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Jean-Philippe Lang
Adds support for multiselect custom fields (#1189)....
r8601 context "PUT /issues/3.xml with multi custom fields" do
setup do
field = CustomField.find(1)
field.update_attribute :multiple, true
@parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, {'id' => '2', 'value' => '150'}]}}
end
should "update custom fields" do
assert_no_difference('Issue.count') do
put '/issues/3.xml', @parameters, credentials('jsmith')
end
issue = Issue.find(3)
assert_equal '150', issue.custom_value_for(2).value
Jean-Philippe Lang
Fixes assertion....
r8655 assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
Jean-Philippe Lang
Adds support for multiselect custom fields (#1189)....
r8601 end
end
Jean-Philippe Lang
Allows project to be changed from the regular issue update action (#4769, #9803)....
r8411 context "PUT /issues/3.xml with project change" do
setup do
@parameters = {:issue => {:project_id => 2, :subject => 'Project changed'}}
end
should "update project" do
assert_no_difference('Issue.count') do
put '/issues/3.xml', @parameters, credentials('jsmith')
end
issue = Issue.find(3)
assert_equal 2, issue.project_id
assert_equal 'Project changed', issue.subject
end
end
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 context "PUT /issues/6.xml with failed update" do
Eric Davis
Convert tests to shoulda...
r3651 setup do
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 @parameters = {:issue => {:subject => ''}}
Eric Davis
Convert tests to shoulda...
r3651 end
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252
Eric Davis
Convert tests to shoulda...
r3651 should "not create a new issue" do
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 assert_no_difference('Issue.count') do
Jean-Philippe Lang
Test cleanup....
r8357 put '/issues/6.xml', @parameters, credentials('jsmith')
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 end
Eric Davis
Convert tests to shoulda...
r3651 end
should "not create a new journal" do
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 assert_no_difference('Journal.count') do
Jean-Philippe Lang
Test cleanup....
r8357 put '/issues/6.xml', @parameters, credentials('jsmith')
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 end
Eric Davis
Convert tests to shoulda...
r3651 end
should "have an errors tag" do
Jean-Philippe Lang
Test cleanup....
r8357 put '/issues/6.xml', @parameters, credentials('jsmith')
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252
Eric Davis
Convert tests to shoulda...
r3651 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
end
end
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 context "PUT /issues/6.json" do
Eric Davis
Added JSON support to the issues API. #1214...
r3652 setup do
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}}
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 should_allow_api_authentication(:put,
'/issues/6.json',
{:issue => {:subject => 'API update', :notes => 'A new note'}},
{:success_code => :ok})
Eric Davis
Added JSON support to the issues API. #1214...
r3652
Jean-Philippe Lang
Adds assertions on response status and body....
r9793 should "update the issue" do
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 assert_no_difference('Issue.count') do
Jean-Philippe Lang
Adds assertions on response status and body....
r9793 assert_difference('Journal.count') do
put '/issues/6.json', @parameters, credentials('jsmith')
Eric Davis
Added JSON support to the issues API. #1214...
r3652
Jean-Philippe Lang
Adds assertions on response status and body....
r9793 assert_response :ok
assert_equal '', response.body
end
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 issue = Issue.find(6)
assert_equal "API update", issue.subject
Jean-Philippe Lang
Adds assertions on response status and body....
r9793 journal = Journal.last
assert_equal "A new note", journal.notes
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 context "PUT /issues/6.json with failed update" do
Jean-Philippe Lang
Adds assertions on response status and body....
r9793 should "return errors" do
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 assert_no_difference('Issue.count') do
Jean-Philippe Lang
Adds assertions on response status and body....
r9793 assert_no_difference('Journal.count') do
put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
Eric Davis
Added JSON support to the issues API. #1214...
r3652
Jean-Philippe Lang
Adds assertions on response status and body....
r9793 assert_response :unprocessable_entity
end
Eric Davis
Allow key authentication when updating issues (with tests) #6447...
r4252 end
Eric Davis
Added JSON support to the issues API. #1214...
r3652 json = ActiveSupport::JSON.decode(response.body)
Jean-Philippe Lang
Adds a template for API error messages so that it does not depend on AR::Errors serialization....
r8974 assert json['errors'].include?("Subject can't be blank")
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
end
Eric Davis
Convert tests to shoulda...
r3651 context "DELETE /issues/1.xml" do
Eric Davis
Allow key authentication when deleting issues (with tests) #6447...
r4253 should_allow_api_authentication(:delete,
'/issues/6.xml',
{},
{:success_code => :ok})
Eric Davis
Convert tests to shoulda...
r3651
should "delete the issue" do
Jean-Philippe Lang
Adds assertions on response status and body....
r9793 assert_difference('Issue.count', -1) do
Jean-Philippe Lang
Test cleanup....
r8357 delete '/issues/6.xml', {}, credentials('jsmith')
Jean-Philippe Lang
Adds assertions on response status and body....
r9793
assert_response :ok
assert_equal '', response.body
Eric Davis
Allow key authentication when deleting issues (with tests) #6447...
r4253 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow key authentication when deleting issues (with tests) #6447...
r4253 assert_nil Issue.find_by_id(6)
Eric Davis
Convert tests to shoulda...
r3651 end
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Eric Davis
Added JSON support to the issues API. #1214...
r3652
context "DELETE /issues/1.json" do
Eric Davis
Allow key authentication when deleting issues (with tests) #6447...
r4253 should_allow_api_authentication(:delete,
'/issues/6.json',
{},
{:success_code => :ok})
Eric Davis
Added JSON support to the issues API. #1214...
r3652
should "delete the issue" do
Jean-Philippe Lang
Adds assertions on response status and body....
r9793 assert_difference('Issue.count', -1) do
Jean-Philippe Lang
Test cleanup....
r8357 delete '/issues/6.json', {}, credentials('jsmith')
Jean-Philippe Lang
Adds assertions on response status and body....
r9793
assert_response :ok
assert_equal '', response.body
Eric Davis
Allow key authentication when deleting issues (with tests) #6447...
r4253 end
Toshi MARUYAMA
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
r6825
Eric Davis
Allow key authentication when deleting issues (with tests) #6447...
r4253 assert_nil Issue.find_by_id(6)
Eric Davis
Added JSON support to the issues API. #1214...
r3652 end
end
Jean-Philippe Lang
Adds support for adding attachments to issues through the REST API (#8171)....
r8808
def test_create_issue_with_uploaded_file
set_tmp_attachments_directory
# upload the file
assert_difference 'Attachment.count' do
Jean-Philippe Lang
Rails 3.1 compatibility....
r8885 post '/uploads.xml', 'test_create_with_upload', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
Jean-Philippe Lang
Adds support for adding attachments to issues through the REST API (#8171)....
r8808 assert_response :created
end
xml = Hash.from_xml(response.body)
token = xml['upload']['token']
attachment = Attachment.first(:order => 'id DESC')
# create the issue with the upload's token
assert_difference 'Issue.count' do
post '/issues.xml',
{:issue => {:project_id => 1, :subject => 'Uploaded file', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}},
credentials('jsmith')
assert_response :created
end
issue = Issue.first(:order => 'id DESC')
assert_equal 1, issue.attachments.count
assert_equal attachment, issue.attachments.first
attachment.reload
assert_equal 'test.txt', attachment.filename
assert_equal 'text/plain', attachment.content_type
assert_equal 'test_create_with_upload'.size, attachment.filesize
assert_equal 2, attachment.author_id
# get the issue with its attachments
get "/issues/#{issue.id}.xml", :include => 'attachments'
assert_response :success
xml = Hash.from_xml(response.body)
attachments = xml['issue']['attachments']
assert_kind_of Array, attachments
assert_equal 1, attachments.size
url = attachments.first['content_url']
assert_not_nil url
# download the attachment
get url
assert_response :success
end
def test_update_issue_with_uploaded_file
set_tmp_attachments_directory
# upload the file
assert_difference 'Attachment.count' do
Jean-Philippe Lang
Rails 3.1 compatibility....
r8885 post '/uploads.xml', 'test_upload_with_upload', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
Jean-Philippe Lang
Adds support for adding attachments to issues through the REST API (#8171)....
r8808 assert_response :created
end
xml = Hash.from_xml(response.body)
token = xml['upload']['token']
attachment = Attachment.first(:order => 'id DESC')
# update the issue with the upload's token
assert_difference 'Journal.count' do
put '/issues/1.xml',
{:issue => {:notes => 'Attachment added', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}},
credentials('jsmith')
assert_response :ok
Jean-Philippe Lang
Fixed that 200 API responses have a body containing one space (#11388)....
r9792 assert_equal '', @response.body
Jean-Philippe Lang
Adds support for adding attachments to issues through the REST API (#8171)....
r8808 end
issue = Issue.find(1)
assert_include attachment, issue.attachments
end
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end