2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-13 23:56:54 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-10-23 09:06:03 +00:00
|
|
|
describe 'Unsubscribe links', :sidekiq_might_not_need_inline do
|
2016-07-13 23:56:54 +00:00
|
|
|
include Warden::Test::Helpers
|
|
|
|
|
|
|
|
let(:recipient) { create(:user) }
|
|
|
|
let(:author) { create(:user) }
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-05-04 12:11:15 +00:00
|
|
|
let(:params) { { title: 'A bug!', description: 'Fix it!', assignees: [recipient] } }
|
2016-07-13 23:56:54 +00:00
|
|
|
let(:issue) { Issues::CreateService.new(project, author, params).execute }
|
|
|
|
|
|
|
|
let(:mail) { ActionMailer::Base.deliveries.last }
|
|
|
|
let(:body) { Capybara::Node::Simple.new(mail.default_part_body.to_s) }
|
2016-09-25 16:06:09 +00:00
|
|
|
let(:header_link) { mail.header['List-Unsubscribe'].to_s[1..-2] } # Strip angle brackets
|
2016-07-13 23:56:54 +00:00
|
|
|
let(:body_link) { body.find_link('unsubscribe')['href'] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
perform_enqueued_jobs { issue }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when logged out' do
|
2016-09-16 15:08:09 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
expect(current_path).to eq unsubscribe_sent_notification_path(SentNotification.last)
|
2017-05-29 20:18:09 +00:00
|
|
|
expect(page).to have_text(%(Unsubscribe from issue))
|
|
|
|
expect(page).to have_text(%(Are you sure you want to unsubscribe from the issue: #{issue.title} (#{issue.to_reference})?))
|
2016-11-04 18:19:08 +00:00
|
|
|
expect(issue.subscribed?(recipient, project)).to be_truthy
|
2016-09-16 15:08:09 +00:00
|
|
|
|
|
|
|
click_link 'Unsubscribe'
|
|
|
|
|
2016-11-04 18:19:08 +00:00
|
|
|
expect(issue.subscribed?(recipient, project)).to be_falsey
|
2016-09-16 15:08:09 +00:00
|
|
|
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)
|
2016-11-04 18:19:08 +00:00
|
|
|
expect(issue.subscribed?(recipient, project)).to be_truthy
|
2016-09-16 15:08:09 +00:00
|
|
|
|
|
|
|
click_link 'Cancel'
|
2016-07-13 23:56:54 +00:00
|
|
|
|
2016-11-04 18:19:08 +00:00
|
|
|
expect(issue.subscribed?(recipient, project)).to be_truthy
|
2016-09-16 15:08:09 +00:00
|
|
|
expect(current_path).to eq new_user_session_path
|
|
|
|
end
|
2016-07-13 23:56:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'unsubscribes from the issue when visiting the link from the header' do
|
|
|
|
visit header_link
|
|
|
|
|
|
|
|
expect(page).to have_text('unsubscribed')
|
2016-11-04 18:19:08 +00:00
|
|
|
expect(issue.subscribed?(recipient, project)).to be_falsey
|
2016-07-13 23:56:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when logged in' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
2017-06-16 16:35:01 +00:00
|
|
|
sign_in(recipient)
|
2017-06-14 18:18:56 +00:00
|
|
|
end
|
2016-07-13 23:56:54 +00:00
|
|
|
|
|
|
|
it 'unsubscribes from the issue when visiting the link from the email body' do
|
|
|
|
visit body_link
|
|
|
|
|
|
|
|
expect(page).to have_text('unsubscribed')
|
2016-11-04 18:19:08 +00:00
|
|
|
expect(issue.subscribed?(recipient, project)).to be_falsey
|
2016-07-13 23:56:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'unsubscribes from the issue when visiting the link from the header' do
|
|
|
|
visit header_link
|
|
|
|
|
|
|
|
expect(page).to have_text('unsubscribed')
|
2016-11-04 18:19:08 +00:00
|
|
|
expect(issue.subscribed?(recipient, project)).to be_falsey
|
2016-07-13 23:56:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|