diff --git a/app/controllers/admin/standing_orders_controller.rb b/app/controllers/admin/standing_orders_controller.rb index cc8247cd9e..152d3f6aea 100644 --- a/app/controllers/admin/standing_orders_controller.rb +++ b/app/controllers/admin/standing_orders_controller.rb @@ -93,7 +93,7 @@ module Admin def load_form_data @customers = Customer.of(@standing_order.shop) @schedules = Schedule.with_coordinator(@standing_order.shop) - @payment_methods = Spree::PaymentMethod.for_distributor(@standing_order.shop) + @payment_methods = Spree::PaymentMethod.for_distributor(@standing_order.shop).for_standing_orders @shipping_methods = Spree::ShippingMethod.for_distributor(@standing_order.shop) @order_cycles = OrderCycle.joins(:schedules).managed_by(spree_current_user) @fee_calculator = fee_calculator diff --git a/app/views/admin/standing_orders/_details.html.haml b/app/views/admin/standing_orders/_details.html.haml index 51312e6fd4..31334dfd25 100644 --- a/app/views/admin/standing_orders/_details.html.haml +++ b/app/views/admin/standing_orders/_details.html.haml @@ -15,7 +15,9 @@ .row .seven.columns.alpha.field - %label{ for: 'payment_method_id'}= t('admin.payment_method') + %label{ for: 'payment_method_id'} + = t('admin.payment_method') + %span.with-tip.icon-question-sign{ data: { powertip: "#{t('.allowed_payment_method_types_tip')}" } } %input.ofn-select2.fullwidth#payment_method_id{ name: 'payment_method_id', type: 'number', data: 'paymentMethods', required: true, placeholder: t('admin.choose'), ng: { model: 'standingOrder.payment_method_id' } } .error{ ng: { show: 'standing_order_form.$submitted && standing_order_details_form.payment_method_id.$error.required' } }= t(:error_required) .error{ ng: { repeat: 'error in errors.payment_method', show: 'standing_order_details_form.payment_method_id.$pristine' } } {{ error }} diff --git a/config/locales/en.yml b/config/locales/en.yml index 673945fd89..4c7f2aba86 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -849,6 +849,7 @@ en: details: details: Details invalid_error: Oops! Please fill in all of the required fields... + allowed_payment_method_types_tip: Only Cash and Stripe payment methods may be used at the moment product_already_in_order: This product has already been added to the order. Please edit the quantity directly. orders: number: Number diff --git a/spec/controllers/admin/standing_orders_controller_spec.rb b/spec/controllers/admin/standing_orders_controller_spec.rb index 3e07b45538..b11bd21a99 100644 --- a/spec/controllers/admin/standing_orders_controller_spec.rb +++ b/spec/controllers/admin/standing_orders_controller_spec.rb @@ -89,25 +89,16 @@ describe Admin::StandingOrdersController, type: :controller do describe 'new' do let!(:user) { create(:user) } let!(:shop) { create(:distributor_enterprise, owner: user) } - let!(:customer1) { create(:customer, enterprise: shop) } - let!(:customer2) { create(:customer, enterprise: shop) } - let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop) } - let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) } - let!(:payment_method) { create(:payment_method, distributors: [shop]) } - let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } before do allow(controller).to receive(:spree_current_user) { user } end it 'loads the preloads the necessary data' do + expect(controller).to receive(:load_form_data) spree_get :new, standing_order: { shop_id: shop.id } expect(assigns(:standing_order)).to be_a_new StandingOrder expect(assigns(:standing_order).shop).to eq shop - expect(assigns(:customers)).to include customer1, customer2 - expect(assigns(:schedules)).to eq [schedule] - expect(assigns(:payment_methods)).to eq [payment_method] - expect(assigns(:shipping_methods)).to eq [shipping_method] end end @@ -225,7 +216,6 @@ describe Admin::StandingOrdersController, type: :controller do let!(:user) { create(:user) } let!(:shop) { create(:distributor_enterprise, owner: user) } let!(:customer1) { create(:customer, enterprise: shop) } - let!(:customer2) { create(:customer, enterprise: shop) } let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop) } let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) } let!(:payment_method) { create(:payment_method, distributors: [shop]) } @@ -243,12 +233,9 @@ describe Admin::StandingOrdersController, type: :controller do end it 'loads the preloads the necessary data' do + expect(controller).to receive(:load_form_data) spree_get :edit, id: standing_order.id expect(assigns(:standing_order)).to eq standing_order - expect(assigns(:customers)).to include customer1, customer2 - expect(assigns(:schedules)).to eq [schedule] - expect(assigns(:payment_methods)).to eq [payment_method] - expect(assigns(:shipping_methods)).to eq [shipping_method] end end @@ -624,4 +611,41 @@ describe Admin::StandingOrdersController, type: :controller do end end end + + describe "#load_form_data" do + let!(:user) { create(:user) } + let!(:shop) { create(:distributor_enterprise, owner: user) } + let!(:customer1) { create(:customer, enterprise: shop) } + let!(:customer2) { create(:customer, enterprise: shop) } + let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop) } + let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) } + let!(:payment_method) { create(:payment_method, distributors: [shop]) } + let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } + + before do + allow(controller).to receive(:spree_current_user) { user } + controller.instance_variable_set(:@standing_order, StandingOrder.new(shop: shop)) + end + + it "assigns data to instance variables" do + controller.send(:load_form_data) + expect(assigns(:customers)).to include customer1, customer2 + expect(assigns(:schedules)).to eq [schedule] + expect(assigns(:order_cycles)).to eq [order_cycle] + expect(assigns(:payment_methods)).to eq [payment_method] + expect(assigns(:shipping_methods)).to eq [shipping_method] + end + + context "when other payment methods exist" do + let!(:stripe) { create(:stripe_payment_method, distributors: [shop], preferred_enterprise_id: shop.id) } + let!(:paypal) { Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", distributor_ids: [shop.id]) } + let!(:bogus) { create(:bogus_payment_method, distributors: [shop]) } + + it "only loads Stripe and Cash payment methods" do + controller.send(:load_form_data) + expect(assigns(:payment_methods)).to include payment_method, stripe + expect(assigns(:payment_methods)).to_not include paypal, bogus + end + end + end end