Allow updating the status of notifications
You can update the same "notifications" section that we allow you to update in "my account". This "subscriptions" section differs from the "my account" section because we do not need to be logged in to update the status of the notifications.
This commit is contained in:
@@ -5,6 +5,12 @@ class SubscriptionsController < ApplicationController
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@user.update!(subscriptions_params)
|
||||
redirect_to edit_subscriptions_path(token: @user.subscriptions_token),
|
||||
notice: t("flash.actions.save_changes.notice")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_user
|
||||
@@ -14,4 +20,12 @@ class SubscriptionsController < ApplicationController
|
||||
current_user || raise(CanCan::AccessDenied)
|
||||
end
|
||||
end
|
||||
|
||||
def subscriptions_params
|
||||
params.require(:user).permit(allowed_params)
|
||||
end
|
||||
|
||||
def allowed_params
|
||||
[:email_on_comment, :email_on_comment_reply, :email_on_direct_message, :email_digest, :newsletter]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,4 +2,4 @@ resource :account, controller: "account", only: [:show, :update, :delete] do
|
||||
get :erase, on: :collection
|
||||
end
|
||||
|
||||
resource :subscriptions, only: [:edit]
|
||||
resource :subscriptions, only: [:edit, :update]
|
||||
|
||||
30
spec/system/subscriptions_spec.rb
Normal file
30
spec/system/subscriptions_spec.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Subscriptions" do
|
||||
let(:user) { create(:user, subscriptions_token: SecureRandom.base58(32)) }
|
||||
|
||||
context "Update" do
|
||||
scenario "Allow updating the status notification" do
|
||||
user.update!(email_on_comment: false,
|
||||
email_on_comment_reply: true,
|
||||
newsletter: true,
|
||||
email_digest: false,
|
||||
email_on_direct_message: true)
|
||||
visit edit_subscriptions_path(token: user.subscriptions_token)
|
||||
|
||||
check "Notify me by email when someone comments on my proposals or debates"
|
||||
uncheck "Notify me by email when someone replies to my comments"
|
||||
uncheck "Receive by email website relevant information"
|
||||
check "Receive a summary of proposal notifications"
|
||||
uncheck "Receive emails about direct messages"
|
||||
click_button "Save changes"
|
||||
|
||||
expect(page).to have_content "Changes saved"
|
||||
expect(page).to have_field "Notify me by email when someone comments on my contents", checked: true
|
||||
expect(page).to have_field "Notify me by email when someone replies to my comments", checked: false
|
||||
expect(page).to have_field "Receive by email website relevant information", checked: false
|
||||
expect(page).to have_field "Receive a summary of proposal notifications", checked: true
|
||||
expect(page).to have_field "Receive emails about direct messages", checked: false
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user