Merge pull request #3361 from luisramos0/2-0-report-spec

[Spree Upgrade] Phase 2 - Fix some specs in reports_spec and in lettuce share report
This commit is contained in:
Pau Pérez Fabregat
2019-02-01 08:26:55 +01:00
committed by GitHub
2 changed files with 33 additions and 30 deletions

View File

@@ -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")]

View File

@@ -1,68 +1,70 @@
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
describe "table" do
it "handles no items" do
report.send(:table).should eq []
report.table.should eq []
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.send(:table).count.should eq 3
report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) }
report.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]) }
report.send(:table).count.should eq 3
variant.count_on_hand = 0
report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3, variant4]) }
report.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 = report.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