diff --git a/app/views/spree/admin/orders/_form/_distribution_fields.html.haml b/app/views/spree/admin/orders/_form/_distribution_fields.html.haml index 1657fcaf71..01cb19ed83 100644 --- a/app/views/spree/admin/orders/_form/_distribution_fields.html.haml +++ b/app/views/spree/admin/orders/_form/_distribution_fields.html.haml @@ -5,14 +5,13 @@ .alpha.six.columns %p %b Distributor: - = f.object.distributor.andand.name || "None" - = f.hidden_field :distributor_id + = @order.distributor.andand.name || "None" + %input{type: "hidden", id: "order_distributor_id", value: @order.distributor.andand.id} .omega.six.columns %p %b Order cycle: - = f.object.order_cycle.andand.name || "None" - = f.hidden_field :order_cycle_id - + = @order.order_cycle.andand.name || "None" + %input{type: "hidden", id: "order_order_cycle_id", value: @order.order_cycle.andand.id} - else .alpha.six.columns .field diff --git a/spec/factories.rb b/spec/factories.rb index 3a46afa718..73e62744ba 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -74,7 +74,7 @@ FactoryGirl.define do factory :order_cycle_with_overrides, parent: :order_cycle do after (:create) do |oc| oc.variants.each do |variant| - create(:variant_override, variant: variant, hub: oc.distributor, price: variant.price + 100) + create(:variant_override, variant: variant, hub: oc.distributors.first, price: variant.price + 100) end end end diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index cf1598f3fe..576b14b69b 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -12,6 +12,7 @@ feature %q{ @product = create(:simple_product) @distributor = create(:distributor_enterprise, owner: @user, charges_sales_tax: true) @order_cycle = create(:simple_order_cycle, name: 'One', distributors: [@distributor], variants: [@product.variants.first]) + @oc_overrides = create(:order_cycle_with_overrides) @order = create(:order_with_totals_and_distribution, user: @user, distributor: @distributor, order_cycle: @order_cycle, state: 'complete', payment_state: 'balance_due') @customer = create(:customer, enterprise: @distributor, email: @user.email, user: @user, ship_address: create(:address)) @@ -22,6 +23,14 @@ feature %q{ create :check_payment, order: @order, amount: @order.total end + def new_order_with_distribution(distributor, order_cycle) + visit 'admin/orders/new' + page.should have_selector('#s2id_order_distributor_id') + select2_select distributor.name, from: 'order_distributor_id' + select2_select order_cycle.name, from: 'order_order_cycle_id' + click_button 'Next' + end + scenario "creating an order with distributor and order cycle" do distributor_disabled = create(:distributor_enterprise) create(:simple_order_cycle, name: 'Two') @@ -43,6 +52,7 @@ feature %q{ select2_select @distributor.name, from: 'order_distributor_id' page.should have_select2 'order_order_cycle_id', options: ['One (open)'] select2_select @order_cycle.name, from: 'order_order_cycle_id' + click_button 'Next' page.should have_content 'ADD PRODUCT' targetted_select2_search @product.name, from: '#add_variant_id', dropdown_css: '.select2-drop' @@ -127,12 +137,11 @@ feature %q{ # When I create a new order quick_login_as @user - visit spree.admin_path - - visit '/admin/orders' - click_link 'New Order' - select2_select @distributor.name, from: 'order_distributor_id' - select2_select @order_cycle.name, from: 'order_order_cycle_id' + new_order_with_distribution(@distributor, @order_cycle) + # visit '/admin/orders' + # click_link 'New Order' + # select2_select @distributor.name, from: 'order_distributor_id' + # select2_select @order_cycle.name, from: 'order_order_cycle_id' 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 @@ -212,11 +221,7 @@ feature %q{ end scenario "creating an order with distributor and order cycle" do - visit '/admin/orders' - click_link 'New Order' - - select2_select distributor1.name, from: 'order_distributor_id' - select2_select order_cycle1.name, from: 'order_order_cycle_id' + new_order_with_distribution(distributor1, order_cycle1) expect(page).to have_content 'ADD PRODUCT' targetted_select2_search product.name, from: '#add_variant_id', dropdown_css: '.select2-drop' @@ -241,6 +246,18 @@ feature %q{ end + scenario "with overrides it uses the overriden price" do + login_to_admin_section + new_order_with_distribution(@oc_overrides.distributors.first, @oc_overrides) + product = @oc_overrides.products.first + 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: "119.99" + + end + + # Working around intermittent click failing # Possible causes of failure: # - the link moves