Removing dead weight

This commit is contained in:
Will Marshall
2014-05-01 17:43:02 +10:00
parent 2d536e01e7
commit 1703f7503b
3 changed files with 146 additions and 355 deletions

View File

@@ -1,171 +0,0 @@
require 'spec_helper'
feature "enterprises distributor info as rich text" do
include AuthenticationWorkflow
include WebHelper
include UIComponentHelper
before(:each) do
OpenFoodNetwork::FeatureToggle.stub(:features).and_return({eaterprises: false,
local_organics: true,
enterprises_distributor_info_rich_text: true})
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
# The deployment is not set to local_organics on Rails init, so these
#
# initializers won't run. Re-call them now that the deployment is set.
end
after do
ActionMailer::Base.deliveries.clear
end
scenario "setting distributor info as admin" do
# Given I'm signed in as an admin
login_to_admin_section
# When I go to create a new enterprise
click_link 'Enterprises'
click_link 'New Enterprise'
# Then I should see fields 'Profile Info' and 'Distributor Info'
page.should have_content 'About Us'
page.should have_content 'How does it work'
# When I fill out the form and create the enterprise
fill_in 'enterprise_name', :with => 'Eaterprises'
fill_in 'enterprise_long_description', with: 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
fill_in 'enterprise_distributor_info', with: 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
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'
click_button 'Create'
# Then I should see the enterprise details
flash_message.should == 'Enterprise "Eaterprises" has been successfully created!'
click_link 'Eaterprises'
page.should have_selector "tr[data-hook='long_description'] th", text: 'Profile Info:'
page.should have_selector "tr[data-hook='long_description'] td", text: 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
page.should have_selector "tr[data-hook='distributor_info'] th", text: 'Distributor Info:'
page.should have_selector "tr[data-hook='distributor_info'] td", text: 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
end
scenario "viewing distributor info with product distribution", js: true do
d = create(:distributor_enterprise, distributor_info: 'Chu ge sai yubi dan <strong>bisento</strong> tobi ashi yubi ge omote.', next_collection_at: 'Thursday 2nd May')
p = create(:product, :distributors => [d])
setup_shipping_details d
login_to_consumer_section
visit spree.select_distributor_order_path(d)
ActionMailer::Base.deliveries.clear
# -- Product details page
visit spree.product_path p
within '#product-distributor-details' do
page.should have_content 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
page.should have_content 'Thursday 2nd May'
end
# -- Checkout
click_button 'Add To Cart'
visit "/checkout"
within 'fieldset#shipping' do
page.should have_content 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
page.should have_content 'Thursday 2nd May'
end
# -- Confirmation
complete_purchase_from_checkout_address_page
#page.should have_content 'Thursday 2nd May'
# -- Purchase email
wait_until { ActionMailer::Base.deliveries.length == 1 }
email = ActionMailer::Base.deliveries.last
email.body.should =~ /Chu ge sai yubi dan bisento tobi ashi yubi ge omote./
email.body.should =~ /Thursday 2nd May/
end
scenario "viewing distributor info with order cycle distribution", js: true do
set_feature_toggle :order_cycles, true
ActionMailer::Base.deliveries.clear
d = create(:distributor_enterprise, name: 'Green Grass', distributor_info: 'Chu ge sai yubi dan <strong>bisento</strong> tobi ashi yubi ge omote.', next_collection_at: 'Thursday 2nd May')
create_enterprise_group_for d
p = create(:product)
oc = create(:simple_order_cycle, distributors: [d], variants: [p.master])
ex = oc.exchanges.outgoing.last
ex = Exchange.find ex.id
ex.pickup_time = 'Friday 4th May'
ex.save!
setup_shipping_details d
login_to_consumer_section
ActionMailer::Base.deliveries.clear
follow_active_table_node 'Green Grass'
visit enterprise_path d
# -- Product details page
click_link p.name
within '#product-distributor-details' do
page.should have_content 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
page.should have_content 'Friday 4th May'
end
# -- Checkout
click_button 'Add To Cart'
find('#checkout-link').click
visit "/checkout"
within 'fieldset#shipping' do
page.should have_content 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
page.should have_content 'Friday 4th May'
end
# -- Confirmation
complete_purchase_from_checkout_address_page
page.should have_content 'Friday 4th May'
# -- Purchase email
wait_until { ActionMailer::Base.deliveries.length == 1 }
email = ActionMailer::Base.deliveries.last
email.body.should =~ /Chu ge sai yubi dan bisento tobi ashi yubi ge omote./
email.body.should =~ /Friday 4th May/
end
private
def setup_shipping_details(distributor)
zone = create(:zone)
c = Spree::Country.find_by_name('Australia')
Spree::ZoneMember.create(:zoneable => c, :zone => zone)
create(:shipping_method, zone: zone, require_ship_address: false)
create(:payment_method, :description => 'Cheque payment method', distributors: [distributor])
end
def complete_purchase_from_checkout_address_page
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')
click_checkout_continue_button
click_checkout_continue_button
click_checkout_continue_button
end
end

