mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
Adding notifications_enabled attribute to users
This diff just contains the migration and profile edition. Refers to [This Project Card](https://github.com/riggraz/astuto/projects/1#card-31194036) and #33
This commit is contained in:
committed by
Riccardo Graziosi
parent
0cc130a797
commit
9dfb13eff6
@@ -5,8 +5,8 @@ class ApplicationController < ActionController::Base
|
||||
protected
|
||||
|
||||
def configure_permitted_parameters
|
||||
devise_parameter_sanitizer.permit(:sign_up, keys: [:full_name])
|
||||
devise_parameter_sanitizer.permit(:account_update, keys: [:full_name])
|
||||
devise_parameter_sanitizer.permit(:sign_up, keys: [:full_name, :notifications_enabled])
|
||||
devise_parameter_sanitizer.permit(:account_update, keys: [:full_name, :notifications_enabled])
|
||||
end
|
||||
|
||||
def load_boards
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :notifications_enabled %>
|
||||
<%= f.check_box :notifications_enabled %>
|
||||
</div>
|
||||
|
||||
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
|
||||
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
|
||||
<% end %>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<%= f.label :full_name, class: "sr-only" %>
|
||||
<%= f.text_field :full_name, autofocus: true, placeholder: "Full name", required: true, class: "form-control" %>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :email, class: "sr-only" %>
|
||||
<%= f.email_field :email, autocomplete: "email", placeholder: "Email address", required: true, class: "form-control" %>
|
||||
@@ -23,9 +23,14 @@
|
||||
<%= f.password_field :password_confirmation, placeholder: "Password confirmation", required: true, class: "form-control" %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :notifications_enabled %>
|
||||
<%= f.check_box :notifications_enabled %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.submit "Sign up", class: "btn btn-block" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "devise/shared/links" %>
|
||||
<%= render "devise/shared/links" %>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddNotificationsEnabledFieldToUsers < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :users, :notifications_enabled, :boolean, null: false, default: true
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_10_01_160859) do
|
||||
ActiveRecord::Schema.define(version: 2021_01_26_215831) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -84,6 +84,7 @@ ActiveRecord::Schema.define(version: 2019_10_01_160859) do
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.integer "role"
|
||||
t.string "full_name"
|
||||
t.boolean "notifications_enabled", default: true, null: false
|
||||
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
sequence(:email) { |n| "user#{n}@example.com" }
|
||||
|
||||
|
||||
full_name { 'First Last' }
|
||||
notifications_enabled { true }
|
||||
password { 'password' }
|
||||
end
|
||||
|
||||
factory :moderator, class: User do
|
||||
sequence(:email) { |n| "mod#{n}@example.com" }
|
||||
|
||||
|
||||
full_name { 'First Last' }
|
||||
password { 'password' }
|
||||
role { 'moderator' }
|
||||
@@ -16,7 +17,7 @@ FactoryBot.define do
|
||||
|
||||
factory :admin, class: User do
|
||||
sequence(:email) { |n| "admin#{n}@example.com" }
|
||||
|
||||
|
||||
full_name { 'First Last' }
|
||||
password { 'password' }
|
||||
role { 'admin' }
|
||||
|
||||
@@ -4,10 +4,10 @@ require 'rails_helper'
|
||||
feature 'edit user profile settings', type: :system do
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
before(:each) do
|
||||
before(:each) do
|
||||
user.confirm # devise helper to confirm user account
|
||||
sign_in user # devise helper to login user
|
||||
|
||||
|
||||
# check that user is confirmed and saved in the db
|
||||
expect(user.confirmed_at).not_to be_nil
|
||||
expect(User.count).to eq(1)
|
||||
@@ -44,6 +44,30 @@ feature 'edit user profile settings', type: :system do
|
||||
expect(page).to have_css('.notice')
|
||||
end
|
||||
|
||||
scenario 'turns on notifications' do
|
||||
user.update(notifications_enabled: false)
|
||||
|
||||
visit edit_user_registration_path
|
||||
check 'Notifications enabled'
|
||||
fill_in 'Current password', with: user.password
|
||||
click_button 'Update profile'
|
||||
|
||||
user.reload
|
||||
expect(user.notifications_enabled).to eq(true)
|
||||
end
|
||||
|
||||
scenario 'turns off notifications' do
|
||||
user.update(notifications_enabled: user)
|
||||
|
||||
visit edit_user_registration_path
|
||||
uncheck 'Notifications enabled'
|
||||
fill_in 'Current password', with: user.password
|
||||
click_button 'Update profile'
|
||||
|
||||
user.reload
|
||||
expect(user.notifications_enabled).to eq(false)
|
||||
end
|
||||
|
||||
# Remember that 'password' is just a virtual attribute (i.e. it is not stored in the db)
|
||||
# so updating the user account password does not update it, but only the
|
||||
# 'encrypted_password' attribute in the db
|
||||
@@ -91,9 +115,9 @@ feature 'edit user profile settings', type: :system do
|
||||
visit edit_user_registration_path
|
||||
click_button 'Cancel my account'
|
||||
page.driver.browser.switch_to.alert.accept # accepts js pop up
|
||||
|
||||
|
||||
expect(page).to have_current_path(root_path)
|
||||
expect(User.count).to eq(user_count - 1)
|
||||
expect(page).to have_css('.notice')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,7 @@ feature 'sign up', type: :system do
|
||||
fill_in 'Email', with: user.email
|
||||
fill_in 'Password', with: user.password
|
||||
fill_in 'Password confirmation', with: user.password
|
||||
check 'Notifications enabled'
|
||||
click_button 'Sign up'
|
||||
end
|
||||
|
||||
@@ -19,14 +20,14 @@ feature 'sign up', type: :system do
|
||||
|
||||
scenario 'with valid fields' do
|
||||
user_count = User.count
|
||||
|
||||
|
||||
sign_up_as user
|
||||
|
||||
|
||||
expect(User.count).to eq(user_count + 1)
|
||||
expect(page).to have_current_path(root_path)
|
||||
expect(page).to have_css('.notice')
|
||||
end
|
||||
|
||||
|
||||
scenario 'with invalid Full Name' do
|
||||
user_count = User.count
|
||||
|
||||
@@ -75,4 +76,16 @@ feature 'sign up', type: :system do
|
||||
expect_to_be_on_sign_up_page
|
||||
expect(page).to have_css('.alert')
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'and disables notifications' do
|
||||
visit new_user_registration_path
|
||||
fill_in 'Full name', with: user.full_name
|
||||
fill_in 'Email', with: user.email
|
||||
fill_in 'Password', with: user.password
|
||||
fill_in 'Password confirmation', with: user.password
|
||||
uncheck 'Notifications enabled'
|
||||
click_button 'Sign up'
|
||||
|
||||
expect(User.last.notifications_enabled).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user