Sha256: 7d31d72293b3b80bc9c1b89003ab24889696fb8f67dab763efb3565a388d4db8

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require 'rails_helper'

RSpec.describe TbCommerce::ProductSkuOption, type: :model do

  before(:each) do
    sizes = FactoryGirl.create(:tb_commerce_option_set, :name => 'Size')
    @small = sizes.options.create(:value => 'Small')

    colors = FactoryGirl.create(:tb_commerce_option_set, :name => 'Color')
    @red = colors.options.create(:value => 'Red')

    @product = FactoryGirl.create(:tb_commerce_product)
    @product.option_sets = [sizes] # NOTE: "Color" option set left out intentionally!
  end

  describe '#product_supports_supplied_option' do
    it 'should set the options to the sku' do
      sku = FactoryGirl.create(:tb_commerce_product_sku, :product => @product)
      sku.options = [@small]
      sku.reload
      expect(sku.options.length).to eq(1)
    end

    it 'should not allow an unsupported option to be saved' do
      sku = FactoryGirl.create(:tb_commerce_product_sku, :product => @product)
      expect{
        sku.options = [@red]
      }.to raise_error(ActiveRecord::RecordInvalid)
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_commerce-0.0.4 spec/models/tb_commerce/product_sku_option_spec.rb
tb_commerce-0.0.3 spec/models/tb_commerce/product_sku_option_spec.rb
tb_commerce-0.0.2 spec/models/tb_commerce/product_sku_option_spec.rb