New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApplicationUploader.enable_processing takes priority over SubclassedUploader.enable_processing #1349

Closed
shekibobo opened this Issue Mar 20, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@shekibobo
Contributor

shekibobo commented Mar 20, 2014

I have an ApplicationUploader and a DocumentUploader. In my specs:

require 'carrierwave/test/matchers'

describe ApplicationUploader do
  include CarrierWave::Test::Matchers

  context "with a pdf" do
    before(:all) do
      puts "\n-- Testing Uploader: ApplicationUploader\n"
      ApplicationUploader.enable_processing = true
      @uploader = ApplicationUploader.new(Fabricate.build(:media_item), :attachment)
      @uploader.store!(File.open(Rails.root.join("spec", "support_files", "sample.pdf")))
    end

    after(:all) do
      ApplicationUploader.enable_processing = false
      @uploader.remove!
    end

    # ...
  end
end
require 'spec_helper'
require 'carrierwave/test/matchers'

describe DocumentUploader do
  include CarrierWave::Test::Matchers

  context "with a pdf" do
    before(:all) do
      puts "\n-- Testing Uploader: DocumentUploader\n"
      # ApplicationUploader.enable_processing = true
      DocumentUploader.enable_processing = true
      @uploader = DocumentUploader.new(Fabricate.build(:media_document), :attachment)
      @uploader.store!(File.open(Rails.root.join("spec", "support_files", "sample.pdf")))
    end

    after(:all) do
      # ApplicationUploader.enable_processing = false
      DocumentUploader.enable_processing = false
      @uploader.remove!
    end
  end
end

If application_uploader_spec runs before document_uploader_spec, document_uploader_spec will not run processing, despite the processing being enabled for the subclassed uploader. If the document_uploader_spec runs first, all is well. In order to get specs to pass, the commented line needs to run to enable processing on both ApplicationUploader and DocumentUploader.

I believe this is also the case when using config.enable_processing - processing will use the highest-level value to determine whether processing should occur, and cannot be overridden by the subclasses.

I don't know if this is actually an issue - which is a better way to go - but I've spent a few hours racking my brain over this and thought that it should at least be documented somewhere. It seems like if I can toggle processing at the instance level, I should be able to toggle processing at the class level as well, rather than the parent class or configuration rule all.

@thomasfedb

This comment has been minimized.

Show comment
Hide comment
@thomasfedb

thomasfedb Nov 16, 2015

Contributor

@shekibobo If you believe this is a bug, please submit a new issue. New features are welcome if you are able to provide an implementation.

Contributor

thomasfedb commented Nov 16, 2015

@shekibobo If you believe this is a bug, please submit a new issue. New features are welcome if you are able to provide an implementation.

@thomasfedb thomasfedb closed this Nov 16, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment