From fb5784fbda03b688622093d5581e97c3bae0b40d Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 31 May 2017 12:36:35 +1000 Subject: [PATCH] Allow updating of account settings from account tabs interface --- app/views/spree/users/_details.html.haml | 2 -- app/views/spree/users/_form.html.haml | 6 +++++ app/views/spree/users/_settings.html.haml | 2 ++ app/views/spree/users/edit.html.haml | 7 +---- app/views/spree/users/show.html.haml | 7 +++-- config/locales/en.yml | 4 ++- .../consumer/account/settings_spec.rb | 27 +++++++++++++++++++ 7 files changed, 42 insertions(+), 13 deletions(-) delete mode 100644 app/views/spree/users/_details.html.haml create mode 100644 app/views/spree/users/_form.html.haml create mode 100644 app/views/spree/users/_settings.html.haml create mode 100644 spec/features/consumer/account/settings_spec.rb diff --git a/app/views/spree/users/_details.html.haml b/app/views/spree/users/_details.html.haml deleted file mode 100644 index fe804d2e18..0000000000 --- a/app/views/spree/users/_details.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -%script{ type: "text/ng-template", id: "account/details.html" } - Details diff --git a/app/views/spree/users/_form.html.haml b/app/views/spree/users/_form.html.haml new file mode 100644 index 0000000000..61f6962abb --- /dev/null +++ b/app/views/spree/users/_form.html.haml @@ -0,0 +1,6 @@ += render :partial => 'spree/shared/error_messages', :locals => { :target => @user } +%h3= t('.account_settings') += form_for Spree::User.new, :as => @user, :url => spree.user_path(@user), :method => :put do |f| + = render :partial => 'spree/shared/user_form', :locals => { :f => f } + %p + = f.submit t(:update), :class => 'button primary' diff --git a/app/views/spree/users/_settings.html.haml b/app/views/spree/users/_settings.html.haml new file mode 100644 index 0000000000..6107172190 --- /dev/null +++ b/app/views/spree/users/_settings.html.haml @@ -0,0 +1,2 @@ +%script{ type: "text/ng-template", id: "account/settings.html" } + = render 'form' diff --git a/app/views/spree/users/edit.html.haml b/app/views/spree/users/edit.html.haml index 9815b5f34d..29e600582c 100644 --- a/app/views/spree/users/edit.html.haml +++ b/app/views/spree/users/edit.html.haml @@ -1,8 +1,3 @@ .darkswarm .row - = render :partial => 'spree/shared/error_messages', :locals => { :target => @user } - %h1= t(:editing_user) - = form_for Spree::User.new, :as => @user, :url => spree.user_path(@user), :method => :put do |f| - = render :partial => 'spree/shared/user_form', :locals => { :f => f } - %p - = f.submit t(:update), :class => 'button primary' + = render 'form' diff --git a/app/views/spree/users/show.html.haml b/app/views/spree/users/show.html.haml index 0aeb37a826..43a7e04f64 100644 --- a/app/views/spree/users/show.html.haml +++ b/app/views/spree/users/show.html.haml @@ -12,12 +12,11 @@ = accurate_title %span.account-summary{"data-hook" => "account_summary"} = @user.email - (#{link_to t(:edit), spree.edit_account_path}) = render 'orders' = render 'cards' = render 'transactions' - = render 'cards' + = render 'settings' .row.tabset-ctrl#account-tabs{ style: 'margin-bottom: 100px', navigate: 'true', selected: 'orders', prefix: 'account' } .small.12.medium-3.columns.tab{ name: "orders" } @@ -26,8 +25,8 @@ %a{ href: 'javascript:void(0)' }=t('.tabs.cards') .small.12.medium-3.columns.tab{ name: "transactions" } %a{ href: 'javascript:void(0)' }=t('.tabs.transactions') - .small.12.medium-3.columns.tab{ name: "details" } - %a{ href: 'javascript:void(0)' }=t('.tabs.details') + .small.12.medium-3.columns.tab{ name: "settings" } + %a{ href: 'javascript:void(0)' }=t('.tabs.settings') .small-12.columns.tab-view = render partial: "shared/footer" diff --git a/config/locales/en.yml b/config/locales/en.yml index 2db4e1b234..bad3671153 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2187,12 +2187,14 @@ Please follow the instructions there to make your enterprise visible on the Open weight: Weight (per kg) zipcode: Postcode users: + form: + account_settings: Account Settings show: tabs: orders: Orders cards: Credit Cards transactions: Transactions - details: Details + settings: Account Settings orders: open_orders: Open Orders past_orders: Past Orders diff --git a/spec/features/consumer/account/settings_spec.rb b/spec/features/consumer/account/settings_spec.rb new file mode 100644 index 0000000000..a7fbf9ce94 --- /dev/null +++ b/spec/features/consumer/account/settings_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +feature "Account Settings", js: true do + include AuthenticationWorkflow + + describe "as a logged in user" do + let(:user) { create(:user) } + + before do + quick_login_as user + end + + it "allows me to update my account details" do + visit "/account" + + click_link I18n.t('spree.users.show.tabs.settings') + expect(page).to have_content I18n.t('spree.users.form.account_settings') + fill_in 'user_email', with: 'new@email.com' + + click_button I18n.t(:update) + + expect(find(".alert-box.success").text.strip).to eq "#{I18n.t(:account_updated)} ×" + user.reload + expect(user.email).to eq 'new@email.com' + end + end +end