From 08126431367a1dbb0da0bc0189f9500d01789a53 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 2 Jul 2015 11:35:57 +0800 Subject: [PATCH] Adding views and feature spec for updating default payment and shipping method --- .../_method_settings.html.haml | 10 +++++ .../edit.html.haml | 40 ++++++++++++------- .../accounts_and_billing_settings_spec.rb | 15 +++++-- 3 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 app/views/admin/accounts_and_billing_settings/_method_settings.html.haml diff --git a/app/views/admin/accounts_and_billing_settings/_method_settings.html.haml b/app/views/admin/accounts_and_billing_settings/_method_settings.html.haml new file mode 100644 index 0000000000..17037d47e9 --- /dev/null +++ b/app/views/admin/accounts_and_billing_settings/_method_settings.html.haml @@ -0,0 +1,10 @@ +.row + .six.columns.alpha + .field + = label :settings, :default_accounts_payment_method_id, t(:default_accounts_payment_method) + = collection_select(:settings, :default_accounts_payment_method_id, @payment_methods, :id, :name, { include_blank: true, selected: Spree::Config.default_accounts_payment_method_id}, { class: "select2 fullwidth" }) + + .six.columns.omega + .field + = label :settings, :default_accounts_shipping_method_id, t(:default_accounts_shipping_method) + = collection_select(:settings, :default_accounts_shipping_method_id, @shipping_methods, :id, :name, { include_blank: true, selected: Spree::Config.default_accounts_shipping_method_id}, { class: "select2 fullwidth" }) diff --git a/app/views/admin/accounts_and_billing_settings/edit.html.haml b/app/views/admin/accounts_and_billing_settings/edit.html.haml index 2cfcbed8a0..eea938532f 100644 --- a/app/views/admin/accounts_and_billing_settings/edit.html.haml +++ b/app/views/admin/accounts_and_billing_settings/edit.html.haml @@ -5,18 +5,30 @@ = render 'spree/shared/error_messages', target: @settings -= form_for @settings, as: :settings, url: main_app.admin_accounts_and_billing_settings_path, :method => :put do |f| - .field - = f.label :accounts_administration_distributor, t(:accounts_administration_distributor) - = f.collection_select(:accounts_distributor_id, @distributors, :id, :name, { include_blank: true }, { class: "select2 fullwidth" }) - .field - = f.hidden_field :collect_billing_information, value: '0' - = f.check_box :collect_billing_information, value: '1' - = f.label :collect_billing_information, t(:collect_billing_information) - .field +%div{ ng: { app: 'admin.accounts_and_billing_settings' } } + = form_for @settings, as: :settings, url: main_app.admin_accounts_and_billing_settings_path, :method => :put do |f| + .row + .twelve.columns.alpha.omega + .field + = f.label :accounts_distributor_id, t(:accounts_administration_distributor) + = f.collection_select(:accounts_distributor_id, @distributors, :id, :name, { include_blank: true }, { class: "select2 fullwidth", 'watch-value-as' => "enterprise_id"}) - = f.hidden_field :create_invoices_for_enterprise_users, value: '0' - = f.check_box :create_invoices_for_enterprise_users, value: '1' - = f.label :create_invoices_for_enterprise_users, t(:create_invoices_for_enterprise_users) - .form-buttons{"data-hook" => "buttons"} - = button t(:update), 'icon-refresh' + = f.hidden_field :default_accounts_payment_method_id, value: '' + = f.hidden_field :default_accounts_shipping_method_id, value: '' + %div{ 'method-settings-for' => 'enterprise_id' } + + .row + .six.columns.alpha + .field + = f.hidden_field :collect_billing_information, value: '0' + = f.check_box :collect_billing_information, value: '1' + = f.label :collect_billing_information, t(:collect_billing_information) + + .six.columns.omega + .field + = f.hidden_field :create_invoices_for_enterprise_users, value: '0' + = f.check_box :create_invoices_for_enterprise_users, value: '1' + = f.label :create_invoices_for_enterprise_users, t(:create_invoices_for_enterprise_users) + + .form-buttons{"data-hook" => "buttons"} + = button t(:update), 'icon-refresh' diff --git a/spec/features/admin/accounts_and_billing_settings_spec.rb b/spec/features/admin/accounts_and_billing_settings_spec.rb index 68e8410fdb..b19b13c155 100644 --- a/spec/features/admin/accounts_and_billing_settings_spec.rb +++ b/spec/features/admin/accounts_and_billing_settings_spec.rb @@ -2,14 +2,19 @@ require 'spec_helper' feature 'Account and Billing Settings' do include AuthenticationWorkflow + include WebHelper describe "updating" do let!(:admin) { create(:admin_user) } - let!(:accounts_distributor) { create(:distributor_enterprise) } + let!(:pm1) { create(:payment_method) } + let!(:sm1) { create(:shipping_method) } + let!(:accounts_distributor) { create(:distributor_enterprise, payment_methods: [pm1], shipping_methods: [sm1]) } before do Spree::Config.set({ accounts_distributor_id: 0, + default_accounts_payment_method_id: 0, + default_accounts_shipping_method_id: 0, collect_billing_information: false, create_invoices_for_enterprise_users: false }) @@ -20,18 +25,22 @@ feature 'Account and Billing Settings' do visit spree.admin_path end - context "as an admin user" do + context "as an admin user", js: true do it "attributes can be changed" do click_link "Configuration" click_link "Accounts & Billing" - select accounts_distributor.name, from: "settings_accounts_distributor_id" + select2_select accounts_distributor.name, from: "settings_accounts_distributor_id" + select pm1.name, from: "settings_default_accounts_payment_method_id" + select sm1.name, from: "settings_default_accounts_shipping_method_id" check "settings_collect_billing_information" check "settings_create_invoices_for_enterprise_users" click_button "Update" expect(Spree::Config.accounts_distributor_id).to eq accounts_distributor.id + expect(Spree::Config.default_accounts_payment_method_id).to eq pm1.id + expect(Spree::Config.default_accounts_shipping_method_id).to eq sm1.id expect(Spree::Config.collect_billing_information).to be true expect(Spree::Config.create_invoices_for_enterprise_users).to be true end