mirror of
https://github.com/meineerde/redmine.git
synced 2026-01-08 16:41:31 +00:00
Removed some test contexts.
git-svn-id: http://svn.redmine.org/redmine/trunk@13646 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
191a4a61f1
commit
4989c9f6a8
@ -29,6 +29,8 @@ class Redmine::ApiTest::HttpBasicLoginTest < Redmine::ApiTest::Base
|
||||
def setup
|
||||
Setting.rest_api_enabled = '1'
|
||||
Setting.login_required = '1'
|
||||
project = Project.find('onlinestore')
|
||||
EnabledModule.create(:project => project, :name => 'news')
|
||||
end
|
||||
|
||||
def teardown
|
||||
@ -36,19 +38,6 @@ class Redmine::ApiTest::HttpBasicLoginTest < Redmine::ApiTest::Base
|
||||
Setting.login_required = '0'
|
||||
end
|
||||
|
||||
# Using the NewsController because it's a simple API.
|
||||
context "get /news" do
|
||||
setup do
|
||||
project = Project.find('onlinestore')
|
||||
EnabledModule.create(:project => project, :name => 'news')
|
||||
end
|
||||
|
||||
context "in :xml format" do
|
||||
should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.xml")
|
||||
end
|
||||
|
||||
context "in :json format" do
|
||||
should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.json")
|
||||
end
|
||||
end
|
||||
should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.xml")
|
||||
should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.json")
|
||||
end
|
||||
|
||||
@ -36,15 +36,6 @@ class Redmine::ApiTest::HttpBasicLoginWithApiTokenTest < Redmine::ApiTest::Base
|
||||
Setting.login_required = '0'
|
||||
end
|
||||
|
||||
# Using the NewsController because it's a simple API.
|
||||
context "get /news" do
|
||||
|
||||
context "in :xml format" do
|
||||
should_allow_http_basic_auth_with_key(:get, "/news.xml")
|
||||
end
|
||||
|
||||
context "in :json format" do
|
||||
should_allow_http_basic_auth_with_key(:get, "/news.json")
|
||||
end
|
||||
end
|
||||
should_allow_http_basic_auth_with_key(:get, "/news.xml")
|
||||
should_allow_http_basic_auth_with_key(:get, "/news.json")
|
||||
end
|
||||
|
||||
@ -48,98 +48,117 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
Setting.rest_api_enabled = '1'
|
||||
end
|
||||
|
||||
context "/issues" do
|
||||
# Use a private project to make sure auth is really working and not just
|
||||
# only showing public issues.
|
||||
should_allow_api_authentication(:get, "/projects/private-child/issues.xml")
|
||||
# Use a private project to make sure auth is really working and not just
|
||||
# only showing public issues.
|
||||
should_allow_api_authentication(:get, "/projects/private-child/issues.xml")
|
||||
should_allow_api_authentication(:get, "/projects/private-child/issues.json")
|
||||
|
||||
should "contain metadata" do
|
||||
get '/issues.xml'
|
||||
should_allow_api_authentication(:get, "/issues/6.xml")
|
||||
should_allow_api_authentication(:get, "/issues/6.json")
|
||||
|
||||
assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]', assigns(:issue_count).to_s
|
||||
should_allow_api_authentication(
|
||||
:post,
|
||||
'/issues.xml',
|
||||
{:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
|
||||
{:success_code => :created}
|
||||
)
|
||||
should_allow_api_authentication(:post,
|
||||
'/issues.json',
|
||||
{:issue => {:project_id => 1, :subject => 'API test',
|
||||
:tracker_id => 2, :status_id => 3}},
|
||||
{:success_code => :created})
|
||||
|
||||
should_allow_api_authentication(:put,
|
||||
'/issues/6.xml',
|
||||
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
{:success_code => :ok})
|
||||
should_allow_api_authentication(:put,
|
||||
'/issues/6.json',
|
||||
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
{:success_code => :ok})
|
||||
|
||||
should_allow_api_authentication(:delete,
|
||||
'/issues/6.xml',
|
||||
{},
|
||||
{:success_code => :ok})
|
||||
should_allow_api_authentication(:delete,
|
||||
'/issues/6.json',
|
||||
{},
|
||||
{:success_code => :ok})
|
||||
|
||||
test "GET /issues.xml should contain metadata" do
|
||||
get '/issues.xml'
|
||||
assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]',
|
||||
assigns(:issue_count).to_s
|
||||
end
|
||||
|
||||
test "GET /issues.xml with nometa param should not contain metadata" do
|
||||
get '/issues.xml?nometa=1'
|
||||
assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
|
||||
end
|
||||
|
||||
test "GET /issues.xml with nometa header should not contain metadata" do
|
||||
get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'}
|
||||
assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
|
||||
end
|
||||
|
||||
test "GET /issues.xml with offset and limit" do
|
||||
get '/issues.xml?offset=2&limit=3'
|
||||
|
||||
assert_equal 3, assigns(:limit)
|
||||
assert_equal 2, assigns(:offset)
|
||||
assert_select 'issues issue', 3
|
||||
end
|
||||
|
||||
test "GET /issues.xml with relations" do
|
||||
get '/issues.xml?include=relations'
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
|
||||
assert_select 'issue id:content(3)' do
|
||||
assert_select '~ relations relation', 1
|
||||
assert_select '~ relations relation[id="2"][issue_id="2"][issue_to_id="3"][relation_type=relates]'
|
||||
end
|
||||
|
||||
context "with offset and limit" do
|
||||
should "use the params" do
|
||||
get '/issues.xml?offset=2&limit=3'
|
||||
|
||||
assert_equal 3, assigns(:limit)
|
||||
assert_equal 2, assigns(:offset)
|
||||
assert_select 'issues issue', 3
|
||||
end
|
||||
assert_select 'issue id:content(1)' do
|
||||
assert_select '~ relations'
|
||||
assert_select '~ relations relation', 0
|
||||
end
|
||||
end
|
||||
|
||||
context "with nometa param" do
|
||||
should "not contain metadata" do
|
||||
get '/issues.xml?nometa=1'
|
||||
test "GET /issues.xml with invalid query params" do
|
||||
get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}}
|
||||
|
||||
assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'errors error', :text => "Start date can't be blank"
|
||||
end
|
||||
|
||||
test "GET /issues.xml with custom field filter" do
|
||||
get '/issues.xml',
|
||||
{:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}}
|
||||
|
||||
expected_ids = Issue.visible.
|
||||
joins(:custom_values).
|
||||
where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
|
||||
assert expected_ids.any?
|
||||
|
||||
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
|
||||
|
||||
context "with nometa header" do
|
||||
should "not contain metadata" do
|
||||
get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'}
|
||||
test "GET /issues.xml with custom field filter (shorthand method)" do
|
||||
get '/issues.xml', {:cf_1 => 'MySQL'}
|
||||
|
||||
assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
|
||||
end
|
||||
end
|
||||
expected_ids = Issue.visible.
|
||||
joins(:custom_values).
|
||||
where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
|
||||
assert expected_ids.any?
|
||||
|
||||
context "with relations" do
|
||||
should "display relations" do
|
||||
get '/issues.xml?include=relations'
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
|
||||
assert_select 'issue id:content(3)' do
|
||||
assert_select '~ relations relation', 1
|
||||
assert_select '~ relations relation[id="2"][issue_id="2"][issue_to_id="3"][relation_type=relates]'
|
||||
end
|
||||
|
||||
assert_select 'issue id:content(1)' do
|
||||
assert_select '~ relations'
|
||||
assert_select '~ relations relation', 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid query params" do
|
||||
should "return errors" do
|
||||
get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}}
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'errors error', :text => "Start date can't be blank"
|
||||
end
|
||||
end
|
||||
|
||||
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.
|
||||
joins(:custom_values).
|
||||
where(: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.
|
||||
joins(:custom_values).
|
||||
where(: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
|
||||
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
|
||||
|
||||
@ -171,234 +190,163 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
assert_select 'issues>issue', :count => 2
|
||||
end
|
||||
|
||||
context "/index.json" do
|
||||
should_allow_api_authentication(:get, "/projects/private-child/issues.json")
|
||||
test "GET /issues.xml with filter" do
|
||||
get '/issues.xml?status_id=5'
|
||||
|
||||
expected_ids = Issue.visible.where(:status_id => 5).map(&:id)
|
||||
assert expected_ids.any?
|
||||
|
||||
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
|
||||
|
||||
context "/index.xml with filter" do
|
||||
should "show only issues with the status_id" do
|
||||
get '/issues.xml?status_id=5'
|
||||
test "GET /issues.json with filter" do
|
||||
get '/issues.json?status_id=5'
|
||||
|
||||
expected_ids = Issue.visible.where(:status_id => 5).map(&:id)
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
status_ids_used = json['issues'].collect {|j| j['status']['id'] }
|
||||
assert_equal 3, status_ids_used.length
|
||||
assert status_ids_used.all? {|id| id == 5 }
|
||||
end
|
||||
|
||||
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
|
||||
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
|
||||
test "GET /issues/:id.xml with journals" do
|
||||
get '/issues/1.xml?include=journals'
|
||||
|
||||
assert_select 'issue journals[type=array]' do
|
||||
assert_select 'journal[id="1"]' do
|
||||
assert_select 'details[type=array]' do
|
||||
assert_select 'detail[name=status_id]' do
|
||||
assert_select 'old_value', :text => '1'
|
||||
assert_select 'new_value', :text => '2'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "/index.json with filter" do
|
||||
should "show only issues with the status_id" do
|
||||
get '/issues.json?status_id=5'
|
||||
test "GET /issues/:id.xml with custom fields" do
|
||||
get '/issues/3.xml'
|
||||
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
status_ids_used = json['issues'].collect {|j| j['status']['id'] }
|
||||
assert_equal 3, status_ids_used.length
|
||||
assert status_ids_used.all? {|id| id == 5 }
|
||||
assert_select 'issue custom_fields[type=array]' do
|
||||
assert_select 'custom_field[id="1"]' do
|
||||
assert_select 'value', :text => 'MySQL'
|
||||
end
|
||||
end
|
||||
assert_nothing_raised do
|
||||
Hash.from_xml(response.body).to_xml
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Issue 6 is on a private project
|
||||
context "/issues/6.xml" do
|
||||
should_allow_api_authentication(:get, "/issues/6.xml")
|
||||
test "GET /issues/:id.xml with multi custom fields" do
|
||||
field = CustomField.find(1)
|
||||
field.update_attribute :multiple, true
|
||||
issue = Issue.find(3)
|
||||
issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
|
||||
issue.save!
|
||||
|
||||
get '/issues/3.xml'
|
||||
assert_response :success
|
||||
|
||||
assert_select 'issue custom_fields[type=array]' do
|
||||
assert_select 'custom_field[id="1"]' do
|
||||
assert_select 'value[type=array] value', 2
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
context "/issues/6.json" do
|
||||
should_allow_api_authentication(:get, "/issues/6.json")
|
||||
test "GET /issues/:id.json with multi custom fields" do
|
||||
field = CustomField.find(1)
|
||||
field.update_attribute :multiple, true
|
||||
issue = Issue.find(3)
|
||||
issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
|
||||
issue.save!
|
||||
|
||||
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
|
||||
|
||||
context "GET /issues/:id" do
|
||||
context "with journals" do
|
||||
context ".xml" do
|
||||
should "display journals" do
|
||||
get '/issues/1.xml?include=journals'
|
||||
test "GET /issues/:id.xml with empty value for multi custom field" do
|
||||
field = CustomField.find(1)
|
||||
field.update_attribute :multiple, true
|
||||
issue = Issue.find(3)
|
||||
issue.custom_field_values = {1 => ['']}
|
||||
issue.save!
|
||||
|
||||
assert_select 'issue journals[type=array]' do
|
||||
assert_select 'journal[id="1"]' do
|
||||
assert_select 'details[type=array]' do
|
||||
assert_select 'detail[name=status_id]' do
|
||||
assert_select 'old_value', :text => '1'
|
||||
assert_select 'new_value', :text => '2'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
get '/issues/3.xml'
|
||||
|
||||
assert_select 'issue custom_fields[type=array]' do
|
||||
assert_select 'custom_field[id="1"]' do
|
||||
assert_select 'value[type=array]:empty'
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
context "with custom fields" do
|
||||
context ".xml" do
|
||||
should "display custom fields" do
|
||||
get '/issues/3.xml'
|
||||
test "GET /issues/:id.json with empty value for multi custom field" do
|
||||
field = CustomField.find(1)
|
||||
field.update_attribute :multiple, true
|
||||
issue = Issue.find(3)
|
||||
issue.custom_field_values = {1 => ['']}
|
||||
issue.save!
|
||||
|
||||
assert_select 'issue custom_fields[type=array]' do
|
||||
assert_select 'custom_field[id="1"]' do
|
||||
assert_select 'value', :text => 'MySQL'
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
assert_nothing_raised do
|
||||
Hash.from_xml(response.body).to_xml
|
||||
end
|
||||
end
|
||||
test "GET /issues/:id.xml with attachments" do
|
||||
get '/issues/3.xml?include=attachments'
|
||||
|
||||
assert_select 'issue attachments[type=array]' do
|
||||
assert_select 'attachment', 5
|
||||
assert_select 'attachment id:content(4)' do
|
||||
assert_select '~ filename', :text => 'source.rb'
|
||||
assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/4/source.rb'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
test "GET /issues/:id.xml with subtasks" do
|
||||
issue = Issue.generate_with_descendants!(:project_id => 1)
|
||||
get "/issues/#{issue.id}.xml?include=children"
|
||||
|
||||
context ".xml" do
|
||||
should "display custom fields" do
|
||||
get '/issues/3.xml'
|
||||
assert_response :success
|
||||
|
||||
assert_select 'issue custom_fields[type=array]' do
|
||||
assert_select 'custom_field[id="1"]' do
|
||||
assert_select 'value[type=array] value', 2
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
assert_select 'issue children[type=array]' do
|
||||
assert_select 'issue', 2
|
||||
assert_select 'issue children', 1
|
||||
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
|
||||
test "GET /issues/:id.json with subtasks" do
|
||||
issue = Issue.generate_with_descendants!(:project_id => 1)
|
||||
get "/issues/#{issue.id}.json?include=children"
|
||||
|
||||
context ".xml" do
|
||||
should "display custom fields" do
|
||||
get '/issues/3.xml'
|
||||
|
||||
assert_select 'issue custom_fields[type=array]' do
|
||||
assert_select 'custom_field[id="1"]' do
|
||||
assert_select 'value[type=array]:empty'
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
context "with attachments" do
|
||||
context ".xml" do
|
||||
should "display attachments" do
|
||||
get '/issues/3.xml?include=attachments'
|
||||
|
||||
assert_select 'issue attachments[type=array]' do
|
||||
assert_select 'attachment', 5
|
||||
assert_select 'attachment id:content(4)' do
|
||||
assert_select '~ filename', :text => 'source.rb'
|
||||
assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/4/source.rb'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with subtasks" 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
|
||||
)
|
||||
@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
|
||||
|
||||
context ".xml" do
|
||||
should "display children" do
|
||||
get '/issues/1.xml?include=children'
|
||||
|
||||
assert_select 'issue children[type=array]' do
|
||||
assert_select 'issue', 2
|
||||
assert_select 'issue[id=?]', @c1.id.to_s do
|
||||
assert_select 'subject', :text => 'child c1'
|
||||
assert_select 'children' do
|
||||
assert_select 'issue[id=?]', @c3.id.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".json" do
|
||||
should "display children" do
|
||||
get '/issues/1.json?include=children'
|
||||
|
||||
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
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_equal 2, json['issue']['children'].size
|
||||
assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size
|
||||
end
|
||||
|
||||
def test_show_should_include_issue_attributes
|
||||
@ -421,29 +369,21 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
end
|
||||
end
|
||||
|
||||
context "POST /issues.xml" do
|
||||
should_allow_api_authentication(
|
||||
:post,
|
||||
'/issues.xml',
|
||||
{:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
|
||||
{:success_code => :created}
|
||||
)
|
||||
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}}, credentials('jsmith')
|
||||
end
|
||||
issue = Issue.order('id DESC').first
|
||||
assert_equal 1, issue.project_id
|
||||
assert_equal 2, issue.tracker_id
|
||||
assert_equal 3, issue.status_id
|
||||
assert_equal 'API test', issue.subject
|
||||
|
||||
assert_response :created
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'issue > id', :text => issue.id.to_s
|
||||
test "POST /issues.xml 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}}, credentials('jsmith')
|
||||
end
|
||||
issue = Issue.order('id DESC').first
|
||||
assert_equal 1, issue.project_id
|
||||
assert_equal 2, issue.tracker_id
|
||||
assert_equal 3, issue.status_id
|
||||
assert_equal 'API test', issue.subject
|
||||
|
||||
assert_response :created
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'issue > id', :text => issue.id.to_s
|
||||
end
|
||||
|
||||
test "POST /issues.xml with watcher_user_ids should create issue with watchers" do
|
||||
@ -458,246 +398,139 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
assert_equal [1, 3], issue.watcher_user_ids.sort
|
||||
end
|
||||
|
||||
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}}, credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_select 'errors error', :text => "Subject can't be blank"
|
||||
test "POST /issues.xml with failure should return errors" do
|
||||
assert_no_difference('Issue.count') do
|
||||
post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
|
||||
end
|
||||
|
||||
assert_select 'errors error', :text => "Subject can't be blank"
|
||||
end
|
||||
|
||||
context "POST /issues.json" do
|
||||
should_allow_api_authentication(:post,
|
||||
'/issues.json',
|
||||
{:issue => {:project_id => 1, :subject => 'API test',
|
||||
:tracker_id => 2, :status_id => 3}},
|
||||
{:success_code => :created})
|
||||
|
||||
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}},
|
||||
credentials('jsmith')
|
||||
end
|
||||
|
||||
issue = Issue.order('id DESC').first
|
||||
assert_equal 1, issue.project_id
|
||||
assert_equal 2, issue.tracker_id
|
||||
assert_equal 3, issue.status_id
|
||||
assert_equal 'API test', issue.subject
|
||||
test "POST /issues.json 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}},
|
||||
credentials('jsmith')
|
||||
end
|
||||
|
||||
issue = Issue.order('id DESC').first
|
||||
assert_equal 1, issue.project_id
|
||||
assert_equal 2, issue.tracker_id
|
||||
assert_equal 3, issue.status_id
|
||||
assert_equal 'API test', issue.subject
|
||||
end
|
||||
|
||||
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}}, credentials('jsmith')
|
||||
end
|
||||
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert json['errors'].include?("Subject can't be blank")
|
||||
test "POST /issues.json with failure should return errors" do
|
||||
assert_no_difference('Issue.count') do
|
||||
post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')
|
||||
end
|
||||
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert json['errors'].include?("Subject can't be blank")
|
||||
end
|
||||
|
||||
# Issue 6 is on a private project
|
||||
context "PUT /issues/6.xml" do
|
||||
setup do
|
||||
@parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}}
|
||||
end
|
||||
|
||||
should_allow_api_authentication(:put,
|
||||
'/issues/6.xml',
|
||||
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
{:success_code => :ok})
|
||||
|
||||
should "not create a new issue" do
|
||||
assert_no_difference('Issue.count') do
|
||||
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, credentials('jsmith')
|
||||
end
|
||||
end
|
||||
|
||||
should "add the note to the journal" do
|
||||
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, credentials('jsmith')
|
||||
|
||||
issue = Issue.find(6)
|
||||
assert_equal "API update", issue.subject
|
||||
test "PUT /issues/:id.xml" do
|
||||
assert_difference('Journal.count') do
|
||||
put '/issues/6.xml',
|
||||
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
credentials('jsmith')
|
||||
end
|
||||
|
||||
issue = Issue.find(6)
|
||||
assert_equal "API update", issue.subject
|
||||
journal = Journal.last
|
||||
assert_equal "A new note", journal.notes
|
||||
end
|
||||
|
||||
context "PUT /issues/3.xml with custom fields" do
|
||||
setup do
|
||||
@parameters = {
|
||||
:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' },
|
||||
{'id' => '2', 'value' => '150'}]}
|
||||
}
|
||||
end
|
||||
test "PUT /issues/:id.xml with custom fields" do
|
||||
put '/issues/3.xml',
|
||||
{:issue => {:custom_fields => [
|
||||
{'id' => '1', 'value' => 'PostgreSQL' },
|
||||
{'id' => '2', 'value' => '150'}
|
||||
]}},
|
||||
credentials('jsmith')
|
||||
|
||||
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
|
||||
assert_equal 'PostgreSQL', issue.custom_value_for(1).value
|
||||
end
|
||||
issue = Issue.find(3)
|
||||
assert_equal '150', issue.custom_value_for(2).value
|
||||
assert_equal 'PostgreSQL', issue.custom_value_for(1).value
|
||||
end
|
||||
|
||||
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
|
||||
test "PUT /issues/:id.xml with multi custom fields" do
|
||||
field = CustomField.find(1)
|
||||
field.update_attribute :multiple, true
|
||||
|
||||
should "update custom fields" do
|
||||
assert_no_difference('Issue.count') do
|
||||
put '/issues/3.xml', @parameters, credentials('jsmith')
|
||||
end
|
||||
put '/issues/3.xml',
|
||||
{:issue => {:custom_fields => [
|
||||
{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] },
|
||||
{'id' => '2', 'value' => '150'}
|
||||
]}},
|
||||
credentials('jsmith')
|
||||
|
||||
issue = Issue.find(3)
|
||||
assert_equal '150', issue.custom_value_for(2).value
|
||||
assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
|
||||
end
|
||||
issue = Issue.find(3)
|
||||
assert_equal '150', issue.custom_value_for(2).value
|
||||
assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
|
||||
end
|
||||
|
||||
context "PUT /issues/3.xml with project change" do
|
||||
setup do
|
||||
@parameters = {:issue => {:project_id => 2, :subject => 'Project changed'}}
|
||||
end
|
||||
test "PUT /issues/:id.xml with project change" do
|
||||
put '/issues/3.xml',
|
||||
{:issue => {:project_id => 2, :subject => 'Project changed'}},
|
||||
credentials('jsmith')
|
||||
|
||||
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
|
||||
issue = Issue.find(3)
|
||||
assert_equal 2, issue.project_id
|
||||
assert_equal 'Project changed', issue.subject
|
||||
end
|
||||
|
||||
context "PUT /issues/6.xml with failed update" do
|
||||
setup do
|
||||
@parameters = {:issue => {:subject => ''}}
|
||||
end
|
||||
test "PUT /issues/:id.xml with failed update" do
|
||||
put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith')
|
||||
|
||||
should "not create a new issue" do
|
||||
assert_no_difference('Issue.count') do
|
||||
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, credentials('jsmith')
|
||||
end
|
||||
end
|
||||
|
||||
should "have an errors tag" do
|
||||
put '/issues/6.xml', @parameters, credentials('jsmith')
|
||||
|
||||
assert_select 'errors error', :text => "Subject can't be blank"
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
assert_select 'errors error', :text => "Subject can't be blank"
|
||||
end
|
||||
|
||||
context "PUT /issues/6.json" do
|
||||
setup do
|
||||
@parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}}
|
||||
test "PUT /issues/:id.json" do
|
||||
assert_difference('Journal.count') do
|
||||
put '/issues/6.json',
|
||||
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
end
|
||||
|
||||
should_allow_api_authentication(:put,
|
||||
'/issues/6.json',
|
||||
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
||||
{:success_code => :ok})
|
||||
|
||||
should "update the issue" do
|
||||
assert_no_difference('Issue.count') do
|
||||
assert_difference('Journal.count') do
|
||||
put '/issues/6.json', @parameters, credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
end
|
||||
end
|
||||
|
||||
issue = Issue.find(6)
|
||||
assert_equal "API update", issue.subject
|
||||
journal = Journal.last
|
||||
assert_equal "A new note", journal.notes
|
||||
end
|
||||
issue = Issue.find(6)
|
||||
assert_equal "API update", issue.subject
|
||||
journal = Journal.last
|
||||
assert_equal "A new note", journal.notes
|
||||
end
|
||||
|
||||
context "PUT /issues/6.json with failed update" do
|
||||
should "return errors" do
|
||||
assert_no_difference('Issue.count') do
|
||||
assert_no_difference('Journal.count') do
|
||||
put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
|
||||
test "PUT /issues/:id.json with failed update" do
|
||||
put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert json['errors'].include?("Subject can't be blank")
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert json['errors'].include?("Subject can't be blank")
|
||||
end
|
||||
|
||||
context "DELETE /issues/1.xml" do
|
||||
should_allow_api_authentication(:delete,
|
||||
'/issues/6.xml',
|
||||
{},
|
||||
{:success_code => :ok})
|
||||
test "DELETE /issues/:id.xml" do
|
||||
assert_difference('Issue.count', -1) do
|
||||
delete '/issues/6.xml', {}, credentials('jsmith')
|
||||
|
||||
should "delete the issue" do
|
||||
assert_difference('Issue.count', -1) do
|
||||
delete '/issues/6.xml', {}, credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
end
|
||||
|
||||
assert_nil Issue.find_by_id(6)
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
end
|
||||
assert_nil Issue.find_by_id(6)
|
||||
end
|
||||
|
||||
context "DELETE /issues/1.json" do
|
||||
should_allow_api_authentication(:delete,
|
||||
'/issues/6.json',
|
||||
{},
|
||||
{:success_code => :ok})
|
||||
test "DELETE /issues/:id.json" do
|
||||
assert_difference('Issue.count', -1) do
|
||||
delete '/issues/6.json', {}, credentials('jsmith')
|
||||
|
||||
should "delete the issue" do
|
||||
assert_difference('Issue.count', -1) do
|
||||
delete '/issues/6.json', {}, credentials('jsmith')
|
||||
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
end
|
||||
|
||||
assert_nil Issue.find_by_id(6)
|
||||
assert_response :ok
|
||||
assert_equal '', response.body
|
||||
end
|
||||
assert_nil Issue.find_by_id(6)
|
||||
end
|
||||
|
||||
test "POST /issues/:id/watchers.xml should add watcher" do
|
||||
|
||||
@ -601,97 +601,62 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
if ldap_configured?
|
||||
context "#try_to_login using LDAP" do
|
||||
context "with failed connection to the LDAP server" do
|
||||
should "return nil" do
|
||||
@auth_source = AuthSourceLdap.find(1)
|
||||
AuthSource.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError, 'Cannot connect')
|
||||
test "#try_to_login using LDAP with failed connection to the LDAP server" do
|
||||
auth_source = AuthSourceLdap.find(1)
|
||||
AuthSource.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError, 'Cannot connect')
|
||||
|
||||
assert_equal nil, User.try_to_login('edavis', 'wrong')
|
||||
end
|
||||
assert_equal nil, User.try_to_login('edavis', 'wrong')
|
||||
end
|
||||
|
||||
test "#try_to_login using LDAP" do
|
||||
assert_equal nil, User.try_to_login('edavis', 'wrong')
|
||||
end
|
||||
|
||||
test "#try_to_login using LDAP binding with user's account" do
|
||||
auth_source = AuthSourceLdap.find(1)
|
||||
auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org"
|
||||
auth_source.account_password = ''
|
||||
auth_source.save!
|
||||
|
||||
ldap_user = User.new(:mail => 'example1@redmine.org', :firstname => 'LDAP', :lastname => 'user', :auth_source_id => 1)
|
||||
ldap_user.login = 'example1'
|
||||
ldap_user.save!
|
||||
|
||||
assert_equal @ldap_user, User.try_to_login('example1', '123456')
|
||||
assert_nil User.try_to_login('example1', '11111')
|
||||
end
|
||||
|
||||
test "#try_to_login using LDAP on the fly registration" do
|
||||
AuthSourceLdap.find(1).update_attribute :onthefly_register, true
|
||||
|
||||
assert_difference('User.count') do
|
||||
assert User.try_to_login('edavis', '123456')
|
||||
end
|
||||
|
||||
context "with an unsuccessful authentication" do
|
||||
should "return nil" do
|
||||
assert_equal nil, User.try_to_login('edavis', 'wrong')
|
||||
end
|
||||
assert_no_difference('User.count') do
|
||||
assert User.try_to_login('edavis', '123456')
|
||||
end
|
||||
|
||||
context "binding with user's account" do
|
||||
setup do
|
||||
@auth_source = AuthSourceLdap.find(1)
|
||||
@auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org"
|
||||
@auth_source.account_password = ''
|
||||
@auth_source.save!
|
||||
assert_nil User.try_to_login('example1', '11111')
|
||||
end
|
||||
|
||||
@ldap_user = User.new(:mail => 'example1@redmine.org', :firstname => 'LDAP', :lastname => 'user', :auth_source_id => 1)
|
||||
@ldap_user.login = 'example1'
|
||||
@ldap_user.save!
|
||||
end
|
||||
test "#try_to_login using LDAP on the fly registration and binding with user's account" do
|
||||
auth_source = AuthSourceLdap.find(1)
|
||||
auth_source.update_attribute :onthefly_register, true
|
||||
auth_source = AuthSourceLdap.find(1)
|
||||
auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org"
|
||||
auth_source.account_password = ''
|
||||
auth_source.save!
|
||||
|
||||
context "with a successful authentication" do
|
||||
should "return the user" do
|
||||
assert_equal @ldap_user, User.try_to_login('example1', '123456')
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unsuccessful authentication" do
|
||||
should "return nil" do
|
||||
assert_nil User.try_to_login('example1', '11111')
|
||||
end
|
||||
end
|
||||
assert_difference('User.count') do
|
||||
assert User.try_to_login('example1', '123456')
|
||||
end
|
||||
|
||||
context "on the fly registration" do
|
||||
setup do
|
||||
@auth_source = AuthSourceLdap.find(1)
|
||||
@auth_source.update_attribute :onthefly_register, true
|
||||
end
|
||||
|
||||
context "with a successful authentication" do
|
||||
should "create a new user account if it doesn't exist" do
|
||||
assert_difference('User.count') do
|
||||
user = User.try_to_login('edavis', '123456')
|
||||
assert !user.admin?
|
||||
end
|
||||
end
|
||||
|
||||
should "retrieve existing user" do
|
||||
user = User.try_to_login('edavis', '123456')
|
||||
user.admin = true
|
||||
user.save!
|
||||
|
||||
assert_no_difference('User.count') do
|
||||
user = User.try_to_login('edavis', '123456')
|
||||
assert user.admin?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "binding with user's account" do
|
||||
setup do
|
||||
@auth_source = AuthSourceLdap.find(1)
|
||||
@auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org"
|
||||
@auth_source.account_password = ''
|
||||
@auth_source.save!
|
||||
end
|
||||
|
||||
context "with a successful authentication" do
|
||||
should "create a new user account if it doesn't exist" do
|
||||
assert_difference('User.count') do
|
||||
user = User.try_to_login('example1', '123456')
|
||||
assert_kind_of User, user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unsuccessful authentication" do
|
||||
should "return nil" do
|
||||
assert_nil User.try_to_login('example1', '11111')
|
||||
end
|
||||
end
|
||||
end
|
||||
assert_no_difference('User.count') do
|
||||
assert User.try_to_login('edavis', '123456')
|
||||
end
|
||||
|
||||
assert_nil User.try_to_login('example1', '11111')
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user