I put a file into my spec/support/images/picture.jpg. When I saved it into there, I changed the file extension of the file. Is that what is wrong?
This is my error, and I think it's because it's not getting passed the extension_white_list method in the uploader:
pry(#<StoryMainImageUploader>)> exit
2) Api::Recipes::RecipeToolsController GET index when given recipe params should have a description attribute for each recipe tool
Failure/Error: rt.story = create(:story, :with_products) if rt.story.blank?
ActiveRecord::RecordInvalid:
Validation failed: Main image is invalid. Allowed file types are jpg, jpeg, gif, and png
This is my story.rb file:
mount_uploader :main_image, StoryMainImageUploader
This is my factory:
factory :story do
title 'Pizza For Dummies'
description 'Are you dumb? Do you like pizza? Then this this is the story for you!'
status Story::Status::INCOMPLETE
main_image { Rack::Test::UploadedFile.new(File.join(Rails.root, 'spec', 'support', 'images', 'blueaproncarrierimage.jpg')) }
....
end
end
This is my uploader:
# encoding: utf-8
require 'carrierwave/processing/mime_types'
class StoryMainImageUploader < CarrierWave::Uploader::Base
include CarrierWaveDirect::Uploader
include CarrierWave::RMagick
include CarrierWave::MimeTypes
include S3DirectUploader
process :set_content_type
def store_dir
"stories/#{model.id}/main_images"
end
def extension_white_list
binding.pry
%w(jpg jpeg gif png)
end
version :medium do
process :resize_to_limit => [800, 800]
end
version :thumb do
process :resize_to_limit => [200, 200]
end
end
This is my s3directuploader:
module S3DirectUploader
attr_accessor :process_url
def bucket_url
"http://ift.tt/1XvEoY9}"
end
def bucket
AppConfigs['fog']['fog_directory']
end
def policy
Base64.encode64(policy_data.to_json).gsub("\n", '')
end
def policy_data
{
expiration: 10.hours.from_now.utc.iso8601,
conditions: ...
}
end
def signature
Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest.new('sha1'),
AppConfigs['fog']['fog_credentials']['aws_secret_access_key'], policy
)
).gsub("\n", '')
end
def acl
'public-read'
end
def to_hash
{
key: key,
bucket_url: bucket_url,
policy: policy,
signature: signature,
acl: acl,
aws_access_key_id: aws_access_key_id,
process_url: process_url
}
end
end
Any idea what is going on and what might the problem be?
Aucun commentaire:
Enregistrer un commentaire