Sha256: 22986b302fefea2f80bc623ceab71aa3e1643f8e7401298a30eb4afde0fb4c96

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe Spree::HomeController, type: :controller do
  it "provides current user to the searcher class" do
    user = mock_model(Spree.user_class, last_incomplete_spree_order: nil, spree_api_key: 'fake')
    allow(controller).to receive_messages try_spree_current_user: user
    expect_any_instance_of(Spree::Config.searcher_class).to receive(:current_user=).with(user)
    spree_get :index
    expect(response.status).to eq(200)
  end

  context "layout" do
    it "renders default layout" do
      spree_get :index
      expect(response).to render_template(layout: 'spree/layouts/spree_application')
    end

    context "different layout specified in config" do
      before { Spree::Config.layout = 'layouts/application' }

      it "renders specified layout" do
        spree_get :index
        expect(response).to render_template(layout: 'layouts/application')
      end
    end
  end

  context "index products" do
    it "calls includes when the retrieved_products object responds to it" do
      searcher = double("Searcher")
      allow(controller).to receive_messages build_searcher: searcher
      expect(searcher).to receive_message_chain("retrieve_products.includes")

      spree_get :index
    end

    it "does not call includes when it's not available" do
      searcher = double("Searcher")
      allow(controller).to receive_messages build_searcher: searcher
      allow(searcher).to receive(:retrieve_products).and_return([])

      spree_get :index

      expect(assigns(:products)).to eq([])
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_frontend-3.3.0.rc1 spec/controllers/spree/home_controller_spec.rb
spree_frontend-3.2.1 spec/controllers/spree/home_controller_spec.rb
spree_frontend-3.2.0 spec/controllers/spree/home_controller_spec.rb
spree_frontend-3.2.0.rc3 spec/controllers/spree/home_controller_spec.rb
spree_frontend-3.2.0.rc2 spec/controllers/spree/home_controller_spec.rb
spree_frontend-3.2.0.rc1 spec/controllers/spree/home_controller_spec.rb