Ben*_*enU 19 rspec ruby-on-rails carrierwave ruby-on-rails-3.1
我正在使用carrierwave制作rails 3.1应用程序将文件上传到aws s3.我已按照carrierwave github存储库上的说明操作,现在可以将文件上传到我的aws存储桶.这是让我陷入困境的测试.在过去的两天里,我一直在谷歌搜索和修改,使用我发现的所有其他问答,但我终于哭了'妈妈'.这是我得到的:
/app/uploaders/image_file_uploader.rb
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
Run Code Online (Sandbox Code Playgroud)
/config/initializers/carrierwave.rb
if Rails.env.test? or Rails.env.cucumber?
CarrierWave.configure do |config|
config.storage = :file
config.enable_processing = false
end
end
Run Code Online (Sandbox Code Playgroud)
/spec/uploaders/image_file_uploader_spec.rb
require 'spec_helper'
require 'support/fog_helper'
require 'carrierwave/test/matchers'
describe ImageFileUploader do
include CarrierWave::Test::Matchers
before do
ImageFileUploader.enable_processing = true
@user = Factory(:user, :email => "photo_taker@example.edu")
@uploader = ImageFileUploader.new(@user, Factory(:image))
@uploader.store!(File.open("#{Rails.root}/tmp/uploads/#{Rails.env}/images/"))
end
after do
@uploader.remove!
ImageFileUploader.enable_processing = false
end
context 'the tiny version' do
it "should scale down a landscape image to be exactly 50 by 50 pixels" do
@uploader.tiny.should have_dimensions(50, 50)
end
end
Run Code Online (Sandbox Code Playgroud)
投机/ factories.rb
Factory.define :image do |image|
include ActionDispatch::TestProcess
image.date_taken "Sun, 09 Oct 2011"
image.time_taken "2000-01-01 03:41:00 UTC"
image.image_file fixture_file_upload('spec/support/test_images/audi.png', 'image/png')
image.taken_by "John Doe"
image.collection "N/A"
image.comments "Beautiful day!"
image.association :user
end
Run Code Online (Sandbox Code Playgroud)
虽然我的/ public/uploads/tmp /正在填充我正在测试的代码的'tiny'(和其他版本),但测试仍然失败,并显示以下错误消息:
1)ImageFileUploader小版本应该缩小横向图像,精确到50乘50像素
Failure/Error: @uploader = ImageFileUploader.new(@user, Factory(:image))
Excon::Errors::NotFound:
Expected(200) <=> Actual(404 Not Found)
request => {:expects=>200}
response => #<Excon::Response:0x0000010569f928 @body="", @headers={}, @status=404>
# ./spec/uploaders/image_file_uploader_spec.rb:11:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
我知道上述意味着rspec没有找到我的测试桶.任何人都对我做错了什么有任何想法?
对于任何新的线索都会非常感激.
更新:10/11/11文件上传工作,但我已经陷入困境,弄清楚如何让涉及图像的测试通过.在短期内,我将使用占位符图像,因为我充实了我的应用程序的其余部分并稍后返回.一旦我搞清楚了,我会发布进一步的更新.(但是,如果您有任何见解,请留下任何想法.)
Jak*_*b W 15
你试过这个吗?
在/app/uploaders/image_file_uploader.rb删除storage :fog
在/config/initializers/carrierwave.rb添加了类似的配置块生产为你的测试和黄瓜,并设置config.storage = :fog在那里.
| 归档时间: |
|
| 查看次数: |
8364 次 |
| 最近记录: |