mirror of
https://github.com/neocities/neocities.git
synced 2025-08-06 01:24:56 +02:00
easy unsubscribe baked into emails
This commit is contained in:
parent
39ce179d16
commit
be0267956b
6 changed files with 91 additions and 3 deletions
|
@ -66,6 +66,49 @@ describe 'site/settings' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'unsubscribe email' do
|
||||
include Capybara::DSL
|
||||
|
||||
before do
|
||||
@email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||
@site = Fabricate :site, email: @email
|
||||
EmailWorker.jobs.clear
|
||||
Mail::TestMailer.deliveries.clear
|
||||
|
||||
@params = {
|
||||
email: @site.email,
|
||||
token: Site.email_unsubscribe_token(@site.email)
|
||||
}
|
||||
@params_query = Rack::Utils.build_query(@params)
|
||||
|
||||
@email_unsubscribe_url = "https://neocities.org/settings/unsubscribe_email?"+@params_query
|
||||
page.set_rack_session id: nil
|
||||
end
|
||||
|
||||
it 'should redirect to settings page if logged in' do
|
||||
page.set_rack_session id: @site.id
|
||||
|
||||
end
|
||||
|
||||
it 'should unsubscribe for valid token' do
|
||||
@site.send_email subject: 'Hello', body: 'Okay'
|
||||
EmailWorker.drain
|
||||
email = Mail::TestMailer.deliveries.first
|
||||
|
||||
email.body.to_s.must_match @email_unsubscribe_url
|
||||
@site.send_emails.must_equal true
|
||||
visit '/settings/unsubscribe_email?'+@params_query
|
||||
|
||||
page.body.must_match /You have been successfully unsubscribed.+#{@site.email}/i
|
||||
|
||||
@site.reload.send_emails.must_equal false
|
||||
end
|
||||
|
||||
it 'should fail to subscribe for bad token' do
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'change password' do
|
||||
include Capybara::DSL
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ describe EmailWorker do
|
|||
mail.from.first.must_equal 'from@example.com'
|
||||
mail.to.first.must_equal 'to@example.com'
|
||||
mail.subject.must_equal 'Hello World'
|
||||
mail.body.to_s.must_equal 'testing'
|
||||
body = mail.body.to_s
|
||||
puts body
|
||||
body.must_match /testing/
|
||||
body.must_match /unsubscribe/
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue