<commit_before>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(: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, 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, variant).should == "Producer (Method)"
      end
    end

    describe "gst" do
      it "handles tax category without rates" do
        report.send(:gst, variant).should == 0
      end
    end

    describe "table" do
      it "handles no items" do
        report.send(:table).should eq []
      end

      describe "lists" do
        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(: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: [variant, variant2, variant3]) }
          report.send(: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
        end

        it "only available items considering overrides" do
          create(:exchange, incoming: false, receiver_id: hub.id, variants: [variant, variant2, variant3])
          # create the overrides
          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 variant.product.name, variant2.product.name
        end

      end
    end
  end
end<commit_msg>In lettuce share report spec, call method directly instead of using send<commit_after>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(: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, 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, variant).should == "Producer (Method)"
      end
    end

    describe "gst" do
      it "handles tax category without rates" do
        report.send(:gst, variant).should == 0
      end
    end

    describe "table" do
      it "handles no items" do
        report.table.should eq []
      end

      describe "lists" do
        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(: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: [variant, variant2, variant3]) }
          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.table.count.should eq 3
        end

        it "only available items considering overrides" do
          create(:exchange, incoming: false, receiver_id: hub.id, variants: [variant, variant2, variant3])
          # create the overrides
          variant2_override
          variant3_override
          report.stub(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) }
          report.stub(:params) { {distributor_id: hub.id} }
          rows = report.table
          rows.count.should eq 2
          rows.map{ |row| row[0] }.should include variant.product.name, variant2.product.name
        end

      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11632987438558165, 'fraction_numerical': 0.011651192426724922, 'mean_word_length': 2.8259052924791086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1367922', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1601, 'n_words': 418}