From 93a5bddeb550809812b69a46152f9b8b51259352 Mon Sep 17 00:00:00 2001 From: Andrew Spinks Date: Mon, 11 Jun 2012 13:18:04 +1000 Subject: [PATCH] Added initial request spec for making a purchase. --- spec/request/{ => admin}/distributors_spec.rb | 0 spec/request/{ => admin}/product_spec.rb | 0 spec/request/{ => admin}/suppliers_spec.rb | 0 spec/request/consumer/checkout_spec.rb | 70 +++++++++++++++++++ spec/spec_helper.rb | 2 +- spec/support/blueprints.rb | 47 +++++++++++++ .../request/authentication_workflow.rb | 18 +++++ 7 files changed, 136 insertions(+), 1 deletion(-) rename spec/request/{ => admin}/distributors_spec.rb (100%) rename spec/request/{ => admin}/product_spec.rb (100%) rename spec/request/{ => admin}/suppliers_spec.rb (100%) create mode 100644 spec/request/consumer/checkout_spec.rb diff --git a/spec/request/distributors_spec.rb b/spec/request/admin/distributors_spec.rb similarity index 100% rename from spec/request/distributors_spec.rb rename to spec/request/admin/distributors_spec.rb diff --git a/spec/request/product_spec.rb b/spec/request/admin/product_spec.rb similarity index 100% rename from spec/request/product_spec.rb rename to spec/request/admin/product_spec.rb diff --git a/spec/request/suppliers_spec.rb b/spec/request/admin/suppliers_spec.rb similarity index 100% rename from spec/request/suppliers_spec.rb rename to spec/request/admin/suppliers_spec.rb diff --git a/spec/request/consumer/checkout_spec.rb b/spec/request/consumer/checkout_spec.rb new file mode 100644 index 0000000000..b298f7fce2 --- /dev/null +++ b/spec/request/consumer/checkout_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c9fd840e42..a5daba09a7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/blueprints.rb b/spec/support/blueprints.rb index e35b2abbc2..44554de459 100644 --- a/spec/support/blueprints.rb +++ b/spec/support/blueprints.rb @@ -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 diff --git a/spec/support/request/authentication_workflow.rb b/spec/support/request/authentication_workflow.rb index 9208b53b0b..79aa9ff55a 100644 --- a/spec/support/request/authentication_workflow.rb +++ b/spec/support/request/authentication_workflow.rb @@ -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