From caa7c22b5a48a9bb7647b8a3eb71764d82399440 Mon Sep 17 00:00:00 2001 From: maclover7 Date: Fri, 28 Aug 2015 17:49:59 -0400 Subject: [PATCH 1/5] Add Rails master appraisals in preparation for Rails 5 - Also bump Travis Ruby 2.2.x version to 2.2.4 --- .travis.yml | 18 ++++++++++++++++-- Appraisals | 14 ++++++++++++-- README.md | 16 +++++++++++----- gemfiles/4.2.awsv2.0.gemfile | 6 +++--- gemfiles/4.2.awsv2.1.gemfile | 4 ++-- gemfiles/4.2.awsv2.gemfile | 20 ++++++++++++++++++++ gemfiles/5.0.awsv2.0.gemfile | 17 +++++++++++++++++ gemfiles/5.0.awsv2.1.gemfile | 17 +++++++++++++++++ gemfiles/5.0.awsv2.gemfile | 25 +++++++++++++++++++++++++ lib/paperclip/callbacks.rb | 8 ++++---- spec/support/model_reconstruction.rb | 10 +++++++++- 11 files changed, 136 insertions(+), 19 deletions(-) create mode 100644 gemfiles/4.2.awsv2.gemfile create mode 100644 gemfiles/5.0.awsv2.0.gemfile create mode 100644 gemfiles/5.0.awsv2.1.gemfile create mode 100644 gemfiles/5.0.awsv2.gemfile diff --git a/.travis.yml b/.travis.yml index 47d00e916..0836d2053 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,26 @@ rvm: - 2.1 - - 2.2 + - 2.2.2 script: "bundle exec rake clean spec cucumber" gemfile: - - gemfiles/4.2.awsv2.1.gemfile - gemfiles/4.2.awsv2.0.gemfile + - gemfiles/4.2.awsv2.1.gemfile + - gemfiles/5.0.awsv2.0.gemfile + - gemfiles/5.0.awsv2.1.gemfile + +matrix: + fast_finish: true + exclude: + - gemfile: gemfiles/5.0.awsv2.0.gemfile + rvm: 2.0 + - gemfile: gemfiles/5.0.awsv2.1.gemfile + rvm: 2.0 + - gemfile: gemfiles/5.0.awsv2.0.gemfile + rvm: 2.1 + - gemfile: gemfiles/5.0.awsv2.1.gemfile + rvm: 2.1 sudo: false cache: bundler diff --git a/Appraisals b/Appraisals index 0570b5899..a3172e6d1 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,8 @@ +appraise "4.2.awsv2.0" do + gem "rails", "~> 4.2.0" + gem "aws-sdk", "~> 2.0.0" +end + appraise "4.2.awsv2.1" do gem "rails", "~> 4.2.0" gem "aws-sdk", "~> 2.1.0" @@ -7,11 +12,16 @@ appraise "4.2.awsv2.1" do end end -appraise "4.2.awsv2.0" do - gem "rails", "~> 4.2.0" +appraise "5.0.awsv2.0" do + gem "rails", "5.0.0.beta3" gem "aws-sdk", "~> 2.0.0" group :development, :test do gem 'mime-types', '>= 1.16', '< 4' end end + +appraise "5.0.awsv2.1" do + gem "rails", "5.0.0.beta3" + gem "aws-sdk", "~> 2.1.0" +end diff --git a/README.md b/README.md index d66b6f64f..4a6b67186 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ Paperclip ========= +## Documentation valid for `master` branch + +Please check the documentation for the paperclip version you are using: +https://github.com/thoughtbot/paperclip/releases + +--- + [![Build Status](https://secure.travis-ci.org/thoughtbot/paperclip.svg?branch=master)](http://travis-ci.org/thoughtbot/paperclip) [![Dependency Status](https://gemnasium.com/thoughtbot/paperclip.svg?travis)](https://gemnasium.com/thoughtbot/paperclip) [![Code Climate](https://codeclimate.com/github/thoughtbot/paperclip.svg)](https://codeclimate.com/github/thoughtbot/paperclip) @@ -71,9 +78,8 @@ Requirements ### Ruby and Rails -Paperclip now requires Ruby version **>= 2.0.0** and Rails version **3.2, >= 4.1** (Only if you're going to use Paperclip with Ruby on Rails.) - -If you're still on Ruby 1.8.7 or Ruby on Rails 2.3.x, you can still use Paperclip 2.7.x with your project. Also, everything in this README might not apply to your version of Paperclip, and you should read [the README for version 2.7](http://www.rubydoc.info/gems/paperclip/2.7.0) instead. +Paperclip now requires Ruby version **>= 2.1** and Rails version **>= 4.2** +(only if you're going to use Paperclip with Ruby on Rails.) ### Image Processor @@ -100,7 +106,7 @@ to install GhostScript. On Mac OS X, you can also install that using Homebrew: brew install gs -If you're on Ubuntu (or any Debian base Linux distribution), you'll want to run +If you are on Ubuntu (or any Debian base Linux distribution), you'll want to run the following with apt-get: sudo apt-get install imagemagick -y @@ -153,7 +159,7 @@ Paperclip is distributed as a gem, which is how it should be used in your app. Include the gem in your Gemfile: ```ruby -gem "paperclip", "~> 4.3" +gem "paperclip", "~> 5.0" ``` Or, if you want to get the latest, you can get master from the main paperclip repository: diff --git a/gemfiles/4.2.awsv2.0.gemfile b/gemfiles/4.2.awsv2.0.gemfile index ef705dfd6..83ffed5d9 100644 --- a/gemfiles/4.2.awsv2.0.gemfile +++ b/gemfiles/4.2.awsv2.0.gemfile @@ -2,16 +2,16 @@ source "https://rubygems.org" -gem "sqlite3", "~> 1.3.8", platforms: :ruby +gem "sqlite3", "~> 1.3.8", :platforms => :ruby gem "pry" gem "rails", "~> 4.2.0" gem "aws-sdk", "~> 2.0.0" group :development, :test do gem "activerecord-import" - gem "mime-types", ">= 1.16", "< 4" + gem "mime-types" gem "builder" gem "rubocop", :require => false end -gemspec path: "../" +gemspec :path => "../" diff --git a/gemfiles/4.2.awsv2.1.gemfile b/gemfiles/4.2.awsv2.1.gemfile index 9b52119cf..b6b17d272 100644 --- a/gemfiles/4.2.awsv2.1.gemfile +++ b/gemfiles/4.2.awsv2.1.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "sqlite3", "~> 1.3.8", platforms: :ruby +gem "sqlite3", "~> 1.3.8", :platforms => :ruby gem "pry" gem "rails", "~> 4.2.0" gem "aws-sdk", "~> 2.1.0" @@ -14,4 +14,4 @@ group :development, :test do gem "rubocop", :require => false end -gemspec path: "../" +gemspec :path => "../" diff --git a/gemfiles/4.2.awsv2.gemfile b/gemfiles/4.2.awsv2.gemfile new file mode 100644 index 000000000..3ac60abcd --- /dev/null +++ b/gemfiles/4.2.awsv2.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "sqlite3", "~> 1.3.8", :platforms => :ruby +gem "jruby-openssl", :platforms => :jruby +gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby +gem "rubysl", :platforms => :rbx +gem "racc", :platforms => :rbx +gem "pry" +gem "rails", "~> 4.2.0" +gem "aws-sdk", "~> 2.0" + +group :development, :test do + gem "mime-types", "~> 1.16" + gem "builder" + gem "rubocop", :require => false +end + +gemspec :path => "../" diff --git a/gemfiles/5.0.awsv2.0.gemfile b/gemfiles/5.0.awsv2.0.gemfile new file mode 100644 index 000000000..4fd23dc14 --- /dev/null +++ b/gemfiles/5.0.awsv2.0.gemfile @@ -0,0 +1,17 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "sqlite3", "~> 1.3.8", :platforms => :ruby +gem "pry" +gem "rails", "5.0.0.beta3" +gem "aws-sdk", "~> 2.0.0" + +group :development, :test do + gem "activerecord-import" + gem "mime-types", ">= 1.16", "< 4" + gem "builder" + gem "rubocop", :require => false +end + +gemspec :path => "../" diff --git a/gemfiles/5.0.awsv2.1.gemfile b/gemfiles/5.0.awsv2.1.gemfile new file mode 100644 index 000000000..75049f705 --- /dev/null +++ b/gemfiles/5.0.awsv2.1.gemfile @@ -0,0 +1,17 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "sqlite3", "~> 1.3.8", :platforms => :ruby +gem "pry" +gem "rails", "5.0.0.beta3" +gem "aws-sdk", "~> 2.1.0" + +group :development, :test do + gem "activerecord-import" + gem "mime-types" + gem "builder" + gem "rubocop", :require => false +end + +gemspec :path => "../" diff --git a/gemfiles/5.0.awsv2.gemfile b/gemfiles/5.0.awsv2.gemfile new file mode 100644 index 000000000..29c4b6020 --- /dev/null +++ b/gemfiles/5.0.awsv2.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "sqlite3", "~> 1.3.8", :platforms => :ruby +gem "jruby-openssl", :platforms => :jruby +gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby +gem "rubysl", :platforms => :rbx +gem "racc", :platforms => :rbx +gem "pry" +gem "rails", :github => "rails/rails" +gem "sprockets-rails", :github => "rails/sprockets-rails" +gem "sprockets", :github => "rails/sprockets" +gem "sass-rails", :github => "rails/sass-rails" +gem "arel", :github => "rails/arel" +gem "rack", :github => "rack/rack" +gem "aws-sdk", "~> 2.0" + +group :development, :test do + gem "mime-types", "~> 1.16" + gem "builder" + gem "rubocop", :require => false +end + +gemspec :path => "../" diff --git a/lib/paperclip/callbacks.rb b/lib/paperclip/callbacks.rb index e3525f6d0..1451ab957 100644 --- a/lib/paperclip/callbacks.rb +++ b/lib/paperclip/callbacks.rb @@ -7,7 +7,7 @@ def self.included(base) module Defining def define_paperclip_callbacks(*callbacks) - define_callbacks(*[callbacks, {:terminator => callback_terminator}].flatten) + define_callbacks(*[callbacks, { terminator: hasta_la_vista_baby }].flatten) callbacks.each do |callback| eval <<-end_callbacks def before_#{callback}(*args, &blk) @@ -22,9 +22,9 @@ def after_#{callback}(*args, &blk) private - def callback_terminator - if ::ActiveSupport::VERSION::STRING >= '4.1' - lambda { |target, result| result == false } + def hasta_la_vista_baby + if ::ActiveSupport::VERSION::STRING >= "5.0" + lambda { |_, result| result.call } else 'result == false' end diff --git a/spec/support/model_reconstruction.rb b/spec/support/model_reconstruction.rb index 0caac56cc..26f1256f6 100644 --- a/spec/support/model_reconstruction.rb +++ b/spec/support/model_reconstruction.rb @@ -10,7 +10,15 @@ def reset_class class_name klass.reset_column_information klass.connection_pool.clear_table_cache!(klass.table_name) if klass.connection_pool.respond_to?(:clear_table_cache!) - klass.connection.schema_cache.clear_table_cache!(klass.table_name) if klass.connection.respond_to?(:schema_cache) + + if klass.connection.respond_to?(:schema_cache) + if `bundle exec rails -v`.include?("4.2") + klass.connection.schema_cache.clear_table_cache!(klass.table_name) + elsif `bundle exec rails -v`.include?("5.0") + klass.connection.schema_cache.clear_data_source_cache!(klass.table_name) + end + end + klass end From 393aac2cef4ba4456449d5f15a78d38cb16ed401 Mon Sep 17 00:00:00 2001 From: Esteban Pastorino Date: Tue, 22 Mar 2016 10:40:25 -0400 Subject: [PATCH 2/5] Compare to ActiveRecord::VERSION instead of shelling out `bundle exec rails -v` was taking seconds every time, making the test suite run very slow. This changes the code to compare the version against `ActiveRecord::VERSION`, which is going to be the same one as `rails -v`, making it much, much faster. Simplifies condition: we no longer support Rails < 4.2, so we test for `>= "5.0"` or fallback to `4.2` branch. --- spec/support/model_reconstruction.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/support/model_reconstruction.rb b/spec/support/model_reconstruction.rb index 26f1256f6..a2e9b4461 100644 --- a/spec/support/model_reconstruction.rb +++ b/spec/support/model_reconstruction.rb @@ -12,10 +12,10 @@ def reset_class class_name klass.connection_pool.clear_table_cache!(klass.table_name) if klass.connection_pool.respond_to?(:clear_table_cache!) if klass.connection.respond_to?(:schema_cache) - if `bundle exec rails -v`.include?("4.2") - klass.connection.schema_cache.clear_table_cache!(klass.table_name) - elsif `bundle exec rails -v`.include?("5.0") + if ActiveRecord::VERSION::STRING >= "5.0" klass.connection.schema_cache.clear_data_source_cache!(klass.table_name) + else + klass.connection.schema_cache.clear_table_cache!(klass.table_name) end end From 49faabb324cb179eafb3906776ef6b97e05471d5 Mon Sep 17 00:00:00 2001 From: Tute Costa Date: Mon, 21 Mar 2016 21:15:15 -0400 Subject: [PATCH 3/5] Update callbacks for Rails 5 Ref: https://github.com/rails/rails/commit/2386daabe7f8c979b453010dc0de3e1f6bbf859d Specifically: > Chains of callbacks defined **with** a `:terminator` option will > maintain their existing behavior of halting as soon as a `before_` > callback matches the terminator's expectation. For instance, > ActiveModel's callbacks will still halt the chain when a `before_` > callback returns `false`. In terminator callbacks, the `result` value changed to be a lambda now. This change reflects that, updating the terminator to compare the result of the block to `false`. Also: * Removes Rails 4.1 branch (we don't support it anymore) * Rewrite for legibility: change `unless` for `if` --- lib/paperclip/attachment.rb | 2 +- lib/paperclip/callbacks.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/paperclip/attachment.rb b/lib/paperclip/attachment.rb index ae8bb27ea..d3e81a0cd 100644 --- a/lib/paperclip/attachment.rb +++ b/lib/paperclip/attachment.rb @@ -501,7 +501,7 @@ def post_process(*style_args) #:nodoc: instance.run_paperclip_callbacks(:post_process) do instance.run_paperclip_callbacks(:"#{name}_post_process") do - unless @options[:check_validity_before_processing] && instance.errors.any? + if !@options[:check_validity_before_processing] || !instance.errors.any? post_process_styles(*style_args) end end diff --git a/lib/paperclip/callbacks.rb b/lib/paperclip/callbacks.rb index 1451ab957..53a436857 100644 --- a/lib/paperclip/callbacks.rb +++ b/lib/paperclip/callbacks.rb @@ -23,10 +23,12 @@ def after_#{callback}(*args, &blk) private def hasta_la_vista_baby - if ::ActiveSupport::VERSION::STRING >= "5.0" - lambda { |_, result| result.call } - else - 'result == false' + lambda do |_, result| + if result.respond_to?(:call) + result.call == false + else + result == false + end end end end From 93c34e76c73ddca13daf479d948b26b0d59dfc18 Mon Sep 17 00:00:00 2001 From: Esteban Pastorino Date: Tue, 22 Mar 2016 12:47:50 -0400 Subject: [PATCH 4/5] Add `silence_stream` method removed in Rails 5 Ref: https://github.com/rails/rails/commit/481e49c64f790e46f4aff3ed539ed227d2eb46cb `silence_stream` was deprecated in Rails 4.2 and removed in Rails 5 because it was not thread safe. Paperclip is not running the tests in threaded mode, it's safe to add the method back in a test support module. --- spec/spec_helper.rb | 1 + spec/support/reporting.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 spec/support/reporting.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 036770123..92e7f431f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -36,6 +36,7 @@ config.include Assertions config.include ModelReconstruction config.include TestData + config.include Reporting config.extend VersionHelper config.mock_framework = :mocha config.before(:all) do diff --git a/spec/support/reporting.rb b/spec/support/reporting.rb new file mode 100644 index 000000000..ed970d2bb --- /dev/null +++ b/spec/support/reporting.rb @@ -0,0 +1,11 @@ +module Reporting + def silence_stream(stream) + old_stream = stream.dup + stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null') + stream.sync = true + yield + ensure + stream.reopen(old_stream) + old_stream.close + end +end From 799845ec1cf35c92405633cd7402e98d2414ece0 Mon Sep 17 00:00:00 2001 From: Tute Costa Date: Tue, 22 Mar 2016 22:38:44 -0400 Subject: [PATCH 5/5] Fix spec While working on this branch, Kito found that this test fails due to: https://github.com/rails/rails/commit/6ec8ba16d85d5feaccb993c9756c1edcbbf0ba13#diff-fdcf8b65b5fb954372c6fe1ddf284c78R76 We are not yet sure if it's a bug in paperclip or in Rails itself. With current `ActiveModel::Errors` implementation the following happens: ``` record.errors # => @messages = {} record.errors.include?(:foo) # => false record.errors # => @messages = { :foo => [] } ``` Which bit us in: https://github.com/thoughtbot/paperclip/blob/69f18375333234b6f395300266e2612936bd242e/lib/paperclip/validators/attachment_file_name_validator.rb#L23 Another related Rails commit: https://github.com/rails/rails/commit/b97035df64f5b2f912425c4a7fcb6e6bb3ddab8d I worked around the issue by changing what we assert in this spec. I am still not sure that this is a bug in current Rails master. cc @kitop for review --- spec/paperclip/validators_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/paperclip/validators_spec.rb b/spec/paperclip/validators_spec.rb index 398948d83..93a57e26b 100644 --- a/spec/paperclip/validators_spec.rb +++ b/spec/paperclip/validators_spec.rb @@ -64,12 +64,11 @@ assert_raises(RuntimeError){ dummy.valid? } end - it 'allows you to attach a file that does not violates these validations' do + it 'allows you to attach a file that does not violate these validations' do dummy = Dummy.new(avatar: File.new(fixture_file('rotated.jpg'))) - expect(dummy.errors.keys).to match_array [] + expect(dummy.errors.full_messages).to be_empty assert dummy.valid? end - end context "using the helper with a conditional" do