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

110 lines
3.5 KiB
Ruby
Raw Normal View History

require 'rails_helper'
describe SentNotificationsController, type: :controller do
2016-09-29 09:46:39 +05:30
let(:user) { create(:user) }
let(:project) { create(:empty_project) }
2017-08-17 22:00:37 +05:30
let(:sent_notification) { create(:sent_notification, project: project, noteable: issue, recipient: user) }
2016-09-29 09:46:39 +05:30
let(:issue) do
create(:issue, project: project, author: user) do |issue|
2017-08-17 22:00:37 +05:30
issue.subscriptions.create(user: user, project: project, subscribed: true)
2016-09-29 09:46:39 +05:30
end
end
describe 'GET unsubscribe' do
context 'when the user is not logged in' do
context 'when the force param is passed' do
before { get(:unsubscribe, id: sent_notification.reply_key, force: true) }
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
expect(controller).to set_flash[:notice].to(/unsubscribed/).now
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
before { get(:unsubscribe, id: sent_notification.reply_key) }
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
2016-09-29 09:46:39 +05:30
it 'does not set the flash message' do
expect(controller).not_to set_flash[:notice]
end
it 'redirects to the login page' do
expect(response).to render_template :unsubscribe
end
end
end
2016-09-29 09:46:39 +05:30
context 'when the user is logged in' do
before { sign_in(user) }
context 'when the ID passed does not exist' do
before { get(:unsubscribe, id: sent_notification.reply_key.reverse) }
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
expect(response).to have_http_status(:not_found)
end
end
context 'when the force param is passed' do
before { get(:unsubscribe, id: sent_notification.reply_key, force: true) }
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
expect(controller).to set_flash[:notice].to(/unsubscribed/).now
end
it 'redirects to the issue page' do
expect(response).
to redirect_to(namespace_project_issue_path(project.namespace, project, issue))
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) }
2016-09-29 09:46:39 +05:30
before { get(:unsubscribe, id: sent_notification.reply_key) }
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
expect(controller).to set_flash[:notice].to(/unsubscribed/).now
end
2016-09-29 09:46:39 +05:30
it 'redirects to the merge request page' do
expect(response).
to redirect_to(namespace_project_merge_request_path(project.namespace, project, merge_request))
end
end
end
end
end