5
我有以下型號:Carrierwave上傳作品在軌控制檯,但不規範
class Face < ActiveRecord::Base
attr_accessible :face_index, :design, :background
belongs_to :template
mount_uploader :background, BackgroundUploader
end
的BackgroundUploader:
class BackgroundUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
當我啓動軌道控制檯,我可以創建頭像和保存背景:
f = Face.create(:face_index => 0)
f.background = File.open("/path/to/image.jpg")
f.save!
這一切工作,但當我嘗試將其移動到rspec我得到失敗:
Failures:
1) Face A new face
Failure/Error: @face.background = File.open(image_path)
NoMethodError:
undefined method `background_will_change!' for #<Face:0x007ff63d9f7410>
該規範:
describe Face do
before(:each) do
image_path = Rails.root.join('spec/support/images', '02.jpg').to_s
@face = FactoryGirl.create(:face)
@face.background = File.open(image_path)
@face.save!
end
describe "A new face" do
it { should belong_to(:template) }
end
end
工廠:
FactoryGirl.define do
factory :face do
face_index 0
end
end
我已經看到了,當上傳柱從數據庫丟失之前的錯誤,但如果我的遷移是正確的dev他們應該是正確的測試,非?我是否需要規範中的某些內容才能使其工作?
謝謝!
謝謝!這正是我需要許多破碎的規格才能工作的! – BenU