2015-12-09 05:59:25 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
describe SentNotificationsController do
|
2016-07-13 19:56:54 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-11-04 14:19:08 -04:00
|
|
|
let(:sent_notification) { create(:sent_notification, project: project, noteable: issue, recipient: user) }
|
2015-12-09 05:59:25 -05:00
|
|
|
|
2016-07-13 19:56:54 -04:00
|
|
|
let(:issue) do
|
|
|
|
create(:issue, project: project, author: user) do |issue|
|
2016-10-31 22:14:53 -04:00
|
|
|
issue.subscriptions.create(user: user, project: project, subscribed: true)
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET unsubscribe' do
|
|
|
|
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
|
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 'does not unsubscribe the user' do
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_truthy
|
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 'does not set the flash message' do
|
|
|
|
expect(controller).not_to set_flash[:notice]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to the login page' do
|
2016-09-16 11:08:09 -04:00
|
|
|
expect(response).to render_template :unsubscribe
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
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
|
|
|
|
|
|
|
it 'does not unsubscribe the user' do
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_truthy
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not set the flash message' do
|
|
|
|
expect(controller).not_to set_flash[:notice]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404' do
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-07-13 19:56:54 -04:00
|
|
|
end
|
|
|
|
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|
|
2016-10-31 22:14:53 -04:00
|
|
|
merge_request.subscriptions.create(user: user, project: project, subscribed: true)
|
2016-09-16 11:08:09 -04:00
|
|
|
end
|
|
|
|
end
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|