View File

@@ -38,7 +38,6 @@ feature "As a consumer I want to shop with a distributor", js: true do
describe "selecting an order cycle" do
let(:exchange1) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) }
let(:exchange2) { Exchange.find(oc2.exchanges.to_enterprises(distributor).outgoing.first.id) }
it "selects an order cycle if only one is open" do
exchange1.update_attribute :pickup_time, "turtles"
@@ -47,6 +46,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
end
describe "with multiple order cycles" do
let(:exchange2) { Exchange.find(oc2.exchanges.to_enterprises(distributor).outgoing.first.id) }
before do
exchange1.update_attribute :pickup_time, "frogs"
exchange2.update_attribute :pickup_time, "turtles"
@@ -58,189 +58,152 @@ feature "As a consumer I want to shop with a distributor", js: true do
page.should have_selector "option", text: 'turtles'
page.should_not have_selector("input.button.right", visible: true)
end
it "shows the table after an order cycle is selected" do
it "shows products after selecting an order cycle" do
exchange1.variants << product.master ## add product to exchange
visit shop_path
page.should_not have_content product.name
Spree::Order.last.order_cycle.should == nil
select "frogs", :from => "order_cycle_id"
page.should have_content distributor.name # This forces a wait, allowing the Ajax call to finish
page.should have_selector("input.button.right", visible: true)
page.should have_selector "products"
page.should have_content "Orders close in 2 days"
Spree::Order.last.order_cycle.should == oc1
page.should have_content product.name
end
end
end
describe "after selecting an order cycle with products visible" do
let(:variant1) { create(:variant, product: product, price: 20) }
let(:variant2) { create(:variant, product: product, price: 30) }
let(:exchange) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) }
before do
exchange.update_attribute :pickup_time, "frogs"
exchange.variants << product.master
exchange.variants << variant1
exchange.variants << variant2
order.order_cycle = oc1
end
it "should not show quantity field for product with variants" do
visit shop_path
page.should_not have_selector("#variants_#{product.master.id}", visible: true)
#it "expands variants" do
find(".collapse").trigger "click"
page.should_not have_text variant1.options_text
end
it "uses the adjusted price" do
enterprise_fee1 = create(:enterprise_fee, amount: 20)
enterprise_fee2 = create(:enterprise_fee, amount: 3)
exchange.enterprise_fees = [enterprise_fee1, enterprise_fee2]
exchange.save
visit shop_path
# Page should not have product.price (with or without fee)
page.should_not have_selector 'tr.product > td', text: "from $10.00"
page.should_not have_selector 'tr.product > td', text: "from $33.00"
# Page should have variant prices (with fee)
page.should have_selector 'tr.variant > td.price', text: "$43.00"
page.should have_selector 'tr.variant > td.price', text: "$53.00"
# Product price should be listed as the lesser of these
page.should have_selector 'tr.product > td', text: "from $43.00"
end
end
describe "group buy products" do
let(:exchange) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) }
let(:product) { create(:simple_product, group_buy: true, on_hand: 15) }
let(:product2) { create(:simple_product, group_buy: false) }
describe "without variants" do
before do
add_product_to_order_cycle(exchange, product)
set_order_cycle(order, oc1)
visit shop_path
end
describe "with products in our order cycle" do
let(:product) { create(:simple_product) }
before do
exchange1.variants << product.master
visit shop_path
end
it "allows us to select an order cycle, thus showing products" do
page.should_not have_content product.name
Spree::Order.last.order_cycle.should == nil
select "frogs", :from => "order_cycle_id"
page.should have_selector "products"
page.should have_content "Orders close in 2 days"
Spree::Order.last.order_cycle.should == oc1
page.should have_content product.name
end
end
end
describe "after selecting an order cycle with products visible" do
let(:variant1) { create(:variant, product: product, price: 20) }
let(:variant2) { create(:variant, product: product, price: 30) }
let(:exchange) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) }
before do
exchange.update_attribute :pickup_time, "frogs"
exchange.variants << product.master
exchange.variants << variant1
exchange.variants << variant2
order.order_cycle = oc1
end
it "should not show quantity field for product with variants" do
visit shop_path
page.should_not have_selector("#variants_#{product.master.id}", visible: true)
#it "expands variants by default" do
page.should have_text variant1.options_text
#it "expands variants" do
find(".collapse").trigger "click"
page.should_not have_text variant1.options_text
end
it "uses the adjusted price" do
enterprise_fee1 = create(:enterprise_fee, amount: 20)
enterprise_fee2 = create(:enterprise_fee, amount: 3)
exchange.enterprise_fees = [enterprise_fee1, enterprise_fee2]
exchange.save
visit shop_path
# Page should not have product.price (with or without fee)
page.should_not have_selector 'tr.product > td', text: "from $10.00"
page.should_not have_selector 'tr.product > td', text: "from $33.00"
# Page should have variant prices (with fee)
page.should have_selector 'tr.variant > td.price', text: "$43.00"
page.should have_selector 'tr.variant > td.price', text: "$53.00"
# Product price should be listed as the lesser of these
page.should have_selector 'tr.product > td', text: "from $43.00"
end
end
describe "group buy products" do
let(:product) { create(:simple_product, group_buy: true, on_hand: 15) }
let(:product2) { create(:simple_product, group_buy: false) }
describe "without variants" do
before do
build_and_select_order_cycle
visit shop_path
end
it "should show group buy input" do
page.should have_field "variant_attributes[#{product.master.id}][max_quantity]", :visible => true
page.should_not have_field "variant_attributes[#{product2.master.id}][max_quantity]", :visible => true
end
it "should save group buy data to ze cart" do
fill_in "variants[#{product.master.id}]", with: 5
fill_in "variant_attributes[#{product.master.id}][max_quantity]", with: 9
first("form.custom > input.button.right").click
page.should have_content product.name
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
li.max_quantity.should == 9
li.quantity.should == 5
end
scenario "adding a product with a max quantity less than quantity results in max_quantity==quantity" do
fill_in "variants[#{product.master.id}]", with: 5
fill_in "variant_attributes[#{product.master.id}][max_quantity]", with: 1
first("form.custom > input.button.right").click
page.should have_content product.name
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
li.max_quantity.should == 5
li.quantity.should == 5
end
end
describe "with variants on the product" do
let(:variant) { create(:variant, product: product, on_hand: 10 ) }
before do
build_and_select_order_cycle_with_variants
visit shop_path
end
it "should show group buy input" do
page.should have_field "variant_attributes[#{variant.id}][max_quantity]", :visible => true
end
it "should save group buy data to ze cart" do
fill_in "variants[#{variant.id}]", with: 6
fill_in "variant_attributes[#{variant.id}][max_quantity]", with: 7
first("form.custom > input.button.right").click
page.should have_content product.name
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
li.max_quantity.should == 7
li.quantity.should == 6
end
end
end
describe "adding products to cart" do
let(:oc) { create(:simple_order_cycle, distributors: [distributor]) }
let(:product) { create(:simple_product) }
let(:variant) { create(:variant, product: product) }
before do
build_and_select_order_cycle_with_variants
visit shop_path
end
it "should let us add products to our cart" do
fill_in "variants[#{variant.id}]", with: "1"
first("form.custom > input.button.right").click
current_path.should == "/cart"
it "should save group buy data to ze cart" do
fill_in "variants[#{product.master.id}]", with: 5
fill_in "variant_attributes[#{product.master.id}][max_quantity]", with: 9
first("form.custom > input.button.right").click
page.should have_content product.name
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
li.max_quantity.should == 9
li.quantity.should == 5
end
# TODO move to controller test
pending "adding a product with a max quantity less than quantity results in max_quantity==quantity" do
fill_in "variants[#{product.master.id}]", with: 5
fill_in "variant_attributes[#{product.master.id}][max_quantity]", with: 1
first("form.custom > input.button.right").click
page.should have_content product.name
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
li.max_quantity.should == 5
li.quantity.should == 5
end
end
context "when no order cycles are available" do
it "tells us orders are closed" do
describe "with variants on the product" do
let(:variant) { create(:variant, product: product, on_hand: 10 ) }
before do
add_product_and_variant_to_order_cycle(exchange, product, variant)
set_order_cycle(order, oc1)
visit shop_path
page.should have_content "Orders are currently closed for this hub"
end
it "shows the last order cycle" do
oc1 = create(:simple_order_cycle, distributors: [distributor], orders_close_at: 10.days.ago)
visit shop_path
page.should have_content "The last cycle closed 10 days ago"
end
it "shows the next order cycle" do
oc1 = create(:simple_order_cycle, distributors: [distributor], orders_open_at: 10.days.from_now)
visit shop_path
page.should have_content "The next cycle opens in 10 days"
it "should save group buy data to ze cart" do
fill_in "variants[#{variant.id}]", with: 6
fill_in "variant_attributes[#{variant.id}][max_quantity]", with: 7
first("form.custom > input.button.right").click
page.should have_content product.name
li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last
li.max_quantity.should == 7
li.quantity.should == 6
end
end
end
it "shows nothing when there is no future order cycle"
describe "adding products to cart" do
let(:exchange) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) }
let(:product) { create(:simple_product) }
let(:variant) { create(:variant, product: product) }
before do
add_product_and_variant_to_order_cycle(exchange, product, variant)
set_order_cycle(order, oc1)
visit shop_path
end
it "should let us add products to our cart" do
fill_in "variants[#{variant.id}]", with: "1"
first("form.custom > input.button.right").click
current_path.should == "/cart"
page.should have_content product.name
end
end
context "when no order cycles are available" do
it "tells us orders are closed" do
visit shop_path
page.should have_content "Orders are currently closed for this hub"
end
it "shows the last order cycle" do
oc1 = create(:simple_order_cycle, distributors: [distributor], orders_close_at: 10.days.ago)
visit shop_path
page.should have_content "The last cycle closed 10 days ago"
end
it "shows the next order cycle" do
oc1 = create(:simple_order_cycle, distributors: [distributor], orders_open_at: 10.days.from_now)
visit shop_path
page.should have_content "The next cycle opens in 10 days"
end
end
end
end
def build_and_select_order_cycle
exchange = Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id)
exchange.update_attribute :pickup_time, "frogs"
exchange.variants << product.master
order.order_cycle = oc1
end
def build_and_select_order_cycle_with_variants
exchange = Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id)
exchange.update_attribute :pickup_time, "frogs"
exchange.variants << product.master
exchange.variants << variant
order.order_cycle = oc1
end

View File

@@ -3,20 +3,6 @@ module ShopWorkflow
ApplicationController.any_instance.stub(:session).and_return({order_id: order.id, access_token: order.token})
end
def select_distributor
# If no order cycles are available this is much faster
visit "/"
follow_active_table_node 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)
exchange.variants << product.master
order.update_attribute :order_cycle, order_cycle
end
def add_product_to_cart
create(:line_item, variant: product.master, order: order)
end
@@ -24,4 +10,17 @@ module ShopWorkflow
def toggle_accordion(name)
find("dd a", text: name).click
end
def add_product_to_order_cycle(exchange, product)
exchange.variants << product.master
end
def add_product_and_variant_to_order_cycle(exchange, product, variant)
exchange.variants << product.master
exchange.variants << variant
end
def set_order_cycle(order, order_cycle)
order.update_attribute(:order_cycle, order_cycle)
end
end