diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb new file mode 100644 index 000000000..fa626ece9 --- /dev/null +++ b/app/controllers/account_controller.rb @@ -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 diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb new file mode 100644 index 000000000..b3d45d967 --- /dev/null +++ b/app/views/account/show.html.erb @@ -0,0 +1,13 @@ +

<%= t("account.show.title") %>

+ +<%= 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 %> + diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 95b5fb7af..4353e164a 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -23,6 +23,12 @@
<%= render 'devise/menu/login_items' %> + + <% if user_signed_in? %> + + <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 0374b471b..9bcc65400 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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." \ No newline at end of file + notice_already_registered: "Your vote is already registered." + account: + show: + title: "My account" + save_changes_submit: "Save changes" diff --git a/config/locales/es.yml b/config/locales/es.yml index e88b83346..b702eb1fd 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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." \ No newline at end of file + notice_already_registered: "Tu voto ya ha sido registrado." + account: + show: + title: "Mi cuenta" + save_changes_submit: "Guardar cambios" diff --git a/config/locales/responders.en.yml b/config/locales/responders.en.yml index c3e147abf..cd0d93fe8 100644 --- a/config/locales/responders.en.yml +++ b/config/locales/responders.en.yml @@ -10,3 +10,6 @@ en: destroy: notice: '%{resource_name} was successfully destroyed.' alert: '%{resource_name} could not be destroyed.' + save_changes: + notice: "Saved" + diff --git a/config/locales/responders.es.yml b/config/locales/responders.es.yml index aa3a47f0d..ad8012f9e 100644 --- a/config/locales/responders.es.yml +++ b/config/locales/responders.es.yml @@ -7,4 +7,6 @@ es: notice: "%{resource_name} actualizado correctamente." destroy: notice: "%{resource_name} borrado correctamente." - alert: "%{resource_name} no ha podido ser borrado." \ No newline at end of file + alert: "%{resource_name} no ha podido ser borrado." + save_changes: + notice: "Cambios guardados" diff --git a/config/routes.rb b/config/routes.rb index a364ef871..f5afd988c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb new file mode 100644 index 000000000..7179b6c6b --- /dev/null +++ b/spec/features/account_spec.rb @@ -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 \ No newline at end of file