Sha256: c8643a43bc205eaabd8a364c1dfe480aca8f75c42ecda07340e00ad5a50aa66f

Contents?: true

Size: 1006 Bytes

Versions: 2

Compression:

Stored size: 1006 Bytes

Contents

require File.expand_path(File.dirname(__FILE__) + "../../../../spec_helper")

describe ActiveRecord::Acts::ShoppingCartItem::InstanceMethods do
  let(:klass) do
    klass = Class.new
    klass.send :include, ActiveRecord::Acts::ShoppingCartItem::InstanceMethods
    klass
  end

  let(:subject) do
    subject = klass.new
    allow(subject).to receive(:save).and_return(true)
    subject
  end

  describe :subtotal do
    it "returns the quantity * price" do
      allow(subject).to receive_messages(quantity: 2, price: 33.99)
      expect(subject.subtotal).to eq(67.98)
    end
  end

  describe :update_quantity do
    it "updates the item quantity" do
      expect(subject).to receive(:quantity=).with(5)
      expect(subject).to receive(:save)
      subject.update_quantity(5)
    end
  end

  describe :update_price do
    it "updates the item price" do
      expect(subject).to receive(:price=).with(55.99)
      expect(subject).to receive(:save)
      subject.update_price(55.99)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_shopping_cart-0.4.1 spec/active_record/acts/shopping_cart_item/instance_methods_spec.rb
acts_as_shopping_cart-0.4.0 spec/active_record/acts/shopping_cart_item/instance_methods_spec.rb