From 5d86d3769e2904f082f8bcc159f0c7119da4f3e1 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 20 Jan 2019 12:42:12 +0000 Subject: [PATCH 1/4] Improve variable names in lettuce_share_report_spec --- .../lettuce_share_report_spec.rb | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/spec/lib/open_food_network/lettuce_share_report_spec.rb b/spec/lib/open_food_network/lettuce_share_report_spec.rb index 42e1ba1715..f7540edeb7 100644 --- a/spec/lib/open_food_network/lettuce_share_report_spec.rb +++ b/spec/lib/open_food_network/lettuce_share_report_spec.rb @@ -1,30 +1,32 @@ +require 'spec_helper' + require 'open_food_network/lettuce_share_report' module OpenFoodNetwork xdescribe LettuceShareReport do let(:user) { create(:user) } let(:report) { LettuceShareReport.new user, {}, true } - let(:v) { create(:variant) } + let(:variant) { create(:variant) } describe "grower and method" do it "shows just the producer when there is no certification" do report.stub(:producer_name) { "Producer" } report.stub(:certification) { "" } - report.send(:grower_and_method, v).should == "Producer" + report.send(:grower_and_method, variant).should == "Producer" end it "shows producer and certification when a certification is present" do report.stub(:producer_name) { "Producer" } report.stub(:certification) { "Method" } - report.send(:grower_and_method, v).should == "Producer (Method)" + report.send(:grower_and_method, variant).should == "Producer (Method)" end end describe "gst" do it "handles tax category without rates" do - report.send(:gst, v).should == 0 + report.send(:gst, variant).should == 0 end end @@ -34,35 +36,35 @@ module OpenFoodNetwork end describe "lists" do - let(:v2) { create(:variant) } - let(:v3) { create(:variant) } - let(:v4) { create(:variant, on_hand: 0, on_demand: true) } + let(:variant2) { create(:variant) } + let(:variant3) { create(:variant) } + let(:variant4) { create(:variant, on_hand: 0, on_demand: true) } let(:hub_address) { create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234") } let(:hub) { create(:distributor_enterprise, :address => hub_address) } - let(:v2o) { create(:variant_override, hub: hub, variant: v2) } - let(:v3o) { create(:variant_override, hub: hub, variant: v3, count_on_hand: 0) } + let(:variant2_override) { create(:variant_override, hub: hub, variant: variant2) } + let(:variant3_override) { create(:variant_override, hub: hub, variant: variant3, count_on_hand: 0) } it "all items" do - report.stub(:child_variants) { Spree::Variant.where(id: [v, v2, v3]) } + report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) } report.send(:table).count.should eq 3 end it "only available items" do - v.update_column(:count_on_hand, 0) - report.stub(:child_variants) { Spree::Variant.where(id: [v, v2, v3, v4]) } + variant.update_column(:count_on_hand, 0) + report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3, variant4]) } report.send(:table).count.should eq 3 end it "only available items considering overrides" do - create(:exchange, incoming: false, receiver_id: hub.id, variants: [v, v2, v3]) + create(:exchange, incoming: false, receiver_id: hub.id, variants: [variant, variant2, variant3]) # create the overrides - v2o - v3o - report.stub(:child_variants) { Spree::Variant.where(id: [v, v2, v3]) } + variant2_override + variant3_override + report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) } report.stub(:params) { {distributor_id: hub.id} } rows = report.send(:table) rows.count.should eq 2 - rows.map{ |row| row[0] }.should include v.product.name, v2.product.name + rows.map{ |row| row[0] }.should include variant.product.name, variant2.product.name end end From 4669c71b19afa3211df9be3216b23f2ab1db05c5 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 20 Jan 2019 12:44:29 +0000 Subject: [PATCH 2/4] Fix lettuce_share_report_spec by adapting count_on_hand setter, it's not a db column anymore --- spec/lib/open_food_network/lettuce_share_report_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/open_food_network/lettuce_share_report_spec.rb b/spec/lib/open_food_network/lettuce_share_report_spec.rb index f7540edeb7..7fe24215ad 100644 --- a/spec/lib/open_food_network/lettuce_share_report_spec.rb +++ b/spec/lib/open_food_network/lettuce_share_report_spec.rb @@ -50,7 +50,7 @@ module OpenFoodNetwork end it "only available items" do - variant.update_column(:count_on_hand, 0) + variant.count_on_hand = 0 report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3, variant4]) } report.send(:table).count.should eq 3 end From 9b2fb56025330482a51d31262d99c0b047891bcd Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 20 Jan 2019 13:21:53 +0000 Subject: [PATCH 3/4] Fix reports_spec sales tax report test by calling count_on_hand setter, setting shipping_method in the right step in the checkout workflow and changing login method to match all other tests in this spec --- spec/features/admin/reports_spec.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 45126cc92b..a673443c7a 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -182,13 +182,13 @@ xfeature %q{ let(:distributor2) { create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true) } let(:user1) { create_enterprise_user enterprises: [distributor1] } let(:user2) { create_enterprise_user enterprises: [distributor2] } - let(:shipping_method) { create(:shipping_method_with, :expensive_name) } - let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) } + let!(:shipping_method) { create(:shipping_method_with, :expensive_name) } let(:enterprise_fee) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 120.0)) } let(:order_cycle) { create(:simple_order_cycle, coordinator: distributor1, coordinator_fees: [enterprise_fee], distributors: [distributor1], variants: [product1.master]) } let!(:zone) { create(:zone_with_member) } - let(:order1) { create(:order, order_cycle: order_cycle, distributor: user1.enterprises.first, shipments: [shipment], bill_address: create(:address)) } + let(:address) { create(:address) } + let(:order1) { create(:order, order_cycle: order_cycle, distributor: user1.enterprises.first, ship_address: address, bill_address: address) } let(:product1) { create(:taxed_product, zone: zone, price: 12.54, tax_rate_amount: 0) } let(:product2) { create(:taxed_product, zone: zone, price: 500.15, tax_rate_amount: 0.2) } @@ -201,13 +201,14 @@ xfeature %q{ Spree::Config.shipment_inc_vat = true Spree::Config.shipping_tax_rate = 0.2 - 3.times { order1.next } + 2.times { order1.next } + order1.select_shipping_method shipping_method.id order1.reload.update_distribution_charge! - order1.finalize! - quick_login_as user1 + quick_login_as_admin visit spree.admin_reports_path + click_link "Sales Tax" select("Tax types", from: "report_type") end @@ -307,11 +308,11 @@ xfeature %q{ product2.set_property 'Organic', 'NASAA 12345' product1.taxons = [taxon] product2.taxons = [taxon] - variant1.update_column(:count_on_hand, 10) + variant1.count_on_hand = 10 variant1.update_column(:sku, "sku1") - variant2.update_column(:count_on_hand, 20) + variant2.count_on_hand = 20 variant2.update_column(:sku, "sku2") - variant3.update_column(:count_on_hand, 9) + variant3.count_on_hand = 9 variant3.update_column(:sku, "") variant1.option_values = [create(:option_value, :presentation => "Test")] variant2.option_values = [create(:option_value, :presentation => "Something")] From 0f26080d792ca38c6bf368f868f8bef4219b6cfe Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Mon, 21 Jan 2019 15:00:37 +0000 Subject: [PATCH 4/4] In lettuce share report spec, call method directly instead of using send --- spec/lib/open_food_network/lettuce_share_report_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/open_food_network/lettuce_share_report_spec.rb b/spec/lib/open_food_network/lettuce_share_report_spec.rb index 7fe24215ad..eb912f58c2 100644 --- a/spec/lib/open_food_network/lettuce_share_report_spec.rb +++ b/spec/lib/open_food_network/lettuce_share_report_spec.rb @@ -32,7 +32,7 @@ module OpenFoodNetwork describe "table" do it "handles no items" do - report.send(:table).should eq [] + report.table.should eq [] end describe "lists" do @@ -46,13 +46,13 @@ module OpenFoodNetwork it "all items" do report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) } - report.send(:table).count.should eq 3 + report.table.count.should eq 3 end it "only available items" do variant.count_on_hand = 0 report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3, variant4]) } - report.send(:table).count.should eq 3 + report.table.count.should eq 3 end it "only available items considering overrides" do @@ -62,7 +62,7 @@ module OpenFoodNetwork variant3_override report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) } report.stub(:params) { {distributor_id: hub.id} } - rows = report.send(:table) + rows = report.table rows.count.should eq 2 rows.map{ |row| row[0] }.should include variant.product.name, variant2.product.name end