Fix it so that emails are (hopefully) able to show the one-click unsubscribe button in Gmail and other mail providers that support the List-Unsubscribe header. This way users can unsubscribe instead of marking emails as spam. * Add the List-Unsubscribe-Post header. * Fix the disable email notifications endpoint to support POST as well as DELETE requests. * Fix the disable email notifications endpoint to disable XSRF protection (we don't need users to be logged in because we use a signed URL instead). https://www.rfc-editor.org/rfc/rfc8058#section-3.1 https://www.rfc-editor.org/rfc/rfc8058#section-8.1
46 lines
1.6 KiB
Ruby
46 lines
1.6 KiB
Ruby
require "test_helper"
|
|
|
|
module Maintenance
|
|
module User
|
|
class EmailNotificationsControllerTest < ActionDispatch::IntegrationTest
|
|
context "Email notifications" do
|
|
setup do
|
|
@user = create(:user, receive_email_notifications: true)
|
|
@verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.email_key, digest: "SHA256", serializer: JSON)
|
|
@sig = @verifier.generate(@user.id.to_s)
|
|
end
|
|
|
|
context "#show" do
|
|
should "render" do
|
|
get_auth maintenance_user_email_notification_path(user_id: @user.id), @user
|
|
assert_response :success
|
|
end
|
|
end
|
|
|
|
context "#destroy" do
|
|
should "disable email notifications" do
|
|
delete maintenance_user_email_notification_path(user_id: @user.id, sig: @sig)
|
|
|
|
assert_response :success
|
|
assert_equal(false, @user.reload.receive_email_notifications)
|
|
end
|
|
|
|
should "disable email notifications from a one-click unsubscribe" do
|
|
post maintenance_user_email_notification_path(user_id: @user.id, sig: @sig), params: { "List-Unsubscribe": "One-Click" }
|
|
|
|
assert_response :success
|
|
assert_equal(false, @user.reload.receive_email_notifications)
|
|
end
|
|
|
|
should "not disable email notifications when given an incorrect signature" do
|
|
delete maintenance_user_email_notification_path(user_id: @user.id, sig: "foo")
|
|
|
|
assert_response 403
|
|
assert_equal(true, @user.reload.receive_email_notifications)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|