Test selecting distributor when adding item to cart, for no/remote distributor selected

This commit is contained in:
Rohan Mitchell
2012-06-24 11:41:10 +10:00
parent a91722a593
commit b2f5e23fa4
3 changed files with 31 additions and 9 deletions

View File

@@ -4,15 +4,8 @@ Spree::ProductsController.class_eval do
include Spree::DistributorsHelper
include OpenFoodWeb::SplitProductsByDistributor
before_filter :load_distributors, :only => :show
respond_override :index => { :html => { :success => lambda {
@products, @products_local, @products_remote = split_products_by_distributor @products, current_distributor
} } }
def load_distributors
@distributors = Spree::Distributor.by_name
end
end

View File

@@ -3,7 +3,7 @@
%p Quantity
= number_field_tag (@product.has_variants? ? :quantity : "variants[#{@product.master.id}]"), 1, :class => 'title', :in => 1..@product.on_hand
%p Distributor
= select_tag "distributor_id", options_from_collection_for_select(@distributors, "id", "name", current_distributor.andand.id)
= select_tag "distributor_id", options_from_collection_for_select(@product.distributors, "id", "name", current_distributor.andand.id)
%br/
= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do
= t(:add_to_cart)

View File

@@ -78,6 +78,19 @@ feature %q{
end
context "viewing a product, it provides a choice of distributor when adding to cart" do
it "works when no distributor is chosen" do
# Given a distributor and a product under it
distributor = create(:distributor)
product = create(:product, :distributors => [distributor])
# When we view the product
visit spree.product_path(product)
# Then we should see a choice of distributor, with no default
page.should have_selector "select#distributor_id option", :text => distributor.name
page.should_not have_selector "select#distributor_id option[selected='selected']"
end
it "displays the local distributor as the default choice when available for the current product" do
# Given a distributor and a product under it
distributor = create(:distributor)
@@ -92,7 +105,23 @@ feature %q{
page.should have_selector "select#distributor_id option[value='#{distributor.id}'][selected='selected']"
end
it "functions with remote distributors also"
it "works when viewing a product from a remote distributor" do
# Given two distributors and a product under one
distributor_product = create(:distributor)
distributor_no_product = create(:distributor)
product = create(:product, :distributors => [distributor_product])
# When we select the distributor without the product and then view the 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']"
end
end
end
end