mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 11:47:56 +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 %>
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
<%= 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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,6 +3,7 @@ FactoryBot.define do
|
||||
sequence(:email) { |n| "user#{n}@example.com" }
|
||||
|
||||
full_name { 'First Last' }
|
||||
notifications_enabled { true }
|
||||
password { 'password' }
|
||||
end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -75,4 +76,16 @@ feature 'sign up', type: :system do
|
||||
expect_to_be_on_sign_up_page
|
||||
expect(page).to have_css('.alert')
|
||||
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