Merge pull request #62 from AyuntamientoMadrid/account
Adds basic "My account" page
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 %>
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
|
||||
<section class="top-bar-section">
|
||||
<%= render 'devise/menu/login_items' %>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<ul class="right">
|
||||
<li><%= link_to(t("layouts.header.my_account_link"), account_path) %></li>
|
||||
</ul>
|
||||
<% end %>
|
||||
</section>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@@ -10,6 +10,7 @@ en:
|
||||
open_city: We are opening Madrid
|
||||
open_city_slogan: So the citizens can decide what kind of city they want.
|
||||
create_debate: Create a debate
|
||||
my_account_link: My account
|
||||
debates:
|
||||
debate:
|
||||
debate: Debate
|
||||
@@ -40,4 +41,8 @@ en:
|
||||
back_link: Back
|
||||
votes:
|
||||
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"
|
||||
|
||||
@@ -10,6 +10,7 @@ es:
|
||||
open_city: Estamos abriendo Madrid
|
||||
open_city_slogan: Para que todos los madrileños decidamos que ciudad queremos tener.
|
||||
create_debate: Crea un debate
|
||||
my_account_link: Mi cuenta
|
||||
debates:
|
||||
debate:
|
||||
debate: Debate
|
||||
@@ -40,4 +41,8 @@ es:
|
||||
back_link: Volver
|
||||
votes:
|
||||
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:
|
||||
notice: '%{resource_name} was successfully destroyed.'
|
||||
alert: '%{resource_name} could not be destroyed.'
|
||||
save_changes:
|
||||
notice: "Saved"
|
||||
|
||||
|
||||
@@ -7,4 +7,6 @@ es:
|
||||
notice: "%{resource_name} actualizado correctamente."
|
||||
destroy:
|
||||
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
|
||||
end
|
||||
|
||||
resource :account, controller: "account", only: [:show, :update]
|
||||
|
||||
# Example of regular route:
|
||||
# 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