I have an Artwork model with an image attribute where Carrierwave is mounted. While writing controller specs I realized that the image field stays blank, even when I thought I was passing in a file object.
My debug info tells me that the problem is with the image attribute I have CarrierWave mounted on, and not something else. I don't think I'm passing in the information it needs, but I don't know what to try.
Here's the the controller action, with some debug information to identify the problem:
def create
@artwork = @imageable.artworks.new(params[:artwork])
logger.debug "Artwork should be valid: #{@artwork.valid?}"
logger.debug "Errors: #{@artwork.errors.full_messages}"
if @artwork.save
flash[:success] = "Artwork created."
redirect_to [@imageable, :artworks]
else
flash[:error] = "Artwork not created."
render :new
end
end
In the test log I see this after running my specs:
Processing by ArtworksController#create as HTML
Parameters: {"artwork"=>{"image"=>"#<File:0x4515480>", "title"=>"Portrait","year"=>"2012", "surface_type"=>"canvas", "size"=>"10 x 10", "price"=>"100.0", "for_sale"=>false, "prints_available"=>false, "notes"=>"extra notes"}, "file"=>"#<File:0x46c6938>", "originals_gallery_id"=>"1"}
[1m[36mOriginalsGallery Load (0.0ms)[0m [1mSELECT "originals_galleries".* FROM "originals_galleries" WHERE "originals_galleries"."id" = ? LIMIT 1[0m [["id", "1"]]
Artwork should be valid: false
Errors: ["Image can't be blank"]
Any thoughts, please? Is there a controller param I'm forgetting to set?