Sha256: cb69de2a715196ce49ab2e506c6fa4aaf2995efa208d1cccb080b43135faa1b8

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

require 'rails_helper'

module Shopper
  RSpec.describe CartController, type: :controller do
    routes { Shopper::Engine.routes }

    before { create_list :product, 10 }
    let(:coupon) { create :coupon }
    let(:second_coupon) { create :coupon }

    describe 'GET #add_product' do
      context 'valid params' do
        it 'renders js' do
          expect do
            post :add_product, params: { type: 'product', id: 1 }, format: :js, xhr: true
          end.to change { OrderItem.count }.by(1)

          expect(response).to render_template :add_product
        end
      end

      context 'invalid params' do
        it 'redirect via js' do
          expect do
            post :add_product, params: { type: 'product', id: 300 }, format: :js, xhr: true
          end.not_to change { OrderItem.count }

          # TODO: not a xhr
          # expect(response.body).to include 'Turbolinks.visit("http://test.host'
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoppper-0.1.0 spec/controllers/cart_controller_spec.rb