2018-05-22 11:22:51 -04:00
|
|
|
require 'spec_helper'
|
2015-07-18 01:54:04 -04:00
|
|
|
|
|
|
|
describe Projects::IssuesController do
|
2017-08-09 09:41:45 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-02-26 03:55:43 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
2015-07-18 01:54:04 -04:00
|
|
|
|
2016-02-26 03:55:43 -05:00
|
|
|
describe "GET #index" do
|
2016-08-01 19:59:44 -04:00
|
|
|
context 'external issue tracker' do
|
2017-06-13 04:25:25 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.add_developer(user)
|
|
|
|
create(:jira_service, project: project)
|
2017-07-17 14:56:35 -04:00
|
|
|
end
|
|
|
|
|
2017-06-13 04:25:25 -04:00
|
|
|
context 'when GitLab issues disabled' do
|
|
|
|
it 'returns 404 status' do
|
|
|
|
project.issues_enabled = false
|
|
|
|
project.save!
|
2015-07-18 01:54:04 -04:00
|
|
|
|
2017-06-13 04:25:25 -04:00
|
|
|
get :index, namespace_id: project.namespace, project_id: project
|
2015-07-18 01:54:04 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-06-13 04:25:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when GitLab issues enabled' do
|
|
|
|
it 'renders the "index" template' do
|
|
|
|
get :index, namespace_id: project.namespace, project_id: project
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-13 04:25:25 -04:00
|
|
|
expect(response).to render_template(:index)
|
|
|
|
end
|
2016-08-01 19:59:44 -04:00
|
|
|
end
|
2015-07-18 01:54:04 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 19:59:44 -04:00
|
|
|
context 'internal issue tracker' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-08-01 19:59:44 -04:00
|
|
|
end
|
2015-09-17 09:56:16 -04:00
|
|
|
|
2017-01-23 15:40:25 -05:00
|
|
|
it_behaves_like "issuables list meta-data", :issue
|
|
|
|
|
2016-08-01 19:59:44 -04:00
|
|
|
it "returns index" do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :index, namespace_id: project.namespace, project_id: project
|
2015-09-17 09:56:16 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-01 19:59:44 -04:00
|
|
|
end
|
2015-07-18 01:54:04 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it "returns 301 if request path doesn't match project path" do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :index, namespace_id: project.namespace, project_id: project.path.upcase
|
2016-08-01 19:59:44 -04:00
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
expect(response).to redirect_to(project_issues_path(project))
|
2016-08-01 19:59:44 -04:00
|
|
|
end
|
2015-07-18 01:54:04 -04:00
|
|
|
|
2016-08-01 19:59:44 -04:00
|
|
|
it "returns 404 when issues are disabled" do
|
|
|
|
project.issues_enabled = false
|
2017-06-13 04:25:25 -04:00
|
|
|
project.save!
|
2016-08-01 19:59:44 -04:00
|
|
|
|
2017-02-23 18:55:01 -05:00
|
|
|
get :index, namespace_id: project.namespace, project_id: project
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-01 21:23:12 -04:00
|
|
|
end
|
|
|
|
end
|
2016-12-20 13:52:09 -05:00
|
|
|
|
|
|
|
context 'with page param' do
|
|
|
|
let(:last_page) { project.issues.page().total_pages }
|
2016-12-21 10:02:05 -05:00
|
|
|
let!(:issue_list) { create_list(:issue, 2, project: project) }
|
2016-12-20 13:52:09 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-12-21 10:02:05 -05:00
|
|
|
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to last_page if page number is larger than number of pages' do
|
|
|
|
get :index,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
2016-12-20 13:52:09 -05:00
|
|
|
page: (last_page + 1).to_param
|
|
|
|
|
2016-12-21 10:02:05 -05:00
|
|
|
expect(response).to redirect_to(namespace_project_issues_path(page: last_page, state: controller.params[:state], scope: controller.params[:scope]))
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to specified page' do
|
|
|
|
get :index,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
2016-12-20 13:52:09 -05:00
|
|
|
page: last_page.to_param
|
|
|
|
|
|
|
|
expect(assigns(:issues).current_page).to eq(last_page)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|
2017-04-05 18:52:19 -04:00
|
|
|
|
|
|
|
it 'does not redirect to external sites when provided a host field' do
|
|
|
|
external_host = "www.example.com"
|
|
|
|
get :index,
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
page: (last_page + 1).to_param,
|
|
|
|
host: external_host
|
|
|
|
|
|
|
|
expect(response).to redirect_to(namespace_project_issues_path(page: last_page, state: controller.params[:state], scope: controller.params[:scope]))
|
|
|
|
end
|
2018-01-29 10:22:58 -05:00
|
|
|
|
|
|
|
it 'does not use pagination if disabled' do
|
|
|
|
allow(controller).to receive(:pagination_disabled?).and_return(true)
|
|
|
|
|
|
|
|
get :index,
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
page: (last_page + 1).to_param
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(assigns(:issues).size).to eq(2)
|
|
|
|
end
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|
2016-08-01 21:23:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #new' do
|
2017-03-06 15:18:39 -05:00
|
|
|
it 'redirects to signin if not logged in' do
|
|
|
|
get :new, namespace_id: project.namespace, project_id: project
|
|
|
|
|
2017-03-23 13:43:47 -04:00
|
|
|
expect(flash[:notice]).to eq 'Please sign in to create the new issue.'
|
2017-03-06 15:18:39 -05:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
|
2016-10-26 17:21:50 -04:00
|
|
|
context 'internal issue tracker' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'builds a new issue' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :new, namespace_id: project.namespace, project_id: project
|
2016-10-26 17:21:50 -04:00
|
|
|
|
|
|
|
expect(assigns(:issue)).to be_a_new(Issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fills in an issue for a merge request' do
|
2017-01-25 16:44:33 -05:00
|
|
|
project_with_repository = create(:project, :repository)
|
2017-12-22 03:18:28 -05:00
|
|
|
project_with_repository.add_developer(user)
|
2016-10-26 17:21:50 -04:00
|
|
|
mr = create(:merge_request_with_diff_notes, source_project: project_with_repository)
|
|
|
|
|
2017-03-10 03:19:12 -05:00
|
|
|
get :new, namespace_id: project_with_repository.namespace, project_id: project_with_repository, merge_request_to_resolve_discussions_of: mr.iid
|
2016-10-26 17:21:50 -04:00
|
|
|
|
|
|
|
expect(assigns(:issue).title).not_to be_empty
|
|
|
|
expect(assigns(:issue).description).not_to be_empty
|
|
|
|
end
|
2016-12-22 07:31:12 -05:00
|
|
|
|
|
|
|
it 'fills in an issue for a discussion' do
|
|
|
|
note = create(:note_on_merge_request, project: project)
|
|
|
|
|
2017-03-10 03:19:12 -05:00
|
|
|
get :new, namespace_id: project.namespace.path, project_id: project, merge_request_to_resolve_discussions_of: note.noteable.iid, discussion_to_resolve: note.discussion_id
|
2016-12-22 07:31:12 -05:00
|
|
|
|
|
|
|
expect(assigns(:issue).title).not_to be_empty
|
|
|
|
expect(assigns(:issue).description).not_to be_empty
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 21:23:12 -04:00
|
|
|
context 'external issue tracker' do
|
2017-07-17 14:56:35 -04:00
|
|
|
let!(:service) do
|
|
|
|
create(:custom_issue_tracker_service, project: project, title: 'Custom Issue Tracker', new_issue_url: 'http://test.com')
|
|
|
|
end
|
|
|
|
|
2017-03-06 15:18:39 -05:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-06-13 04:25:25 -04:00
|
|
|
|
|
|
|
external = double
|
|
|
|
allow(project).to receive(:external_issue_tracker).and_return(external)
|
2017-03-06 15:18:39 -05:00
|
|
|
end
|
|
|
|
|
2017-06-13 04:25:25 -04:00
|
|
|
context 'when GitLab issues disabled' do
|
|
|
|
it 'returns 404 status' do
|
|
|
|
project.issues_enabled = false
|
|
|
|
project.save!
|
2016-08-01 21:23:12 -04:00
|
|
|
|
2017-06-13 04:25:25 -04:00
|
|
|
get :new, namespace_id: project.namespace, project_id: project
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-06-13 04:25:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when GitLab issues enabled' do
|
|
|
|
it 'renders the "new" template' do
|
|
|
|
get :new, namespace_id: project.namespace, project_id: project
|
2016-08-01 21:23:12 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-13 04:25:25 -04:00
|
|
|
expect(response).to render_template(:new)
|
|
|
|
end
|
2016-08-01 19:59:44 -04:00
|
|
|
end
|
2015-07-18 01:54:04 -04:00
|
|
|
end
|
2016-03-17 15:38:51 -04:00
|
|
|
end
|
|
|
|
|
2017-05-19 14:35:08 -04:00
|
|
|
describe 'Redirect after sign in' do
|
|
|
|
context 'with an AJAX request' do
|
|
|
|
it 'does not store the visited URL' do
|
|
|
|
xhr :get,
|
|
|
|
:show,
|
|
|
|
format: :json,
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: issue.iid
|
|
|
|
|
|
|
|
expect(session['user_return_to']).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without an AJAX request' do
|
|
|
|
it 'stores the visited URL' do
|
|
|
|
get :show,
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: issue.iid
|
|
|
|
|
|
|
|
expect(session['user_return_to']).to eq("/#{project.namespace.to_param}/#{project.to_param}/issues/#{issue.iid}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-14 03:26:19 -04:00
|
|
|
describe 'POST #move' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when moving issue to another private project' do
|
|
|
|
let(:another_project) { create(:project, :private) }
|
|
|
|
|
|
|
|
context 'when user has access to move issue' do
|
|
|
|
before do
|
|
|
|
another_project.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'moves issue to another project' do
|
|
|
|
move_issue
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status :ok
|
2017-08-14 03:26:19 -04:00
|
|
|
expect(another_project.issues).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have access to move issue' do
|
|
|
|
it 'responds with 404' do
|
|
|
|
move_issue
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status :not_found
|
2017-08-14 03:26:19 -04:00
|
|
|
end
|
|
|
|
end
|
2017-02-14 14:07:11 -05:00
|
|
|
|
2016-04-30 15:14:40 -04:00
|
|
|
def move_issue
|
2017-08-14 03:26:19 -04:00
|
|
|
post :move,
|
|
|
|
format: :json,
|
2016-04-30 15:14:40 -04:00
|
|
|
namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project,
|
2016-04-30 15:14:40 -04:00
|
|
|
id: issue.iid,
|
|
|
|
move_to_project_id: another_project.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-01 13:35:14 -04:00
|
|
|
describe 'PUT #update' do
|
|
|
|
subject do
|
|
|
|
put :update,
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: issue.to_param,
|
|
|
|
issue: { title: 'New title' }, format: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has access to update issue' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the issue' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(issue.reload.title).to eq('New title')
|
|
|
|
end
|
2017-12-08 07:26:39 -05:00
|
|
|
|
|
|
|
context 'when Akismet is enabled and the issue is identified as spam' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(recaptcha_enabled: true)
|
|
|
|
allow_any_instance_of(SpamService).to receive(:check_for_spam?).and_return(true)
|
|
|
|
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders json with recaptcha_html' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(JSON.parse(response.body)).to have_key('recaptcha_html')
|
|
|
|
end
|
|
|
|
end
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have access to update issue' do
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with 404' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-11 11:22:00 -05:00
|
|
|
describe 'GET #realtime_changes' do
|
|
|
|
def go(id:)
|
|
|
|
get :realtime_changes,
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: id
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an issue was edited' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
issue.update!(last_edited_by: user, last_edited_at: issue.created_at + 1.minute)
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns last edited time' do
|
|
|
|
go(id: issue.iid)
|
|
|
|
|
|
|
|
data = JSON.parse(response.body)
|
|
|
|
|
|
|
|
expect(data).to include('updated_at')
|
|
|
|
expect(data['updated_at']).to eq(issue.last_edited_at.to_time.iso8601)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an issue was edited by a deleted user' do
|
|
|
|
let(:deleted_user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
issue.update!(last_edited_by: deleted_user, last_edited_at: Time.now)
|
|
|
|
|
|
|
|
deleted_user.destroy
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200' do
|
|
|
|
go(id: issue.iid)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-17 15:38:51 -04:00
|
|
|
describe 'Confidential Issues' do
|
2016-03-19 10:35:24 -04:00
|
|
|
let(:project) { create(:project_empty_repo, :public) }
|
2016-03-17 15:38:51 -04:00
|
|
|
let(:assignee) { create(:assignee) }
|
|
|
|
let(:author) { create(:user) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let(:member) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let!(:issue) { create(:issue, project: project) }
|
|
|
|
let!(:unescaped_parameter_value) { create(:issue, :confidential, project: project, author: author) }
|
2017-05-04 08:11:15 -04:00
|
|
|
let!(:request_forgery_timing_attack) { create(:issue, :confidential, project: project, assignees: [assignee]) }
|
2016-03-17 15:38:51 -04:00
|
|
|
|
|
|
|
describe 'GET #index' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'does not list confidential issues for guests' do
|
2016-03-17 15:38:51 -04:00
|
|
|
sign_out(:user)
|
|
|
|
get_issues
|
|
|
|
|
|
|
|
expect(assigns(:issues)).to eq [issue]
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'does not list confidential issues for non project members' do
|
2016-03-17 15:38:51 -04:00
|
|
|
sign_in(non_member)
|
|
|
|
get_issues
|
|
|
|
|
|
|
|
expect(assigns(:issues)).to eq [issue]
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'does not list confidential issues for project members with guest role' do
|
2016-06-06 15:13:31 -04:00
|
|
|
sign_in(member)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_guest(member)
|
2016-06-06 15:13:31 -04:00
|
|
|
|
|
|
|
get_issues
|
|
|
|
|
|
|
|
expect(assigns(:issues)).to eq [issue]
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'lists confidential issues for author' do
|
2016-03-17 15:38:51 -04:00
|
|
|
sign_in(author)
|
|
|
|
get_issues
|
|
|
|
|
|
|
|
expect(assigns(:issues)).to include unescaped_parameter_value
|
|
|
|
expect(assigns(:issues)).not_to include request_forgery_timing_attack
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'lists confidential issues for assignee' do
|
2016-03-17 15:38:51 -04:00
|
|
|
sign_in(assignee)
|
|
|
|
get_issues
|
|
|
|
|
|
|
|
expect(assigns(:issues)).not_to include unescaped_parameter_value
|
|
|
|
expect(assigns(:issues)).to include request_forgery_timing_attack
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'lists confidential issues for project members' do
|
2016-03-17 15:38:51 -04:00
|
|
|
sign_in(member)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(member)
|
2016-03-17 15:38:51 -04:00
|
|
|
|
|
|
|
get_issues
|
|
|
|
|
|
|
|
expect(assigns(:issues)).to include unescaped_parameter_value
|
|
|
|
expect(assigns(:issues)).to include request_forgery_timing_attack
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'lists confidential issues for admin' do
|
2016-03-17 15:38:51 -04:00
|
|
|
sign_in(admin)
|
|
|
|
get_issues
|
|
|
|
|
|
|
|
expect(assigns(:issues)).to include unescaped_parameter_value
|
|
|
|
expect(assigns(:issues)).to include request_forgery_timing_attack
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_issues
|
|
|
|
get :index,
|
|
|
|
namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project
|
2016-03-17 15:38:51 -04:00
|
|
|
end
|
|
|
|
end
|
2015-07-18 01:54:04 -04:00
|
|
|
|
2016-03-17 15:38:51 -04:00
|
|
|
shared_examples_for 'restricted action' do |http_status|
|
|
|
|
it 'returns 404 for guests' do
|
2016-06-06 15:13:31 -04:00
|
|
|
sign_out(:user)
|
2016-03-17 15:38:51 -04:00
|
|
|
go(id: unescaped_parameter_value.to_param)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status :not_found
|
2016-03-17 15:38:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 for non project members' do
|
|
|
|
sign_in(non_member)
|
|
|
|
go(id: unescaped_parameter_value.to_param)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status :not_found
|
2016-06-06 15:13:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 for project members with guest role' do
|
|
|
|
sign_in(member)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_guest(member)
|
2016-06-06 15:13:31 -04:00
|
|
|
go(id: unescaped_parameter_value.to_param)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status :not_found
|
2016-03-17 15:38:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns #{http_status[:success]} for author" do
|
|
|
|
sign_in(author)
|
|
|
|
go(id: unescaped_parameter_value.to_param)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status http_status[:success]
|
2016-03-17 15:38:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns #{http_status[:success]} for assignee" do
|
|
|
|
sign_in(assignee)
|
|
|
|
go(id: request_forgery_timing_attack.to_param)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status http_status[:success]
|
2016-03-17 15:38:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns #{http_status[:success]} for project members" do
|
|
|
|
sign_in(member)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(member)
|
2016-03-17 15:38:51 -04:00
|
|
|
go(id: unescaped_parameter_value.to_param)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status http_status[:success]
|
2016-03-17 15:38:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns #{http_status[:success]} for admin" do
|
|
|
|
sign_in(admin)
|
|
|
|
go(id: unescaped_parameter_value.to_param)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status http_status[:success]
|
2016-03-17 15:38:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-03 05:28:42 -04:00
|
|
|
describe 'PUT #update' do
|
|
|
|
def update_issue(issue_params: {}, additional_params: {}, id: nil)
|
|
|
|
id ||= issue.iid
|
|
|
|
params = {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: id,
|
|
|
|
issue: { title: 'New title' }.merge(issue_params),
|
|
|
|
format: :json
|
|
|
|
}.merge(additional_params)
|
|
|
|
|
|
|
|
put :update, params
|
|
|
|
end
|
|
|
|
|
|
|
|
def go(id:)
|
|
|
|
update_issue(id: id)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-10-03 05:28:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'restricted action', success: 200
|
|
|
|
it_behaves_like 'update invalid issuable', Issue
|
|
|
|
|
|
|
|
context 'changing the assignee' do
|
|
|
|
it 'limits the attributes exposed on the assignee' do
|
|
|
|
assignee = create(:user)
|
|
|
|
project.add_developer(assignee)
|
|
|
|
|
|
|
|
update_issue(issue_params: { assignee_ids: [assignee.id] })
|
|
|
|
|
|
|
|
body = JSON.parse(response.body)
|
|
|
|
|
|
|
|
expect(body['assignees'].first.keys)
|
|
|
|
.to match_array(%w(id name username avatar_url state web_url))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Akismet is enabled' do
|
|
|
|
before do
|
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
stub_application_setting(recaptcha_enabled: true)
|
|
|
|
allow_any_instance_of(SpamService).to receive(:check_for_spam?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an issue is not identified as spam' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(false)
|
|
|
|
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'normally updates the issue' do
|
|
|
|
expect { update_issue(issue_params: { title: 'Foo' }) }.to change { issue.reload.title }.to('Foo')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an issue is identified as spam' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when captcha is not verified' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects an issue recognized as a spam' do
|
|
|
|
expect { update_issue }.not_to change { issue.reload.title }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects an issue recognized as a spam when recaptcha disabled' do
|
|
|
|
stub_application_setting(recaptcha_enabled: false)
|
|
|
|
|
|
|
|
expect { update_issue }.not_to change { issue.reload.title }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a spam log' do
|
|
|
|
update_issue(issue_params: { title: 'Spam title' })
|
|
|
|
|
|
|
|
spam_logs = SpamLog.all
|
|
|
|
|
|
|
|
expect(spam_logs.count).to eq(1)
|
|
|
|
expect(spam_logs.first.title).to eq('Spam title')
|
|
|
|
expect(spam_logs.first.recaptcha_verified).to be_falsey
|
|
|
|
end
|
|
|
|
|
2017-12-08 07:26:39 -05:00
|
|
|
it 'renders recaptcha_html json response' do
|
2017-10-03 05:28:42 -04:00
|
|
|
update_issue
|
|
|
|
|
2017-12-08 07:26:39 -05:00
|
|
|
expect(json_response).to have_key('recaptcha_html')
|
2017-10-03 05:28:42 -04:00
|
|
|
end
|
|
|
|
|
2017-12-08 07:26:39 -05:00
|
|
|
it 'returns 200 status' do
|
2017-10-03 05:28:42 -04:00
|
|
|
update_issue
|
|
|
|
|
2017-12-08 07:26:39 -05:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-10-03 05:28:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when captcha is verified' do
|
|
|
|
let(:spammy_title) { 'Whatever' }
|
|
|
|
let!(:spam_logs) { create_list(:spam_log, 2, user: user, title: spammy_title) }
|
|
|
|
|
|
|
|
def update_verified_issue
|
|
|
|
update_issue(
|
|
|
|
issue_params: { title: spammy_title },
|
|
|
|
additional_params: { spam_log_id: spam_logs.last.id, recaptcha_verification: true })
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:verify_recaptcha)
|
|
|
|
.and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200 status' do
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-10-03 05:28:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts an issue after recaptcha is verified' do
|
|
|
|
expect { update_verified_issue }.to change { issue.reload.title }.to(spammy_title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks spam log as recaptcha_verified' do
|
|
|
|
expect { update_verified_issue }.to change { SpamLog.last.recaptcha_verified }.from(false).to(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not mark spam log as recaptcha_verified when it does not belong to current_user' do
|
|
|
|
spam_log = create(:spam_log)
|
|
|
|
|
|
|
|
expect { update_issue(issue_params: { spam_log_id: spam_log.id, recaptcha_verification: true }) }
|
|
|
|
.not_to change { SpamLog.last.recaptcha_verified }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-17 15:38:51 -04:00
|
|
|
describe 'GET #show' do
|
|
|
|
it_behaves_like 'restricted action', success: 200
|
|
|
|
|
|
|
|
def go(id:)
|
|
|
|
get :show,
|
|
|
|
namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project,
|
2016-03-17 15:38:51 -04:00
|
|
|
id: id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-17 10:38:43 -04:00
|
|
|
describe 'GET #realtime_changes' do
|
|
|
|
it_behaves_like 'restricted action', success: 200
|
|
|
|
|
|
|
|
def go(id:)
|
|
|
|
get :realtime_changes,
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: id
|
|
|
|
end
|
|
|
|
end
|
2017-10-26 07:04:07 -04:00
|
|
|
|
|
|
|
describe 'GET #edit' do
|
|
|
|
it_behaves_like 'restricted action', success: 200
|
|
|
|
|
|
|
|
def go(id:)
|
|
|
|
get :edit,
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT #update' do
|
|
|
|
it_behaves_like 'restricted action', success: 302
|
|
|
|
|
|
|
|
def go(id:)
|
|
|
|
put :update,
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: id,
|
|
|
|
issue: { title: 'New title' }
|
|
|
|
end
|
|
|
|
end
|
2015-07-18 01:54:04 -04:00
|
|
|
end
|
2016-02-26 03:55:43 -05:00
|
|
|
|
2016-07-16 12:42:44 -04:00
|
|
|
describe 'POST #create' do
|
2017-01-27 11:25:39 -05:00
|
|
|
def post_new_issue(issue_attrs = {}, additional_params = {})
|
2016-12-23 00:44:02 -05:00
|
|
|
sign_in(user)
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :public)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-12-23 00:44:02 -05:00
|
|
|
|
|
|
|
post :create, {
|
|
|
|
namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project,
|
2017-01-27 11:25:39 -05:00
|
|
|
issue: { title: 'Title', description: 'Description' }.merge(issue_attrs)
|
|
|
|
}.merge(additional_params)
|
2016-12-23 00:44:02 -05:00
|
|
|
|
|
|
|
project.issues.first
|
|
|
|
end
|
|
|
|
|
2016-10-26 17:21:50 -04:00
|
|
|
context 'resolving discussions in MergeRequest' do
|
2017-03-09 20:29:11 -05:00
|
|
|
let(:discussion) { create(:diff_note_on_merge_request).to_discussion }
|
2016-10-26 17:21:50 -04:00
|
|
|
let(:merge_request) { discussion.noteable }
|
|
|
|
let(:project) { merge_request.source_project }
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-10-26 17:21:50 -04:00
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:merge_request_params) do
|
2017-03-10 03:19:12 -05:00
|
|
|
{ merge_request_to_resolve_discussions_of: merge_request.iid }
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2017-02-27 04:23:36 -05:00
|
|
|
def post_issue(issue_params, other_params: {})
|
2017-03-10 03:19:12 -05:00
|
|
|
post :create, { namespace_id: project.namespace.to_param, project_id: project, issue: issue_params, merge_request_to_resolve_discussions_of: merge_request.iid }.merge(other_params)
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates an issue for the project' do
|
|
|
|
expect { post_issue({ title: 'Hello' }) }.to change { project.issues.reload.size }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't overwrite given params" do
|
|
|
|
post_issue(description: 'Manually entered description')
|
|
|
|
|
|
|
|
expect(assigns(:issue).description).to eq('Manually entered description')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'resolves the discussion in the merge_request' do
|
|
|
|
post_issue(title: 'Hello')
|
|
|
|
discussion.first_note.reload
|
|
|
|
|
|
|
|
expect(discussion.resolved?).to eq(true)
|
|
|
|
end
|
2017-02-27 04:23:36 -05:00
|
|
|
|
2017-03-08 14:16:17 -05:00
|
|
|
it 'sets a flash message' do
|
|
|
|
post_issue(title: 'Hello')
|
|
|
|
|
2017-03-09 08:25:54 -05:00
|
|
|
expect(flash[:notice]).to eq('Resolved all discussions.')
|
2017-03-08 14:16:17 -05:00
|
|
|
end
|
|
|
|
|
2017-03-09 08:25:54 -05:00
|
|
|
describe "resolving a single discussion" do
|
|
|
|
before do
|
|
|
|
post_issue({ title: 'Hello' }, other_params: { discussion_to_resolve: discussion.id })
|
|
|
|
end
|
|
|
|
it 'resolves a single discussion' do
|
|
|
|
discussion.first_note.reload
|
2017-03-08 14:16:17 -05:00
|
|
|
|
2017-03-09 08:25:54 -05:00
|
|
|
expect(discussion.resolved?).to eq(true)
|
|
|
|
end
|
2017-02-27 04:23:36 -05:00
|
|
|
|
2017-03-09 08:25:54 -05:00
|
|
|
it 'sets a flash message that one discussion was resolved' do
|
|
|
|
expect(flash[:notice]).to eq('Resolved 1 discussion.')
|
|
|
|
end
|
2017-02-27 04:23:36 -05:00
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2016-07-16 12:42:44 -04:00
|
|
|
context 'Akismet is enabled' do
|
|
|
|
before do
|
2017-01-27 11:25:39 -05:00
|
|
|
stub_application_setting(recaptcha_enabled: true)
|
2016-08-09 13:43:47 -04:00
|
|
|
allow_any_instance_of(SpamService).to receive(:check_for_spam?).and_return(true)
|
2016-07-16 12:42:44 -04:00
|
|
|
end
|
|
|
|
|
2017-02-14 14:07:11 -05:00
|
|
|
context 'when an issue is not identified as spam' do
|
2017-01-27 11:25:39 -05:00
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(false)
|
2017-08-24 13:05:02 -04:00
|
|
|
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(false)
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
2016-07-16 12:42:44 -04:00
|
|
|
|
2017-01-27 11:25:39 -05:00
|
|
|
it 'does not create an issue' do
|
|
|
|
expect { post_new_issue(title: '') }.not_to change(Issue, :count)
|
|
|
|
end
|
2016-07-16 12:42:44 -04:00
|
|
|
end
|
|
|
|
|
2017-02-14 14:07:11 -05:00
|
|
|
context 'when an issue is identified as spam' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-08-24 13:05:02 -04:00
|
|
|
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
|
|
|
|
context 'when captcha is not verified' do
|
|
|
|
def post_spam_issue
|
|
|
|
post_new_issue(title: 'Spam Title', description: 'Spam lives here')
|
|
|
|
end
|
|
|
|
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(false)
|
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
|
|
|
|
it 'rejects an issue recognized as a spam' do
|
|
|
|
expect { post_spam_issue }.not_to change(Issue, :count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a spam log' do
|
|
|
|
post_spam_issue
|
|
|
|
spam_logs = SpamLog.all
|
|
|
|
|
|
|
|
expect(spam_logs.count).to eq(1)
|
|
|
|
expect(spam_logs.first.title).to eq('Spam Title')
|
|
|
|
expect(spam_logs.first.recaptcha_verified).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create an issue when it is not valid' do
|
|
|
|
expect { post_new_issue(title: '') }.not_to change(Issue, :count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create an issue when recaptcha is not enabled' do
|
|
|
|
stub_application_setting(recaptcha_enabled: false)
|
|
|
|
|
|
|
|
expect { post_spam_issue }.not_to change(Issue, :count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when captcha is verified' do
|
|
|
|
let!(:spam_logs) { create_list(:spam_log, 2, user: user, title: 'Title') }
|
|
|
|
|
|
|
|
def post_verified_issue
|
|
|
|
post_new_issue({}, { spam_log_id: spam_logs.last.id, recaptcha_verification: true } )
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts an issue after recaptcha is verified' do
|
|
|
|
expect { post_verified_issue }.to change(Issue, :count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks spam log as recaptcha_verified' do
|
|
|
|
expect { post_verified_issue }.to change { SpamLog.last.recaptcha_verified }.from(false).to(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not mark spam log as recaptcha_verified when it does not belong to current_user' do
|
|
|
|
spam_log = create(:spam_log)
|
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect { post_new_issue({}, { spam_log_id: spam_log.id, recaptcha_verification: true } ) }
|
|
|
|
.not_to change { SpamLog.last.recaptcha_verified }
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
end
|
2016-07-16 12:42:44 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-27 20:03:06 -04:00
|
|
|
|
|
|
|
context 'user agent details are saved' do
|
|
|
|
before do
|
|
|
|
request.env['action_dispatch.remote_ip'] = '127.0.0.1'
|
|
|
|
end
|
|
|
|
|
2016-12-23 00:44:02 -05:00
|
|
|
it 'creates a user agent detail' do
|
2017-01-27 11:25:39 -05:00
|
|
|
expect { post_new_issue }.to change(UserAgentDetail, :count).by(1)
|
2016-12-23 00:44:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
context 'when description has quick actions' do
|
2016-12-23 00:44:02 -05:00
|
|
|
before do
|
2016-07-27 20:03:06 -04:00
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2016-12-23 00:44:02 -05:00
|
|
|
it 'can add spent time' do
|
|
|
|
issue = post_new_issue(description: '/spend 1h')
|
|
|
|
|
|
|
|
expect(issue.total_time_spent).to eq(3600)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can set the time estimate' do
|
|
|
|
issue = post_new_issue(description: '/estimate 2h')
|
|
|
|
|
|
|
|
expect(issue.time_estimate).to eq(7200)
|
2016-07-27 20:03:06 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-16 12:42:44 -04:00
|
|
|
end
|
|
|
|
|
2016-08-02 17:21:57 -04:00
|
|
|
describe 'POST #mark_as_spam' do
|
|
|
|
context 'properly submits to Akismet' do
|
|
|
|
before do
|
2016-08-09 13:43:47 -04:00
|
|
|
allow_any_instance_of(AkismetService).to receive_messages(submit_spam: true)
|
2016-08-05 18:10:08 -04:00
|
|
|
allow_any_instance_of(ApplicationSetting).to receive_messages(akismet_enabled: true)
|
2016-08-02 17:21:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def post_spam
|
|
|
|
admin = create(:admin)
|
|
|
|
create(:user_agent_detail, subject: issue)
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(admin)
|
2016-08-02 17:21:57 -04:00
|
|
|
sign_in(admin)
|
|
|
|
post :mark_as_spam, {
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2016-08-02 17:21:57 -04:00
|
|
|
id: issue.iid
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates issue' do
|
|
|
|
post_spam
|
2016-08-09 13:43:47 -04:00
|
|
|
expect(issue.submittable_as_spam?).to be_falsey
|
2016-08-02 17:21:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-26 03:55:43 -05:00
|
|
|
describe "DELETE #destroy" do
|
2016-03-21 09:12:52 -04:00
|
|
|
context "when the user is a developer" do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2016-03-21 09:12:52 -04:00
|
|
|
it "rejects a developer to destroy an issue" do
|
2017-02-23 18:55:01 -05:00
|
|
|
delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-03-21 09:12:52 -04:00
|
|
|
end
|
2016-02-26 03:55:43 -05:00
|
|
|
end
|
|
|
|
|
2016-03-21 09:12:52 -04:00
|
|
|
context "when the user is owner" do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
let(:namespace) { create(:namespace, owner: owner) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, namespace: namespace) }
|
2016-03-21 09:12:52 -04:00
|
|
|
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
sign_in(owner)
|
|
|
|
end
|
2016-02-26 03:55:43 -05:00
|
|
|
|
2016-03-21 09:12:52 -04:00
|
|
|
it "deletes the issue" do
|
2017-02-23 18:55:01 -05:00
|
|
|
delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid
|
2016-02-26 03:55:43 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2017-07-24 08:21:16 -04:00
|
|
|
expect(controller).to set_flash[:notice].to(/The issue was successfully deleted\./)
|
2016-02-26 03:55:43 -05:00
|
|
|
end
|
2016-09-01 18:12:05 -04:00
|
|
|
|
|
|
|
it 'delegates the update of the todos count cache to TodoService' do
|
2017-12-08 07:17:22 -05:00
|
|
|
expect_any_instance_of(TodoService).to receive(:destroy_target).with(issue).once
|
2016-09-01 18:12:05 -04:00
|
|
|
|
2017-02-23 18:55:01 -05:00
|
|
|
delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid
|
2016-09-01 18:12:05 -04:00
|
|
|
end
|
2016-02-26 03:55:43 -05:00
|
|
|
end
|
|
|
|
end
|
2016-04-25 14:10:20 -04:00
|
|
|
|
|
|
|
describe 'POST #toggle_award_emoji' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-08-10 11:53:55 -04:00
|
|
|
project.add_developer(user)
|
2016-04-25 14:10:20 -04:00
|
|
|
end
|
|
|
|
|
2016-05-11 16:43:58 -04:00
|
|
|
it "toggles the award emoji" do
|
2016-06-01 05:23:09 -04:00
|
|
|
expect do
|
2017-02-23 18:55:01 -05:00
|
|
|
post(:toggle_award_emoji, namespace_id: project.namespace,
|
|
|
|
project_id: project, id: issue.iid, name: "thumbsup")
|
2016-06-01 05:23:09 -04:00
|
|
|
end.to change { issue.award_emoji.count }.by(1)
|
2016-04-25 14:10:20 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-04-25 14:10:20 -04:00
|
|
|
end
|
|
|
|
end
|
2017-05-04 04:09:21 -04:00
|
|
|
|
|
|
|
describe 'POST create_merge_request' do
|
2018-04-06 13:58:53 -04:00
|
|
|
let(:project) { create(:project, :repository, :public) }
|
2017-08-11 08:10:43 -04:00
|
|
|
|
2017-05-04 04:09:21 -04:00
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new merge request' do
|
|
|
|
expect { create_merge_request }.to change(project.merge_requests, :count).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'render merge request as json' do
|
|
|
|
create_merge_request
|
|
|
|
|
|
|
|
expect(response).to match_response_schema('merge_request')
|
|
|
|
end
|
|
|
|
|
2018-04-06 13:58:53 -04:00
|
|
|
it 'is not available when the project is archived' do
|
2018-04-11 17:14:02 -04:00
|
|
|
project.update!(archived: true)
|
2018-04-06 13:58:53 -04:00
|
|
|
|
|
|
|
create_merge_request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not available for users who cannot create merge requests' do
|
|
|
|
sign_in(create(:user))
|
|
|
|
|
|
|
|
create_merge_request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
|
2017-05-04 04:09:21 -04:00
|
|
|
def create_merge_request
|
|
|
|
post :create_merge_request, namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project.to_param,
|
|
|
|
id: issue.to_param,
|
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
end
|
2017-08-11 12:48:06 -04:00
|
|
|
|
|
|
|
describe 'GET #discussions' do
|
|
|
|
let!(:discussion) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) }
|
2017-10-17 06:12:24 -04:00
|
|
|
context 'when authenticated' do
|
2017-09-17 02:25:34 -04:00
|
|
|
before do
|
2017-10-17 06:12:24 -04:00
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
2017-09-17 02:25:34 -04:00
|
|
|
end
|
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
it 'returns discussion json' do
|
2017-09-17 02:25:34 -04:00
|
|
|
get :discussions, namespace_id: project.namespace, project_id: project, id: issue.iid
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(json_response.first.keys).to match_array(%w[id reply_id expanded notes diff_discussion discussion_path individual_note resolvable resolved resolved_at resolved_by resolved_by_push commit_id for_commit project_id])
|
2017-09-17 02:25:34 -04:00
|
|
|
end
|
|
|
|
|
2018-07-16 12:18:52 -04:00
|
|
|
it 'renders the author status html if there is a status' do
|
|
|
|
create(:user_status, user: discussion.author)
|
|
|
|
|
|
|
|
get :discussions, namespace_id: project.namespace, project_id: project, id: issue.iid
|
|
|
|
|
|
|
|
note_json = json_response.first['notes'].first
|
|
|
|
|
|
|
|
expect(note_json['author']['status_tooltip_html']).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not cause an extra query for the status' do
|
|
|
|
control = ActiveRecord::QueryRecorder.new do
|
|
|
|
get :discussions, namespace_id: project.namespace, project_id: project, id: issue.iid
|
|
|
|
end
|
|
|
|
|
|
|
|
create(:user_status, user: discussion.author)
|
|
|
|
second_discussion = create(:discussion_note_on_issue, noteable: issue, project: issue.project, author: create(:user))
|
|
|
|
create(:user_status, user: second_discussion.author)
|
|
|
|
|
|
|
|
expect { get :discussions, namespace_id: project.namespace, project_id: project, id: issue.iid }
|
|
|
|
.not_to exceed_query_limit(control)
|
|
|
|
end
|
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
context 'with cross-reference system note', :request_store do
|
|
|
|
let(:new_issue) { create(:issue) }
|
|
|
|
let(:cross_reference) { "mentioned in #{new_issue.to_reference(issue.project)}" }
|
2017-09-17 02:25:34 -04:00
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
before do
|
|
|
|
create(:discussion_note_on_issue, :system, noteable: issue, project: issue.project, note: cross_reference)
|
|
|
|
end
|
2017-09-17 02:25:34 -04:00
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
it 'filters notes that the user should not see' do
|
2017-09-17 02:25:34 -04:00
|
|
|
get :discussions, namespace_id: project.namespace, project_id: project, id: issue.iid
|
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
expect(JSON.parse(response.body).count).to eq(1)
|
|
|
|
end
|
2017-09-17 02:25:34 -04:00
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
it 'does not result in N+1 queries' do
|
|
|
|
# Instantiate the controller variables to ensure QueryRecorder has an accurate base count
|
|
|
|
get :discussions, namespace_id: project.namespace, project_id: project, id: issue.iid
|
2017-09-17 02:25:34 -04:00
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
RequestStore.clear!
|
|
|
|
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new do
|
|
|
|
get :discussions, namespace_id: project.namespace, project_id: project, id: issue.iid
|
|
|
|
end.count
|
|
|
|
|
|
|
|
RequestStore.clear!
|
|
|
|
|
|
|
|
create_list(:discussion_note_on_issue, 2, :system, noteable: issue, project: issue.project, note: cross_reference)
|
|
|
|
|
|
|
|
expect { get :discussions, namespace_id: project.namespace, project_id: project, id: issue.iid }.not_to exceed_query_limit(control_count)
|
|
|
|
end
|
2017-09-17 02:25:34 -04:00
|
|
|
end
|
|
|
|
end
|
2017-08-11 12:48:06 -04:00
|
|
|
end
|
2015-07-18 01:54:04 -04:00
|
|
|
end
|