We add new method set_user_locale to render the page with the user's preferred locale. Note that we add a condition 'if params[:locale].blank?' to recover the user's preferred locale. This is necessary because it may be the case that the user does not have an associated locale, and when execute '@user.locale' when this value is 'nil', by default returns the default locale. As we do not want this to happen and we want the locale we receive as parameter to prevail in this case.
53 lines
2.5 KiB
Ruby
53 lines
2.5 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Subscriptions" do
|
|
let(:user) { create(:user, subscriptions_token: SecureRandom.base58(32)) }
|
|
|
|
context "Edit page" do
|
|
scenario "Render content in the user's preferred locale" do
|
|
user.update!(locale: "es")
|
|
visit edit_subscriptions_path(token: user.subscriptions_token)
|
|
|
|
expect(page).to have_content "Notificaciones"
|
|
expect(page).to have_field "Recibir un email cuando alguien comenta en mis propuestas o debates",
|
|
type: :checkbox
|
|
expect(page).to have_field "Recibir un email cuando alguien contesta a mis comentarios", type: :checkbox
|
|
expect(page).to have_field "Recibir emails con información interesante sobre la web", type: :checkbox
|
|
expect(page).to have_field "Recibir resumen de notificaciones sobre propuestas", type: :checkbox
|
|
expect(page).to have_field "Recibir emails con mensajes privados", type: :checkbox
|
|
expect(page).to have_button "Guardar cambios"
|
|
end
|
|
|
|
scenario "Use the locale in the parameters when accessing anonymously" do
|
|
visit edit_subscriptions_path(token: user.subscriptions_token, locale: :es)
|
|
|
|
expect(page).to have_content "Notificaciones"
|
|
end
|
|
end
|
|
|
|
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
|