Sha256: abc5bfa20bf79a8f105963c01d55c8602da5bff854b0692fe31e8fcc2b9cbdee

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

module Spree
  module Admin
    describe StockItemsController, type: :controller do
      stub_authorization!

      describe "#create" do
        let!(:variant) { create(:variant) }
        let!(:stock_location) { variant.stock_locations.first }
        let(:stock_item) { variant.stock_items.first }
        let!(:user) { create :user }

        before { expect(controller).to receive(:spree_current_user).and_return(user) }
        before { request.env["HTTP_REFERER"] = "product_admin_page" }

        subject do
          post :create, { variant_id: variant, stock_location_id: stock_location, stock_movement: { quantity: 1, stock_item_id: stock_item.id } }
        end

        it "creates a stock movement with originator" do
          expect { subject }.to change { Spree::StockMovement.count }.by(1)
          stock_movement = Spree::StockMovement.last
          expect(stock_movement.originator_type).to eq "Spree::LegacyUser"
        end
      end

      describe "#index" do
        let!(:variant_1) { create(:variant) }
        let!(:variant_2) { create(:variant) }

        context "with product_slug param" do
          it "scopes the variants by the product" do
            get :index, product_slug: variant_1.product.slug
            expect(assigns(:variants)).to include variant_1
            expect(assigns(:variants)).not_to include variant_2
          end
        end

        context "without product_slug params" do
          it "allows all accessible variants to be returned" do
            get :index
            expect(assigns(:variants)).to include variant_1
            expect(assigns(:variants)).to include variant_2
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
solidus_backend-1.4.2 spec/controllers/spree/admin/stock_items_controller_spec.rb
solidus_backend-1.4.1 spec/controllers/spree/admin/stock_items_controller_spec.rb
solidus_backend-1.4.0 spec/controllers/spree/admin/stock_items_controller_spec.rb
solidus_backend-1.4.0.rc1 spec/controllers/spree/admin/stock_items_controller_spec.rb
solidus_backend-1.4.0.beta1 spec/controllers/spree/admin/stock_items_controller_spec.rb