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:
Juanjo Bazán
2015-07-30 17:35:35 +02:00
parent 58b43a9dc4
commit 8f6e5ecfc8
8 changed files with 87 additions and 3 deletions

View 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

View 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 %>

View File

@@ -41,3 +41,7 @@ en:
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"

View File

@@ -41,3 +41,7 @@ es:
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"

View File

@@ -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"

View File

@@ -8,3 +8,5 @@ es:
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"

View File

@@ -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'

View 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