0
我試着寫RSpec的測試我禮包自定義變量,我需要創造產品的變種。即使我看起來和rspec測試完全一樣,但它是spree核心的一部分,我似乎無法做到這一點。爲施普雷寫作測試,不能創造產品
def build_option_type_with_values(name, values)
ot = create(:option_type, :name => name)
values.each do |val|
ot.option_values.create(:name => val.downcase, :presentation => val)
end
ot
end
let(:number_size_option_type) do
size = build_option_type_with_values("number sizes", %w(1 2 3 4))
end
let(:product1) { create(:product, name: 'product1') }
it "should have variants" do
hash = {number_size_option_type.id.to_s => number_size_option_type.option_value_ids}
product1.option_values_hash = hash
product1.save
product1.reload
expect(product1.variants.length).to eq(4)
end
無論我做什麼,我的產品變體的數量總是爲零。