emails: fix exception when disabling dmail notifications.
Fix an `undefined method 'find' for Maintenance::User:Module` exception when disabling email notifications using the "Disable notifications" link in dmails.
This commit is contained in:
@@ -5,6 +5,8 @@ module Maintenance
|
|||||||
class EmailNotificationsController < ApplicationController
|
class EmailNotificationsController < ApplicationController
|
||||||
class VerificationError < StandardError; end
|
class VerificationError < StandardError; end
|
||||||
|
|
||||||
|
respond_to :html, :json, :xml
|
||||||
|
|
||||||
before_action :validate_sig, :only => [:destroy]
|
before_action :validate_sig, :only => [:destroy]
|
||||||
rescue_from VerificationError, with: :render_verification_error
|
rescue_from VerificationError, with: :render_verification_error
|
||||||
|
|
||||||
@@ -12,9 +14,9 @@ module Maintenance
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@user = User.find(params[:user_id])
|
@user = ::User.find(params[:user_id])
|
||||||
@user.receive_email_notifications = false
|
@user.update!(receive_email_notifications: false)
|
||||||
@user.save
|
respond_with(@user)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
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_auth maintenance_user_email_notification_path(user_id: @user.id, sig: @sig), @user
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_equal(false, @user.reload.receive_email_notifications)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not disable email notifications when given an incorrect signature" do
|
||||||
|
delete_auth maintenance_user_email_notification_path(user_id: @user.id, sig: "foo"), @user
|
||||||
|
|
||||||
|
assert_response 403
|
||||||
|
assert_equal(true, @user.reload.receive_email_notifications)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user