2012-07-24 12:19:51 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-04-11 19:45:56 +00:00
|
|
|
describe API::API, api: true do
|
2012-08-25 17:31:50 +00:00
|
|
|
include ApiHelpers
|
2016-08-09 22:08:59 +00:00
|
|
|
|
2016-03-18 18:11:25 +00:00
|
|
|
let(:user) { create(:user) }
|
2016-04-08 12:17:42 +00:00
|
|
|
let(:user2) { create(:user) }
|
2016-03-18 18:11:25 +00:00
|
|
|
let(:non_member) { create(:user) }
|
2016-06-06 19:13:31 +00:00
|
|
|
let(:guest) { create(:user) }
|
2016-03-18 18:11:25 +00:00
|
|
|
let(:author) { create(:author) }
|
|
|
|
let(:assignee) { create(:assignee) }
|
|
|
|
let(:admin) { create(:user, :admin) }
|
2016-04-07 12:07:17 +00:00
|
|
|
let!(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) }
|
2014-09-04 22:01:12 +00:00
|
|
|
let!(:closed_issue) do
|
|
|
|
create :closed_issue,
|
|
|
|
author: user,
|
|
|
|
assignee: user,
|
|
|
|
project: project,
|
|
|
|
state: :closed,
|
2016-09-09 14:16:14 +00:00
|
|
|
milestone: milestone,
|
2016-09-12 13:11:49 +00:00
|
|
|
created_at: generate(:issue_created_at),
|
2016-09-09 14:16:14 +00:00
|
|
|
updated_at: 3.hours.ago
|
2014-09-04 22:01:12 +00:00
|
|
|
end
|
2016-03-17 20:45:00 +00:00
|
|
|
let!(:confidential_issue) do
|
|
|
|
create :issue,
|
|
|
|
:confidential,
|
|
|
|
project: project,
|
|
|
|
author: author,
|
2016-09-09 14:16:14 +00:00
|
|
|
assignee: assignee,
|
2016-09-12 13:11:49 +00:00
|
|
|
created_at: generate(:issue_created_at),
|
2016-09-09 14:16:14 +00:00
|
|
|
updated_at: 2.hours.ago
|
2016-03-17 20:45:00 +00:00
|
|
|
end
|
2014-09-04 22:01:12 +00:00
|
|
|
let!(:issue) do
|
|
|
|
create :issue,
|
|
|
|
author: user,
|
|
|
|
assignee: user,
|
|
|
|
project: project,
|
2016-09-09 14:16:14 +00:00
|
|
|
milestone: milestone,
|
2016-09-12 13:11:49 +00:00
|
|
|
created_at: generate(:issue_created_at),
|
2016-09-09 14:16:14 +00:00
|
|
|
updated_at: 1.hour.ago
|
2014-09-04 22:01:12 +00:00
|
|
|
end
|
2014-08-14 08:17:52 +00:00
|
|
|
let!(:label) do
|
|
|
|
create(:label, title: 'label', color: '#FFAABB', project: project)
|
|
|
|
end
|
2014-08-14 14:17:19 +00:00
|
|
|
let!(:label_link) { create(:label_link, label: label, target: issue) }
|
2014-09-04 22:01:12 +00:00
|
|
|
let!(:milestone) { create(:milestone, title: '1.0.0', project: project) }
|
|
|
|
let!(:empty_milestone) do
|
|
|
|
create(:milestone, title: '2.0.0', project: project)
|
|
|
|
end
|
2016-03-15 15:17:24 +00:00
|
|
|
let!(:note) { create(:note_on_issue, author: user, project: project, noteable: issue) }
|
2014-08-14 08:17:52 +00:00
|
|
|
|
2016-06-06 19:13:31 +00:00
|
|
|
before do
|
|
|
|
project.team << [user, :reporter]
|
|
|
|
project.team << [guest, :guest]
|
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
|
|
|
|
describe "GET /issues" do
|
2012-09-12 12:11:56 +00:00
|
|
|
context "when unauthenticated" do
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns authentication error" do
|
2012-09-12 12:11:56 +00:00
|
|
|
get api("/issues")
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(401)
|
2012-09-12 12:11:56 +00:00
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
|
|
|
|
2012-09-12 12:11:56 +00:00
|
|
|
context "when authenticated" do
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns an array of issues" do
|
2012-08-25 17:43:55 +00:00
|
|
|
get api("/issues", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['title']).to eq(issue.title)
|
2016-08-02 17:37:04 +00:00
|
|
|
expect(json_response.last).to have_key('web_url')
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
2013-10-29 09:41:20 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "adds pagination headers and keep query params" do
|
2016-02-02 13:34:46 +00:00
|
|
|
get api("/issues?state=closed&per_page=3", user)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(response.headers['Link']).to eq(
|
2016-02-02 13:34:46 +00:00
|
|
|
'<http://www.example.com/api/v3/issues?page=1&per_page=3&private_token=%s&state=closed>; rel="first", <http://www.example.com/api/v3/issues?page=1&per_page=3&private_token=%s&state=closed>; rel="last"' % [user.private_token, user.private_token]
|
2015-02-12 18:17:35 +00:00
|
|
|
)
|
2013-10-29 09:41:20 +00:00
|
|
|
end
|
2014-08-14 10:41:16 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of closed issues' do
|
2014-08-14 10:41:16 +00:00
|
|
|
get api('/issues?state=closed', user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['id']).to eq(closed_issue.id)
|
2014-08-14 10:41:16 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of opened issues' do
|
2014-08-14 10:41:16 +00:00
|
|
|
get api('/issues?state=opened', user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['id']).to eq(issue.id)
|
2014-08-14 10:41:16 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of all issues' do
|
2014-08-14 10:41:16 +00:00
|
|
|
get api('/issues?state=all', user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.first['id']).to eq(issue.id)
|
|
|
|
expect(json_response.second['id']).to eq(closed_issue.id)
|
2014-08-14 10:41:16 +00:00
|
|
|
end
|
2014-08-14 14:17:19 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of labeled issues' do
|
2014-08-14 14:17:19 +00:00
|
|
|
get api("/issues?labels=#{label.title}", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
2014-08-14 14:17:19 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of labeled issues when at least one label matches' do
|
2014-08-14 14:17:19 +00:00
|
|
|
get api("/issues?labels=#{label.title},foo,bar", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
2014-08-14 14:17:19 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an empty array if no issue matches labels' do
|
2014-08-14 14:17:19 +00:00
|
|
|
get api('/issues?labels=foo,bar', user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-08-14 14:17:19 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of labeled issues matching given state' do
|
2014-08-14 14:17:19 +00:00
|
|
|
get api("/issues?labels=#{label.title}&state=opened", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
|
|
|
expect(json_response.first['state']).to eq('opened')
|
2014-08-14 14:17:19 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an empty array if no issue matches labels and state filters' do
|
2014-08-14 14:17:19 +00:00
|
|
|
get api("/issues?labels=#{label.title}&state=closed", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-08-14 14:17:19 +00:00
|
|
|
end
|
2016-09-09 14:16:14 +00:00
|
|
|
|
|
|
|
it 'sorts by created_at descending by default' do
|
|
|
|
get api('/issues', user)
|
|
|
|
response_dates = json_response.map { |issue| issue['created_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort.reverse)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts ascending when requested' do
|
|
|
|
get api('/issues?sort=asc', user)
|
|
|
|
response_dates = json_response.map { |issue| issue['created_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts by updated_at descending when requested' do
|
|
|
|
get api('/issues?order_by=updated_at', user)
|
|
|
|
response_dates = json_response.map { |issue| issue['updated_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort.reverse)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts by updated_at ascending when requested' do
|
|
|
|
get api('/issues?order_by=updated_at&sort=asc', user)
|
|
|
|
response_dates = json_response.map { |issue| issue['updated_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort)
|
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-07 22:01:54 +00:00
|
|
|
describe "GET /groups/:id/issues" do
|
|
|
|
let!(:group) { create(:group) }
|
|
|
|
let!(:group_project) { create(:project, :public, creator_id: user.id, namespace: group) }
|
|
|
|
let!(:group_closed_issue) do
|
|
|
|
create :closed_issue,
|
|
|
|
author: user,
|
|
|
|
assignee: user,
|
|
|
|
project: group_project,
|
|
|
|
state: :closed,
|
2016-09-09 14:16:14 +00:00
|
|
|
milestone: group_milestone,
|
|
|
|
updated_at: 3.hours.ago
|
2016-06-07 22:01:54 +00:00
|
|
|
end
|
|
|
|
let!(:group_confidential_issue) do
|
|
|
|
create :issue,
|
|
|
|
:confidential,
|
|
|
|
project: group_project,
|
|
|
|
author: author,
|
2016-09-09 14:16:14 +00:00
|
|
|
assignee: assignee,
|
|
|
|
updated_at: 2.hours.ago
|
2016-06-07 22:01:54 +00:00
|
|
|
end
|
|
|
|
let!(:group_issue) do
|
|
|
|
create :issue,
|
|
|
|
author: user,
|
|
|
|
assignee: user,
|
|
|
|
project: group_project,
|
2016-09-09 14:16:14 +00:00
|
|
|
milestone: group_milestone,
|
|
|
|
updated_at: 1.hour.ago
|
2016-06-07 22:01:54 +00:00
|
|
|
end
|
|
|
|
let!(:group_label) do
|
|
|
|
create(:label, title: 'group_lbl', color: '#FFAABB', project: group_project)
|
|
|
|
end
|
|
|
|
let!(:group_label_link) { create(:label_link, label: group_label, target: group_issue) }
|
|
|
|
let!(:group_milestone) { create(:milestone, title: '3.0.0', project: group_project) }
|
|
|
|
let!(:group_empty_milestone) do
|
|
|
|
create(:milestone, title: '4.0.0', project: group_project)
|
|
|
|
end
|
|
|
|
let!(:group_note) { create(:note_on_issue, author: user, project: group_project, noteable: group_issue) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group_project.team << [user, :reporter]
|
|
|
|
end
|
|
|
|
let(:base_url) { "/groups/#{group.id}/issues" }
|
|
|
|
|
|
|
|
it 'returns group issues without confidential issues for non project members' do
|
|
|
|
get api(base_url, non_member)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['title']).to eq(group_issue.title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns group confidential issues for author' do
|
|
|
|
get api(base_url, author)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns group confidential issues for assignee' do
|
|
|
|
get api(base_url, assignee)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns group issues with confidential issues for project members' do
|
|
|
|
get api(base_url, user)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns group confidential issues for admin' do
|
|
|
|
get api(base_url, admin)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an array of labeled group issues' do
|
|
|
|
get api("#{base_url}?labels=#{group_label.title}", user)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([group_label.title])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an array of labeled group issues where all labels match' do
|
|
|
|
get api("#{base_url}?labels=#{group_label.title},foo,bar", user)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty array if no group issue matches labels' do
|
|
|
|
get api("#{base_url}?labels=foo,bar", user)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty array if no issue matches milestone' do
|
|
|
|
get api("#{base_url}?milestone=#{group_empty_milestone.title}", user)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty array if milestone does not exist' do
|
|
|
|
get api("#{base_url}?milestone=foo", user)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an array of issues in given milestone' do
|
|
|
|
get api("#{base_url}?milestone=#{group_milestone.title}", user)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['id']).to eq(group_issue.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an array of issues matching state in milestone' do
|
|
|
|
get api("#{base_url}?milestone=#{group_milestone.title}"\
|
|
|
|
'&state=closed', user)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-07 22:01:54 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['id']).to eq(group_closed_issue.id)
|
|
|
|
end
|
2016-09-09 14:16:14 +00:00
|
|
|
|
|
|
|
it 'sorts by created_at descending by default' do
|
|
|
|
get api(base_url, user)
|
|
|
|
response_dates = json_response.map { |issue| issue['created_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort.reverse)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts ascending when requested' do
|
|
|
|
get api("#{base_url}?sort=asc", user)
|
|
|
|
response_dates = json_response.map { |issue| issue['created_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts by updated_at descending when requested' do
|
|
|
|
get api("#{base_url}?order_by=updated_at", user)
|
|
|
|
response_dates = json_response.map { |issue| issue['updated_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort.reverse)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts by updated_at ascending when requested' do
|
|
|
|
get api("#{base_url}?order_by=updated_at&sort=asc", user)
|
|
|
|
response_dates = json_response.map { |issue| issue['updated_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort)
|
|
|
|
end
|
2016-06-07 22:01:54 +00:00
|
|
|
end
|
|
|
|
|
2012-07-24 12:19:51 +00:00
|
|
|
describe "GET /projects/:id/issues" do
|
2014-09-04 22:01:12 +00:00
|
|
|
let(:base_url) { "/projects/#{project.id}" }
|
|
|
|
let(:title) { milestone.title }
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns project issues without confidential issues for non project members' do
|
2016-03-17 20:45:00 +00:00
|
|
|
get api("#{base_url}/issues", non_member)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.first['title']).to eq(issue.title)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns project issues without confidential issues for project members with guest role' do
|
2016-06-06 19:13:31 +00:00
|
|
|
get api("#{base_url}/issues", guest)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-06-06 19:13:31 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.first['title']).to eq(issue.title)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns project confidential issues for author' do
|
2016-03-17 20:45:00 +00:00
|
|
|
get api("#{base_url}/issues", author)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(3)
|
|
|
|
expect(json_response.first['title']).to eq(issue.title)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns project confidential issues for assignee' do
|
2016-03-17 20:45:00 +00:00
|
|
|
get api("#{base_url}/issues", assignee)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(3)
|
|
|
|
expect(json_response.first['title']).to eq(issue.title)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns project issues with confidential issues for project members' do
|
2014-09-04 22:01:12 +00:00
|
|
|
get api("#{base_url}/issues", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response.length).to eq(3)
|
|
|
|
expect(json_response.first['title']).to eq(issue.title)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns project confidential issues for admin' do
|
2016-03-17 20:45:00 +00:00
|
|
|
get api("#{base_url}/issues", admin)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(3)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response.first['title']).to eq(issue.title)
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
2014-08-14 14:17:19 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of labeled project issues' do
|
2014-09-04 22:01:12 +00:00
|
|
|
get api("#{base_url}/issues?labels=#{label.title}", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
2014-08-14 14:17:19 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of labeled project issues when at least one label matches' do
|
2014-09-04 22:01:12 +00:00
|
|
|
get api("#{base_url}/issues?labels=#{label.title},foo,bar", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
2014-08-14 14:17:19 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an empty array if no project issue matches labels' do
|
2014-09-04 22:01:12 +00:00
|
|
|
get api("#{base_url}/issues?labels=foo,bar", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-09-04 22:01:12 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an empty array if no issue matches milestone' do
|
2014-09-04 22:01:12 +00:00
|
|
|
get api("#{base_url}/issues?milestone=#{empty_milestone.title}", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-08-14 14:17:19 +00:00
|
|
|
end
|
2014-09-04 22:01:12 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an empty array if milestone does not exist' do
|
2014-09-04 22:01:12 +00:00
|
|
|
get api("#{base_url}/issues?milestone=foo", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-09-04 22:01:12 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of issues in given milestone' do
|
2014-09-04 22:01:12 +00:00
|
|
|
get api("#{base_url}/issues?milestone=#{title}", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.first['id']).to eq(issue.id)
|
|
|
|
expect(json_response.second['id']).to eq(closed_issue.id)
|
2014-09-04 22:01:12 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns an array of issues matching state in milestone' do
|
2014-09-04 22:01:12 +00:00
|
|
|
get api("#{base_url}/issues?milestone=#{milestone.title}"\
|
|
|
|
'&state=closed', user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['id']).to eq(closed_issue.id)
|
2014-09-04 22:01:12 +00:00
|
|
|
end
|
2016-09-09 14:16:14 +00:00
|
|
|
|
|
|
|
it 'sorts by created_at descending by default' do
|
|
|
|
get api("#{base_url}/issues", user)
|
|
|
|
response_dates = json_response.map { |issue| issue['created_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort.reverse)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts ascending when requested' do
|
|
|
|
get api("#{base_url}/issues?sort=asc", user)
|
|
|
|
response_dates = json_response.map { |issue| issue['created_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts by updated_at descending when requested' do
|
|
|
|
get api("#{base_url}/issues?order_by=updated_at", user)
|
|
|
|
response_dates = json_response.map { |issue| issue['updated_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort.reverse)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts by updated_at ascending when requested' do
|
|
|
|
get api("#{base_url}/issues?order_by=updated_at&sort=asc", user)
|
|
|
|
response_dates = json_response.map { |issue| issue['updated_at'] }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response_dates).to eq(response_dates.sort)
|
|
|
|
end
|
2016-03-15 15:17:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/issues/:issue_id" do
|
|
|
|
it 'exposes known attributes' do
|
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}", user)
|
2016-02-23 21:59:32 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-15 15:17:24 +00:00
|
|
|
expect(json_response['id']).to eq(issue.id)
|
|
|
|
expect(json_response['iid']).to eq(issue.iid)
|
|
|
|
expect(json_response['project_id']).to eq(issue.project.id)
|
|
|
|
expect(json_response['title']).to eq(issue.title)
|
|
|
|
expect(json_response['description']).to eq(issue.description)
|
|
|
|
expect(json_response['state']).to eq(issue.state)
|
|
|
|
expect(json_response['created_at']).to be_present
|
|
|
|
expect(json_response['updated_at']).to be_present
|
|
|
|
expect(json_response['labels']).to eq(issue.label_names)
|
|
|
|
expect(json_response['milestone']).to be_a Hash
|
|
|
|
expect(json_response['assignee']).to be_a Hash
|
|
|
|
expect(json_response['author']).to be_a Hash
|
2016-07-15 14:21:53 +00:00
|
|
|
expect(json_response['confidential']).to be_falsy
|
2016-02-23 21:59:32 +00:00
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns a project issue by id" do
|
2013-01-02 17:46:06 +00:00
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}", user)
|
2016-03-15 15:17:24 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['title']).to eq(issue.title)
|
|
|
|
expect(json_response['iid']).to eq(issue.iid)
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
2013-02-27 13:36:20 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns a project issue by iid' do
|
2015-01-17 22:45:39 +00:00
|
|
|
get api("/projects/#{project.id}/issues?iid=#{issue.iid}", user)
|
2015-06-13 22:24:51 +00:00
|
|
|
expect(response.status).to eq 200
|
|
|
|
expect(json_response.first['title']).to eq issue.title
|
|
|
|
expect(json_response.first['id']).to eq issue.id
|
|
|
|
expect(json_response.first['iid']).to eq issue.iid
|
2015-01-17 22:45:39 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns 404 if issue id not found" do
|
2013-02-27 13:36:20 +00:00
|
|
|
get api("/projects/#{project.id}/issues/54321", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2013-02-27 13:36:20 +00:00
|
|
|
end
|
2016-03-17 20:45:00 +00:00
|
|
|
|
|
|
|
context 'confidential issues' do
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns 404 for non project members" do
|
2016-03-17 20:45:00 +00:00
|
|
|
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-03-17 20:45:00 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns 404 for project members with guest role" do
|
2016-06-06 19:13:31 +00:00
|
|
|
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", guest)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-06-06 19:13:31 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns confidential issue for project members" do
|
2016-03-17 20:45:00 +00:00
|
|
|
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", user)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response['title']).to eq(confidential_issue.title)
|
|
|
|
expect(json_response['iid']).to eq(confidential_issue.iid)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns confidential issue for author" do
|
2016-03-17 20:45:00 +00:00
|
|
|
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", author)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response['title']).to eq(confidential_issue.title)
|
|
|
|
expect(json_response['iid']).to eq(confidential_issue.iid)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns confidential issue for assignee" do
|
2016-03-17 20:45:00 +00:00
|
|
|
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", assignee)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response['title']).to eq(confidential_issue.title)
|
|
|
|
expect(json_response['iid']).to eq(confidential_issue.iid)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns confidential issue for admin" do
|
2016-03-17 20:45:00 +00:00
|
|
|
get api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response['title']).to eq(confidential_issue.title)
|
|
|
|
expect(json_response['iid']).to eq(confidential_issue.iid)
|
|
|
|
end
|
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/issues" do
|
2016-07-15 14:21:53 +00:00
|
|
|
it 'creates a new project issue' do
|
2013-01-02 17:46:06 +00:00
|
|
|
post api("/projects/#{project.id}/issues", user),
|
2012-08-10 22:07:50 +00:00
|
|
|
title: 'new issue', labels: 'label, label2'
|
2016-07-15 14:21:53 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(201)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['title']).to eq('new issue')
|
|
|
|
expect(json_response['description']).to be_nil
|
|
|
|
expect(json_response['labels']).to eq(['label', 'label2'])
|
2016-07-15 14:21:53 +00:00
|
|
|
expect(json_response['confidential']).to be_falsy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new confidential project issue' do
|
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'new issue', confidential: true
|
|
|
|
|
|
|
|
expect(response).to have_http_status(201)
|
|
|
|
expect(json_response['title']).to eq('new issue')
|
|
|
|
expect(json_response['confidential']).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new confidential project issue with a different param' do
|
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'new issue', confidential: 'y'
|
|
|
|
|
|
|
|
expect(response).to have_http_status(201)
|
|
|
|
expect(json_response['title']).to eq('new issue')
|
|
|
|
expect(json_response['confidential']).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a public issue when confidential param is false' do
|
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'new issue', confidential: false
|
|
|
|
|
|
|
|
expect(response).to have_http_status(201)
|
|
|
|
expect(json_response['title']).to eq('new issue')
|
|
|
|
expect(json_response['confidential']).to be_falsy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a public issue when confidential param is invalid' do
|
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'new issue', confidential: 'foo'
|
|
|
|
|
|
|
|
expect(response).to have_http_status(201)
|
|
|
|
expect(json_response['title']).to eq('new issue')
|
|
|
|
expect(json_response['confidential']).to be_falsy
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
2013-02-27 13:36:20 +00:00
|
|
|
|
2016-08-15 16:50:41 +00:00
|
|
|
it "sends notifications for subscribers of newly added labels" do
|
2016-08-09 22:08:59 +00:00
|
|
|
label = project.labels.first
|
2016-11-04 18:19:08 +00:00
|
|
|
label.toggle_subscription(user2, project)
|
2016-08-09 22:08:59 +00:00
|
|
|
|
2016-08-15 16:50:41 +00:00
|
|
|
perform_enqueued_jobs do
|
2016-08-09 22:08:59 +00:00
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'new issue', labels: label.title
|
2016-08-15 16:50:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
should_email(user2)
|
2016-08-09 22:08:59 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns a 400 bad request if title not given" do
|
2013-02-27 13:36:20 +00:00
|
|
|
post api("/projects/#{project.id}/issues", user), labels: 'label, label2'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(400)
|
2013-02-27 13:36:20 +00:00
|
|
|
end
|
2014-08-14 08:17:52 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'allows special label names' do
|
2014-08-14 08:17:52 +00:00
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'new issue',
|
2016-06-16 23:09:13 +00:00
|
|
|
labels: 'label, label?, label&foo, ?, &'
|
|
|
|
expect(response.status).to eq(201)
|
|
|
|
expect(json_response['labels']).to include 'label'
|
|
|
|
expect(json_response['labels']).to include 'label?'
|
|
|
|
expect(json_response['labels']).to include 'label&foo'
|
|
|
|
expect(json_response['labels']).to include '?'
|
|
|
|
expect(json_response['labels']).to include '&'
|
2014-08-14 08:17:52 +00:00
|
|
|
end
|
2014-08-18 18:09:09 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns 400 if title is too long' do
|
2014-08-18 18:09:09 +00:00
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'g' * 256
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(400)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['message']['title']).to eq([
|
2014-08-18 18:09:09 +00:00
|
|
|
'is too long (maximum is 255 characters)'
|
2015-02-12 18:17:35 +00:00
|
|
|
])
|
2014-08-18 18:09:09 +00:00
|
|
|
end
|
2016-03-25 21:21:50 +00:00
|
|
|
|
2016-07-12 15:59:21 +00:00
|
|
|
context 'with due date' do
|
|
|
|
it 'creates a new project issue' do
|
|
|
|
due_date = 2.weeks.from_now.strftime('%Y-%m-%d')
|
|
|
|
|
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'new issue', due_date: due_date
|
|
|
|
|
|
|
|
expect(response).to have_http_status(201)
|
|
|
|
expect(json_response['title']).to eq('new issue')
|
|
|
|
expect(json_response['description']).to be_nil
|
|
|
|
expect(json_response['due_date']).to eq(due_date)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-25 21:21:50 +00:00
|
|
|
context 'when an admin or owner makes the request' do
|
2016-04-05 17:05:55 +00:00
|
|
|
it 'accepts the creation date to be set' do
|
|
|
|
creation_time = 2.weeks.ago
|
2016-03-25 21:21:50 +00:00
|
|
|
post api("/projects/#{project.id}/issues", user),
|
2016-04-05 17:05:55 +00:00
|
|
|
title: 'new issue', labels: 'label, label2', created_at: creation_time
|
2016-03-25 21:21:50 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(201)
|
2016-10-17 12:40:02 +00:00
|
|
|
expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
|
2016-03-25 21:21:50 +00:00
|
|
|
end
|
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
|
|
|
|
2016-01-09 19:30:34 +00:00
|
|
|
describe 'POST /projects/:id/issues with spam filtering' do
|
|
|
|
before do
|
2016-08-09 17:43:47 +00:00
|
|
|
allow_any_instance_of(SpamService).to receive(:check_for_spam?).and_return(true)
|
2016-08-05 22:10:08 +00:00
|
|
|
allow_any_instance_of(AkismetService).to receive_messages(is_spam?: true)
|
2016-01-09 19:30:34 +00:00
|
|
|
end
|
|
|
|
|
2016-01-26 21:51:52 +00:00
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
title: 'new issue',
|
|
|
|
description: 'content here',
|
|
|
|
labels: 'label, label2'
|
|
|
|
}
|
|
|
|
end
|
2016-01-26 20:08:20 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "does not create a new project issue" do
|
2016-01-26 21:51:52 +00:00
|
|
|
expect { post api("/projects/#{project.id}/issues", user), params }.not_to change(Issue, :count)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(400)
|
2016-01-09 19:30:34 +00:00
|
|
|
expect(json_response['message']).to eq({ "error" => "Spam detected" })
|
2016-01-26 20:08:20 +00:00
|
|
|
|
2016-01-09 19:30:34 +00:00
|
|
|
spam_logs = SpamLog.all
|
|
|
|
expect(spam_logs.count).to eq(1)
|
|
|
|
expect(spam_logs[0].title).to eq('new issue')
|
2016-01-26 20:08:20 +00:00
|
|
|
expect(spam_logs[0].description).to eq('content here')
|
2016-01-09 19:30:34 +00:00
|
|
|
expect(spam_logs[0].user).to eq(user)
|
|
|
|
expect(spam_logs[0].noteable_type).to eq('Issue')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-18 09:10:58 +00:00
|
|
|
describe "PUT /projects/:id/issues/:issue_id to update only title" do
|
2016-08-01 15:00:44 +00:00
|
|
|
it "updates a project issue" do
|
2013-01-02 17:46:06 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
2013-02-18 09:10:58 +00:00
|
|
|
title: 'updated title'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2013-02-18 09:10:58 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['title']).to eq('updated title')
|
2013-02-18 09:10:58 +00:00
|
|
|
end
|
2013-02-27 13:36:20 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns 404 error if issue id not found" do
|
2013-02-27 13:36:20 +00:00
|
|
|
put api("/projects/#{project.id}/issues/44444", user),
|
|
|
|
title: 'updated title'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2013-02-27 13:36:20 +00:00
|
|
|
end
|
2014-08-14 08:17:52 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'allows special label names' do
|
2014-08-14 08:17:52 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
title: 'updated title',
|
2016-06-16 23:09:13 +00:00
|
|
|
labels: 'label, label?, label&foo, ?, &'
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['labels']).to include 'label'
|
|
|
|
expect(json_response['labels']).to include 'label?'
|
|
|
|
expect(json_response['labels']).to include 'label&foo'
|
|
|
|
expect(json_response['labels']).to include '?'
|
|
|
|
expect(json_response['labels']).to include '&'
|
2014-08-17 20:22:01 +00:00
|
|
|
end
|
2016-03-17 20:45:00 +00:00
|
|
|
|
|
|
|
context 'confidential issues' do
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns 403 for non project members" do
|
2016-03-17 20:45:00 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member),
|
|
|
|
title: 'updated title'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(403)
|
2016-03-17 20:45:00 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "returns 403 for project members with guest role" do
|
2016-06-06 19:13:31 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", guest),
|
|
|
|
title: 'updated title'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(403)
|
2016-06-06 19:13:31 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "updates a confidential issue for project members" do
|
2016-03-17 20:45:00 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", user),
|
|
|
|
title: 'updated title'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response['title']).to eq('updated title')
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "updates a confidential issue for author" do
|
2016-03-17 20:45:00 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", author),
|
|
|
|
title: 'updated title'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response['title']).to eq('updated title')
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "updates a confidential issue for admin" do
|
2016-03-17 20:45:00 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin),
|
|
|
|
title: 'updated title'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-17 20:45:00 +00:00
|
|
|
expect(json_response['title']).to eq('updated title')
|
|
|
|
end
|
2016-07-15 14:21:53 +00:00
|
|
|
|
|
|
|
it 'sets an issue to confidential' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
confidential: true
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response['confidential']).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes a confidential issue public' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", user),
|
|
|
|
confidential: false
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response['confidential']).to be_falsy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update a confidential issue with wrong confidential flag' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{confidential_issue.id}", user),
|
|
|
|
confidential: 'foo'
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response['confidential']).to be_truthy
|
|
|
|
end
|
2016-03-17 20:45:00 +00:00
|
|
|
end
|
2014-08-17 20:22:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/issues/:issue_id to update labels' do
|
|
|
|
let!(:label) { create(:label, title: 'dummy', project: project) }
|
|
|
|
let!(:label_link) { create(:label_link, label: label, target: issue) }
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'does not update labels if not present' do
|
2014-08-17 20:22:01 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
title: 'updated title'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['labels']).to eq([label.title])
|
2014-08-17 20:22:01 +00:00
|
|
|
end
|
|
|
|
|
2016-08-15 16:50:41 +00:00
|
|
|
it "sends notifications for subscribers of newly added labels when issue is updated" do
|
2016-08-18 10:24:44 +00:00
|
|
|
label = create(:label, title: 'foo', color: '#FFAABB', project: project)
|
2016-11-04 18:19:08 +00:00
|
|
|
label.toggle_subscription(user2, project)
|
2016-08-15 16:50:41 +00:00
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
title: 'updated title', labels: label.title
|
|
|
|
end
|
|
|
|
|
|
|
|
should_email(user2)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'removes all labels' do
|
2014-08-17 20:22:01 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: ''
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['labels']).to eq([])
|
2014-08-17 20:22:01 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'updates labels' do
|
2014-08-17 20:22:01 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: 'foo,bar'
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['labels']).to include 'foo'
|
|
|
|
expect(json_response['labels']).to include 'bar'
|
2014-08-17 20:22:01 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'allows special label names' do
|
2014-08-17 20:22:01 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
2016-06-16 23:09:13 +00:00
|
|
|
labels: 'label:foo, label-bar,label_bar,label/bar,label?bar,label&bar,?,&'
|
|
|
|
expect(response.status).to eq(200)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['labels']).to include 'label:foo'
|
|
|
|
expect(json_response['labels']).to include 'label-bar'
|
|
|
|
expect(json_response['labels']).to include 'label_bar'
|
|
|
|
expect(json_response['labels']).to include 'label/bar'
|
2016-06-16 23:09:13 +00:00
|
|
|
expect(json_response['labels']).to include 'label?bar'
|
|
|
|
expect(json_response['labels']).to include 'label&bar'
|
|
|
|
expect(json_response['labels']).to include '?'
|
|
|
|
expect(json_response['labels']).to include '&'
|
2014-08-14 08:17:52 +00:00
|
|
|
end
|
2014-08-18 18:09:09 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'returns 400 if title is too long' do
|
2014-08-18 18:09:09 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
title: 'g' * 256
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(400)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['message']['title']).to eq([
|
2014-08-18 18:09:09 +00:00
|
|
|
'is too long (maximum is 255 characters)'
|
2015-02-12 18:17:35 +00:00
|
|
|
])
|
2014-08-18 18:09:09 +00:00
|
|
|
end
|
2013-02-18 09:10:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /projects/:id/issues/:issue_id to update state and label" do
|
2016-08-01 15:00:44 +00:00
|
|
|
it "updates a project issue" do
|
2013-02-18 09:10:58 +00:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: 'label2', state_event: "close"
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2013-02-18 09:10:58 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response['labels']).to include 'label2'
|
|
|
|
expect(json_response['state']).to eq "closed"
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
2016-04-05 17:05:55 +00:00
|
|
|
|
|
|
|
context 'when an admin or owner makes the request' do
|
|
|
|
it 'accepts the update date to be set' do
|
|
|
|
update_time = 2.weeks.ago
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: 'label3', state_event: 'close', updated_at: update_time
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-04-05 17:05:55 +00:00
|
|
|
|
|
|
|
expect(json_response['labels']).to include 'label3'
|
2016-10-17 12:40:02 +00:00
|
|
|
expect(Time.parse(json_response['updated_at'])).to be_like_time(update_time)
|
2016-04-05 17:05:55 +00:00
|
|
|
end
|
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
|
|
|
|
2016-07-12 15:59:21 +00:00
|
|
|
describe 'PUT /projects/:id/issues/:issue_id to update due date' do
|
|
|
|
it 'creates a new project issue' do
|
|
|
|
due_date = 2.weeks.from_now.strftime('%Y-%m-%d')
|
|
|
|
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user), due_date: due_date
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response['due_date']).to eq(due_date)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 12:19:51 +00:00
|
|
|
describe "DELETE /projects/:id/issues/:issue_id" do
|
2016-03-21 13:12:52 +00:00
|
|
|
it "rejects a non member from deleting an issue" do
|
2016-03-18 18:11:25 +00:00
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}", non_member)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(403)
|
2016-02-26 08:55:43 +00:00
|
|
|
end
|
|
|
|
|
2016-03-21 13:12:52 +00:00
|
|
|
it "rejects a developer from deleting an issue" do
|
2016-03-18 18:11:25 +00:00
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}", author)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(403)
|
2016-03-18 18:11:25 +00:00
|
|
|
end
|
2016-02-26 08:55:43 +00:00
|
|
|
|
2016-03-21 13:12:52 +00:00
|
|
|
context "when the user is project owner" do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
let(:project) { create(:project, namespace: owner.namespace) }
|
|
|
|
|
|
|
|
it "deletes the issue if an admin requests it" do
|
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}", owner)
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-21 13:12:52 +00:00
|
|
|
expect(json_response['state']).to eq 'opened'
|
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
|
|
|
end
|
2016-04-07 12:07:17 +00:00
|
|
|
|
|
|
|
describe '/projects/:id/issues/:issue_id/move' do
|
|
|
|
let!(:target_project) { create(:project, path: 'project2', creator_id: user.id, namespace: user.namespace ) }
|
|
|
|
let!(:target_project2) { create(:project, creator_id: non_member.id, namespace: non_member.namespace ) }
|
|
|
|
|
|
|
|
it 'moves an issue' do
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
2016-04-12 16:38:18 +00:00
|
|
|
to_project_id: target_project.id
|
2016-04-07 12:07:17 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(201)
|
2016-04-07 12:07:17 +00:00
|
|
|
expect(json_response['project_id']).to eq(target_project.id)
|
|
|
|
end
|
|
|
|
|
2016-04-12 16:38:18 +00:00
|
|
|
context 'when source and target projects are the same' do
|
|
|
|
it 'returns 400 when trying to move an issue' do
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
|
|
|
to_project_id: project.id
|
2016-04-07 12:07:17 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(400)
|
2016-04-12 16:38:18 +00:00
|
|
|
expect(json_response['message']).to eq('Cannot move issue to project it originates from!')
|
|
|
|
end
|
2016-04-07 12:07:17 +00:00
|
|
|
end
|
|
|
|
|
2016-04-12 16:38:18 +00:00
|
|
|
context 'when the user does not have the permission to move issues' do
|
|
|
|
it 'returns 400 when trying to move an issue' do
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
|
|
|
to_project_id: target_project2.id
|
2016-04-07 12:07:17 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(400)
|
2016-04-12 16:38:18 +00:00
|
|
|
expect(json_response['message']).to eq('Cannot move issue due to insufficient permissions!')
|
|
|
|
end
|
2016-04-07 12:07:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'moves the issue to another namespace if I am admin' do
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", admin),
|
2016-04-12 16:38:18 +00:00
|
|
|
to_project_id: target_project2.id
|
2016-04-07 12:07:17 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(201)
|
2016-04-07 12:07:17 +00:00
|
|
|
expect(json_response['project_id']).to eq(target_project2.id)
|
|
|
|
end
|
|
|
|
|
2016-04-12 16:38:18 +00:00
|
|
|
context 'when issue does not exist' do
|
|
|
|
it 'returns 404 when trying to move an issue' do
|
|
|
|
post api("/projects/#{project.id}/issues/123/move", user),
|
|
|
|
to_project_id: target_project.id
|
2016-04-07 12:07:17 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-12 16:38:18 +00:00
|
|
|
end
|
2016-04-07 12:07:17 +00:00
|
|
|
end
|
|
|
|
|
2016-04-12 16:38:18 +00:00
|
|
|
context 'when source project does not exist' do
|
|
|
|
it 'returns 404 when trying to move an issue' do
|
|
|
|
post api("/projects/123/issues/#{issue.id}/move", user),
|
|
|
|
to_project_id: target_project.id
|
2016-04-07 12:07:17 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-12 16:38:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when target project does not exist' do
|
|
|
|
it 'returns 404 when trying to move an issue' do
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
|
|
|
to_project_id: 123
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-12 16:38:18 +00:00
|
|
|
end
|
2016-04-07 12:07:17 +00:00
|
|
|
end
|
|
|
|
end
|
2016-04-08 12:17:42 +00:00
|
|
|
|
2016-04-12 12:46:59 +00:00
|
|
|
describe 'POST :id/issues/:issue_id/subscription' do
|
2016-04-08 12:17:42 +00:00
|
|
|
it 'subscribes to an issue' do
|
2016-04-12 12:46:59 +00:00
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2)
|
2016-04-08 12:17:42 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(201)
|
2016-04-08 12:17:42 +00:00
|
|
|
expect(json_response['subscribed']).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 304 if already subscribed' do
|
2016-04-12 12:46:59 +00:00
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user)
|
2016-04-08 12:17:42 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(304)
|
2016-04-08 12:17:42 +00:00
|
|
|
end
|
2016-04-12 12:46:59 +00:00
|
|
|
|
|
|
|
it 'returns 404 if the issue is not found' do
|
|
|
|
post api("/projects/#{project.id}/issues/123/subscription", user)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-12 12:46:59 +00:00
|
|
|
end
|
2016-05-12 20:48:09 +00:00
|
|
|
|
|
|
|
it 'returns 404 if the issue is confidential' do
|
|
|
|
post api("/projects/#{project.id}/issues/#{confidential_issue.id}/subscription", non_member)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-05-12 20:48:09 +00:00
|
|
|
end
|
2016-04-08 12:17:42 +00:00
|
|
|
end
|
|
|
|
|
2016-04-12 12:46:59 +00:00
|
|
|
describe 'DELETE :id/issues/:issue_id/subscription' do
|
2016-04-08 12:17:42 +00:00
|
|
|
it 'unsubscribes from an issue' do
|
2016-04-13 14:30:20 +00:00
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user)
|
2016-04-08 12:17:42 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-04-08 12:17:42 +00:00
|
|
|
expect(json_response['subscribed']).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 304 if not subscribed' do
|
2016-04-13 14:30:20 +00:00
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2)
|
2016-04-08 12:17:42 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(304)
|
2016-04-08 12:17:42 +00:00
|
|
|
end
|
2016-04-12 12:46:59 +00:00
|
|
|
|
|
|
|
it 'returns 404 if the issue is not found' do
|
2016-04-13 14:30:20 +00:00
|
|
|
delete api("/projects/#{project.id}/issues/123/subscription", user)
|
2016-04-12 12:46:59 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-12 12:46:59 +00:00
|
|
|
end
|
2016-05-12 20:48:09 +00:00
|
|
|
|
|
|
|
it 'returns 404 if the issue is confidential' do
|
|
|
|
delete api("/projects/#{project.id}/issues/#{confidential_issue.id}/subscription", non_member)
|
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-05-12 20:48:09 +00:00
|
|
|
end
|
2016-04-08 12:17:42 +00:00
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|