From 7cc24f7340e77cde7811eea81046e2a452a4ca3a Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 5 Apr 2013 10:28:08 +1100 Subject: [PATCH] Handle the case where we're viewing a product from a remote distributor that we can change to --- app/views/spree/products/_add_to_cart.html.haml | 5 ++++- spec/features/consumer/browse_products_spec.rb | 15 ++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index 0b0e118e54..db937fce00 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -26,9 +26,12 @@ - if available_distributors.length > 1 %div Distributor for your order: = select_tag "distributor_id", options_from_collection_for_select(available_distributors, "id", "name", current_distributor.andand.id) + - elsif !@product.distributors.include? order.distributor + = hidden_field_tag "distributor_id", available_distributors.first.id + .distributor-fixed= "Your distributor for this order will be changed to #{available_distributors.first.name} if you add this product to your cart." - else = hidden_field_tag "distributor_id", order.distributor.id .distributor-fixed= "Your distributor for this order is #{order.distributor.name}" %br = button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do - = t(:add_to_cart) \ No newline at end of file + = t(:add_to_cart) diff --git a/spec/features/consumer/browse_products_spec.rb b/spec/features/consumer/browse_products_spec.rb index 0e35c91df2..ea751ac350 100644 --- a/spec/features/consumer/browse_products_spec.rb +++ b/spec/features/consumer/browse_products_spec.rb @@ -8,15 +8,14 @@ feature %q{ include AuthenticationWorkflow include WebHelper - context "when a distributor is selected" do + describe "selecting a distributor" do it "displays the distributor's details" do # Given a distributor with a product d = create(:distributor_enterprise, :name => 'Melb Uni Co-op', :description => '

Hello, world!

') create(:product, :distributors => [d]) # When I select the distributor - visit spree.root_path - click_link d.name + visit spree.select_distributor_order_path(d) # Then I should see the name of the distributor that I've selected page.should have_selector 'h2', :text => 'Melb Uni Co-op' @@ -118,15 +117,13 @@ feature %q{ create(:product, :distributors => [distributor_no_product]) # When we select the distributor without the product and then view the product + visit spree.select_distributor_order_path(distributor_no_product) visit spree.root_path - click_link distributor_no_product.name visit spree.product_path(product) - # Then we should see a choice of distributor, - # with no default and no option for the distributor that the product does not belong to - page.should have_selector "select#distributor_id option", :text => distributor_product.name - page.should_not have_selector "select#distributor_id option", :text => distributor_no_product.name - page.should_not have_selector "select#distributor_id option[selected='selected']" + # Then we should be told that our distributor will be set to the one with the product + page.should_not have_selector "select#distributor_id" + page.should have_content "our distributor for this order will be changed to #{distributor_product.name} if you add this product to your cart." end end end