سؤال

I have carrierwave set up and it processes my images fine. I get nicely resized thumb versions in a subfolder and all that. Both from my frontend (HTML) and from my rails console. I use MiniMagic

But in my rspec the thumb test fails always.

describe 'processed images' do
  before(:each) do
    AttachmentUploader.enable_processing = true
    AttachmentUploader.enable_processing = true
    @uploader = AttachmentUploader.new(@post, :image)
    @uploader.store!(File.open(@file))
  end

  after(:each) do
    @uploader.remove!
    AttachmentUploader.enable_processing = false
  end

  describe 'the thumb version' do
    it "should scale down ane image to be exactly 50 by 50 pixels" do
      @uploader.recreate_versions!
      @uploader.thumb.should have_dimensions(50, 50)
    end
  end

@file is a file found in fixtures. It is found and attached (other tests pass). And if I comment out the line @uploader.remove!, It leaves a file in e.g. .../public/uploads/post/image/thumb_fig.png. That file, however is not resized. When invoking the same sequence trough rails console it gets resized just fine.

Am I missing something in my specs? Do I need to set a special flag? Force a certain method to be ran?

هل كانت مفيدة؟

المحلول

a little late to this party but working on something similar myself. From what I can tell your test looks fine although I believe @uploader.recreate_Versions! is unnecessary. Otherwise check to make sure that you do have a call to process in your Uploader class and that you include CarrierWave::Test::Matchers in your tests

نصائح أخرى

Make sure you have enabled processing for Carrierwave in config/initializers/carrierwave.rb.

It should read:

config.enable_processing = true
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top