diff --git a/Appraisals b/Appraisals index bb94087..8c02edb 100644 --- a/Appraisals +++ b/Appraisals @@ -9,3 +9,8 @@ end appraise "rails3_1" do gem "rails", "~> 3.1.0" end + +appraise "rails3_2" do + gem "rails", "~> 3.2.0" + gem "delayed_job_active_record" +end diff --git a/Gemfile b/Gemfile index 6d2ad7c..67f5d86 100644 --- a/Gemfile +++ b/Gemfile @@ -2,11 +2,13 @@ source "http://rubygems.org" gemspec -gem "paperclip", '2.4.5' +gem "paperclip" gem "appraisal" gem "mocha" gem "sqlite3" +gem "json", :platforms => :ruby_18 + gem "delayed_job", :require => false + gem "resque", :require => false -gem "json", :platforms => :ruby_18 \ No newline at end of file diff --git a/delayed_paperclip.gemspec b/delayed_paperclip.gemspec index 20e96fc..8168ef2 100644 --- a/delayed_paperclip.gemspec +++ b/delayed_paperclip.gemspec @@ -8,7 +8,7 @@ end.flatten spec = Gem::Specification.new do |s| s.name = %q{delayed_paperclip} - s.version = "2.4.5.1" + s.version = "2.4.5.2" s.authors = ["Jesse Storimer", "Bert Goethals"] s.summary = %q{Process your Paperclip attachments in the background.} diff --git a/gemfiles/rails2.gemfile b/gemfiles/rails2.gemfile index b65cd4d..c716573 100644 --- a/gemfiles/rails2.gemfile +++ b/gemfiles/rails2.gemfile @@ -2,13 +2,13 @@ source "http://rubygems.org" -gem "paperclip", "2.4.5" +gem "paperclip" gem "appraisal" gem "mocha" gem "sqlite3" +gem "json", :platforms=>:ruby_18 gem "delayed_job", :require=>false gem "resque", :require=>false -gem "json", :platforms=>:ruby_18 gem "rails", "~> 2.3.14" gemspec :path=>"../" \ No newline at end of file diff --git a/gemfiles/rails2.gemfile.lock b/gemfiles/rails2.gemfile.lock index d594f9a..8e6b406 100644 --- a/gemfiles/rails2.gemfile.lock +++ b/gemfiles/rails2.gemfile.lock @@ -1,7 +1,7 @@ PATH - remote: /Users/bertg/Development/delayed_paperclip + remote: /Users/tom/Development/Projects/delayed_paperclip specs: - delayed_paperclip (2.4.5.0) + delayed_paperclip (2.4.5.2) paperclip (>= 2.4.5) GEM @@ -20,7 +20,7 @@ GEM appraisal (0.3.8) bundler rake - cocaine (0.2.0) + cocaine (0.2.1) daemons (1.0.10) delayed_job (2.0.7) activesupport (~> 2.0) @@ -31,7 +31,7 @@ GEM mocha (0.10.0) metaclass (~> 0.0.1) multi_json (1.0.3) - paperclip (2.4.5) + paperclip (2.7.0) activerecord (>= 2.3.0) activesupport (>= 2.3.2) cocaine (>= 0.0.2) @@ -70,7 +70,7 @@ DEPENDENCIES delayed_paperclip! json mocha - paperclip (= 2.4.5) + paperclip rails (~> 2.3.14) resque sqlite3 diff --git a/gemfiles/rails3.gemfile b/gemfiles/rails3.gemfile index c084ae3..d59f943 100644 --- a/gemfiles/rails3.gemfile +++ b/gemfiles/rails3.gemfile @@ -2,13 +2,13 @@ source "http://rubygems.org" -gem "paperclip", "2.4.5" +gem "paperclip" gem "appraisal" gem "mocha" gem "sqlite3" +gem "json", :platforms=>:ruby_18 gem "delayed_job", :require=>false gem "resque", :require=>false -gem "json", :platforms=>:ruby_18 gem "rails", "~> 3.0.10" gemspec :path=>"../" \ No newline at end of file diff --git a/gemfiles/rails3.gemfile.lock b/gemfiles/rails3.gemfile.lock index 793f2b1..09b3942 100644 --- a/gemfiles/rails3.gemfile.lock +++ b/gemfiles/rails3.gemfile.lock @@ -1,7 +1,7 @@ PATH - remote: /Users/bertg/Development/delayed_paperclip + remote: /Users/tom/Development/Projects/delayed_paperclip specs: - delayed_paperclip (2.4.5.0) + delayed_paperclip (2.4.5.2) paperclip (>= 2.4.5) GEM @@ -39,7 +39,7 @@ GEM rake arel (2.0.10) builder (2.1.2) - cocaine (0.2.0) + cocaine (0.2.1) daemons (1.1.4) delayed_job (2.1.4) activesupport (~> 3.0) @@ -58,7 +58,7 @@ GEM mocha (0.10.0) metaclass (~> 0.0.1) multi_json (1.0.3) - paperclip (2.4.5) + paperclip (2.7.0) activerecord (>= 2.3.0) activesupport (>= 2.3.2) cocaine (>= 0.0.2) @@ -116,7 +116,7 @@ DEPENDENCIES delayed_paperclip! json mocha - paperclip (= 2.4.5) + paperclip rails (~> 3.0.10) resque sqlite3 diff --git a/gemfiles/rails3_1.gemfile b/gemfiles/rails3_1.gemfile index a57068a..36a3650 100644 --- a/gemfiles/rails3_1.gemfile +++ b/gemfiles/rails3_1.gemfile @@ -2,13 +2,13 @@ source "http://rubygems.org" -gem "paperclip", "2.4.5" +gem "paperclip" gem "appraisal" gem "mocha" gem "sqlite3" +gem "json", :platforms=>:ruby_18 gem "delayed_job", :require=>false gem "resque", :require=>false -gem "json", :platforms=>:ruby_18 gem "rails", "~> 3.1.0" gemspec :path=>"../" \ No newline at end of file diff --git a/gemfiles/rails3_1.gemfile.lock b/gemfiles/rails3_1.gemfile.lock index 3d11b89..07d5af4 100644 --- a/gemfiles/rails3_1.gemfile.lock +++ b/gemfiles/rails3_1.gemfile.lock @@ -1,7 +1,7 @@ PATH - remote: /Users/bertg/Development/delayed_paperclip + remote: /Users/tom/Development/Projects/delayed_paperclip specs: - delayed_paperclip (2.4.5.0) + delayed_paperclip (2.4.5.2) paperclip (>= 2.4.5) GEM @@ -40,7 +40,7 @@ GEM rake arel (2.2.1) builder (3.0.0) - cocaine (0.2.0) + cocaine (0.2.1) daemons (1.1.4) delayed_job (2.1.4) activesupport (~> 3.0) @@ -58,7 +58,7 @@ GEM mocha (0.10.0) metaclass (~> 0.0.1) multi_json (1.0.3) - paperclip (2.4.5) + paperclip (2.7.0) activerecord (>= 2.3.0) activesupport (>= 2.3.2) cocaine (>= 0.0.2) @@ -128,7 +128,7 @@ DEPENDENCIES delayed_paperclip! json mocha - paperclip (= 2.4.5) + paperclip rails (~> 3.1.0) resque sqlite3 diff --git a/gemfiles/rails3_2.gemfile b/gemfiles/rails3_2.gemfile new file mode 100644 index 0000000..a4645c9 --- /dev/null +++ b/gemfiles/rails3_2.gemfile @@ -0,0 +1,15 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "paperclip" +gem "appraisal" +gem "mocha" +gem "sqlite3" +gem "json", :platforms=>:ruby_18 +gem "delayed_job", :require=>false +gem "resque", :require=>false +gem "rails", "~> 3.2.0" +gem "delayed_job_active_record" + +gemspec :path=>"../" \ No newline at end of file diff --git a/gemfiles/rails3_2.gemfile.lock b/gemfiles/rails3_2.gemfile.lock new file mode 100644 index 0000000..c2f13e6 --- /dev/null +++ b/gemfiles/rails3_2.gemfile.lock @@ -0,0 +1,134 @@ +PATH + remote: /Users/tom/Development/Projects/delayed_paperclip + specs: + delayed_paperclip (2.4.5.2) + paperclip (>= 2.4.5) + +GEM + remote: http://rubygems.org/ + specs: + actionmailer (3.2.2) + actionpack (= 3.2.2) + mail (~> 2.4.0) + actionpack (3.2.2) + activemodel (= 3.2.2) + activesupport (= 3.2.2) + builder (~> 3.0.0) + erubis (~> 2.7.0) + journey (~> 1.0.1) + rack (~> 1.4.0) + rack-cache (~> 1.1) + rack-test (~> 0.6.1) + sprockets (~> 2.1.2) + activemodel (3.2.2) + activesupport (= 3.2.2) + builder (~> 3.0.0) + activerecord (3.2.2) + activemodel (= 3.2.2) + activesupport (= 3.2.2) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activeresource (3.2.2) + activemodel (= 3.2.2) + activesupport (= 3.2.2) + activesupport (3.2.2) + i18n (~> 0.6) + multi_json (~> 1.0) + appraisal (0.4.1) + bundler + rake + arel (3.0.2) + builder (3.0.0) + cocaine (0.2.1) + delayed_job (3.0.1) + activesupport (~> 3.0) + delayed_job_active_record (0.3.2) + activerecord (> 2.1.0) + delayed_job (~> 3.0.0) + erubis (2.7.0) + hike (1.2.1) + i18n (0.6.0) + journey (1.0.3) + json (1.6.5) + mail (2.4.1) + i18n (>= 0.4.0) + mime-types (~> 1.16) + treetop (~> 1.4.8) + metaclass (0.0.1) + mime-types (1.17.2) + mocha (0.10.5) + metaclass (~> 0.0.1) + multi_json (1.1.0) + paperclip (2.7.0) + activerecord (>= 2.3.0) + activesupport (>= 2.3.2) + cocaine (>= 0.0.2) + mime-types + polyglot (0.3.3) + rack (1.4.1) + rack-cache (1.1) + rack (>= 0.4) + rack-protection (1.2.0) + rack + rack-ssl (1.3.2) + rack + rack-test (0.6.1) + rack (>= 1.0) + rails (3.2.2) + actionmailer (= 3.2.2) + actionpack (= 3.2.2) + activerecord (= 3.2.2) + activeresource (= 3.2.2) + activesupport (= 3.2.2) + bundler (~> 1.0) + railties (= 3.2.2) + railties (3.2.2) + actionpack (= 3.2.2) + activesupport (= 3.2.2) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (~> 0.14.6) + rake (0.9.2.2) + rdoc (3.12) + json (~> 1.4) + redis (2.2.2) + redis-namespace (1.0.3) + redis (< 3.0.0) + resque (1.20.0) + multi_json (~> 1.0) + redis-namespace (~> 1.0.2) + sinatra (>= 0.9.2) + vegas (~> 0.1.2) + sinatra (1.3.2) + rack (~> 1.3, >= 1.3.6) + rack-protection (~> 1.2) + tilt (~> 1.3, >= 1.3.3) + sprockets (2.1.2) + hike (~> 1.2) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sqlite3 (1.3.5) + thor (0.14.6) + tilt (1.3.3) + treetop (1.4.10) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.31) + vegas (0.1.11) + rack (>= 1.0.0) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + delayed_job + delayed_job_active_record + delayed_paperclip! + json + mocha + paperclip + rails (~> 3.2.0) + resque + sqlite3 diff --git a/lib/delayed_paperclip.rb b/lib/delayed_paperclip.rb index c8e0226..1276c6e 100644 --- a/lib/delayed_paperclip.rb +++ b/lib/delayed_paperclip.rb @@ -1,5 +1,6 @@ require 'delayed_paperclip/jobs' require 'delayed_paperclip/attachment' +require 'delayed_paperclip/url_generator' require 'delayed_paperclip/railtie' module DelayedPaperclip diff --git a/lib/delayed_paperclip/attachment.rb b/lib/delayed_paperclip/attachment.rb index 24969e2..bf135fa 100644 --- a/lib/delayed_paperclip/attachment.rb +++ b/lib/delayed_paperclip/attachment.rb @@ -7,7 +7,6 @@ def self.included(base) base.alias_method_chain :post_processing, :delay base.alias_method_chain :post_processing=, :delay base.alias_method_chain :save, :prepare_enqueueing - base.alias_method_chain :most_appropriate_url, :processed base.alias_method_chain :post_process_styles, :processing end @@ -39,19 +38,20 @@ def processing? def process_delayed! self.job_is_processing = true + self.post_processing = true + reprocess! + self.job_is_processing = false end def post_process_styles_with_processing(*args) post_process_styles_without_processing(*args) - # update_column is available in rails 3.1 instead we can do this to update the attribute without callbacks - - #instance.update_column("#{name}_processing", false) if instance.respond_to?(:"#{name}_processing?") if instance.respond_to?(:"#{name}_processing?") instance.send("#{name}_processing=", false) - instance.class.update_all({ "#{name}_processing" => false }, instance.class.primary_key => instance.id) + + instance.class.update_all({ "#{name}_processing" => false, "#{name}_updated_at" => Time.at(self.updated_at) }, instance.class.primary_key => instance.id) end end @@ -64,14 +64,6 @@ def save_with_prepare_enqueueing end end - def most_appropriate_url_with_processed - if original_filename.nil? || delayed_default_url? - default_url - else - @options.url - end - end - def delayed_default_url? !(job_is_processing || dirty? || !delayed_options.try(:[], :url_with_processing) || !(@instance.respond_to?(:"#{name}_processing?") && processing?)) end @@ -79,3 +71,5 @@ def delayed_default_url? end end end + + diff --git a/lib/delayed_paperclip/jobs/resque.rb b/lib/delayed_paperclip/jobs/resque.rb index 67ac9ef..5152acb 100644 --- a/lib/delayed_paperclip/jobs/resque.rb +++ b/lib/delayed_paperclip/jobs/resque.rb @@ -14,4 +14,4 @@ def self.perform(instance_klass, instance_id, attachment_name) end end end -end \ No newline at end of file +end diff --git a/lib/delayed_paperclip/url_generator.rb b/lib/delayed_paperclip/url_generator.rb new file mode 100644 index 0000000..3bc2767 --- /dev/null +++ b/lib/delayed_paperclip/url_generator.rb @@ -0,0 +1,13 @@ +module Paperclip + class UrlGenerator + + def most_appropriate_url + if @attachment.original_filename.nil? || @attachment.delayed_default_url? + default_url + else + @attachment_options[:url] + end + end + + end +end \ No newline at end of file diff --git a/test/base_delayed_paperclip_test.rb b/test/base_delayed_paperclip_test.rb index 6195262..e98be08 100644 --- a/test/base_delayed_paperclip_test.rb +++ b/test/base_delayed_paperclip_test.rb @@ -70,6 +70,15 @@ def test_processed_true_when_delayed_jobs_completed assert !dummy.image_processing?, "Image should no longer be processing" end + def test_post_processing_value_updated_for_reprocessing + Paperclip::Attachment.any_instance.expects(:post_processing=).with(true) + + dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png")) + dummy.save! + process_jobs + assert !dummy.image.post_processing, "Image should no longer have post processing marked" + end + def test_unprocessed_image_returns_missing_url dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png")) dummy.save!