Carrierwave upload works in rails console but not in spec
carrierwave, factory-bot, rspec, ruby, ruby-on-rails
Solution
Doh, the answer was my final paragraph, I forgot to run
rake db:test:load
A good example of taking a break and coming back to a problem.
Problem
I have the following model: ``` class Face < ActiveRecord::Base attr_accessible :face_index, :design, :background belongs_to :template mount_uploader :background, BackgroundUploader end ``` The 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 a background to it: ``` f = Face.create(:face_index => 0) f.background = File.open("/path/to/image.jpg") f.save! ``` That all works, but when I try to move it to rspec I'm getting 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> ``` The spec: ``` 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 ``` The factory: ``` FactoryGirl.define do factory :face do face_index 0 end end ``` I've seen that error before when uploader column was missing from the db, but if my migrations are correct for dev they should be correct for test, non? Do I need to require something in the spec to make it work? thanks!