Allow users to manage their notifications
The user can access this page without being logged in. We identify the user through the "subscriptions_token" parameter and show a list of the notifications that can be enable/disable. We will return a 404 error in case someone accesses the page with a non-existent token. We also control the case that some anonymous user tries to access the page without any token, by returning the CanCan::AccessDenied exception.
This commit is contained in:
19
spec/components/subscriptions/edit_component_spec.rb
Normal file
19
spec/components/subscriptions/edit_component_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Subscriptions::EditComponent do
|
||||
let(:user) { create(:user, subscriptions_token: SecureRandom.base58(32)) }
|
||||
let(:component) { Subscriptions::EditComponent.new(user) }
|
||||
|
||||
it "renders checkboxes to change the subscriptions preferences" do
|
||||
render_inline component
|
||||
|
||||
expect(page).to have_content "Notifications"
|
||||
expect(page).to have_field "Notify me by email when someone comments on my proposals or debates",
|
||||
type: :checkbox
|
||||
expect(page).to have_field "Notify me by email when someone replies to my comments", type: :checkbox
|
||||
expect(page).to have_field "Receive by email website relevant information", type: :checkbox
|
||||
expect(page).to have_field "Receive a summary of proposal notifications", type: :checkbox
|
||||
expect(page).to have_field "Receive emails about direct messages", type: :checkbox
|
||||
expect(page).to have_button "Save changes"
|
||||
end
|
||||
end
|
||||
16
spec/controllers/subscriptions_controller_spec.rb
Normal file
16
spec/controllers/subscriptions_controller_spec.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe SubscriptionsController do
|
||||
describe "GET edit" do
|
||||
it "returns a 404 code with a wrong token" do
|
||||
expect { get :edit, params: { token: "non_existent" } }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it "doesn't allow access to anonymous users without a token" do
|
||||
get :edit, params: { token: "" }
|
||||
|
||||
expect(response).to redirect_to "/"
|
||||
expect(flash[:alert]).to eq "You do not have permission to access this page."
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user