Sha256: 35c43ef144c933b76dc604801e281f196f9879a818cf278a534452d05aaa170a

Contents?: true

Size: 1023 Bytes

Versions: 6

Compression:

Stored size: 1023 Bytes

Contents

require 'spec_helper'

describe "Rabl Cache", type: :request, caching: true do
  let!(:user)  { create(:admin_user) }

  before do
    create(:variant)
    user.generate_spree_api_key!
    expect(Spree::Product.count).to eq(1)
  end

  it "doesn't create a cache key collision for models with different rabl templates" do
    get "/api/v1/variants", params: { token: user.spree_api_key }
    expect(response.status).to eq(200)

    # Make sure we get a non master variant
    variant_a = JSON.parse(response.body)['variants'].select do |v|
      !v['is_master']
    end.first

    expect(variant_a['is_master']).to be false
    expect(variant_a['stock_items']).not_to be_nil

    get "/api/v1/products/#{Spree::Product.first.id}", params: { token: user.spree_api_key }
    expect(response.status).to eq(200)
    variant_b = JSON.parse(response.body)['variants'].last
    expect(variant_b['is_master']).to be false

    expect(variant_a['id']).to eq(variant_b['id'])
    expect(variant_b['stock_items']).to be_nil
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_api-3.3.0.rc1 spec/requests/rabl_cache_spec.rb
spree_api-3.2.1 spec/requests/rabl_cache_spec.rb
spree_api-3.2.0 spec/requests/rabl_cache_spec.rb
spree_api-3.2.0.rc3 spec/requests/rabl_cache_spec.rb
spree_api-3.2.0.rc2 spec/requests/rabl_cache_spec.rb
spree_api-3.2.0.rc1 spec/requests/rabl_cache_spec.rb