diff --git a/delayed_paperclip.gemspec b/delayed_paperclip.gemspec index 1c05f57..a212493 100644 --- a/delayed_paperclip.gemspec +++ b/delayed_paperclip.gemspec @@ -23,6 +23,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'appraisal' s.add_development_dependency 'rake' s.add_development_dependency 'bundler' + s.add_development_dependency 'railties' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") diff --git a/gemfiles/rails3_1.gemfile.lock b/gemfiles/rails3_1.gemfile.lock index a841091..63d0f2e 100644 --- a/gemfiles/rails3_1.gemfile.lock +++ b/gemfiles/rails3_1.gemfile.lock @@ -155,6 +155,7 @@ DEPENDENCIES delayed_paperclip! mocha rails (~> 3.1.12) + railties rake resque rspec diff --git a/gemfiles/rails3_2.gemfile.lock b/gemfiles/rails3_2.gemfile.lock index 5bcd019..0960ee9 100644 --- a/gemfiles/rails3_2.gemfile.lock +++ b/gemfiles/rails3_2.gemfile.lock @@ -153,6 +153,7 @@ DEPENDENCIES delayed_paperclip! mocha rails (~> 3.2.17) + railties rake resque rspec diff --git a/gemfiles/rails4.gemfile.lock b/gemfiles/rails4.gemfile.lock index 6c6de60..0554eb6 100644 --- a/gemfiles/rails4.gemfile.lock +++ b/gemfiles/rails4.gemfile.lock @@ -149,6 +149,7 @@ DEPENDENCIES delayed_paperclip! mocha rails (~> 4.0.3) + railties rake resque rspec diff --git a/lib/delayed_paperclip.rb b/lib/delayed_paperclip.rb index 54aec2c..96eb76d 100644 --- a/lib/delayed_paperclip.rb +++ b/lib/delayed_paperclip.rb @@ -51,9 +51,11 @@ def process_in_background(name, options = {}) paperclip_definitions[name][:delayed] = {} # Set Defaults + only_process_default = paperclip_definitions[name][:only_process] + only_process_default ||= [] { :priority => 0, - :only_process => paperclip_definitions[name][:only_process], + :only_process => only_process_default, :url_with_processing => DelayedPaperclip.options[:url_with_processing], :processing_image_url => options[:processing_image_url], :queue => nil diff --git a/lib/delayed_paperclip/attachment.rb b/lib/delayed_paperclip/attachment.rb index ad245f9..9e21b0e 100644 --- a/lib/delayed_paperclip/attachment.rb +++ b/lib/delayed_paperclip/attachment.rb @@ -13,7 +13,7 @@ def self.included(base) module InstanceMethods def delayed_options - @instance.class.paperclip_definitions[@name][:delayed] unless @instance.class.paperclip_definitions[@name].nil? + @options[:delayed] end # Attr accessor in Paperclip @@ -36,9 +36,9 @@ def delay_processing? end def split_processing? - @instance.class.paperclip_definitions[@name][:only_process] && - @instance.class.paperclip_definitions[@name][:only_process] != - delayed_options[:only_process] + options[:only_process] && + options[:only_process] != + options[:delayed][:only_process] end def processing? diff --git a/spec/delayed_paperclip/attachment_spec.rb b/spec/delayed_paperclip/attachment_spec.rb index d525154..eaf874b 100644 --- a/spec/delayed_paperclip/attachment_spec.rb +++ b/spec/delayed_paperclip/attachment_spec.rb @@ -15,7 +15,7 @@ it "returns the specific options for delayed paperclip" do dummy.image.delayed_options.should == { :priority => 0, - :only_process => nil, + :only_process => [], :url_with_processing => true, :processing_image_url => nil, :queue => nil diff --git a/spec/delayed_paperclip/class_methods_spec.rb b/spec/delayed_paperclip/class_methods_spec.rb index 03a2e50..6f7a42b 100644 --- a/spec/delayed_paperclip/class_methods_spec.rb +++ b/spec/delayed_paperclip/class_methods_spec.rb @@ -18,7 +18,7 @@ Dummy.paperclip_definitions.should == { :image => { :delayed => { :priority => 0, - :only_process => nil, + :only_process => [], :url_with_processing => true, :processing_image_url => nil, :queue => nil} @@ -35,7 +35,7 @@ Dummy.paperclip_definitions.should == { :image => { :delayed => { :priority => 0, - :only_process => nil, + :only_process => [], :url_with_processing => true, :processing_image_url => "/processing/url", :queue => nil} diff --git a/spec/delayed_paperclip_spec.rb b/spec/delayed_paperclip_spec.rb index d8a4379..3064c61 100644 --- a/spec/delayed_paperclip_spec.rb +++ b/spec/delayed_paperclip_spec.rb @@ -47,7 +47,7 @@ it "returns paperclip options regardless of version" do Dummy.paperclip_definitions.should == {:image => { :styles => { :thumbnail => "25x25" }, :delayed => { :priority => 0, - :only_process => nil, + :only_process => [], :url_with_processing => true, :processing_image_url => nil, :queue => nil} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 73c35db..4fce827 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,19 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib")) -require 'rails' require 'active_record' +require 'active_record/version' +require 'active_support' +require 'active_support/core_ext' require 'rspec' require 'mocha/api' +begin + require 'pry' +rescue LoadError + # Pry is not available, just ignore. +end + require 'paperclip/railtie' Paperclip::Railtie.insert diff --git a/test/base_delayed_paperclip_test.rb b/test/base_delayed_paperclip_test.rb index cb1fc97..ee8d05f 100644 --- a/test/base_delayed_paperclip_test.rb +++ b/test/base_delayed_paperclip_test.rb @@ -185,11 +185,16 @@ def test_delayed_paperclip_functioning_with_paperclip_only_process_option dummy.save! process_jobs end - + def test_delayed_paperclip_functioning_with_only_process_and_paperclip_only_process_option reset_class "Dummy", :with_processed => true, :only_process => [:small], :paperclip => { :only_process => [:thumbnail] } + Paperclip::Attachment.any_instance.expects(:post_process).with(:thumbnail) + Paperclip::Attachment.any_instance.expects(:post_process).with(:small).never + Paperclip::Attachment.any_instance.expects(:reprocess!).with(:small) + Paperclip::Attachment.any_instance.expects(:reprocess!).with(:thumbnail).never + dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png")) dummy.save! process_jobs diff --git a/test/test_helper.rb b/test/test_helper.rb index 3637a81..226c5f9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,10 +2,19 @@ require 'test/unit' require 'mocha/setup' require 'active_record' +require 'active_record/version' +require 'active_support' +require 'active_support/core_ext' require 'logger' require 'sqlite3' -require 'paperclip/railtie' +begin + require 'pry' +rescue LoadError + # Pry is not available, just ignore. +end + +require 'paperclip/railtie' Paperclip::Railtie.insert ROOT = File.join(File.dirname(__FILE__), '..')