2016-09-29 09:46:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'Unsubscribe links', feature: true do
|
|
|
|
include Warden::Test::Helpers
|
|
|
|
|
|
|
|
let(:recipient) { create(:user) }
|
|
|
|
let(:author) { create(:user) }
|
|
|
|
let(:project) { create(:empty_project, :public) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:params) { { title: 'A bug!', description: 'Fix it!', assignees: [recipient] } }
|
2016-09-29 09:46:39 +05:30
|
|
|
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-10-01 15:18:49 +05:30
|
|
|
let(:header_link) { mail.header['List-Unsubscribe'].to_s[1..-2] } # Strip angle brackets
|
2016-09-29 09:46:39 +05:30
|
|
|
let(:body_link) { body.find_link('unsubscribe')['href'] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
perform_enqueued_jobs { issue }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when logged out' 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
|
|
|
|
|
|
|
|
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})?))
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.subscribed?(recipient, project)).to be_truthy
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
click_link 'Unsubscribe'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.subscribed?(recipient, project)).to be_falsey
|
2016-09-29 09:46:39 +05:30
|
|
|
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)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.subscribed?(recipient, project)).to be_truthy
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
click_link 'Cancel'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.subscribed?(recipient, project)).to be_truthy
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(current_path).to eq new_user_session_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'unsubscribes from the issue when visiting the link from the header' do
|
|
|
|
visit header_link
|
|
|
|
|
|
|
|
expect(page).to have_text('unsubscribed')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.subscribed?(recipient, project)).to be_falsey
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when logged in' do
|
|
|
|
before { login_as(recipient) }
|
|
|
|
|
|
|
|
it 'unsubscribes from the issue when visiting the link from the email body' do
|
|
|
|
visit body_link
|
|
|
|
|
|
|
|
expect(page).to have_text('unsubscribed')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.subscribed?(recipient, project)).to be_falsey
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'unsubscribes from the issue when visiting the link from the header' do
|
|
|
|
visit header_link
|
|
|
|
|
|
|
|
expect(page).to have_text('unsubscribed')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(issue.subscribed?(recipient, project)).to be_falsey
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|