Commit c61a54f7 authored by Rémy Coutable's avatar Rémy Coutable

Fix initial implementation to actually render the unsubscribe page

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent b3357308
...@@ -2,12 +2,15 @@ class SentNotificationsController < ApplicationController ...@@ -2,12 +2,15 @@ class SentNotificationsController < ApplicationController
skip_before_action :authenticate_user! skip_before_action :authenticate_user!
def unsubscribe def unsubscribe
return redirect_to new_user_session_path unless current_user || params[:force]
@sent_notification = SentNotification.for(params[:id]) @sent_notification = SentNotification.for(params[:id])
return render_404 unless @sent_notification && @sent_notification.unsubscribable? return render_404 unless @sent_notification && @sent_notification.unsubscribable?
return unsubscribe_and_redirect if current_user || params[:force]
end
private
def unsubscribe_and_redirect
noteable = @sent_notification.noteable noteable = @sent_notification.noteable
noteable.unsubscribe(@sent_notification.recipient) noteable.unsubscribe(@sent_notification.recipient)
......
%h3.page-title - noteable = @sent_notification.noteable
Are you sure you want to unsubscribe from this thread? - noteable_type = @sent_notification.noteable_type.humanize(capitalize: false)
- noteable_text = %(#{noteable_type} "#{noteable.title}" (#{noteable.to_reference}))
- title = "Unsubscribe from #{noteable_text}"
= link_to "Unsubscribe", unsubscribe_sent_notification_path(@sent_notification, force: true), class: 'btn btn-primary wide' - page_title title
%h3.page-title= title
%p= "Are you sure you want to unsubscribe from #{noteable_text}?"
%p
= link_to 'Unsubscribe', unsubscribe_sent_notification_path(@sent_notification, force: true),
class: 'btn btn-primary append-right-10'
= link_to 'Cancel', new_user_session_path, class: 'btn append-right-10'
...@@ -41,7 +41,7 @@ describe SentNotificationsController, type: :controller do ...@@ -41,7 +41,7 @@ describe SentNotificationsController, type: :controller do
end end
it 'redirects to the login page' do it 'redirects to the login page' do
expect(response).to redirect_to(new_user_session_path) expect(response).to render_template :unsubscribe
end end
end end
end end
...@@ -83,19 +83,25 @@ describe SentNotificationsController, type: :controller do ...@@ -83,19 +83,25 @@ describe SentNotificationsController, type: :controller do
end end
context 'when the force param is not passed' do context 'when the force param is not passed' do
let(:merge_request) do
create(:merge_request, source_project: project, author: user) do |merge_request|
merge_request.subscriptions.create(user: user, subscribed: true)
end
end
let(:sent_notification) { create(:sent_notification, noteable: merge_request, recipient: user) }
before { get(:unsubscribe, id: sent_notification.reply_key) } before { get(:unsubscribe, id: sent_notification.reply_key) }
it 'unsubscribes the user' do it 'unsubscribes the user' do
expect(issue.subscribed?(user)).to be_falsey expect(merge_request.subscribed?(user)).to be_falsey
end end
it 'sets the flash message' do it 'sets the flash message' do
expect(controller).to set_flash[:notice].to(/unsubscribed/).now expect(controller).to set_flash[:notice].to(/unsubscribed/).now
end end
it 'redirects to the issue page' do it 'redirects to the merge request page' do
expect(response). expect(response).
to redirect_to(namespace_project_issue_path(project.namespace, project, issue)) to redirect_to(namespace_project_merge_request_path(project.namespace, project, merge_request))
end end
end end
end end
......
...@@ -19,11 +19,32 @@ describe 'Unsubscribe links', feature: true do ...@@ -19,11 +19,32 @@ describe 'Unsubscribe links', feature: true do
end end
context 'when logged out' do context 'when logged out' do
it 'redirects to the login page when visiting the link from the body' do context 'when visiting the link from the body' do
it 'shows the unsubscribe confirmation page and redirects to root path when confirming' do
visit body_link visit body_link
expect(current_path).to eq unsubscribe_sent_notification_path(SentNotification.last)
expect(page).to have_text(%(Unsubscribe from issue "#{issue.title}" (#{issue.to_reference})))
expect(page).to have_text(%(Are you sure you want to unsubscribe from issue "#{issue.title}" (#{issue.to_reference})?))
expect(issue.subscribed?(recipient)).to be_truthy
click_link 'Unsubscribe'
expect(issue.subscribed?(recipient)).to be_falsey
expect(current_path).to eq new_user_session_path expect(current_path).to eq new_user_session_path
end
it 'shows the unsubscribe confirmation page and redirects to root path when canceling' do
visit body_link
expect(current_path).to eq unsubscribe_sent_notification_path(SentNotification.last)
expect(issue.subscribed?(recipient)).to be_truthy
click_link 'Cancel'
expect(issue.subscribed?(recipient)).to be_truthy expect(issue.subscribed?(recipient)).to be_truthy
expect(current_path).to eq new_user_session_path
end
end end
it 'unsubscribes from the issue when visiting the link from the header' do it 'unsubscribes from the issue when visiting the link from the header' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment