Upgrade capybara, spec/requests changed to spec/features

This commit is contained in:
Rohan Mitchell
2013-01-15 10:10:24 +11:00
parent a10eb0d0c7
commit 488fc2d60e
15 changed files with 11 additions and 9 deletions

View 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

View 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

View 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

View 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

View 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

View 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

View 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