diff --git a/.hound.yml b/.hound.yml index 6bc7805fd..94886f03c 100644 --- a/.hound.yml +++ b/.hound.yml @@ -1040,7 +1040,7 @@ Lint/UselessAssignment: Description: Checks for useless assignment to a local variable. StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars Enabled: true -Lint/UselessComparison: +Lint/BinaryOperatorWithIdenticalOperands: Description: Checks for comparison of something with itself. Enabled: true Lint/UselessElseWithoutRescue: diff --git a/.travis.yml b/.travis.yml index def3c67f2..5ce7b34a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ rvm: - 2.4 - 2.5 - 2.6 + - 2.7 script: "bundle exec rake clean spec cucumber" @@ -36,3 +37,9 @@ matrix: rvm: 2.3 - gemfile: gemfiles/6.0.gemfile rvm: 2.4 + - gemfile: gemfiles/4.2.gemfile + rvm: 2.7 + - gemfile: gemfiles/5.0.gemfile + rvm: 2.7 + - gemfile: gemfiles/5.1.gemfile + rvm: 2.7 diff --git a/lib/paperclip/io_adapters/http_url_proxy_adapter.rb b/lib/paperclip/io_adapters/http_url_proxy_adapter.rb index 80651b479..13be95b74 100644 --- a/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +++ b/lib/paperclip/io_adapters/http_url_proxy_adapter.rb @@ -9,8 +9,8 @@ def self.register REGEXP = /\Ahttps?:\/\//.freeze def initialize(target, options = {}) - escaped = URI.escape(target) - super(URI(target == URI.unescape(target) ? escaped : target), options) + escaped = Paperclip::UrlGenerator.escape(target) + super(URI(target == Paperclip::UrlGenerator.unescape(target) ? escaped : target), options) end end end diff --git a/lib/paperclip/io_adapters/uri_adapter.rb b/lib/paperclip/io_adapters/uri_adapter.rb index 2725d5e6a..8405345c8 100644 --- a/lib/paperclip/io_adapters/uri_adapter.rb +++ b/lib/paperclip/io_adapters/uri_adapter.rb @@ -53,7 +53,7 @@ def default_filename def download_content options = { read_timeout: Paperclip.options[:read_timeout] }.compact - open(@target, **options) + self.open(@target, options) end def copy_to_tempfile(src) diff --git a/lib/paperclip/schema.rb b/lib/paperclip/schema.rb index a6ce81977..f16395808 100644 --- a/lib/paperclip/schema.rb +++ b/lib/paperclip/schema.rb @@ -26,7 +26,7 @@ def add_attachment(table_name, *attachment_names) attachment_names.each do |attachment_name| COLUMNS.each_pair do |column_name, column_type| column_options = options.merge(options[column_name.to_sym] || {}) - add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options) + add_column(table_name, "#{attachment_name}_#{column_name}", column_type, **column_options) end end end @@ -55,7 +55,7 @@ def attachment(*attachment_names) attachment_names.each do |attachment_name| COLUMNS.each_pair do |column_name, column_type| column_options = options.merge(options[column_name.to_sym] || {}) - column("#{attachment_name}_#{column_name}", column_type, column_options) + column("#{attachment_name}_#{column_name}", column_type, **column_options) end end end diff --git a/lib/paperclip/url_generator.rb b/lib/paperclip/url_generator.rb index 29c09c46f..cef1c033d 100644 --- a/lib/paperclip/url_generator.rb +++ b/lib/paperclip/url_generator.rb @@ -3,6 +3,13 @@ module Paperclip class UrlGenerator + class << self + def encoder + @encoder ||= URI::RFC2396_Parser.new + end + delegate :escape, :unescape, to: :encoder + end + def initialize(attachment) @attachment = attachment end @@ -65,7 +72,7 @@ def escape_url(url) if url.respond_to?(:escape) url.escape else - URI.escape(url).gsub(escape_regex) { |m| "%#{m.ord.to_s(16).upcase}" } + self.class.escape(url).gsub(escape_regex) { |m| "%#{m.ord.to_s(16).upcase}" } end end diff --git a/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb b/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb index 3e188fdb8..9cfca350d 100644 --- a/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +++ b/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb @@ -16,54 +16,59 @@ context "a new instance" do before do @url = "http://thoughtbot.com/images/thoughtbot-logo.png" - @subject = Paperclip.io_adapters.for(@url, hash_digest: Digest::MD5) end + subject { Paperclip.io_adapters.for(@url, hash_digest: Digest::MD5) } + after do - @subject.close + subject.close end it "returns a file name" do - assert_equal "thoughtbot-logo.png", @subject.original_filename + expect(subject.original_filename).to(eq("thoughtbot-logo.png")) end it "closes open handle after reading" do - assert_equal true, @open_return.closed? + expect { subject }.to(change { @open_return.closed? }.from(false).to(true)) end it "returns a content type" do - assert_equal "image/png", @subject.content_type + expect(subject.content_type).to(eq("image/png")) end it "returns the size of the data" do - assert_equal @open_return.size, @subject.size + expect(subject.size).to(eq(@open_return.size)) end it "generates an MD5 hash of the contents" do - assert_equal Digest::MD5.hexdigest("xxx"), @subject.fingerprint + expect(subject.fingerprint).to(eq(Digest::MD5.hexdigest("xxx"))) end it "generates correct fingerprint after read" do - fingerprint = Digest::MD5.hexdigest(@subject.read) - assert_equal fingerprint, @subject.fingerprint + fingerprint = Digest::MD5.hexdigest(subject.read) + expect(subject.fingerprint).to(eq(fingerprint)) end it "generates same fingerprint" do - assert_equal @subject.fingerprint, @subject.fingerprint + expect(subject.fingerprint).to(eq(subject.fingerprint)) end it "returns the data contained in the StringIO" do - assert_equal "xxx", @subject.read + expect(subject.read).to(eq("xxx")) end it "accepts a content_type" do - @subject.content_type = "image/png" - assert_equal "image/png", @subject.content_type + subject.content_type = "image/png" + expect(subject.content_type).to(eq("image/png")) end it "accepts an original_filename" do - @subject.original_filename = "image.png" - assert_equal "image.png", @subject.original_filename + subject.original_filename = "image.png" + expect(subject.original_filename).to(eq("image.png")) + end + + it "doesn't emit deprecation warnings" do + expect { subject }.to_not(output(/URI\.(un)?escape is obsolete/).to_stderr) end end diff --git a/spec/paperclip/url_generator_spec.rb b/spec/paperclip/url_generator_spec.rb index ceffa54d9..dc3f67f95 100644 --- a/spec/paperclip/url_generator_spec.rb +++ b/spec/paperclip/url_generator_spec.rb @@ -194,6 +194,16 @@ def escape "expected the interpolator to be passed #{expected.inspect} but it wasn't" end + it "doesn't emit deprecation warnings" do + expected = "the expected result" + mock_interpolator = MockInterpolator.new(result: expected) + options = { interpolator: mock_interpolator } + mock_attachment = MockAttachment.new(options) + url_generator = Paperclip::UrlGenerator.new(mock_attachment) + + expect { url_generator.for(:style_name, escape: true) }.to_not(output(/URI\.(un)?escape is obsolete/).to_stderr) + end + describe "should be able to escape (, ), [, and ]." do def generate(expected, updated_at = nil) mock_interpolator = MockInterpolator.new(result: expected) diff --git a/spec/support/model_reconstruction.rb b/spec/support/model_reconstruction.rb index 3583cd1d7..a03978a72 100644 --- a/spec/support/model_reconstruction.rb +++ b/spec/support/model_reconstruction.rb @@ -28,7 +28,7 @@ def reset_class(class_name) def reset_table(_table_name, &block) block ||= lambda { |_table| true } - ActiveRecord::Base.connection.create_table :dummies, { force: true }, &block + ActiveRecord::Base.connection.create_table :dummies, **{ force: true }, &block end def modify_table(&block)