From bf6eb4ace15c3688761dc73206502ef0fd66dcc6 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Tue, 1 Apr 2014 13:53:37 +1100 Subject: [PATCH] Refactoring checkout specs some more --- .rspec | 1 + .../consumer/shopping/checkout_auth_spec.rb | 2 ++ .../shopping/checkout_plumbing_spec.rb | 2 ++ .../consumer/shopping/checkout_spec.rb | 22 +------------------ spec/support/request/shop_workflow.rb | 21 ++++++++++++++++++ 5 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 spec/support/request/shop_workflow.rb diff --git a/.rspec b/.rspec index 53607ea52b..333fedd86c 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,2 @@ --colour +--profile diff --git a/spec/features/consumer/shopping/checkout_auth_spec.rb b/spec/features/consumer/shopping/checkout_auth_spec.rb index de14f121e7..7c5e4e8fe1 100644 --- a/spec/features/consumer/shopping/checkout_auth_spec.rb +++ b/spec/features/consumer/shopping/checkout_auth_spec.rb @@ -3,11 +3,13 @@ require 'spec_helper' feature "As a consumer I want to check out my cart", js: true do include AuthenticationWorkflow include WebHelper + include ShopWorkflow let(:distributor) { create(:distributor_enterprise) } let(:supplier) { create(:supplier_enterprise) } let(:order_cycle) { create(:order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) } let(:product) { create(:simple_product, supplier: supplier) } + let(:order) { Spree::Order.last } before do create_enterprise_group_for distributor diff --git a/spec/features/consumer/shopping/checkout_plumbing_spec.rb b/spec/features/consumer/shopping/checkout_plumbing_spec.rb index b972667ca9..32d627c5b1 100644 --- a/spec/features/consumer/shopping/checkout_plumbing_spec.rb +++ b/spec/features/consumer/shopping/checkout_plumbing_spec.rb @@ -3,12 +3,14 @@ require 'spec_helper' feature "As a consumer I want to check out my cart", js: true do include AuthenticationWorkflow + include ShopWorkflow include WebHelper let(:distributor) { create(:distributor_enterprise) } let(:supplier) { create(:supplier_enterprise) } let(:order_cycle) { create(:order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) } let(:product) { create(:simple_product, supplier: supplier) } + let(:order) { Spree::Order.last } before do create_enterprise_group_for distributor diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 71d4cd72ab..c227e5ef19 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' feature "As a consumer I want to check out my cart", js: true do include AuthenticationWorkflow + include ShopWorkflow include WebHelper let(:distributor) { create(:distributor_enterprise) } @@ -151,24 +152,3 @@ feature "As a consumer I want to check out my cart", js: true do end end - -def select_distributor - visit "/" - click_link distributor.name - #@order = Spree::Order.last -end - -# This method is naughty and writes to the DB directly -# Because loading the whole Angular app is slow -def select_order_cycle - #exchange = Exchange.find(order_cycle.exchanges.to_enterprises(distributor).outgoing.first.id) - #visit "/shop" - #select exchange.pickup_time, from: "order_cycle_id" - order.update_attribute :order_cycle, order_cycle -end - -def add_product_to_cart - #fill_in "variants[#{product.master.id}]", with: product.master.on_hand - 1 - #first("form.custom > input.button.right").click - create(:line_item, variant: product.master, order: order) -end diff --git a/spec/support/request/shop_workflow.rb b/spec/support/request/shop_workflow.rb new file mode 100644 index 0000000000..98b50f5ddf --- /dev/null +++ b/spec/support/request/shop_workflow.rb @@ -0,0 +1,21 @@ +module ShopWorkflow + def select_distributor + visit "/" + click_link distributor.name + end + + # These methods are naughty and write to the DB directly + # Because loading the whole Angular app is slow + def select_order_cycle + #exchange = Exchange.find(order_cycle.exchanges.to_enterprises(distributor).outgoing.first.id) + #visit "/shop" + #select exchange.pickup_time, from: "order_cycle_id" + order.update_attribute :order_cycle, order_cycle + end + + def add_product_to_cart + #fill_in "variants[#{product.master.id}]", with: product.master.on_hand - 1 + #first("form.custom > input.button.right").click + create(:line_item, variant: product.master, order: order) + end +end