Sha256: e1b35721f47b030d3fd03f07ac33fccea3d511a2feedd229179ee98625bb0c51

Contents?: true

Size: 1.56 KB

Versions: 7

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe Spree::ProductsController, :type => :controller do
  let!(:product) { create(:product, :available_on => 1.year.from_now) }

  # Regression test for https://github.com/spree/spree/issues/1390
  it "allows admins to view non-active products" do
    allow(controller).to receive_messages :spree_current_user => mock_model(Spree.user_class, :has_spree_role? => true, :last_incomplete_spree_order => nil, :spree_api_key => 'fake')
    spree_get :show, :id => product.to_param
    expect(response.status).to eq(200)
  end

  it "cannot view non-active products" do
    spree_get :show, :id => product.to_param
    expect(response.status).to eq(404)
  end

  it "should provide the 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 :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

  # Regression test for https://github.com/spree/spree/issues/2249
  it "doesn't error when given an invalid referer" do
    current_user = mock_model(Spree.user_class, :has_spree_role? => true, :last_incomplete_spree_order => nil, :generate_spree_api_key! => nil)
    allow(controller).to receive_messages :spree_current_user => current_user
    request.env['HTTP_REFERER'] = "not|a$url"

    # Previously a URI::InvalidURIError exception was being thrown
    spree_get :show, :id => product.to_param
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_frontend-1.2.3 spec/controllers/spree/products_controller_spec.rb
solidus_frontend-1.2.2 spec/controllers/spree/products_controller_spec.rb
solidus_frontend-1.2.1 spec/controllers/spree/products_controller_spec.rb
solidus_frontend-1.2.0 spec/controllers/spree/products_controller_spec.rb
solidus_frontend-1.2.0.rc2 spec/controllers/spree/products_controller_spec.rb
solidus_frontend-1.2.0.rc1 spec/controllers/spree/products_controller_spec.rb
solidus_frontend-1.2.0.beta1 spec/controllers/spree/products_controller_spec.rb