<commit_before>require 'open_food_network/user_balance_calculator'
require 'spec_helper'

module OpenFoodNetwork
  describe UserBalanceCalculator do

    describe "finding the account balance of a user with a hub" do

      let!(:usr) { create(:user) }
      let!(:entrprs) { create(:distributor_enterprise) }

      let!(:o1) { create(:order_with_totals_and_distribution, user: usr, distributor: entrprs) } #total=10
      let!(:o2) { create(:order_with_totals_and_distribution, user: usr, distributor: entrprs) } #total=10
      let!(:p1) { create(:payment, order: o1, amount: 15.00) }
      let!(:p2) { create(:payment, order: o2, amount: 10.00) }

      it "finds the user balance for this enterprise" do
        UserBalanceCalculator.new(usr, entrprs).balance.to_i.should == 5
      end

      it "does not find the balance for other enterprises" do
        entrprs2 = create(:distributor_enterprise)
        o3 = create(:order_with_totals_and_distribution, 
                    user: usr, distributor: entrprs2) #total=10
        p3 = create(:payment, order: o3, amount: 10.00)
        UserBalanceCalculator.new(usr, entrprs2).balance.to_i.should == 0
      end

      it "does not find the balance for other users" do
        usr2 = create(:user)
        o4 = create(:order_with_totals_and_distribution, 
                    user: usr2, distributor: entrprs) #total=10
        p3 = create(:payment, order: o4, amount: 20.00)
        UserBalanceCalculator.new(usr2, entrprs).balance.to_i.should == 10
      end
    end 
  end
end<commit_msg>Variable naming<commit_after>require 'open_food_network/user_balance_calculator'
require 'spec_helper'

module OpenFoodNetwork
  describe UserBalanceCalculator do

    describe "finding the account balance of a user with a hub" do

      let!(:user1) { create(:user) }
      let!(:hub1) { create(:distributor_enterprise) }

      let!(:o1) { create(:order_with_totals_and_distribution, user: user1, distributor: hub1) } #total=10
      let!(:o2) { create(:order_with_totals_and_distribution, user: user1, distributor: hub1) } #total=10
      let!(:p1) { create(:payment, order: o1, amount: 15.00) }
      let!(:p2) { create(:payment, order: o2, amount: 10.00) }

      it "finds the user balance for this enterprise" do
        UserBalanceCalculator.new(user1, hub1).balance.to_i.should == 5
      end

      it "does not find the balance for other enterprises" do
        hub2 = create(:distributor_enterprise)
        o3 = create(:order_with_totals_and_distribution, 
                    user: user1, distributor: hub2) #total=10
        p3 = create(:payment, order: o3, amount: 10.00)
        UserBalanceCalculator.new(user1, hub2).balance.to_i.should == 0
      end

      it "does not find the balance for other users" do
        user2 = create(:user)
        o4 = create(:order_with_totals_and_distribution, 
                    user: user2, distributor: hub1) #total=10
        p3 = create(:payment, order: o4, amount: 20.00)
        UserBalanceCalculator.new(user2, hub1).balance.to_i.should == 10
      end
    end 
  end
end
{'fraction_non_alphanumeric': 0.10710808179162609, 'fraction_numerical': 0.03375527426160337, 'mean_word_length': 3.176151761517615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6125010', 'n_tokens_mistral': 1066, 'n_tokens_neox': 975, 'n_words': 250}