2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2015-12-09 05:59:25 -05:00
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe SentNotificationsController do
|
2016-07-13 19:56:54 -04:00
|
|
|
let(:user) { create(:user) }
|
2019-05-09 09:09:04 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:private_project) { create(:project, :private) }
|
|
|
|
let(:sent_notification) { create(:sent_notification, project: target_project, noteable: noteable, recipient: user) }
|
2015-12-09 05:59:25 -05:00
|
|
|
|
2016-07-13 19:56:54 -04:00
|
|
|
let(:issue) do
|
2019-05-09 09:09:04 -04:00
|
|
|
create(:issue, project: target_project) do |issue|
|
2021-12-07 07:10:33 -05:00
|
|
|
issue.subscriptions.create!(user: user, project: target_project, subscribed: true)
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-09 09:09:04 -04:00
|
|
|
let(:confidential_issue) do
|
|
|
|
create(:issue, project: target_project, confidential: true) do |issue|
|
2021-12-07 07:10:33 -05:00
|
|
|
issue.subscriptions.create!(user: user, project: target_project, subscribed: true)
|
2019-05-09 09:09:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, source_project: target_project, target_project: target_project) do |mr|
|
2021-12-07 07:10:33 -05:00
|
|
|
mr.subscriptions.create!(user: user, project: target_project, subscribed: true)
|
2019-05-09 09:09:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:noteable) { issue }
|
|
|
|
let(:target_project) { project }
|
|
|
|
|
2016-07-13 19:56:54 -04:00
|
|
|
describe 'GET unsubscribe' do
|
2020-01-28 07:08:44 -05:00
|
|
|
shared_examples 'returns 404' do
|
|
|
|
it 'does not set the flash message' do
|
|
|
|
expect(controller).not_to set_flash[:notice]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404' do
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-13 19:56:54 -04:00
|
|
|
context 'when the user is not logged in' do
|
|
|
|
context 'when the force param is passed' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:unsubscribe, params: { id: sent_notification.reply_key, force: true })
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-07-13 19:56:54 -04:00
|
|
|
|
|
|
|
it 'unsubscribes the user' do
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_falsey
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the flash message' do
|
2017-07-24 08:21:16 -04:00
|
|
|
expect(controller).to set_flash[:notice].to(/unsubscribed/)
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to the login page' do
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the force param is not passed' do
|
2019-05-09 09:09:04 -04:00
|
|
|
render_views
|
|
|
|
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:unsubscribe, params: { id: sent_notification.reply_key })
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-07-13 19:56:54 -04:00
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
shared_examples 'unsubscribing as anonymous' do |project_visibility|
|
2019-05-09 09:09:04 -04:00
|
|
|
it 'does not unsubscribe the user' do
|
|
|
|
expect(noteable.subscribed?(user, target_project)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not set the flash message' do
|
|
|
|
expect(controller).not_to set_flash[:notice]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders unsubscribe page' do
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-05-09 09:09:04 -04:00
|
|
|
expect(response).to render_template :unsubscribe
|
|
|
|
end
|
2020-01-02 16:07:38 -05:00
|
|
|
|
|
|
|
if project_visibility == :private
|
|
|
|
it 'does not show project name or path' do
|
|
|
|
expect(response.body).not_to include(noteable.project.name)
|
|
|
|
expect(response.body).not_to include(noteable.project.full_name)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
it 'shows project name or path' do
|
|
|
|
expect(response.body).to include(noteable.project.name)
|
|
|
|
expect(response.body).to include(noteable.project.full_name)
|
|
|
|
end
|
|
|
|
end
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
2015-12-09 05:59:25 -05:00
|
|
|
|
2019-05-09 09:09:04 -04:00
|
|
|
context 'when project is public' do
|
|
|
|
context 'when unsubscribing from issue' do
|
|
|
|
let(:noteable) { issue }
|
|
|
|
|
|
|
|
it 'shows issue title' do
|
|
|
|
expect(response.body).to include(issue.title)
|
|
|
|
end
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
it_behaves_like 'unsubscribing as anonymous', :public
|
2019-05-09 09:09:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unsubscribing from confidential issue' do
|
|
|
|
let(:noteable) { confidential_issue }
|
|
|
|
|
|
|
|
it 'does not show issue title' do
|
|
|
|
expect(response.body).not_to include(confidential_issue.title)
|
|
|
|
expect(response.body).to include(confidential_issue.to_reference)
|
|
|
|
end
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
it_behaves_like 'unsubscribing as anonymous', :public
|
2019-05-09 09:09:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unsubscribing from merge request' do
|
|
|
|
let(:noteable) { merge_request }
|
|
|
|
|
|
|
|
it 'shows merge request title' do
|
|
|
|
expect(response.body).to include(merge_request.title)
|
|
|
|
end
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
it 'shows project name or path' do
|
|
|
|
expect(response.body).to include(issue.project.name)
|
|
|
|
expect(response.body).to include(issue.project.full_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'unsubscribing as anonymous', :public
|
2019-05-09 09:09:04 -04:00
|
|
|
end
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
|
2019-05-09 09:09:04 -04:00
|
|
|
context 'when project is not public' do
|
|
|
|
let(:target_project) { private_project }
|
|
|
|
|
|
|
|
context 'when unsubscribing from issue' do
|
|
|
|
let(:noteable) { issue }
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
it 'does not show issue title' do
|
2019-05-09 09:09:04 -04:00
|
|
|
expect(response.body).not_to include(issue.title)
|
|
|
|
end
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
it_behaves_like 'unsubscribing as anonymous', :private
|
2019-05-09 09:09:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unsubscribing from confidential issue' do
|
|
|
|
let(:noteable) { confidential_issue }
|
|
|
|
|
|
|
|
it 'does not show issue title' do
|
|
|
|
expect(response.body).not_to include(confidential_issue.title)
|
|
|
|
expect(response.body).to include(confidential_issue.to_reference)
|
|
|
|
end
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
it_behaves_like 'unsubscribing as anonymous', :private
|
2019-05-09 09:09:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unsubscribing from merge request' do
|
|
|
|
let(:noteable) { merge_request }
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
it 'dos not show merge request title' do
|
2019-05-09 09:09:04 -04:00
|
|
|
expect(response.body).not_to include(merge_request.title)
|
|
|
|
end
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
it_behaves_like 'unsubscribing as anonymous', :private
|
2019-05-09 09:09:04 -04:00
|
|
|
end
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
end
|
2020-01-28 07:08:44 -05:00
|
|
|
|
|
|
|
context 'when the noteable associated to the notification has been deleted' do
|
|
|
|
before do
|
|
|
|
sent_notification.noteable.destroy!
|
|
|
|
|
|
|
|
get(:unsubscribe, params: { id: sent_notification.reply_key })
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'returns 404'
|
|
|
|
end
|
2015-12-09 05:59:25 -05:00
|
|
|
end
|
|
|
|
|
2016-07-13 19:56:54 -04:00
|
|
|
context 'when the user is logged in' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2016-07-13 19:56:54 -04:00
|
|
|
|
|
|
|
context 'when the ID passed does not exist' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:unsubscribe, params: { id: sent_notification.reply_key.reverse })
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-07-13 19:56:54 -04:00
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
it_behaves_like 'returns 404'
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the force param is passed' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:unsubscribe, params: { id: sent_notification.reply_key, force: true })
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-07-13 19:56:54 -04:00
|
|
|
|
|
|
|
it 'unsubscribes the user' do
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_falsey
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the flash message' do
|
2017-07-24 08:21:16 -04:00
|
|
|
expect(controller).to set_flash[:notice].to(/unsubscribed/)
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to the issue page' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(response)
|
2017-06-29 13:06:35 -04:00
|
|
|
.to redirect_to(project_issue_path(project, issue))
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the force param is not passed' do
|
2016-09-16 11:08:09 -04:00
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, source_project: project, author: user) do |merge_request|
|
2021-12-07 07:10:33 -05:00
|
|
|
merge_request.subscriptions.create!(user: user, project: project, subscribed: true)
|
2016-09-16 11:08:09 -04:00
|
|
|
end
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2016-11-04 14:19:08 -04:00
|
|
|
let(:sent_notification) { create(:sent_notification, project: project, noteable: merge_request, recipient: user) }
|
2017-06-14 14:18:56 -04:00
|
|
|
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:unsubscribe, params: { id: sent_notification.reply_key })
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-07-13 19:56:54 -04:00
|
|
|
|
|
|
|
it 'unsubscribes the user' do
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(merge_request.subscribed?(user, project)).to be_falsey
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
2015-12-09 05:59:25 -05:00
|
|
|
|
2016-07-13 19:56:54 -04:00
|
|
|
it 'sets the flash message' do
|
2017-07-24 08:21:16 -04:00
|
|
|
expect(controller).to set_flash[:notice].to(/unsubscribed/)
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
2015-12-09 05:59:25 -05:00
|
|
|
|
2016-09-16 11:08:09 -04:00
|
|
|
it 'redirects to the merge request page' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(response)
|
2017-06-29 13:06:35 -04:00
|
|
|
.to redirect_to(project_merge_request_path(project, merge_request))
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
2015-12-09 05:59:25 -05:00
|
|
|
end
|
2019-09-10 08:30:07 -04:00
|
|
|
|
|
|
|
context 'when project is private' do
|
|
|
|
context 'and user does not have access' do
|
|
|
|
let(:noteable) { issue }
|
|
|
|
let(:target_project) { private_project }
|
|
|
|
|
|
|
|
before do
|
|
|
|
get(:unsubscribe, params: { id: sent_notification.reply_key })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'unsubscribes user and redirects to root path' do
|
|
|
|
expect(response).to redirect_to(root_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and user has access' do
|
|
|
|
let(:noteable) { issue }
|
|
|
|
let(:target_project) { private_project }
|
|
|
|
|
|
|
|
before do
|
|
|
|
private_project.add_developer(user)
|
|
|
|
get(:unsubscribe, params: { id: sent_notification.reply_key })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'unsubscribes user and redirects to issue path' do
|
|
|
|
expect(response).to redirect_to(project_issue_path(private_project, issue))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-28 07:08:44 -05:00
|
|
|
|
|
|
|
context 'when the noteable associated to the notification has been deleted' do
|
|
|
|
before do
|
|
|
|
sent_notification.noteable.destroy!
|
|
|
|
|
|
|
|
get(:unsubscribe, params: { id: sent_notification.reply_key })
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'returns 404'
|
|
|
|
end
|
2015-12-09 05:59:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|