debian-mirror-gitlab/spec/features/unsubscribe_links_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
require 'spec_helper'
2022-11-25 23:54:43 +05:30
RSpec.describe 'Unsubscribe links', :sidekiq_inline do
2016-09-29 09:46:39 +05:30
include Warden::Test::Helpers
2022-11-25 23:54:43 +05:30
let_it_be(:project) { create(:project, :public) }
let_it_be(:author) { create(:user).tap { |u| project.add_reporter(u) } }
let_it_be(:recipient) { create(:user) }
let(:params) { { title: 'A bug!', description: 'Fix it!', assignee_ids: [recipient.id] } }
let(:issue) { Issues::CreateService.new(project: project, current_user: author, params: params, spam_params: nil).execute[:issue] }
2016-09-29 09:46:39 +05:30
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
2022-08-13 15:12:31 +05:30
let(:body_link) { body.find_link('Unsubscribe')['href'] }
2016-09-29 09:46:39 +05:30
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
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path unsubscribe_sent_notification_path(SentNotification.last), ignore_query: true
2017-09-10 17:25:29 +05:30
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})?))
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
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path new_user_session_path, ignore_query: true
2016-09-29 09:46:39 +05:30
end
it 'shows the unsubscribe confirmation page and redirects to root path when canceling' do
visit body_link
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path unsubscribe_sent_notification_path(SentNotification.last), ignore_query: true
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
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path new_user_session_path, ignore_query: true
2016-09-29 09:46:39 +05:30
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
2017-09-10 17:25:29 +05:30
before do
sign_in(recipient)
end
2016-09-29 09:46:39 +05:30
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