adds basic 'my account' page
Fields related with authentication are not included because the auth system will change to integrate with Madrid.es's Ciudadano360 ref: #22
This commit is contained in:
23
app/controllers/account_controller.rb
Normal file
23
app/controllers/account_controller.rb
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
class AccountController < ApplicationController
|
||||||
|
|
||||||
|
before_action :authenticate_user!
|
||||||
|
before_action :set_account
|
||||||
|
|
||||||
|
def show
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
flash[:notice] = t("flash.actions.save_changes.notice") if @account.update(account_params)
|
||||||
|
redirect_to account_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_account
|
||||||
|
@account = current_user
|
||||||
|
end
|
||||||
|
|
||||||
|
def account_params
|
||||||
|
params.require(:account).permit(:first_name, :last_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
13
app/views/account/show.html.erb
Normal file
13
app/views/account/show.html.erb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<h1><%= t("account.show.title") %></h1>
|
||||||
|
|
||||||
|
<%= form_for @account, as: :account, url: account_path do |f| %>
|
||||||
|
<%= f.label :first_name, t("account.show.first_name_label") %>
|
||||||
|
<%= f.text_field :first_name %>
|
||||||
|
<%= f.label :last_name, t("account.show.last_name_label") %>
|
||||||
|
<%= f.text_field :last_name %>
|
||||||
|
|
||||||
|
<%= f.submit t("account.show.save_changes_submit"), class: "button radius" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to t("account.show.change_credentials_link"), edit_user_registration_path %>
|
||||||
|
|
||||||
@@ -40,4 +40,8 @@ en:
|
|||||||
back_link: Back
|
back_link: Back
|
||||||
votes:
|
votes:
|
||||||
notice_thanks: "Thanks for voting."
|
notice_thanks: "Thanks for voting."
|
||||||
notice_already_registered: "Your vote is already registered."
|
notice_already_registered: "Your vote is already registered."
|
||||||
|
account:
|
||||||
|
show:
|
||||||
|
title: "My account"
|
||||||
|
save_changes_submit: "Save changes"
|
||||||
|
|||||||
@@ -40,4 +40,8 @@ es:
|
|||||||
back_link: Volver
|
back_link: Volver
|
||||||
votes:
|
votes:
|
||||||
notice_thanks: "Gracias por votar."
|
notice_thanks: "Gracias por votar."
|
||||||
notice_already_registered: "Tu voto ya ha sido registrado."
|
notice_already_registered: "Tu voto ya ha sido registrado."
|
||||||
|
account:
|
||||||
|
show:
|
||||||
|
title: "Mi cuenta"
|
||||||
|
save_changes_submit: "Guardar cambios"
|
||||||
|
|||||||
@@ -10,3 +10,6 @@ en:
|
|||||||
destroy:
|
destroy:
|
||||||
notice: '%{resource_name} was successfully destroyed.'
|
notice: '%{resource_name} was successfully destroyed.'
|
||||||
alert: '%{resource_name} could not be destroyed.'
|
alert: '%{resource_name} could not be destroyed.'
|
||||||
|
save_changes:
|
||||||
|
notice: "Saved"
|
||||||
|
|
||||||
|
|||||||
@@ -7,4 +7,6 @@ es:
|
|||||||
notice: "%{resource_name} actualizado correctamente."
|
notice: "%{resource_name} actualizado correctamente."
|
||||||
destroy:
|
destroy:
|
||||||
notice: "%{resource_name} borrado correctamente."
|
notice: "%{resource_name} borrado correctamente."
|
||||||
alert: "%{resource_name} no ha podido ser borrado."
|
alert: "%{resource_name} no ha podido ser borrado."
|
||||||
|
save_changes:
|
||||||
|
notice: "Cambios guardados"
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ Rails.application.routes.draw do
|
|||||||
resources :comments, only: :create
|
resources :comments, only: :create
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resource :account, controller: "account", only: [:show, :update]
|
||||||
|
|
||||||
# Example of regular route:
|
# Example of regular route:
|
||||||
# get 'products/:id' => 'catalog#view'
|
# get 'products/:id' => 'catalog#view'
|
||||||
|
|
||||||
|
|||||||
33
spec/features/account_spec.rb
Normal file
33
spec/features/account_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Account' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
@user = create(:user, first_name: "Manuela", last_name:"Colau")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Show' do
|
||||||
|
login_as(@user)
|
||||||
|
visit root_path
|
||||||
|
click_link "My account"
|
||||||
|
|
||||||
|
expect(page).to have_selector("input[value='Manuela']")
|
||||||
|
expect(page).to have_selector("input[value='Colau']")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Edit' do
|
||||||
|
login_as(@user)
|
||||||
|
visit account_path
|
||||||
|
|
||||||
|
fill_in 'account_first_name', with: 'Larry'
|
||||||
|
fill_in 'account_last_name', with: 'Bird'
|
||||||
|
click_button 'Save changes'
|
||||||
|
|
||||||
|
expect(page).to have_content "Saved"
|
||||||
|
|
||||||
|
visit account_path
|
||||||
|
|
||||||
|
expect(page).to have_selector("input[value='Larry']")
|
||||||
|
expect(page).to have_selector("input[value='Bird']")
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user