Merge branch 'master' into product-amount-units

Conflicts:
	app/assets/javascripts/admin/bulk_product_update.js.coffee
	spec/spec_helper.rb
This commit is contained in:
Rohan Mitchell
2014-01-14 15:34:05 +11:00
88 changed files with 1723 additions and 719 deletions

View File

@@ -21,14 +21,45 @@ feature %q{
login_to_admin_section
end
it "displays a 'loading' splash for products" do
FactoryGirl.create(:simple_product)
visit '/admin/products/bulk_edit'
page.should have_selector "div.loading", :text => "Loading Products..."
end
it "displays a list of products" do
p1 = FactoryGirl.create(:product)
p2 = FactoryGirl.create(:product)
visit '/admin/products/bulk_edit'
page.should have_field "product_name", with: p1.name
page.should have_field "product_name", with: p2.name
page.should have_field "product_name", with: p1.name, :visible => true
page.should have_field "product_name", with: p2.name, :visible => true
end
it "displays a message when number of products is zero" do
visit '/admin/products/bulk_edit'
page.should have_text "No matching products found."
end
pending "displays a message when number of products is too great" do
501.times { FactoryGirl.create(:simple_product) }
visit '/admin/products/bulk_edit'
page.should have_text "Search returned too many products to display (500+), please apply more search filters to reduce the number of matching products"
end
it "displays pagination information" do
p1 = FactoryGirl.create(:product)
p2 = FactoryGirl.create(:product)
visit '/admin/products/bulk_edit'
page.should have_text "Displaying 1-2 of 2 products"
end
it "displays a select box for suppliers, with the appropriate supplier selected" do
@@ -209,6 +240,9 @@ feature %q{
login_to_admin_section
visit '/admin/products/bulk_edit'
first("div.option_tab_titles h6", :text => "Toggle Columns").click
first("li.column-list-item", text: "Available On").click
page.should have_field "product_name", with: p.name
page.should have_select "supplier", selected: s1.name
@@ -342,6 +376,53 @@ feature %q{
page.find("span#update-status-message").should have_content "Update complete"
end
scenario "updating a product after cloning a product" do
FactoryGirl.create(:product, :name => "product 1")
login_to_admin_section
visit '/admin/products/bulk_edit'
first("a.clone-product").click
fill_in "product_name", :with => "new product name"
click_button 'Update'
page.find("span#update-status-message").should have_content "Update complete"
end
scenario "updating when no changes have been made" do
Capybara.default_wait_time = 2
FactoryGirl.create(:product, :name => "product 1")
FactoryGirl.create(:product, :name => "product 2")
login_to_admin_section
visit '/admin/products/bulk_edit'
click_button 'Update'
page.find("span#update-status-message").should have_content "No changes to update."
Capybara.default_wait_time = 5
end
scenario "updating when a filter has been applied" do
p1 = FactoryGirl.create(:simple_product, :name => "product1")
p2 = FactoryGirl.create(:simple_product, :name => "product2")
login_to_admin_section
visit '/admin/products/bulk_edit'
first("div.option_tab_titles h6", :text => "Filter Products").click
select "Name", :from => "filter_property"
select "Contains", :from => "filter_predicate"
fill_in "filter_value", :with => "1"
click_button "Apply Filter"
page.should_not have_field "product_name", with: p2.name
fill_in "product_name", :with => "new product1"
click_on 'Update'
page.find("span#update-status-message").should have_content "Update complete"
end
scenario "updating a product when there are more products than the default API page size" do
26.times { FactoryGirl.create(:simple_product) }
login_to_admin_section
@@ -447,7 +528,6 @@ feature %q{
page.should have_selector "a.clone-product", :count => 3
first("a.clone-product").click
page.should have_selector "a.clone-product", :count => 4
page.should have_field "product_name", with: "COPY OF #{p1.name}"
page.should have_select "supplier", selected: "#{p1.supplier.name}"
@@ -462,24 +542,61 @@ feature %q{
end
describe "using the page" do
describe "using column display toggle" do
describe "using tabs to hide and display page controls" do
it "shows a column display toggle button, which shows a list of columns when clicked" do
FactoryGirl.create(:simple_product)
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_selector "div.column_toggle", :visible => false
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Toggle Columns"
first("div.option_tab_titles h6", :text => "Toggle Columns").click
page.should have_selector "div.option_tab_titles h6.selected", :text => "Toggle Columns"
page.should have_selector "div.column_toggle", :visible => true
page.should have_selector "li.column-list-item", text: "Available On"
page.should have_selector "div.filters", :visible => false
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Filter Products"
first("div.option_tab_titles h6", :text => "Filter Products").click
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Toggle Columns"
page.should have_selector "div.option_tab_titles h6.selected", :text => "Filter Products"
page.should have_selector "div.filters", :visible => true
page.should have_selector "li.column-list-item", text: "Available On"
first("div.option_tab_titles h6", :text => "Filter Products").click
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Filter Products"
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Toggle Columns"
page.should have_selector "div.filters", :visible => false
page.should have_selector "div.column_toggle", :visible => false
end
end
describe "using column display toggle" do
it "shows a column display toggle button, which shows a list of columns when clicked" do
FactoryGirl.create(:simple_product)
login_to_admin_section
visit '/admin/products/bulk_edit'
first("div.option_tab_titles h6", :text => "Toggle Columns").click
first("li.column-list-item", text: "Available On").click
page.should have_selector "th", :text => "NAME"
page.should have_selector "th", :text => "SUPPLIER"
page.should have_selector "th", :text => "PRICE"
page.should have_selector "th", :text => "ON HAND"
page.should have_selector "th", :text => "AV. ON"
page.should have_button "Toggle Columns"
click_button "Toggle Columns"
page.should have_selector "div.option_tab_titles h6", :text => "Toggle Columns"
page.should have_selector "div ul.column-list li.column-list-item", text: "Supplier"
all("div ul.column-list li.column-list-item").select{ |e| e.text == "Supplier" }.first.click
first("li.column-list-item", text: "Supplier").click
page.should_not have_selector "th", :text => "SUPPLIER"
page.should have_selector "th", :text => "NAME"
@@ -488,6 +605,147 @@ feature %q{
page.should have_selector "th", :text => "AV. ON"
end
end
describe "using pagination controls" do
it "shows pagination controls" do
27.times { FactoryGirl.create(:product) }
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_select 'perPage', :selected => '25'
within '.pagination' do
page.should have_text "1 2"
page.should have_text "Next"
page.should have_text "Last"
end
end
it "allows the number of visible products to be altered" do
27.times { FactoryGirl.create(:product) }
login_to_admin_section
visit '/admin/products/bulk_edit'
select '25', :from => 'perPage'
page.all("input[name='product_name']").select{ |e| e.visible? }.length.should == 25
select '50', :from => 'perPage'
page.all("input[name='product_name']").select{ |e| e.visible? }.length.should == 27
end
it "displays the correct products when changing pages" do
25.times { FactoryGirl.create(:product, :name => "page1product") }
5.times { FactoryGirl.create(:product, :name => "page2product") }
login_to_admin_section
visit '/admin/products/bulk_edit'
select '25', :from => 'perPage'
page.all("input[name='product_name']").select{ |e| e.visible? }.all?{ |e| e.value == "page1product" }.should == true
click_link "2"
page.all("input[name='product_name']").select{ |e| e.visible? }.all?{ |e| e.value == "page2product" }.should == true
end
it "moves the user to the last available page when changing the number of pages in any way causes user to become orphaned" do
50.times { FactoryGirl.create(:product) }
FactoryGirl.create(:product, :name => "fancy_product_name")
login_to_admin_section
visit '/admin/products/bulk_edit'
select '25', :from => 'perPage'
click_link "3"
select '50', :from => 'perPage'
page.first("div.pagenav span.page.current").should have_text "2"
page.all("input[name='product_name']", :visible => true).length.should == 1
select '25', :from => 'perPage'
fill_in "quick_filter", :with => "fancy_product_name"
page.first("div.pagenav span.page.current").should have_text "1"
page.all("input[name='product_name']", :visible => true).length.should == 1
end
it "paginates the filtered product list rather than all products" do
25.times { FactoryGirl.create(:product, :name => "product_name") }
3.times { FactoryGirl.create(:product, :name => "test_product_name") }
login_to_admin_section
visit '/admin/products/bulk_edit'
select '25', :from => 'perPage'
page.should have_text "1 2"
fill_in "quick_filter", :with => "test_product_name"
page.all("input[name='product_name']", :visible => true).length.should == 3
page.all("input[name='product_name']", :visible => true).all?{ |e| e.value == "test_product_name" }.should == true
page.should_not have_text "1 2"
page.should have_text "1"
end
end
describe "using filtering controls" do
it "displays basic filtering controls" do
FactoryGirl.create(:simple_product)
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_selector "div.option_tab_titles h6", :text => "Filter Products"
first("div.option_tab_titles h6", :text => "Filter Products").click
page.should have_select "filter_property", :with_options => ["Supplier", "Name"]
page.should have_select "filter_predicate", :with_options => ["Equals", "Contains"]
page.should have_field "filter_value"
end
describe "clicking the 'Apply Filter' Button" do
before(:each) do
FactoryGirl.create(:simple_product, :name => "Product1")
FactoryGirl.create(:simple_product, :name => "Product2")
login_to_admin_section
visit '/admin/products/bulk_edit'
first("div.option_tab_titles h6", :text => "Filter Products").click
select "Name", :from => "filter_property"
select "Equals", :from => "filter_predicate"
fill_in "filter_value", :with => "Product1"
click_button "Apply Filter"
end
it "adds a new filter to the list of applied filters" do
page.should have_text "Name Equals Product1"
end
it "displays the 'loading' splash" do
page.should have_selector "div.loading", :text => "Loading Products..."
end
it "loads appropriate products" do
page.should have_field "product_name", :with => "Product1"
page.should_not have_field "product_name", :with => "Product2"
end
describe "clicking the 'Remove Filter' link" do
before(:each) do
click_link "Remove Filter"
end
it "removes the filter from the list of applied filters" do
page.should_not have_text "Name Equals Product1"
end
it "displays the 'loading' splash" do
page.should have_selector "div.loading", :text => "Loading Products..."
end
it "loads appropriate products" do
page.should have_field "product_name", :with => "Product1"
page.should have_field "product_name", :with => "Product2"
end
end
end
end
end
context "as an enterprise manager" do
@@ -535,6 +793,9 @@ feature %q{
p = product_supplied
visit '/admin/products/bulk_edit'
first("div.option_tab_titles h6", :text => "Toggle Columns").click
first("li.column-list-item", text: "Available On").click
page.should have_field "product_name", with: p.name
page.should have_select "supplier", selected: s1.name

View File

@@ -379,8 +379,8 @@ feature %q{
# Then my times should have been saved
flash_message.should == 'Order cycles have been updated.'
OrderCycle.all.map { |oc| oc.orders_open_at.sec }.should == [0, 2, 4]
OrderCycle.all.map { |oc| oc.orders_close_at.sec }.should == [1, 3, 5]
OrderCycle.order('id ASC').map { |oc| oc.orders_open_at.sec }.should == [0, 2, 4]
OrderCycle.order('id ASC').map { |oc| oc.orders_close_at.sec }.should == [1, 3, 5]
end
scenario "cloning an order cycle" do

View File

@@ -30,7 +30,7 @@ feature 'shipping methods' do
sm = Spree::ShippingMethod.last
sm.name.should == 'Carrier Pidgeon'
sm.distributors.should == [d1, d2]
sm.distributors.sort.should == [d1, d2].sort
end
it "at checkout, user can only see shipping methods for their current distributor (checkout spec)"

View File

@@ -21,123 +21,13 @@ feature %q{
click_button 'Add To Cart'
# Then I should see an error message
page.should have_content "Please choose a distributor for this order."
page.should have_content "That product is not available from the chosen distributor or order cycle"
# And the product should not have been added to my cart
Spree::Order.last.line_items.should be_empty
end
scenario "adding the first product to the cart", :future => true do
# Given a product, some distributors and a defined shipping cost
d1 = create(:distributor_enterprise, :name => "Green Grass")
d2 = create(:distributor_enterprise, :name => "AusFarmers United")
create(:product, :distributors => [d2])
p = create(:product, :price => 12.34)
create(:product_distribution, :product => p, :distributor => d1)
# ... with a flat rate distribution fee of $1.23
ef = p.product_distributions.first.enterprise_fee
ef.calculator = Spree::Calculator::FlatRate.new preferred_amount: 1.23
ef.calculator.save!
# When I choose a distributor
visit spree.root_path
click_on "AusFarmers United"
# And I add an item to my cart from a different distributor
visit spree.product_path p
select(d1.name, :from => 'distributor_id')
click_button 'Add To Cart'
# Then the correct totals should be displayed
page.should have_selector 'span.item-total', :text => '$12.34'
page.should have_selector 'span.distribution-total', :text => '$1.23'
page.should have_selector 'span.grand-total', :text => '$13.57'
# And the item should be in my cart
order = Spree::Order.last
line_item = order.line_items.first
line_item.product.should == p
# And my order should have its distributor set to the chosen distributor
order.distributor.should == d1
end
context "adding a subsequent product to the cart" do
it "when there are several valid distributors, allows a choice from these options" do
# Given two products, both distributed by two distributors
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product, :distributors => [d1, d2])
p2 = create(:product, :distributors => [d1, d2])
# When I add the first to my cart via d1
visit spree.product_path p1
select d1.name, :from => 'distributor_id'
click_button 'Add To Cart'
# And I go to add the second, I should have a choice of distributor
visit spree.product_path p2
page.should have_selector '#distributor_id option', :text => d1.name
page.should have_selector '#distributor_id option', :text => d2.name
# When I add the second, both should be in my cart, and my distributor should be the one chosen second
select d2.name, :from => 'distributor_id'
click_button 'Add To Cart'
visit spree.cart_path
page.should have_selector 'h4 a', :text => p1.name
page.should have_selector 'h4 a', :text => p2.name
page.should have_selector "#logo h1 a", :text => d2.name
end
it "when the only valid distributor is the chosen one, does not allow the user to choose a distributor" do
# Given two products, each at the same distributor
d = create(:distributor_enterprise)
p1 = create(:product, :distributors => [d])
p2 = create(:product, :distributors => [d])
# When I add the first to my cart
visit spree.product_path p1
select d.name, :from => 'distributor_id'
click_button 'Add To Cart'
# And I go to add the second, I should not have a choice of distributor
visit spree.product_path p2
page.should_not have_selector 'select#distributor_id'
page.should have_selector '.distributor-fixed', :text => "Your distributor for this order is #{d.name}"
# When I add the second, both should be in my cart
click_button 'Add To Cart'
visit spree.cart_path
page.should have_selector 'h4 a', :text => p1.name
page.should have_selector 'h4 a', :text => p2.name
end
it "when the only valid distributor differs from the chosen one, alerts the user and changes distributor on add to cart" do
# Given two products, one available at only one distributor
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product, :distributors => [d1, d2])
p2 = create(:product, :distributors => [d2])
# When I add the first to my cart
visit spree.product_path p1
select d1.name, from: 'distributor_id'
click_button 'Add To Cart'
# And I go to add the second
visit spree.product_path p2
# Then I should see a message offering to change distributor for my order
page.should have_content "Your distributor for this order will be changed to #{d2.name} if you add this product to your cart."
# When I add the second to my cart
click_button 'Add To Cart'
# Then My distributor should have changed
page.should have_selector "#logo h1 a", :text => d2.name
end
it "does not allow the user to add a product from a distributor that cannot supply the cart's products" do
# Given two products, each at a different distributor
d1 = create(:distributor_enterprise)
@@ -146,8 +36,8 @@ feature %q{
p2 = create(:product, :distributors => [d2])
# When I add one of them to my cart
select_distribution d1
visit spree.product_path p1
select d1.name, :from => 'distributor_id'
click_button 'Add To Cart'
# And I attempt to add the other
@@ -205,7 +95,7 @@ feature %q{
click_button 'Add To Cart'
# Then I should see an error message
page.should have_content "Please choose a distributor and order cycle for this order."
page.should have_content "Please choose an order cycle for this order."
# And the product should not have been added to my cart
Spree::Order.last.line_items.should be_empty
@@ -218,9 +108,8 @@ feature %q{
oc = create(:simple_order_cycle, :distributors => [d], :variants => [p.master])
# When I add an item to my cart
select_distribution d, oc
visit spree.product_path p
select d.name, :from => 'distributor_id'
select oc.name, :from => 'order_cycle_id'
click_button 'Add To Cart'
# Then the correct totals should be displayed
@@ -239,144 +128,6 @@ feature %q{
order.distributor.should == d
order.order_cycle.should == oc
end
scenario "adding a product to the cart with an invalid distribution combination" do
# Given a product and some distributors
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p = create(:product, :price => 12.34)
oc1 = create(:simple_order_cycle, :distributors => [d1], :variants => [p.master])
oc2 = create(:simple_order_cycle, :distributors => [d2], :variants => [p.master])
# When I attempt to add the product to my cart with an invalid distribution
visit spree.product_path p
select d1.name, :from => 'distributor_id'
select oc2.name, :from => 'order_cycle_id'
click_button 'Add To Cart'
# Then I should see an error message
page.should have_content "That product is not available from the chosen distributor or order cycle."
# And the product should not be in my cart
Spree::Order.last.line_items.should be_empty
end
context "adding a subsequent product to the cart" do
it "when there are several valid order cycles, allows a choice from these options" do
# Given two products, both distributed by two distributors
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
oc1 = create(:simple_order_cycle,
:distributors => [d1, d2], :variants => [p1.master, p2.master])
oc2 = create(:simple_order_cycle,
:distributors => [d1, d2], :variants => [p1.master, p2.master])
# When I add the first to my cart via d1/oc1
visit spree.product_path p1
select d1.name, :from => 'distributor_id'
select oc1.name, :from => 'order_cycle_id'
click_button 'Add To Cart'
# And I go to add the second, I should have a choice of order cycle and distributor
visit spree.product_path p2
page.should have_selector '#distributor_id option', :text => d1.name
page.should have_selector '#distributor_id option', :text => d2.name
page.should have_selector '#order_cycle_id option', :text => oc1.name
page.should have_selector '#order_cycle_id option', :text => oc2.name
# When I add the second, both should be in my cart, and my
# distributor and order cycle should be the one chosen second
select d2.name, :from => 'distributor_id'
select oc2.name, :from => 'order_cycle_id'
click_button 'Add To Cart'
visit spree.cart_path
page.should have_selector 'h4 a', :text => p1.name
page.should have_selector 'h4 a', :text => p2.name
page.should have_selector "#logo h1 a", :text => d2.name
end
it "when the only valid order cycle is the chosen one, does not allow the user to choose an order cycle" do
# Given two products, each at the same distributor
d = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
oc = create(:simple_order_cycle, :distributors => [d],
:variants => [p1.master, p2.master])
# When I add the first to my cart
visit spree.product_path p1
select d.name, :from => 'distributor_id'
select oc.name, :from => 'order_cycle_id'
click_button 'Add To Cart'
# And I go to add the second, I should not have a choice of distributor or order cycle
visit spree.product_path p2
page.should_not have_selector 'select#distributor_id'
page.should have_selector '.distributor-fixed', :text => "Your distributor for this order is #{d.name}"
page.should_not have_selector 'select#order_cycle_id'
page.should have_selector '.order-cycle-fixed', :text => "Your order cycle for this order is #{oc.name}"
# When I add the second, both should be in my cart
click_button 'Add To Cart'
visit spree.cart_path
page.should have_selector 'h4 a', :text => p1.name
page.should have_selector 'h4 a', :text => p2.name
end
it "when the only valid distributor differs from the chosen one, alerts the user and changes distributor on add to cart" do
# Given two products, one available at only one distributor
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
oc1 = create(:simple_order_cycle, :distributors => [d1], :variants => [p1.master])
oc2 = create(:simple_order_cycle, :distributors => [d2], :variants => [p1.master, p2.master])
# When I add the first to my cart
visit spree.product_path p1
select d1.name, from: 'distributor_id'
select oc1.name, from: 'order_cycle_id'
click_button 'Add To Cart'
# And I go to add the second
visit spree.product_path p2
# Then I should see a message offering to change distributor for my order
page.should have_content "Your distributor for this order will be changed to #{d2.name} if you add this product to your cart."
# When I add the second to my cart
click_button 'Add To Cart'
# Then my distributor should have changed
page.should have_selector "#logo h1 a", :text => d2.name
end
it "does not allow the user to add a product from an order cycle that cannot supply the cart's products" do
# Given two products, each at a different order cycle
d = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
oc1 = create(:simple_order_cycle, :distributors => [d], :variants => [p1.master])
oc2 = create(:simple_order_cycle, :distributors => [d], :variants => [p2.master])
# When I add one of them to my cart
visit spree.product_path p1
select d.name, :from => 'distributor_id'
select oc1.name, :from => 'order_cycle_id'
click_button 'Add To Cart'
# And I attempt to add the other
visit spree.product_path p2
# Then I should not be allowed to add the product
page.should_not have_selector "button#add-to-cart-button"
page.should have_content "Please complete your order from #{oc1.name} before shopping in a different order cycle."
end
end
end
context "group buys" do
@@ -386,8 +137,8 @@ feature %q{
p = create(:product, :distributors => [d], :group_buy => true)
# When I add the item to my cart
select_distribution d
visit spree.product_path p
select d.name, :from => 'distributor_id'
fill_in "variants_#{p.master.id}", :with => 2
fill_in "variant_attributes_#{p.master.id}_max_quantity", :with => 3
click_button 'Add To Cart'
@@ -407,8 +158,8 @@ feature %q{
create(:variant, :product => p)
# When I add the item to my cart
select_distribution d
visit spree.product_path p
select d.name, :from => 'distributor_id'
fill_in "quantity", :with => 2
fill_in "max_quantity", :with => 3
click_button 'Add To Cart'
@@ -438,8 +189,8 @@ feature %q{
p = create(:product, :distributors => [d], :group_buy => true)
# When I add the item to my cart
select_distribution d
visit spree.product_path p
select d.name, :from => 'distributor_id'
fill_in "variants_#{p.master.id}", :with => 2
fill_in "variant_attributes_#{p.master.id}_max_quantity", :with => 1
click_button 'Add To Cart'

View File

@@ -90,79 +90,5 @@ feature %q{
page.all('#product-variants li input').count.should == 1
end
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_enterprise)
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
distributor1 = create(:distributor_enterprise)
distributor2 = create(:distributor_enterprise)
product = create(:product, :distributors => [distributor1,distributor2])
# When we select the distributor and view the product
visit spree.select_distributor_order_path(distributor1)
visit spree.product_path(product)
# Then we should see our distributor as the default option when adding the item to our cart
page.should have_selector "select#distributor_id option[value='#{distributor1.id}'][selected='selected']"
end
it "works when viewing a product from a remote distributor" do
# Given two distributors and our product under one
distributor_product = create(:distributor_enterprise)
distributor_no_product = create(:distributor_enterprise)
product = create(:product, :distributors => [distributor_product])
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
visit spree.product_path(product)
# 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
describe "selecting an order cycle" do
before(:each) do
OrderCyclesHelper.class_eval do
def order_cycles_enabled?
true
end
end
end
it "displays the distributor and order cycle name on the home page when an order cycle is selected" do
# Given a distributor with a product
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op')
p = create(:product)
oc = create(:simple_order_cycle, :name => 'Bulk Foods', :distributors => [d], :variants => [p.master])
# When I select the distributor and order cycle
visit spree.product_path p
select d.name, :from => 'distributor_id'
select oc.name, :from => 'order_cycle_id'
click_button 'Add To Cart'
# Then I should see the name of the distributor and order cycle that I've selected
page.should have_content 'Melb Uni Co-op'
page.should_not have_selector 'div.distributor-description'
end
end
end

View File

@@ -122,6 +122,7 @@ feature %q{
click_button 'Add To Cart'
# Then I should see a breakdown of my delivery fees:
checkout_fees_table.should ==
[["Bananas - packing fee by supplier Supplier 1", "$3.00", ""],
["Bananas - transport fee by supplier Supplier 1", "$4.00", ""],

View File

@@ -279,25 +279,6 @@ feature %q{
page.should have_selector "input[value='#{@oc1.id}'][checked='checked']"
page.should have_selector "option[value='#{@d1.id}'][selected='selected']"
end
scenario "selection form is not shown when there are products in the cart" do
# Given a product
d = create(:distributor_enterprise)
p = create(:product, :distributors => [d])
# When I go to the products listing page, I should see the selection form
visit spree.products_path
page.should have_selector "#distribution-selection"
# When I add a product to the cart
visit spree.product_path p
select d.name, :from => 'distributor_id'
click_button 'Add To Cart'
# Then I should no longer see the selection form
visit spree.products_path
page.should_not have_selector "#distribution-selection"
end
end
end

View File

@@ -51,24 +51,5 @@ feature %q{
end
end
end
context "with Javascript", js: true do
it "changes distributor details when the distributor is changed" do
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
d3 = create(:distributor_enterprise)
p = create(:product, :distributors => [d1, d2, d3])
visit spree.product_path p
[d1, d2, d3].each do |d|
select d.name, :from => 'distributor_id'
within '#product-distributor-details' do
page.should have_selector 'h2', :text => d.name
end
end
end
end
end
end

View File

@@ -0,0 +1,136 @@
require 'spec_helper'
feature "As a consumer I want to shop with a distributor", js: true do
include AuthenticationWorkflow
include WebHelper
describe "Viewing a distributor" do
let(:distributor) { create(:distributor_enterprise) }
before do #temporarily using the old way to select distributor
create_enterprise_group_for distributor
visit "/"
click_link distributor.name
end
it "shows a distributor" do
visit shop_path
page.should have_text distributor.name
end
describe "With products in order cycles" do
let(:supplier) { create(:supplier_enterprise) }
let(:product) { create(:product, supplier: supplier) }
let(:order_cycle) { create(:order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) }
before do
exchange = Exchange.find(order_cycle.exchanges.to_enterprises(distributor).outgoing.first.id)
exchange.variants << product.master
end
it "shows the suppliers/producers for a distributor" do
visit shop_path
click_link "Our Producers"
page.should have_content supplier.name
end
end
describe "selecting an order cycle" do
it "selects an order cycle if only one is open" do
# create order cycle
oc1 = create(:simple_order_cycle, distributors: [distributor])
exchange = Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id)
exchange.update_attribute :pickup_time, "turtles"
visit shop_path
page.should have_selector "option[selected]", text: 'turtles'
end
describe "with multiple order cycles" do
let(:oc1) {create(:simple_order_cycle, distributors: [distributor])}
let(:oc2) {create(:simple_order_cycle, distributors: [distributor])}
before do
exchange = Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id)
exchange.update_attribute :pickup_time, "frogs"
exchange = Exchange.find(oc2.exchanges.to_enterprises(distributor).outgoing.first.id)
exchange.update_attribute :pickup_time, "turtles"
end
it "shows a select with all order cycles" do
visit shop_path
page.should have_selector "option", text: 'frogs'
page.should have_selector "option", text: 'turtles'
end
describe "with products in our order cycle" do
let(:product) { create(:simple_product) }
before do
exchange = Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id)
exchange.variants << product.master
visit shop_path
end
it "allows us to select an order cycle" do
select "frogs", :from => "order_cycle_id"
Spree::Order.last.order_cycle.should == nil
page.should have_selector "products"
page.should have_content "Orders close #{oc1.orders_close_at.strftime('%A %m')}"
Spree::Order.last.order_cycle.should == oc1
end
it "doesn't show products before an order cycle is selected" do
page.should_not have_content product.name
end
it "shows products when an order cycle has been selected" do
select "frogs", :from => "order_cycle_id"
page.should have_content product.name
end
it "updates the orders close note when order cycle is changed" do
select "frogs", :from => "order_cycle_id"
page.should have_content "Orders close #{oc1.orders_close_at.strftime('%A %m')}"
end
end
end
describe "adding products to cart" do
let(:oc) { create(:simple_order_cycle, distributors: [distributor]) }
let(:product) { create(:simple_product) }
let(:variant) { create(:variant, product: product) }
before do
exchange = Exchange.find(oc.exchanges.to_enterprises(distributor).outgoing.first.id)
exchange.update_attribute :pickup_time, "frogs"
exchange.variants << product.master
exchange.variants << variant
visit shop_path
select "frogs", :from => "order_cycle_id"
end
it "should let us add products to our cart" do
fill_in "variants[#{variant.id}]", with: "1"
first("form.custom > input.button.right").click
current_path.should == "/cart"
page.should have_content product.name
end
end
context "when no order cycles are available" do
it "tells us orders are closed" do
visit shop_path
page.should have_content "Orders are currently closed for this hub"
end
it "shows the last order cycle" do
oc1 = create(:simple_order_cycle, distributors: [distributor], orders_close_at: 10.days.ago)
visit shop_path
page.should have_content "The last cycle closed 10 days ago"
end
it "shows the next order cycle" do
oc1 = create(:simple_order_cycle, distributors: [distributor], orders_open_at: 10.days.from_now)
visit shop_path
page.should have_content "The next cycle opens in 10 days"
end
end
end
end
end