Sha256: abe7fdbbcc0f2524f1598893f2d03ac83dacb9809c646351f4fadd765c0303d4

Contents?: true

Size: 1.84 KB

Versions: 6

Compression:

Stored size: 1.84 KB

Contents

require 'test_helper'

class CreditTest < ActiveSupport::TestCase
  should_validate_presence_of :amount
  should_validate_numericality_of :amount
  should_validate_presence_of :description
  context "order instance with discounts" do
    setup do
      @order = Factory(:order)
      @credit = Factory(:credit, :amount => 2.00, :order => @order)
      @order.save
    end

    should "set positive credit_total" do
      assert_equal("2.0", @order.credit_total.to_s)
    end

    should "not set negative charge_total" do
      assert_equal("0.0", @order.charge_total.to_s)
    end

    should "set negative adjustment_total" do
      assert_equal("-2.0", @order.adjustment_total.to_s)
    end

    should "decrase total" do
      assert_equal(@order.item_total - 2.00, @order.total)
    end

    context "when adding another discount" do
      setup do
        Factory(:credit, :amount => 1.00, :order => @order)
        @order.save
      end

      should_change("@order.total", :by => BigDecimal("-1.00")) { @order.total }
      should_change("@order.credit_total", :by => BigDecimal("1.00")) { @order.credit_total }
      should_not_change("@order.item_total") { @order.item_total }
    end

    context "when destroying a credit" do
      setup do
        @order.credits.destroy_all
        @order.save
      end
      should_change("@order.total", :by => BigDecimal("2.00")) { @order.total }
      should_change("@order.credit_total", :by => BigDecimal("-2.00")) { @order.credit_total }
      should_not_change("@order.item_total") { @order.item_total }
    end
  end
  
  context "Credit#calculate_adjustment" do
    setup { @coupon_credit = Factory(:coupon_credit) }
    context "with empty line items" do
      setup { @coupon_credit.order.line_items.clear }
      should "return nil" do
        assert_equal 0, @coupon_credit.calculate_adjustment
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
spree-enriquez-0.9.4 test/unit/credit_test.rb
spree-0.9.4 test/unit/credit_test.rb
spree-0.9.3 test/unit/credit_test.rb
spree-0.9.2 test/unit/credit_test.rb
spree-0.9.1 test/unit/credit_test.rb
spree-0.9.0 test/unit/credit_test.rb