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