<commit_before>require 'spec_helper'

describe SalesEngine::Item do
  context "Searching" do
    describe ".random" do
      it "usually returns different things on subsequent calls" do
        item_one =SalesEngine::Item.random
        item_two = SalesEngine::Item.random

        10.times do
          break if item_one.id != item_two.id
          item_two = SalesEngine::Item.random
        end

        item_one.id.should_not == item_two.id
      end
    end

    describe ".find_by_unit_price" do
      it "can find one record" do
        item = SalesEngine::Item.find_by_unit_price BigDecimal.new("935.19")
        item.name.should == "Item Alias Nihil"
      end
    end

    describe ".find_all_by_name" do
      it "can find multiple records" do
        items = SalesEngine::Item.find_all_by_name "Item Eos Et"
        items.should have(3).items
      end
    end
  end

  context "Relationships" do
    let(:item) { SalesEngine::Item.find_by_name "Item Saepe Ipsum" }

    describe "#invoice_items" do
      it "has 8 of them" do
        item.invoice_items.should have(8).items
      end

      it "really owns them all" do
        item.invoice_items.each do |ii|
          ii.item_id.should == item.id
        end
      end
    end

    describe "#merchant" do
      it "exists" do
        item.merchant.name.should == "Kilback Inc"
      end
    end

  end

  context "Business Intelligence" do

    describe ".most_revenue" do
      it "returns the top n items ranked by most total revenue" do
        most = SalesEngine::Item.most_revenue(5)

        most.first.name.should == "Item Dicta Autem"
        most.last.name.should  == "Item Amet Accusamus"
      end
    end

    describe ".most_items" do
      it "returns the top n items ranked by most sold" do
        most = SalesEngine::Item.most_items(42)

        most[1].name.should == "Item Dicta Autem"
        most.last.name.should   == "Item Quidem Dolorum"
      end
    end

    describe "#best_day" do
      let(:item) { SalesEngine::Item.find_by_name "Item Accusamus Ut" }

      it "returns something castable to date" do
        date = Date.parse "Tue, 27 Mar 2012"
        item.best_day.to_date.should == date
      end
    end

  end
end<commit_msg>Date from invoice in calculated answer<commit_after>require 'spec_helper'

describe SalesEngine::Item do
  context "Searching" do
    describe ".random" do
      it "usually returns different things on subsequent calls" do
        item_one =SalesEngine::Item.random
        item_two = SalesEngine::Item.random

        10.times do
          break if item_one.id != item_two.id
          item_two = SalesEngine::Item.random
        end

        item_one.id.should_not == item_two.id
      end
    end

    describe ".find_by_unit_price" do
      it "can find one record" do
        item = SalesEngine::Item.find_by_unit_price BigDecimal.new("935.19")
        item.name.should == "Item Alias Nihil"
      end
    end

    describe ".find_all_by_name" do
      it "can find multiple records" do
        items = SalesEngine::Item.find_all_by_name "Item Eos Et"
        items.should have(3).items
      end
    end
  end

  context "Relationships" do
    let(:item) { SalesEngine::Item.find_by_name "Item Saepe Ipsum" }

    describe "#invoice_items" do
      it "has 8 of them" do
        item.invoice_items.should have(8).items
      end

      it "really owns them all" do
        item.invoice_items.each do |ii|
          ii.item_id.should == item.id
        end
      end
    end

    describe "#merchant" do
      it "exists" do
        item.merchant.name.should == "Kilback Inc"
      end
    end

  end

  context "Business Intelligence" do

    describe ".most_revenue" do
      it "returns the top n items ranked by most total revenue" do
        most = SalesEngine::Item.most_revenue(5)

        most.first.name.should == "Item Dicta Autem"
        most.last.name.should  == "Item Amet Accusamus"
      end
    end

    describe ".most_items" do
      it "returns the top n items ranked by most sold" do
        most = SalesEngine::Item.most_items(42)

        most[1].name.should == "Item Dicta Autem"
        most.last.name.should   == "Item Quidem Dolorum"
      end
    end

    describe "#best_day" do
      let(:item) { SalesEngine::Item.find_by_name "Item Accusamus Ut" }

      it "returns something castable to date" do
        date = Date.parse "Sat, 24 Mar 2012"
        item.best_day.to_date.should == date
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.08703414416424905, 'fraction_numerical': 0.00892657888864093, 'mean_word_length': 2.2384393063583814, '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': '2438010', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1381, 'n_words': 412}