mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-15 04:14:24 +00:00
Upgrade capybara, spec/requests changed to spec/features
This commit is contained in:
219
spec/features/consumer/add_to_cart_spec.rb
Normal file
219
spec/features/consumer/add_to_cart_spec.rb
Normal file
@@ -0,0 +1,219 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
As a consumer
|
||||
I want to choose a distributor when adding products to my cart
|
||||
So that I can avoid making an order from many different distributors
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
scenario "adding a product to the cart with no distributor chosen" do
|
||||
# Given a product and some distributors
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d1])
|
||||
create(:product, :distributors => [d2])
|
||||
|
||||
# When I add an item to my cart without choosing a distributor
|
||||
visit spree.product_path p
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# Then I should see an error message
|
||||
page.should have_content "Please choose a distributor for this order."
|
||||
|
||||
# And the product should not have been added to my cart
|
||||
Spree::Order.last.should be_nil
|
||||
end
|
||||
|
||||
scenario "adding the first product to the cart" do
|
||||
create(:itemwise_shipping_method)
|
||||
|
||||
# Given a product, some distributors and a defined shipping cost
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
create(:product, :distributors => [d2])
|
||||
p = create(:product, :price => 12.34)
|
||||
create(:product_distribution, :product => p, :distributor => d1, :shipping_method => create(:shipping_method))
|
||||
|
||||
# ... with a flat rate shipping method of cost $1.23
|
||||
sm = p.product_distributions.first.shipping_method
|
||||
sm.calculator.preferred_amount = 1.23
|
||||
sm.calculator.save!
|
||||
|
||||
# When I choose a distributor
|
||||
visit spree.root_path
|
||||
click_link d2.name
|
||||
|
||||
# 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.shipping-total', :text => '$1.23'
|
||||
page.should have_selector 'span.grand-total', :text => '$13.57'
|
||||
|
||||
# And the item should be in my cart, with shipping method set for the line item
|
||||
order = Spree::Order.last
|
||||
line_item = order.line_items.first
|
||||
line_item.product.should == p
|
||||
line_item.shipping_method.should == p.product_distributions.first.shipping_method
|
||||
|
||||
# And my order should have its distributor set to the chosen distributor
|
||||
order.distributor.should == d1
|
||||
end
|
||||
|
||||
it "does not allow the user to change distributor after a product has been added to the cart" do
|
||||
# Given a product and some distributors
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d1])
|
||||
|
||||
# When I add a product to my cart (which sets my distributor)
|
||||
visit spree.product_path p
|
||||
select d1.name, :from => 'distributor_id'
|
||||
click_button 'Add To Cart'
|
||||
page.should have_content "You are shopping at #{d1.name}"
|
||||
|
||||
# Then I should not be able to change distributor
|
||||
visit spree.root_path
|
||||
page.should_not have_selector "a[href*='select']", :text => d1.name
|
||||
page.should_not have_selector "a[href*='select']", :text => d2.name
|
||||
page.should_not have_selector "a", :text => 'Leave distributor'
|
||||
end
|
||||
|
||||
context "adding a subsequent product to the cart" do
|
||||
it "does not allow the user to choose a distributor" do
|
||||
# Given a product under a distributor
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
# And a product in my cart
|
||||
visit spree.product_path p
|
||||
select d.name, :from => 'distributor_id'
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# When I go to add it again, I should not have a choice of distributor
|
||||
visit spree.product_path p
|
||||
page.should_not have_selector 'select#distributor_id'
|
||||
page.should have_selector '.distributor-fixed', :text => "Your distributor for this order is #{d.name}"
|
||||
end
|
||||
|
||||
it "does not allow the user to add a product from another distributor" do
|
||||
# Given two products, each at a different distributor
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p1 = create(:product, :distributors => [d1])
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
# When I add one of them to my cart
|
||||
visit spree.product_path p1
|
||||
select d1.name, :from => 'distributor_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 at #{d1.name} before shopping with another distributor."
|
||||
end
|
||||
|
||||
it "adds products with valid distributors" 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 add the second
|
||||
visit spree.product_path p2
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# Then both should be in my cart
|
||||
visit spree.cart_path
|
||||
page.should have_selector 'h4 a', :text => p1.name
|
||||
page.should have_selector 'h4 a', :text => p2.name
|
||||
end
|
||||
end
|
||||
|
||||
context "group buys" do
|
||||
scenario "adding a product to the cart for a group buy" do
|
||||
# Given a group buy product and a distributor
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d], :group_buy => true)
|
||||
|
||||
# When I add the item to my cart
|
||||
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'
|
||||
|
||||
# Then the item should be in my cart with correct quantities
|
||||
order = Spree::Order.last
|
||||
li = order.line_items.first
|
||||
li.product.should == p
|
||||
li.quantity.should == 2
|
||||
li.max_quantity.should == 3
|
||||
end
|
||||
|
||||
scenario "adding a product with variants to the cart for a group buy" do
|
||||
# Given a group buy product with variants and a distributor
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d], :group_buy => true)
|
||||
create(:variant, :product => p)
|
||||
|
||||
# When I add the item to my cart
|
||||
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'
|
||||
|
||||
# Then the item should be in my cart with correct quantities
|
||||
order = Spree::Order.last
|
||||
li = order.line_items.first
|
||||
li.product.should == p
|
||||
li.quantity.should == 2
|
||||
li.max_quantity.should == 3
|
||||
end
|
||||
|
||||
scenario "adding a product to cart that is not a group buy does not show max quantity field" do
|
||||
# Given a group buy product and a distributor
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d], :group_buy => false)
|
||||
|
||||
# When I view the add to cart form, there should not be a max quantity field
|
||||
visit spree.product_path p
|
||||
|
||||
page.should_not have_selector "#variant_attributes_#{p.master.id}_max_quantity"
|
||||
end
|
||||
|
||||
scenario "adding a product with a max quantity less than quantity results in max_quantity==quantity" do
|
||||
# Given a group buy product and a distributor
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d], :group_buy => true)
|
||||
|
||||
# When I add the item to my cart
|
||||
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'
|
||||
|
||||
# Then the item should be in my cart with correct quantities
|
||||
order = Spree::Order.last
|
||||
li = order.line_items.first
|
||||
li.product.should == p
|
||||
li.quantity.should == 2
|
||||
li.max_quantity.should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
132
spec/features/consumer/checkout_spec.rb
Normal file
132
spec/features/consumer/checkout_spec.rb
Normal file
@@ -0,0 +1,132 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature %q{
|
||||
As a consumer
|
||||
I want select a distributor for collection
|
||||
So that I can pick up orders from the closest possible location
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
background do
|
||||
@distributor = create(:distributor_enterprise, :name => 'Edible garden',
|
||||
:address => create(:address,
|
||||
:address1 => '12 Bungee Rd',
|
||||
:city => 'Carion',
|
||||
:zipcode => 3056,
|
||||
:state => Spree::State.find_by_name('Victoria'),
|
||||
:country => Spree::Country.find_by_name('Australia')),
|
||||
:pickup_times => 'Tuesday, 4 PM')
|
||||
|
||||
@shipping_method_1 = create(:shipping_method, :name => 'Shipping Method One')
|
||||
@shipping_method_1.calculator.set_preference :amount, 1
|
||||
@shipping_method_1.calculator.save!
|
||||
|
||||
@shipping_method_2 = create(:shipping_method, :name => 'Shipping Method Two')
|
||||
@shipping_method_2.calculator.set_preference :amount, 2
|
||||
@shipping_method_2.calculator.save!
|
||||
|
||||
@product_1 = create(:product, :name => 'Fuji apples')
|
||||
@product_1.product_distributions.create(:distributor => @distributor, :shipping_method => @shipping_method_1)
|
||||
|
||||
@product_2 = create(:product, :name => 'Garlic')
|
||||
@product_2.product_distributions.create(:distributor => @distributor, :shipping_method => @shipping_method_2)
|
||||
|
||||
@zone = create(:zone)
|
||||
c = Spree::Country.find_by_name('Australia')
|
||||
Spree::ZoneMember.create(:zoneable => c, :zone => @zone)
|
||||
create(:itemwise_shipping_method, zone: @zone)
|
||||
create(:payment_method, :description => 'Cheque payment method')
|
||||
end
|
||||
|
||||
|
||||
scenario "viewing delivery fees" do
|
||||
# Given I am logged in
|
||||
login_to_consumer_section
|
||||
|
||||
# When I add some apples and some garlic to my cart
|
||||
click_link 'Fuji apples'
|
||||
select @distributor.name, :from => 'distributor_id'
|
||||
click_button 'Add To Cart'
|
||||
click_link 'Continue shopping'
|
||||
|
||||
click_link 'Garlic'
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# Then I should see a breakdown of my delivery fees:
|
||||
# Item | Shipping Method | Delivery Fee
|
||||
# Garlic | Shipping Method Two | $2.00
|
||||
# Fuji apples | Shipping Method One | $1.00
|
||||
#
|
||||
# Subtotal: $3.00
|
||||
table = page.find 'table#delivery'
|
||||
rows = table.all('tr')
|
||||
rows[0].all('th').map { |cell| cell.text.strip }.should == ['Item', 'Shipping Method', 'Delivery Fee']
|
||||
rows[1].all('td').map { |cell| cell.text.strip }.should == ['Fuji apples', 'Shipping Method One', '$1.00']
|
||||
rows[2].all('td').map { |cell| cell.text.strip }.should == ['Garlic', 'Shipping Method Two', '$2.00']
|
||||
page.should have_selector '#delivery-fees span.order-total', :text => '$3.00'
|
||||
end
|
||||
|
||||
|
||||
scenario "buying a product", :js => true do
|
||||
login_to_consumer_section
|
||||
|
||||
click_link 'Fuji apples'
|
||||
select @distributor.name, :from => 'distributor_id'
|
||||
click_button 'Add To Cart'
|
||||
click_link 'Continue shopping'
|
||||
|
||||
click_link 'Garlic'
|
||||
click_button 'Add To Cart'
|
||||
click_link 'Checkout'
|
||||
|
||||
# -- Checkout: Address
|
||||
fill_in_fields('order_bill_address_attributes_firstname' => 'Joe',
|
||||
'order_bill_address_attributes_lastname' => 'Luck',
|
||||
'order_bill_address_attributes_address1' => '19 Sycamore Lane',
|
||||
'order_bill_address_attributes_city' => 'Horse Hill',
|
||||
'order_bill_address_attributes_zipcode' => '3213',
|
||||
'order_bill_address_attributes_phone' => '12999911111')
|
||||
|
||||
select('Australia', :from => 'order_bill_address_attributes_country_id')
|
||||
select('Victoria', :from => 'order_bill_address_attributes_state_id')
|
||||
|
||||
# Distributor details should be displayed
|
||||
within('fieldset#shipping') do
|
||||
[@distributor.name,
|
||||
@distributor.address.address1,
|
||||
@distributor.address.city,
|
||||
@distributor.address.zipcode,
|
||||
@distributor.address.state_text,
|
||||
@distributor.address.country.name,
|
||||
@distributor.pickup_times,
|
||||
@distributor.next_collection_at,
|
||||
@distributor.contact,
|
||||
@distributor.phone,
|
||||
@distributor.email,
|
||||
@distributor.description,
|
||||
@distributor.website].each do |value|
|
||||
|
||||
page.should have_content value
|
||||
end
|
||||
end
|
||||
|
||||
click_button 'Save and Continue'
|
||||
|
||||
# -- Checkout: Delivery
|
||||
page.should have_selector 'label', :text => "Delivery $3.00"
|
||||
click_button 'Save and Continue'
|
||||
|
||||
# -- Checkout: Payment
|
||||
click_button 'Process My Order'
|
||||
|
||||
# -- Checkout: Order complete
|
||||
page.should have_content('Your order has been processed successfully')
|
||||
page.should have_content('Cheque payment method')
|
||||
|
||||
|
||||
# page.should have_content('Your order will be available on:')
|
||||
# page.should have_content('On Tuesday, 4 PM')
|
||||
# page.should have_content('12 Bungee Rd, Carion')
|
||||
end
|
||||
end
|
||||
65
spec/features/consumer/cms_spec.rb
Normal file
65
spec/features/consumer/cms_spec.rb
Normal file
@@ -0,0 +1,65 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
In order to learn about food
|
||||
As a user of the site
|
||||
I want to see static content pages
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
|
||||
scenario "viewing the home page" do
|
||||
# Given a CMS home page
|
||||
create(:cms_page, content: 'Home page content')
|
||||
|
||||
# When I visit the home page
|
||||
visit spree.root_path
|
||||
|
||||
# Then I should see my content
|
||||
page.should have_content 'Home page content'
|
||||
end
|
||||
|
||||
scenario "viewing another products listing page does not display home page content" do
|
||||
# Given a CMS home page
|
||||
create(:cms_page, content: 'Home page content')
|
||||
|
||||
# When I visit a products listing page
|
||||
visit spree.products_path
|
||||
|
||||
# Then I should not see the home page content
|
||||
page.should_not have_content 'Home page content'
|
||||
end
|
||||
|
||||
scenario "viewing the menu of CMS pages" do
|
||||
# Given some CMS pages
|
||||
home_page = create(:cms_page, content: 'Home')
|
||||
create(:cms_page, parent: home_page, label: 'One')
|
||||
create(:cms_page, parent: home_page, label: 'Two')
|
||||
create(:cms_page, parent: home_page, label: 'Three')
|
||||
|
||||
# When I visit the home page
|
||||
visit spree.root_path
|
||||
|
||||
# Then I should see a menu with these pages
|
||||
page.should have_selector 'ul#main-nav-bar li', :text => 'One'
|
||||
page.should have_selector 'ul#main-nav-bar li', :text => 'Two'
|
||||
page.should have_selector 'ul#main-nav-bar li', :text => 'Three'
|
||||
end
|
||||
|
||||
scenario "viewing a page from the CMS menu" do
|
||||
# Given some CMS pages
|
||||
home_page = create(:cms_page, content: 'Home')
|
||||
create(:cms_page, parent: home_page, label: 'One')
|
||||
create(:cms_page, parent: home_page, label: 'Two', content: 'This is the page')
|
||||
create(:cms_page, parent: home_page, label: 'Three')
|
||||
|
||||
# When I go to one of the pages
|
||||
visit spree.root_path
|
||||
click_link 'Two'
|
||||
|
||||
# Then I should see the page
|
||||
page.should have_content 'This is the page'
|
||||
end
|
||||
|
||||
end
|
||||
174
spec/features/consumer/distributors_spec.rb
Normal file
174
spec/features/consumer/distributors_spec.rb
Normal file
@@ -0,0 +1,174 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
As a consumer
|
||||
I want to see a list of distributors
|
||||
So that I can shop by a particular distributor
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
scenario "viewing a list of distributors" do
|
||||
# Given some distributors
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
d3 = create(:distributor_enterprise)
|
||||
|
||||
# And some of those distributors have a product
|
||||
create(:product, :distributors => [d1, d2])
|
||||
|
||||
# When I go to the home page
|
||||
visit spree.root_path
|
||||
|
||||
# Then I should see a list containing the distributors that have products
|
||||
page.should have_selector 'a', :text => d1.name
|
||||
page.should have_selector 'a', :text => d2.name
|
||||
page.should_not have_selector 'a', :text => d3.name
|
||||
end
|
||||
|
||||
scenario "viewing a distributor" do
|
||||
# Given some distributors with products
|
||||
d1 = create(:distributor_enterprise, :long_description => "<p>Hello, world!</p>")
|
||||
d2 = create(:distributor_enterprise)
|
||||
p1 = create(:product, :distributors => [d1])
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
# When I go to the first distributor page
|
||||
visit spree.root_path
|
||||
click_link d1.name
|
||||
|
||||
# Then I should see the distributor details
|
||||
page.should have_selector 'h2', :text => d1.name
|
||||
page.should have_selector 'div.enterprise-description', :text => 'Hello, world!'
|
||||
|
||||
# And I should see the first, but not the second product
|
||||
page.should have_content p1.name
|
||||
page.should_not have_content p2.name
|
||||
end
|
||||
|
||||
|
||||
context "when a distributor is selected" do
|
||||
it "displays the distributor's details" do
|
||||
# Given a distributor with a product
|
||||
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op', :description => '<p>Hello, world!</p>')
|
||||
create(:product, :distributors => [d])
|
||||
|
||||
# When I select the distributor
|
||||
visit spree.root_path
|
||||
click_link d.name
|
||||
|
||||
# Then I should see the name of the distributor that I've selected
|
||||
page.should have_selector 'h2', :text => 'Melb Uni Co-op'
|
||||
|
||||
# And I should see the distributor's long description
|
||||
page.should have_selector 'div.enterprise-description', :text => 'Hello, world!'
|
||||
end
|
||||
|
||||
it "displays the distributor's name on the home page" do
|
||||
# Given a distributor with a product
|
||||
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op', :description => '<p>Hello, world!</p>')
|
||||
create(:product, :distributors => [d])
|
||||
|
||||
# When I select the distributor
|
||||
visit spree.root_path
|
||||
click_link d.name
|
||||
visit spree.root_path
|
||||
|
||||
# Then I should see the name of the distributor that I've selected
|
||||
page.should have_content 'You are shopping at Melb Uni Co-op'
|
||||
page.should_not have_selector 'div.distributor-description'
|
||||
end
|
||||
|
||||
it "splits the product listing by local/remote distributor" do
|
||||
# Given two distributors, with a product under each, and each product under a taxon
|
||||
taxonomy = Spree::Taxonomy.find_by_name('Products') || create(:taxonomy, :name => 'Products')
|
||||
taxonomy_root = taxonomy.root
|
||||
taxon = create(:taxon, :name => 'Taxon one', :parent_id => taxonomy_root.id)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p1 = create(:product, :distributors => [d1], :taxons => [taxon])
|
||||
p2 = create(:product, :distributors => [d2], :taxons => [taxon])
|
||||
|
||||
# When I select the first distributor
|
||||
visit spree.root_path
|
||||
click_link d1.name
|
||||
visit spree.root_path
|
||||
|
||||
# Then I should see products split by local/remote distributor
|
||||
# on the home page, the products page, the search results page and the taxon page
|
||||
[spree.root_path,
|
||||
spree.products_path,
|
||||
spree.products_path(:keywords => 'Product'),
|
||||
spree.nested_taxons_path(taxon.permalink)
|
||||
].each do |path|
|
||||
|
||||
visit path
|
||||
page.should_not have_selector '#products'
|
||||
page.should have_selector '#products-local', :text => p1.name
|
||||
page.should have_selector '#products-remote', :text => p2.name
|
||||
end
|
||||
end
|
||||
|
||||
it "allows the user to leave the distributor" do
|
||||
# Given a distributor with a product
|
||||
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op')
|
||||
create(:product, :distributors => [d])
|
||||
|
||||
# When I select the distributor and then leave it
|
||||
visit spree.root_path
|
||||
click_link d.name
|
||||
click_button 'Browse All Distributors'
|
||||
|
||||
# Then I should have left the distributor
|
||||
page.should_not have_selector '#current-distributor', :text => 'You are shopping at Melb Uni Co-op'
|
||||
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
|
||||
distributor = create(:distributor_enterprise)
|
||||
product = create(:product, :distributors => [distributor])
|
||||
|
||||
# When we select the distributor and view the product
|
||||
visit spree.root_path
|
||||
click_link distributor.name
|
||||
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='#{distributor.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.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
|
||||
83
spec/features/consumer/product_spec.rb
Normal file
83
spec/features/consumer/product_spec.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
As a consumer
|
||||
I want to see products
|
||||
So that I can shop
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
scenario "viewing a product shows its supplier and distributor" do
|
||||
# Given a product with a supplier and distributor
|
||||
s = create(:supplier_enterprise)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :supplier => s, :distributors => [d])
|
||||
|
||||
# When I view the product
|
||||
visit spree.product_path p
|
||||
|
||||
# Then I should see the product's supplier and distributor
|
||||
page.should have_selector 'td', :text => s.name
|
||||
page.should have_selector 'td', :text => d.name
|
||||
end
|
||||
|
||||
describe "viewing distributor details" do
|
||||
context "without Javascript" do
|
||||
it "displays a holding message when no distributor is selected" do
|
||||
p = create(:product)
|
||||
|
||||
visit spree.product_path p
|
||||
|
||||
page.should have_selector '#product-distributor-details', :text => 'When you select a distributor for your order, their address and pickup times will be displayed here.'
|
||||
end
|
||||
|
||||
it "displays distributor details when one is selected" do
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
visit spree.root_path
|
||||
click_link d.name
|
||||
visit spree.product_path p
|
||||
|
||||
within '#product-distributor-details' do
|
||||
[d.name,
|
||||
d.address.address1,
|
||||
d.address.city,
|
||||
d.address.zipcode,
|
||||
d.address.state_text,
|
||||
d.address.country.name,
|
||||
d.pickup_times,
|
||||
d.next_collection_at,
|
||||
d.contact,
|
||||
d.phone,
|
||||
d.email,
|
||||
d.description,
|
||||
d.website].each do |value|
|
||||
|
||||
page.should have_content value
|
||||
end
|
||||
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
|
||||
71
spec/features/consumer/suppliers_spec.rb
Normal file
71
spec/features/consumer/suppliers_spec.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
As a consumer
|
||||
I want to see a list of products from a supplier
|
||||
So that I can connect with them (and maybe buy stuff too)
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
scenario "viewing a list of suppliers in the sidebar" do
|
||||
# Given some suppliers
|
||||
s1 = create(:supplier_enterprise)
|
||||
s2 = create(:supplier_enterprise)
|
||||
s3 = create(:supplier_enterprise)
|
||||
|
||||
# And some of those suppliers have a product
|
||||
create(:product, :supplier => s1)
|
||||
create(:product, :supplier => s3)
|
||||
|
||||
# When I go to the home page
|
||||
visit spree.root_path
|
||||
|
||||
# Then I should see a list containing all the suppliers that have products in stock
|
||||
page.should have_selector 'a', :text => s1.name
|
||||
page.should have_selector 'a', :text => s3.name
|
||||
page.should_not have_selector 'a', :text => s2.name
|
||||
end
|
||||
|
||||
scenario "viewing a list of all suppliers" do
|
||||
# Given some suppliers
|
||||
s1 = create(:supplier_enterprise)
|
||||
s2 = create(:supplier_enterprise)
|
||||
s3 = create(:supplier_enterprise)
|
||||
|
||||
# And some of those suppliers have a product
|
||||
create(:product, :supplier => s1)
|
||||
create(:product, :supplier => s3)
|
||||
|
||||
# When I go to the suppliers listing page
|
||||
visit spree.root_path
|
||||
click_button 'Browse All Suppliers'
|
||||
|
||||
# Then I should see a list containing all the suppliers
|
||||
page.should have_selector '#content a', :text => s1.name
|
||||
page.should have_selector '#content a', :text => s2.name
|
||||
page.should have_selector '#content a', :text => s3.name
|
||||
end
|
||||
|
||||
scenario "viewing products provided by a supplier" do
|
||||
# Given a supplier with a product
|
||||
s1 = create(:supplier_enterprise, :name => 'Murrnong', :long_description => "<p>Hello, world!</p>")
|
||||
p1 = create(:product, :supplier => s1)
|
||||
|
||||
# And a different supplier with another product
|
||||
s2 = create(:supplier_enterprise, :name => 'Red Herring')
|
||||
p2 = create(:product, :supplier => s2)
|
||||
|
||||
# When I select the first supplier
|
||||
visit spree.root_path
|
||||
click_link s1.name
|
||||
|
||||
# Then I should see the supplier details
|
||||
page.should have_selector 'h2', :text => s1.name
|
||||
page.should have_selector 'div.enterprise-description', :text => 'Hello, world!'
|
||||
|
||||
# And I should see the first, but not the second product
|
||||
page.should have_content p1.name
|
||||
page.should_not have_content p2.name
|
||||
end
|
||||
end
|
||||
62
spec/features/consumer/taxonomy_spec.rb
Normal file
62
spec/features/consumer/taxonomy_spec.rb
Normal file
@@ -0,0 +1,62 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
As a consumer
|
||||
I want to see product counts (for my chosen distributor) next to each taxon
|
||||
So that I can locate products (at my chosen distributor)
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
scenario "viewing product counts when no distributor selected" do
|
||||
# Given some taxons and some products
|
||||
taxonomy = Spree::Taxonomy.find_by_name('Products') || create(:taxonomy, :name => 'Products')
|
||||
taxonomy_root = taxonomy.root
|
||||
|
||||
taxon_one = create(:taxon, :name => 'Taxon one', :parent_id => taxonomy_root.id)
|
||||
taxon_two = create(:taxon, :name => 'Taxon two', :parent_id => taxonomy_root.id)
|
||||
taxon_three = create(:taxon, :name => 'Taxon three', :parent_id => taxonomy_root.id)
|
||||
|
||||
1.times { create(:product, :taxons => [taxon_one]) }
|
||||
2.times { create(:product, :taxons => [taxon_two]) }
|
||||
3.times { create(:product, :taxons => [taxon_three]) }
|
||||
|
||||
# When I visit the home page
|
||||
visit spree.root_path
|
||||
|
||||
# Then I should see product counts next to the taxons
|
||||
page.should have_selector 'nav#taxonomies li', :text => 'Taxon one (1)'
|
||||
page.should have_selector 'nav#taxonomies li', :text => 'Taxon two (2)'
|
||||
page.should have_selector 'nav#taxonomies li', :text => 'Taxon three (3)'
|
||||
end
|
||||
|
||||
|
||||
scenario "viewing product counts when a distributor is selected" do
|
||||
# Given some taxons and some products under distributors
|
||||
taxonomy = Spree::Taxonomy.find_by_name('Products') || create(:taxonomy, :name => 'Products')
|
||||
taxonomy_root = taxonomy.root
|
||||
|
||||
taxon_one = create(:taxon, :name => 'Taxon one', :parent_id => taxonomy_root.id)
|
||||
taxon_two = create(:taxon, :name => 'Taxon two', :parent_id => taxonomy_root.id)
|
||||
taxon_three = create(:taxon, :name => 'Taxon three', :parent_id => taxonomy_root.id)
|
||||
|
||||
my_distributor = create(:distributor_enterprise, :name => 'My Distributor')
|
||||
other_distributor = create(:distributor_enterprise, :name => 'Other Distributor')
|
||||
|
||||
1.times { create(:product, :taxons => [taxon_one], :distributors => [other_distributor]) }
|
||||
2.times { create(:product, :taxons => [taxon_two], :distributors => [other_distributor]) }
|
||||
2.times { create(:product, :taxons => [taxon_three], :distributors => [other_distributor]) }
|
||||
2.times { create(:product, :taxons => [taxon_three], :distributors => [my_distributor]) }
|
||||
|
||||
# When I visit the home page and select my distributor
|
||||
visit spree.root_path
|
||||
click_link my_distributor.name
|
||||
page.should have_content 'You are shopping at My Distributor'
|
||||
|
||||
# Then I should see distributor-scoped product counts next to the taxons
|
||||
page.should have_selector 'nav#taxonomies li', :text => 'Taxon one (0)'
|
||||
page.should have_selector 'nav#taxonomies li', :text => 'Taxon two (0)'
|
||||
page.should have_selector 'nav#taxonomies li', :text => 'Taxon three (2)'
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user