diff --git a/app/overrides/spree/admin/orders/_form/add_distribution_fields.html.haml.deface b/app/overrides/spree/admin/orders/_form/add_distribution_fields.html.haml.deface new file mode 100644 index 0000000000..3f79fccc03 --- /dev/null +++ b/app/overrides/spree/admin/orders/_form/add_distribution_fields.html.haml.deface @@ -0,0 +1,14 @@ +/ insert_before "[data-hook='admin_order_form_buttons']" + +%fieldset.no-border-bottom + %legend{align => 'center'} Distribution + + .alpha.six.columns + .field + = f.label :distributor_id + = f.collection_select :distributor_id, Enterprise.is_distributor.managed_by(spree_current_user), :id, :name, include_blank: true + + .omega.six.columns + .field + = f.label :order_cycle_id + = f.collection_select :order_cycle_id, OrderCycle.managed_by(spree_current_user), :id, :name, include_blank: true diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index a7e8542be9..8c63627505 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -17,26 +17,52 @@ feature %q{ create :check_payment, order: @order, amount: @order.total end - context "managing orders" do - scenario "capture multiple payments from the orders index page" do - # d.cook: could also test for an order that has had payment voided, then a new check payment created but not yet captured. But it's not critical and I know it works anyway. + scenario "creating an order with distributor and order cycle", js: true do + order_cycle = create(:order_cycle) + distributor = order_cycle.distributors.first + product = order_cycle.products.first - login_to_admin_section + login_to_admin_section - click_link 'Orders' - current_path.should == spree.admin_orders_path + click_link 'Orders' + click_link 'New Order' - # click the 'capture' link for the order - page.find("[data-action=capture][href*=#{@order.number}]").click + page.should have_content 'ADD PRODUCT' + targetted_select2_search product.name, from: '#add_variant_id', dropdown_css: '.select2-drop' + click_link 'Add' + page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS + page.should have_selector 'td', text: product.name - flash_message.should == "Payment Updated" + select distributor.name, from: 'order_distributor_id' + select order_cycle.name, from: 'order_order_cycle_id' + click_button 'Update' - # check the order was captured - @order.reload - @order.payment_state.should == "paid" + page.should have_selector 'h1', text: 'Customer Details' + o = Spree::Order.last + o.distributor.should == distributor + o.order_cycle.should == order_cycle + end - # we should still be on the same page - current_path.should == spree.admin_orders_path - end + it "can't change distributor and order cycle once order is created (or similar restriction)" + + scenario "capture multiple payments from the orders index page" do + # d.cook: could also test for an order that has had payment voided, then a new check payment created but not yet captured. But it's not critical and I know it works anyway. + + login_to_admin_section + + click_link 'Orders' + current_path.should == spree.admin_orders_path + + # click the 'capture' link for the order + page.find("[data-action=capture][href*=#{@order.number}]").click + + flash_message.should == "Payment Updated" + + # check the order was captured + @order.reload + @order.payment_state.should == "paid" + + # we should still be on the same page + current_path.should == spree.admin_orders_path end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 20d9668177..1d82a2b9fd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,6 +22,7 @@ WebMock.disable_net_connect!(:allow_localhost => true) # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} require 'spree/core/testing_support/controller_requests' +require 'spree/core/testing_support/capybara_ext' require 'active_record/fixtures' fixtures_dir = File.expand_path('../../db/default', __FILE__)