Sha256: fc78a047c7a22e8b0edd23cdef24c222862a8d85452d878211656dbeccb88757

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'rails_helper'

module Shopper
  RSpec.describe CartPage::AddProduct do
    context 'book exists in current_order' do
      let!(:order) { create :order, :with_items, number_of_items: 3 }
      subject { CartPage::AddProduct.new(type: 'product', id: 1, quantity: 100) }

      before do
        caller = double('some controller')
        allow(caller).to receive(:current_order) { order }
        subject.instance_variable_set(:@caller, caller)
      end

      it 'sums quantities' do
        expect { subject.call }.to change {
          order.reload
               .order_items
               .sort_by(&:product_id)
               .collect(&:quantity)
        }.from([1, 1, 1]).to([101, 1, 1])
      end

      it 'dont add new order_item' do
        expect { subject.call }.not_to change {
          order.reload
               .order_items
               .sort_by(&:product_id)
               .collect(&:product_id)
        }
      end

      it 'broadcasts ok' do
        expect(subject).to receive(:broadcast).with(:ok)
        subject.call
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoppper-0.1.0 spec/commands/add_product_spec.rb