Added initial request spec for making a purchase.

This commit is contained in:
Andrew Spinks
2012-06-11 13:18:04 +10:00
parent d089500a5e
commit 93a5bddeb5
7 changed files with 136 additions and 1 deletions

View File

@@ -0,0 +1,70 @@
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
@distributor1 = Spree::Distributor.make!(:name => 'Eaterprises')
@distributor2 = Spree::Distributor.make!(:name => 'Edible garden',
:pickup_address => '12 Bungee Rd',
:city => 'Carion',
:pickup_times => 'Tuesday, 4 PM')
@product = Spree::Product.make!(:name => 'Fuji apples')
@zone = Spree::Zone.make!
Spree::ZoneMember.create(zone: @zone, zoneable: Spree::Country.find_by_name('Australia'))
Spree::ShippingMethod.make!(zone: @zone)
Spree::PaymentMethod.make!
end
context "Given I am buying a product", :js => true do
scenario "I should be able choose a distributor to pick up from" do
login_to_consumer_section
click_link 'Fuji apples'
click_button 'Add To Cart'
click_link 'Checkout'
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')
select('Edible garden', :from => 'order_distributor_id')
# within('.distributor-details') do
# page.should have_content('12 Bungee Rd')
# page.should have_content('Carion')
# page.should have_content('Tuesday, 4 PM')
# end
click_button 'Save and Continue'
#display delivery details?
click_button 'Save and Continue'
fill_in 'card_number', :with => '4111111111111111'
select('1', :from => 'payment_source_1_month')
select("#{DateTime.now.year + 1}", :from => 'payment_source_1_year')
fill_in 'card_code', :with => '234'
click_button 'Save and Continue'
page.should have_content('Your order has been processed successfully')
# 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
end

View File

@@ -38,7 +38,7 @@ RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false
config.before(:suite) do
DatabaseCleaner.strategy = :truncation, { :except => ['spree_countries', 'spree_zones', 'spree_zone_members', 'spree_states', 'spree_roles'] }
DatabaseCleaner.strategy = :truncation, { :except => ['spree_countries', 'spree_states'] }
end
config.before(:each) do

View File

@@ -14,3 +14,50 @@ Spree::Supplier.blueprint do
state { Spree::State.find_by_name('Victoria') }
country { Spree::Country.find_by_name('Australia') }
end
Spree::Distributor.blueprint do
name { "Distributor" }
contact { "Mr Turing"}
phone { "1000100100" }
description { 'The creator' }
email { 'alan@somewhere.com' }
pickup_address { 'Wilmslow' }
pickup_times{ "Whenever you're free" }
city { 'Cheshire' }
post_code { '2312' }
state { Spree::State.find_by_name('Victoria') }
country { Spree::Country.find_by_name('Australia') }
end
Spree::Product.blueprint do
name { "Apples" }
description { 'Tasty apples' }
available_on{ Date.today - 2.days }
count_on_hand { 5 }
price { 10.99 }
end
Spree::Variant.blueprint do
sku { "12345" }
price { 10.99 }
cost_price { 10.99 }
end
Spree::Zone.blueprint do
name {"Australia"}
description {"Australia"}
default_tax { true }
end
Spree::ShippingMethod.blueprint do
name {"Eeaterprises"}
calculator_type { 'Spree::Calculator::FlatPercentItemTotal' }
end
Spree::PaymentMethod.blueprint do
name { "Bogus " }
description { "" }
environment { "test" }
type { "Spree::Gateway::BogusSimple" }
active { true }
end

View File

@@ -15,4 +15,22 @@ module AuthenticationWorkflow
fill_in 'user_password', :with => 'passw0rd'
click_button 'Login'
end
def login_to_consumer_section
user_role = Spree::Role.create(:name => 'user')
user = Spree::User.create({
:email => 'someone@ofw.org',
:password => 'passw0rd',
:password_confirmation => 'passw0rd',
:remember_me => false,
:persistence_token => 'pass',
:login => 'someone@ofw.org',
:role_ids => [user_role.id]})
visit spree.root_path
click_link 'Login'
fill_in 'user_email', :with => 'someone@ofw.org'
fill_in 'user_password', :with => 'passw0rd'
click_button 'Login'
end
end