I have the following model:
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
When I launch the rails console, I can create a Face and save the background for it:
f = Face.create(:face_index => 0)
f.background = File.open("/path/to/image.jpg")
f.save!
Everything works, but when I try to move it to rspec, I get a failure:
Failures:
1) Face A new face
Failure/Error: @face.background = File.open(image_path)
NoMethodError:
undefined method `background_will_change!' for #<Face:0x007ff63d9f7410>
Specification:
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
factory:
FactoryGirl.define do
factory :face do
face_index 0
end
end
I saw this error before the loader column was missing in db, but if my migrations are correct for dev, they should be correct for testing, not? Do I need to require something in the specification to make it work?
thank!
source
share