mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
Upgrade capybara, spec/requests changed to spec/features
This commit is contained in:
34
spec/features/admin/cms_spec.rb
Normal file
34
spec/features/admin/cms_spec.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
In order to provide content to users of the site
|
||||
As an administrator
|
||||
I want to access the CMS admin site
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
|
||||
scenario "admin can access CMS admin and return to Spree admin" do
|
||||
login_to_admin_section
|
||||
click_link 'CMS Admin'
|
||||
page.should have_content "ComfortableMexicanSofa"
|
||||
|
||||
click_link 'Spree Admin'
|
||||
page.should have_selector 'h1', :text => 'Administration'
|
||||
end
|
||||
|
||||
scenario "anonymous user can't access CMS admin" do
|
||||
visit cms_admin_path
|
||||
page.should_not have_content "ComfortableMexicanSofa"
|
||||
page.should have_content "Login"
|
||||
end
|
||||
|
||||
scenario "non-admin user can't access CMS admin" do
|
||||
login_to_consumer_section
|
||||
visit cms_admin_path
|
||||
page.should_not have_content "ComfortableMexicanSofa"
|
||||
page.should have_content "Open Food Web"
|
||||
end
|
||||
|
||||
end
|
||||
94
spec/features/admin/enterprise_fees_spec.rb
Normal file
94
spec/features/admin/enterprise_fees_spec.rb
Normal file
@@ -0,0 +1,94 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
As an administrator
|
||||
I want to manage enterprise fees
|
||||
}, js: true do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
scenario "listing enterprise fees" do
|
||||
fee = create(:enterprise_fee)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Configuration'
|
||||
click_link 'Enterprise Fees'
|
||||
|
||||
page.should have_selector "option[selected]", text: fee.enterprise.name
|
||||
page.should have_selector "option[selected]", text: 'Packing'
|
||||
page.should have_selector "input[value='$0.50 / kg']"
|
||||
page.should have_selector "option[selected]", text: 'Weight (per kg)'
|
||||
page.should have_selector "input[value='0.5']"
|
||||
end
|
||||
|
||||
scenario "creating an enterprise fee" do
|
||||
# Given an enterprise
|
||||
e = create(:supplier_enterprise, name: 'Feedme')
|
||||
|
||||
# When I go to the enterprise fees page
|
||||
login_to_admin_section
|
||||
click_link 'Configuration'
|
||||
click_link 'Enterprise Fees'
|
||||
|
||||
# And I fill in the fields for a new enterprise fee and click update
|
||||
select 'Feedme', from: 'enterprise_fee_set_collection_attributes_0_enterprise_id'
|
||||
select 'Admin', from: 'enterprise_fee_set_collection_attributes_0_fee_type'
|
||||
fill_in 'enterprise_fee_set_collection_attributes_0_name', with: 'Hello!'
|
||||
select 'Flat Percent', from: 'enterprise_fee_set_collection_attributes_0_calculator_type'
|
||||
click_button 'Update'
|
||||
|
||||
# Then I should see my fee and fields for the calculator
|
||||
page.should have_content "Your enterprise fees have been updated."
|
||||
page.should have_selector "input[value='Hello!']"
|
||||
|
||||
# When I fill in the calculator fields and click update
|
||||
fill_in 'enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent', with: '12.34'
|
||||
click_button 'Update'
|
||||
|
||||
# Then I should see the correct values in my calculator fields
|
||||
page.should have_selector "#enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent[value='12.34']"
|
||||
end
|
||||
|
||||
scenario "editing an enterprise fee" do
|
||||
# Given an enterprise fee
|
||||
fee = create(:enterprise_fee)
|
||||
create(:enterprise, name: 'Foo')
|
||||
|
||||
# When I go to the enterprise fees page
|
||||
login_to_admin_section
|
||||
click_link 'Configuration'
|
||||
click_link 'Enterprise Fees'
|
||||
|
||||
# And I update the fields for the enterprise fee and click update
|
||||
select 'Foo', from: 'enterprise_fee_set_collection_attributes_0_enterprise_id'
|
||||
select 'Admin', from: 'enterprise_fee_set_collection_attributes_0_fee_type'
|
||||
fill_in 'enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!'
|
||||
select 'Flat Percent', from: 'enterprise_fee_set_collection_attributes_0_calculator_type'
|
||||
click_button 'Update'
|
||||
|
||||
# Then I should see the updated fields for my fee
|
||||
page.should have_selector "option[selected]", text: 'Foo'
|
||||
page.should have_selector "option[selected]", text: 'Admin'
|
||||
page.should have_selector "input[value='Greetings!']"
|
||||
page.should have_selector "option[selected]", text: 'Flat Percent'
|
||||
end
|
||||
|
||||
scenario "deleting an enterprise fee" do
|
||||
# Given an enterprise fee
|
||||
fee = create(:enterprise_fee)
|
||||
|
||||
# When I go to the enterprise fees page
|
||||
login_to_admin_section
|
||||
click_link 'Configuration'
|
||||
click_link 'Enterprise Fees'
|
||||
|
||||
# And I click delete
|
||||
click_link 'Delete'
|
||||
page.driver.wait_until(page.driver.browser.switch_to.alert.accept)
|
||||
|
||||
# Then my enterprise fee should have been deleted
|
||||
visit admin_enterprise_fees_path
|
||||
page.should_not have_selector "input[value='#{fee.name}']"
|
||||
end
|
||||
|
||||
end
|
||||
122
spec/features/admin/enterprises_spec.rb
Normal file
122
spec/features/admin/enterprises_spec.rb
Normal file
@@ -0,0 +1,122 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature %q{
|
||||
As an administrator
|
||||
I want to manage enterprises
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
|
||||
scenario "listing enterprises" do
|
||||
e = create(:enterprise)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Enterprises'
|
||||
|
||||
page.should have_content e.name
|
||||
end
|
||||
|
||||
scenario "viewing an enterprise" do
|
||||
e = create(:enterprise)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Enterprises'
|
||||
click_link e.name
|
||||
|
||||
page.should have_content e.name
|
||||
end
|
||||
|
||||
scenario "creating a new enterprise" do
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Enterprises'
|
||||
click_link 'New Enterprise'
|
||||
|
||||
fill_in 'enterprise_name', :with => 'Eaterprises'
|
||||
fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'
|
||||
fill_in 'enterprise_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
|
||||
|
||||
uncheck 'enterprise_is_primary_producer'
|
||||
check 'enterprise_is_distributor'
|
||||
|
||||
fill_in 'enterprise_contact', :with => 'Kirsten or Ren'
|
||||
fill_in 'enterprise_phone', :with => '0413 897 321'
|
||||
fill_in 'enterprise_email', :with => 'info@eaterprises.com.au'
|
||||
fill_in 'enterprise_website', :with => 'http://eaterprises.com.au'
|
||||
fill_in 'enterprise_twitter', :with => '@eaterprises'
|
||||
fill_in 'enterprise_abn', :with => '09812309823'
|
||||
fill_in 'enterprise_acn', :with => ''
|
||||
|
||||
fill_in 'enterprise_address_attributes_address1', :with => '35 Ballantyne St'
|
||||
fill_in 'enterprise_address_attributes_city', :with => 'Thornbury'
|
||||
fill_in 'enterprise_address_attributes_zipcode', :with => '3072'
|
||||
select('Australia', :from => 'enterprise_address_attributes_country_id')
|
||||
select('Victoria', :from => 'enterprise_address_attributes_state_id')
|
||||
|
||||
fill_in 'enterprise_pickup_times', :with => 'Thursday, 22nd Feb, 6 - 9 PM. Friday, 23nd Feb, 6 - 9 PM'
|
||||
fill_in 'enterprise_next_collection_at', :with => 'Thursday, 22nd Feb, 6 - 9 PM'
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Enterprise "Eaterprises" has been successfully created!'
|
||||
end
|
||||
|
||||
scenario "editing an existing enterprise" do
|
||||
@enterprise = create(:enterprise)
|
||||
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Enterprises'
|
||||
click_link 'Edit'
|
||||
|
||||
fill_in 'enterprise_name', :with => 'Eaterprises'
|
||||
fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'
|
||||
fill_in 'enterprise_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
|
||||
|
||||
uncheck 'enterprise_is_primary_producer'
|
||||
check 'enterprise_is_distributor'
|
||||
|
||||
fill_in 'enterprise_contact', :with => 'Kirsten or Ren'
|
||||
fill_in 'enterprise_phone', :with => '0413 897 321'
|
||||
fill_in 'enterprise_email', :with => 'info@eaterprises.com.au'
|
||||
fill_in 'enterprise_website', :with => 'http://eaterprises.com.au'
|
||||
fill_in 'enterprise_twitter', :with => '@eaterprises'
|
||||
fill_in 'enterprise_abn', :with => '09812309823'
|
||||
fill_in 'enterprise_acn', :with => ''
|
||||
|
||||
fill_in 'enterprise_address_attributes_address1', :with => '35 Ballantyne St'
|
||||
fill_in 'enterprise_address_attributes_city', :with => 'Thornbury'
|
||||
fill_in 'enterprise_address_attributes_zipcode', :with => '3072'
|
||||
select('Australia', :from => 'enterprise_address_attributes_country_id')
|
||||
select('Victoria', :from => 'enterprise_address_attributes_state_id')
|
||||
|
||||
fill_in 'enterprise_pickup_times', :with => 'Thursday, 22nd Feb, 6 - 9 PM. Friday, 23nd Feb, 6 - 9 PM'
|
||||
fill_in 'enterprise_next_collection_at', :with => 'Thursday, 22nd Feb, 6 - 9 PM'
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!'
|
||||
end
|
||||
|
||||
|
||||
scenario "updating many distributor next collection times at once" do
|
||||
# Given three distributors
|
||||
3.times { create(:distributor_enterprise) }
|
||||
|
||||
# When I go to the enterprises page
|
||||
login_to_admin_section
|
||||
click_link 'Enterprises'
|
||||
|
||||
# And I fill in some new collection times and save them
|
||||
fill_in 'enterprise_set_collection_attributes_0_next_collection_at', :with => 'One'
|
||||
fill_in 'enterprise_set_collection_attributes_1_next_collection_at', :with => 'Two'
|
||||
fill_in 'enterprise_set_collection_attributes_2_next_collection_at', :with => 'Three'
|
||||
click_button 'Update'
|
||||
|
||||
# Then my times should have been saved
|
||||
flash_message.should == 'Distributor collection times updated.'
|
||||
Enterprise.is_distributor.map { |d| d.next_collection_at }.should == %w(One Two Three)
|
||||
end
|
||||
|
||||
end
|
||||
182
spec/features/admin/order_cycles_spec.rb
Normal file
182
spec/features/admin/order_cycles_spec.rb
Normal file
@@ -0,0 +1,182 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
As an administrator
|
||||
I want to manage order cycles
|
||||
}, js: true do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
scenario "listing order cycles" do
|
||||
# Given an order cycle
|
||||
oc = create(:order_cycle)
|
||||
|
||||
# When I go to the admin order cycles page
|
||||
login_to_admin_section
|
||||
click_link 'Order Cycles'
|
||||
|
||||
# Then I should see the basic fields
|
||||
page.should have_selector 'a', text: oc.name
|
||||
|
||||
page.should have_selector "input[value='#{oc.orders_open_at}']"
|
||||
page.should have_selector "input[value='#{oc.orders_close_at}']"
|
||||
page.should have_content oc.coordinator.name
|
||||
|
||||
# And I should see the suppliers and distributors
|
||||
oc.suppliers.each { |s| page.should have_content s.name }
|
||||
oc.distributors.each { |d| page.should have_content d.name }
|
||||
|
||||
# And I should see a thumbnail image for each product
|
||||
all('td.products img').count.should == 2
|
||||
end
|
||||
|
||||
scenario "creating an order cycle" do
|
||||
# Given a coordinating enterprise and a supplying enterprise with some products with variants
|
||||
create(:enterprise, name: 'My coordinator')
|
||||
supplier = create(:supplier_enterprise, name: 'My supplier')
|
||||
product = create(:product, supplier: supplier)
|
||||
create(:variant, product: product)
|
||||
create(:variant, product: product)
|
||||
|
||||
# When I go to the new order cycle page
|
||||
login_to_admin_section
|
||||
click_link 'Order Cycles'
|
||||
click_link 'New Order Cycle'
|
||||
|
||||
# And I fill in the basic fields
|
||||
fill_in 'order_cycle_name', with: 'Plums & Avos'
|
||||
fill_in 'order_cycle_orders_open_at', with: '2012-11-06 06:00:00'
|
||||
fill_in 'order_cycle_orders_close_at', with: '2012-11-13 17:00:00'
|
||||
select 'My coordinator', from: 'order_cycle_coordinator_id'
|
||||
|
||||
# And I add a supplier and some products
|
||||
select 'My supplier', from: 'new_supplier_id'
|
||||
click_button 'Add supplier'
|
||||
click_button 'Products'
|
||||
check 'order_cycle_exchange_0_variants_1'
|
||||
check 'order_cycle_exchange_0_variants_3'
|
||||
|
||||
# And I click Create
|
||||
click_button 'Create'
|
||||
|
||||
# Then my order cycle should have been created
|
||||
page.should have_content 'Your order cycle has been created.'
|
||||
|
||||
page.should have_selector 'a', text: 'Plums & Avos'
|
||||
|
||||
page.should have_selector "input[value='2012-11-06 06:00:00 UTC']"
|
||||
page.should have_selector "input[value='2012-11-13 17:00:00 UTC']"
|
||||
page.should have_content 'My coordinator'
|
||||
|
||||
page.should have_selector 'td.suppliers', text: 'My supplier'
|
||||
|
||||
# And it should have some variants selected
|
||||
OrderCycle.last.exchanges.first.variants.count.should == 2
|
||||
end
|
||||
|
||||
|
||||
scenario "editing an order cycle" do
|
||||
# Given an order cycle with all the settings
|
||||
oc = create(:order_cycle)
|
||||
|
||||
# When I edit it
|
||||
login_to_admin_section
|
||||
click_link 'Order Cycles'
|
||||
click_link oc.name
|
||||
|
||||
# Then I should see the basic settings
|
||||
sleep(1)
|
||||
page.find('#order_cycle_name').value.should == oc.name
|
||||
page.find('#order_cycle_orders_open_at').value.should == oc.orders_open_at.to_s
|
||||
page.find('#order_cycle_orders_close_at').value.should == oc.orders_close_at.to_s
|
||||
page.find('#order_cycle_coordinator_id').value.to_i.should == oc.coordinator_id
|
||||
|
||||
# And I should see the suppliers with products
|
||||
page.should have_selector 'td.supplier_name', :text => oc.suppliers.first.name
|
||||
page.should have_selector 'td.supplier_name', :text => oc.suppliers.last.name
|
||||
|
||||
page.all('table.exchanges tbody tr.supplier').each do |row|
|
||||
row.find('td.products input').click
|
||||
|
||||
products_row = page.find('table.exchanges tr.products')
|
||||
products_row.should have_selector "input[type='checkbox'][checked='checked']"
|
||||
|
||||
row.find('td.products input').click
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
scenario "updating an order cycle" do
|
||||
# Given an order cycle with all the settings
|
||||
oc = create(:order_cycle)
|
||||
|
||||
# And a coordinating enterprise and a supplying enterprise with some products with variants
|
||||
create(:enterprise, name: 'My coordinator')
|
||||
supplier = create(:supplier_enterprise, name: 'My supplier')
|
||||
product = create(:product, supplier: supplier)
|
||||
v1 = create(:variant, product: product)
|
||||
v2 = create(:variant, product: product)
|
||||
|
||||
# When I go to its edit page
|
||||
login_to_admin_section
|
||||
click_link 'Order Cycles'
|
||||
click_link oc.name
|
||||
|
||||
# And I update it
|
||||
fill_in 'order_cycle_name', with: 'Plums & Avos'
|
||||
fill_in 'order_cycle_orders_open_at', with: '2012-11-06 06:00:00'
|
||||
fill_in 'order_cycle_orders_close_at', with: '2012-11-13 17:00:00'
|
||||
select 'My coordinator', from: 'order_cycle_coordinator_id'
|
||||
|
||||
# And I add a supplier and some products
|
||||
select 'My supplier', from: 'new_supplier_id'
|
||||
click_button 'Add supplier'
|
||||
page.all("table.exchanges tr.supplier td.products input").each { |e| e.click }
|
||||
|
||||
uncheck "order_cycle_exchange_1_variants_2"
|
||||
check "order_cycle_exchange_2_variants_#{v1.id}"
|
||||
check "order_cycle_exchange_2_variants_#{v2.id}"
|
||||
|
||||
# And I click Update
|
||||
click_button 'Update'
|
||||
|
||||
# Then my order cycle should have been updated
|
||||
page.should have_content 'Your order cycle has been updated.'
|
||||
|
||||
page.should have_selector 'a', text: 'Plums & Avos'
|
||||
|
||||
page.should have_selector "input[value='2012-11-06 06:00:00 UTC']"
|
||||
page.should have_selector "input[value='2012-11-13 17:00:00 UTC']"
|
||||
page.should have_content 'My coordinator'
|
||||
|
||||
page.should have_selector 'td.suppliers', text: 'My supplier'
|
||||
|
||||
# And it should have some variants selected
|
||||
OrderCycle.last.variants.map { |v| v.id }.sort.should == [1, v1.id, v2.id].sort
|
||||
end
|
||||
|
||||
|
||||
scenario "updating many order cycle opening/closing times at once" do
|
||||
# Given three order cycles
|
||||
3.times { create(:order_cycle) }
|
||||
|
||||
# When I go to the order cycles page
|
||||
login_to_admin_section
|
||||
click_link 'Order Cycles'
|
||||
|
||||
# And I fill in some new opening/closing times and save them
|
||||
fill_in 'order_cycle_set_collection_attributes_0_orders_open_at', :with => '2012-12-01 12:00:00'
|
||||
fill_in 'order_cycle_set_collection_attributes_0_orders_close_at', :with => '2012-12-01 12:00:01'
|
||||
fill_in 'order_cycle_set_collection_attributes_1_orders_open_at', :with => '2012-12-01 12:00:02'
|
||||
fill_in 'order_cycle_set_collection_attributes_1_orders_close_at', :with => '2012-12-01 12:00:03'
|
||||
fill_in 'order_cycle_set_collection_attributes_2_orders_open_at', :with => '2012-12-01 12:00:04'
|
||||
fill_in 'order_cycle_set_collection_attributes_2_orders_close_at', :with => '2012-12-01 12:00:05'
|
||||
click_button 'Update'
|
||||
|
||||
# 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]
|
||||
end
|
||||
|
||||
end
|
||||
63
spec/features/admin/product_spec.rb
Normal file
63
spec/features/admin/product_spec.rb
Normal file
@@ -0,0 +1,63 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature %q{
|
||||
As a supplier
|
||||
I want set a supplier and distributor(s) for a product
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
background do
|
||||
@supplier = create(:supplier_enterprise, :name => 'New supplier')
|
||||
@distributors = (1..3).map { create(:distributor_enterprise) }
|
||||
@shipping_method = create(:shipping_method, :name => 'My shipping method')
|
||||
end
|
||||
|
||||
context "creating a product" do
|
||||
scenario "assigning a supplier and distributors to the product" do
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Products'
|
||||
click_link 'New Product'
|
||||
|
||||
fill_in 'product_name', :with => 'A new product !!!'
|
||||
fill_in 'product_price', :with => '19.99'
|
||||
select 'New supplier', :from => 'product_supplier_id'
|
||||
|
||||
check @distributors[0].name
|
||||
select 'My shipping method', :from => 'product_product_distributions_attributes_0_shipping_method_id'
|
||||
check @distributors[2].name
|
||||
select 'My shipping method', :from => 'product_product_distributions_attributes_2_shipping_method_id'
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.supplier.should == @supplier
|
||||
product.distributors.should == [@distributors[0], @distributors[2]]
|
||||
product.product_distributions.map { |pd| pd.shipping_method }.should == [@shipping_method, @shipping_method]
|
||||
product.group_buy.should be_false
|
||||
end
|
||||
|
||||
scenario "making a group buy product" do
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Products'
|
||||
click_link 'New Product'
|
||||
|
||||
fill_in 'product_name', :with => 'A new product !!!'
|
||||
fill_in 'product_price', :with => '19.99'
|
||||
select 'New supplier', :from => 'product_supplier_id'
|
||||
choose 'product_group_buy_1'
|
||||
fill_in 'Group buy unit size', :with => '10'
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.group_buy.should be_true
|
||||
product.group_buy_unit_size.should == 10.0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
51
spec/features/admin/reports_spec.rb
Normal file
51
spec/features/admin/reports_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature %q{
|
||||
As an administrator
|
||||
I want numbers, all the numbers!
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
|
||||
scenario "orders and distributors report" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Orders And Distributors'
|
||||
|
||||
page.should have_content 'Order date'
|
||||
end
|
||||
|
||||
scenario "group buys report" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Group Buys'
|
||||
|
||||
page.should have_content 'Supplier'
|
||||
end
|
||||
|
||||
scenario "bulk co-op report" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Bulk Co-Op'
|
||||
|
||||
page.should have_content 'Supplier'
|
||||
end
|
||||
|
||||
scenario "payments reports" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Payment Reports'
|
||||
|
||||
page.should have_content 'Payment State'
|
||||
end
|
||||
|
||||
scenario "order cycle reports" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Order Cycle Reports'
|
||||
|
||||
page.should have_content 'Supplier'
|
||||
end
|
||||
|
||||
end
|
||||
58
spec/features/admin/shipping_methods_spec.rb
Normal file
58
spec/features/admin/shipping_methods_spec.rb
Normal file
@@ -0,0 +1,58 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'shipping methods' do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
before :each do
|
||||
login_to_admin_section
|
||||
@sm = create(:shipping_method)
|
||||
end
|
||||
|
||||
scenario "deleting a shipping method" do
|
||||
visit_delete spree.admin_shipping_method_path(@sm)
|
||||
|
||||
page.should have_content "Shipping method \"#{@sm.name}\" has been successfully removed!"
|
||||
Spree::ShippingMethod.where(:id => @sm.id).should be_empty
|
||||
end
|
||||
|
||||
scenario "deleting a shipping method referenced by an order" do
|
||||
o = create(:order, shipping_method: @sm)
|
||||
|
||||
visit_delete spree.admin_shipping_method_path(@sm)
|
||||
|
||||
page.should have_content "That shipping method cannot be deleted as it is referenced by an order: #{o.number}."
|
||||
Spree::ShippingMethod.find(@sm.id).should_not be_nil
|
||||
end
|
||||
|
||||
scenario "deleting a shipping method referenced by a product distribution" do
|
||||
p = create(:product)
|
||||
d = create(:distributor_enterprise)
|
||||
create(:product_distribution, product: p, distributor: d, shipping_method: @sm)
|
||||
|
||||
visit_delete spree.admin_shipping_method_path(@sm)
|
||||
|
||||
page.should have_content "That shipping method cannot be deleted as it is referenced by a product distribution: #{p.id} - #{p.name}."
|
||||
Spree::ShippingMethod.find(@sm.id).should_not be_nil
|
||||
end
|
||||
|
||||
scenario "deleting a shipping method referenced by a line item" do
|
||||
sm2 = create(:shipping_method)
|
||||
d = create(:distributor_enterprise)
|
||||
|
||||
p = create(:product)
|
||||
create(:product_distribution, product: p, distributor: d, shipping_method: sm2)
|
||||
|
||||
o = create(:order, distributor: d)
|
||||
o.shipping_method = sm2
|
||||
o.save!
|
||||
li = create(:line_item, order: o, product: p)
|
||||
li.shipping_method = @sm
|
||||
li.save!
|
||||
|
||||
visit_delete spree.admin_shipping_method_path(@sm)
|
||||
|
||||
page.should have_content "That shipping method cannot be deleted as it is referenced by a line item in order: #{o.number}."
|
||||
Spree::ShippingMethod.find(@sm.id).should_not be_nil
|
||||
end
|
||||
end
|
||||
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