Sha256: a8ccb932b708ae570828276e505ec273d3c1ab08b02f902a8fd9e6602c641c92

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

require 'test_helper'

class InventoryUnitTest < ActiveSupport::TestCase
  context InventoryUnit do
    context "when sold" do
      setup do
        line_item = Factory(:line_item, :quantity => 5)
        @order = line_item.order.reload
        InventoryUnit.sell_units(@order)
      end

      should_change("InventoryUnit.count", :by => 5) { InventoryUnit.count }
      context "when sold (again - b/c of unexpected error) " do
        setup do
          @order.state = "in_progress"
          InventoryUnit.sell_units(@order)
        end
        should_not_change("InventoryUnit.count") { InventoryUnit.count }
      end

      context "and line_item quantity is increased" do
        setup do
          @line_item = @order.line_items[0]
          @line_item.update_attribute(:quantity, @line_item.quantity + 1)
          InventoryUnit.adjust_units(@order)
        end

        should_change("InventoryUnit.count", :from => 5, :to => 6) { InventoryUnit.count }
      end

      context "and line_item quantity is decreased" do
        setup do
          @line_item = @order.line_items[0]
          @line_item.update_attribute(:quantity, @line_item.quantity - 1)
          InventoryUnit.adjust_units(@order)
        end

        should_change("InventoryUnit.count", :from => 5, :to => 4) { InventoryUnit.count }
      end

      context "and a line_item is destroyed" do
        setup do
          @line_item = @order.line_items[0].destroy
          @line_item.destroy
          InventoryUnit.adjust_units(@order.reload)
        end

        should_change("InventoryUnit.count", :from => 5, :to => 0) { InventoryUnit.count }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree-0.11.4 test/unit/inventory_unit_test.rb
spree-0.11.3 test/unit/inventory_unit_test.rb
spree-0.11.2 test/unit/inventory_unit_test.rb
spree-0.11.1 test/unit/inventory_unit_test.rb
spree-0.11.0 test/unit/inventory_unit_test.rb