debian-mirror-gitlab/spec/controllers/sent_notifications_controller_spec.rb

214 lines
6.5 KiB
Ruby
Raw Normal View History

2019-06-05 12:25:43 +05:30
# frozen_string_literal: true
require 'rails_helper'
2017-09-10 17:25:29 +05:30
describe SentNotificationsController do
2016-09-29 09:46:39 +05:30
let(:user) { create(:user) }
2019-06-05 12:25:43 +05:30
let(:project) { create(:project, :public) }
let(:private_project) { create(:project, :private) }
let(:sent_notification) { create(:sent_notification, project: target_project, noteable: noteable, recipient: user) }
2016-09-29 09:46:39 +05:30
let(:issue) do
2019-06-05 12:25:43 +05:30
create(:issue, project: target_project) do |issue|
issue.subscriptions.create(user: user, project: target_project, subscribed: true)
end
end
let(:confidential_issue) do
create(:issue, project: target_project, confidential: true) do |issue|
issue.subscriptions.create(user: user, project: target_project, subscribed: true)
2016-09-29 09:46:39 +05:30
end
end
2019-06-05 12:25:43 +05:30
let(:merge_request) do
create(:merge_request, source_project: target_project, target_project: target_project) do |mr|
mr.subscriptions.create(user: user, project: target_project, subscribed: true)
end
end
let(:noteable) { issue }
let(:target_project) { project }
2016-09-29 09:46:39 +05:30
describe 'GET unsubscribe' do
context 'when the user is not logged in' do
context 'when the force param is passed' do
2017-09-10 17:25:29 +05:30
before do
2019-02-15 15:39:39 +05:30
get(:unsubscribe, params: { id: sent_notification.reply_key, force: true })
2017-09-10 17:25:29 +05:30
end
2016-09-29 09:46:39 +05:30
it 'unsubscribes the user' do
2017-08-17 22:00:37 +05:30
expect(issue.subscribed?(user, project)).to be_falsey
2016-09-29 09:46:39 +05:30
end
it 'sets the flash message' do
2017-09-10 17:25:29 +05:30
expect(controller).to set_flash[:notice].to(/unsubscribed/)
2016-09-29 09:46:39 +05:30
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-06-05 12:25:43 +05:30
render_views
2017-09-10 17:25:29 +05:30
before do
2019-02-15 15:39:39 +05:30
get(:unsubscribe, params: { id: sent_notification.reply_key })
2017-09-10 17:25:29 +05:30
end
2016-09-29 09:46:39 +05:30
2019-06-05 12:25:43 +05:30
shared_examples 'unsubscribing as anonymous' do
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
expect(response.status).to eq(200)
expect(response).to render_template :unsubscribe
end
2016-09-29 09:46:39 +05:30
end
2019-06-05 12:25:43 +05:30
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
it_behaves_like 'unsubscribing as anonymous'
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
it_behaves_like 'unsubscribing as anonymous'
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
it_behaves_like 'unsubscribing as anonymous'
end
2016-09-29 09:46:39 +05:30
end
2019-06-05 12:25:43 +05:30
context 'when project is not public' do
let(:target_project) { private_project }
context 'when unsubscribing from issue' do
let(:noteable) { issue }
it 'shows issue title' do
expect(response.body).not_to include(issue.title)
end
it_behaves_like 'unsubscribing as anonymous'
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
it_behaves_like 'unsubscribing as anonymous'
end
context 'when unsubscribing from merge request' do
let(:noteable) { merge_request }
it 'shows merge request title' do
expect(response.body).not_to include(merge_request.title)
end
it_behaves_like 'unsubscribing as anonymous'
end
2016-09-29 09:46:39 +05:30
end
end
end
2016-09-29 09:46:39 +05:30
context 'when the user is logged in' do
2017-09-10 17:25:29 +05:30
before do
sign_in(user)
end
2016-09-29 09:46:39 +05:30
context 'when the ID passed does not exist' do
2017-09-10 17:25:29 +05:30
before do
2019-02-15 15:39:39 +05:30
get(:unsubscribe, params: { id: sent_notification.reply_key.reverse })
2017-09-10 17:25:29 +05:30
end
2016-09-29 09:46:39 +05:30
it 'does not unsubscribe the user' do
2017-08-17 22:00:37 +05:30
expect(issue.subscribed?(user, project)).to be_truthy
2016-09-29 09:46:39 +05:30
end
it 'does not set the flash message' do
expect(controller).not_to set_flash[:notice]
end
it 'returns a 404' do
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-29 09:46:39 +05:30
end
end
context 'when the force param is passed' do
2017-09-10 17:25:29 +05:30
before do
2019-02-15 15:39:39 +05:30
get(:unsubscribe, params: { id: sent_notification.reply_key, force: true })
2017-09-10 17:25:29 +05:30
end
2016-09-29 09:46:39 +05:30
it 'unsubscribes the user' do
2017-08-17 22:00:37 +05:30
expect(issue.subscribed?(user, project)).to be_falsey
2016-09-29 09:46:39 +05:30
end
it 'sets the flash message' do
2017-09-10 17:25:29 +05:30
expect(controller).to set_flash[:notice].to(/unsubscribed/)
2016-09-29 09:46:39 +05:30
end
it 'redirects to the issue page' do
2017-09-10 17:25:29 +05:30
expect(response)
.to redirect_to(project_issue_path(project, issue))
2016-09-29 09:46:39 +05:30
end
end
context 'when the force param is not passed' do
let(:merge_request) do
create(:merge_request, source_project: project, author: user) do |merge_request|
2017-08-17 22:00:37 +05:30
merge_request.subscriptions.create(user: user, project: project, subscribed: true)
2016-09-29 09:46:39 +05:30
end
end
2017-08-17 22:00:37 +05:30
let(:sent_notification) { create(:sent_notification, project: project, noteable: merge_request, recipient: user) }
2017-09-10 17:25:29 +05:30
before do
2019-02-15 15:39:39 +05:30
get(:unsubscribe, params: { id: sent_notification.reply_key })
2017-09-10 17:25:29 +05:30
end
2016-09-29 09:46:39 +05:30
it 'unsubscribes the user' do
2017-08-17 22:00:37 +05:30
expect(merge_request.subscribed?(user, project)).to be_falsey
2016-09-29 09:46:39 +05:30
end
2016-09-29 09:46:39 +05:30
it 'sets the flash message' do
2017-09-10 17:25:29 +05:30
expect(controller).to set_flash[:notice].to(/unsubscribed/)
2016-09-29 09:46:39 +05:30
end
2016-09-29 09:46:39 +05:30
it 'redirects to the merge request page' do
2017-09-10 17:25:29 +05:30
expect(response)
.to redirect_to(project_merge_request_path(project, merge_request))
2016-09-29 09:46:39 +05:30
end
end
end
end
end