require 'spec_helper'

describe SalesEngine::Invoice, invoice: true do
  context "extensions" do
    describe ".pending" do
      it "returns Invoices without a successful transaction" do
        invoice =  SalesEngine::Invoice.find_by_id(13)
        pending_invoices = SalesEngine::Invoice.pending

        pending_invoices[1].should == invoice
      end
    end

    describe ".average_revenue" do
      it "returns the average of the totals of each invoice" do
        SalesEngine::Invoice.average_revenue.should == BigDecimal("12369.53")
      end
    end

    describe ".average_revenue(date)" do
      it "returns the average of the invoice revenues for that date" do
        SalesEngine::Invoice.average_revenue(Date.parse("March 17, 2012")).should == BigDecimal("11603.14")
      end
    end

    describe ".average_items" do
      it "returns the average of the number of items for each invoice" do
        SalesEngine::Invoice.average_items.should == BigDecimal("24.45")
      end
    end

    describe ".average_items(date)" do
      it "returns the average of the invoice items for that date" do
        SalesEngine::Invoice.average_items(Date.parse("March 21, 2012")).should == BigDecimal("24.29")
      end
    end
  end
end
require 'spec_helper'

describe SalesEngine::Invoice, invoice: true do
  context "extensions" do
    describe ".pending" do
      it "returns Invoices without a successful transaction" do
        invoice = SalesEngine::Invoice.find_by_id(13)
        pending_invoice = SalesEngine::Invoice.pending

        pending_invoices.map(&:id).include?(invoice).should == true
      end
    end

    describe ".average_revenue" do
      it "returns the average of the totals of each invoice" do
        SalesEngine::Invoice.average_revenue.should == BigDecimal("12369.53")
      end
    end

    describe ".average_revenue(date)" do
      it "returns the average of the invoice revenues for that date" do
        SalesEngine::Invoice.average_revenue(Date.parse("March 17, 2012")).should == BigDecimal("11603.14")
      end
    end

    describe ".average_items" do
      it "returns the average of the number of items for each invoice" do
        SalesEngine::Invoice.average_items.should == BigDecimal("24.45")
      end
    end

    describe ".average_items(date)" do
      it "returns the average of the invoice items for that date" do
        SalesEngine::Invoice.average_items(Date.parse("March 21, 2012")).should == BigDecimal("24.29")
      end
    end
  end
end

Change test to be order independent
Change test to be order independent
