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">
|
<section class="top-bar-section">
|
||||||
<%= render 'devise/menu/login_items' %>
|
<%= 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>
|
</section>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ en:
|
|||||||
open_city: We are opening Madrid
|
open_city: We are opening Madrid
|
||||||
open_city_slogan: So the citizens can decide what kind of city they want.
|
open_city_slogan: So the citizens can decide what kind of city they want.
|
||||||
create_debate: Create a debate
|
create_debate: Create a debate
|
||||||
|
my_account_link: My account
|
||||||
debates:
|
debates:
|
||||||
debate:
|
debate:
|
||||||
debate: Debate
|
debate: Debate
|
||||||
@@ -41,3 +42,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"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ es:
|
|||||||
open_city: Estamos abriendo Madrid
|
open_city: Estamos abriendo Madrid
|
||||||
open_city_slogan: Para que todos los madrileños decidamos que ciudad queremos tener.
|
open_city_slogan: Para que todos los madrileños decidamos que ciudad queremos tener.
|
||||||
create_debate: Crea un debate
|
create_debate: Crea un debate
|
||||||
|
my_account_link: Mi cuenta
|
||||||
debates:
|
debates:
|
||||||
debate:
|
debate:
|
||||||
debate: Debate
|
debate: Debate
|
||||||
@@ -41,3 +42,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"
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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