From 7cef86bb49b12820352f8e6da6033a457180946a Mon Sep 17 00:00:00 2001 From: Vasily Fedoseyev Date: Wed, 10 Apr 2024 19:27:24 +0300 Subject: [PATCH] Rubocop --- lib/paperclip.rb | 2 +- lib/paperclip/callback_compatability.rb | 4 ++-- test/attachment_test.rb | 6 +++++- test/matchers/have_attached_file_matcher_test.rb | 2 +- ...alidate_attachment_content_type_matcher_test.rb | 14 +++++++++++--- .../validate_attachment_presence_matcher_test.rb | 2 +- .../validate_attachment_size_matcher_test.rb | 2 +- test/optimizer_test.rb | 2 +- test/paperclip_test.rb | 4 ++-- test/railtie_test.rb | 2 +- test/recursive_thumbnail_test.rb | 8 +++++--- test/test_helper.rb | 3 +-- test/upfile_test.rb | 3 +-- 13 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lib/paperclip.rb b/lib/paperclip.rb index dc6a765..c811f13 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -344,6 +344,6 @@ end # Set it all up. if Object.const_defined?("ActiveRecord") - ActiveRecord::Base.include(Paperclip) + ActiveSupport.on_load(:active_record) { include Paperclip } File.include(Paperclip::Upfile) end diff --git a/lib/paperclip/callback_compatability.rb b/lib/paperclip/callback_compatability.rb index 20943fd..b11a61e 100644 --- a/lib/paperclip/callback_compatability.rb +++ b/lib/paperclip/callback_compatability.rb @@ -15,11 +15,11 @@ module Paperclip def define_paperclip_callbacks(*callbacks) define_callbacks(*callbacks.flatten, {}) callbacks.map(&:to_sym).each do |callback| - define_singleton_method "before_#{callback}" do |*args, &blk| + define_singleton_method :"before_#{callback}" do |*args, &blk| set_callback(callback, :before, *args, &blk) end - define_singleton_method "after_#{callback}" do |*args, &blk| + define_singleton_method :"after_#{callback}" do |*args, &blk| set_callback(callback, :after, *args, &blk) end end diff --git a/test/attachment_test.rb b/test/attachment_test.rb index 5db8815..4c20987 100644 --- a/test/attachment_test.rb +++ b/test/attachment_test.rb @@ -140,7 +140,11 @@ class AttachmentTest < Test::Unit::TestCase Tempfile.create do |tempfile| content = "file contents" tempfile.write(content) - upload = { 'original_name' => 'foo.jpg', 'content_type' => 'application/jpg', 'filepath' => tempfile.tap(&:rewind).path } + upload = { + 'original_name' => 'foo.jpg', + 'content_type' => 'application/jpg', + 'filepath' => tempfile.tap(&:rewind).path + } @attachment.assign(upload) assert_equal "foo.png", @attachment.path assert_equal content, @attachment.queued_for_write[:original].tap(&:rewind).read diff --git a/test/matchers/have_attached_file_matcher_test.rb b/test/matchers/have_attached_file_matcher_test.rb index 9d80a0d..04b26e3 100644 --- a/test/matchers/have_attached_file_matcher_test.rb +++ b/test/matchers/have_attached_file_matcher_test.rb @@ -21,7 +21,7 @@ class HaveAttachedFileMatcherTest < Test::Unit::TestCase end should "have messages" do - assert_equal "have an attachment named avatar", @matcher.description + assert_equal "have an attachment named avatar", @matcher.description assert_equal "Should have an attachment named avatar", @matcher.failure_message assert_equal "Should not have an attachment named avatar", @matcher.negative_failure_message end diff --git a/test/matchers/validate_attachment_content_type_matcher_test.rb b/test/matchers/validate_attachment_content_type_matcher_test.rb index ff9f8f2..be048e8 100644 --- a/test/matchers/validate_attachment_content_type_matcher_test.rb +++ b/test/matchers/validate_attachment_content_type_matcher_test.rb @@ -28,9 +28,17 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase end should "have messages" do - assert_equal "validate the content types allowed on attachment avatar", @matcher.description - assert_equal "Content types image/png, image/jpeg should be accepted and audio/mp3, application/octet-stream rejected by avatar", @matcher.failure_message - assert_equal "Content types image/png, image/jpeg should be rejected and audio/mp3, application/octet-stream accepted by avatar", @matcher.negative_failure_message + assert_equal "validate the content types allowed on attachment avatar", @matcher.description + assert_equal( + "Content types image/png, image/jpeg should be accepted and audio/mp3, " \ + "application/octet-stream rejected by avatar", + @matcher.failure_message + ) + assert_equal( + "Content types image/png, image/jpeg should be rejected and audio/mp3, " \ + "application/octet-stream accepted by avatar", + @matcher.negative_failure_message + ) end end end diff --git a/test/matchers/validate_attachment_presence_matcher_test.rb b/test/matchers/validate_attachment_presence_matcher_test.rb index c7bb1c6..a503e70 100644 --- a/test/matchers/validate_attachment_presence_matcher_test.rb +++ b/test/matchers/validate_attachment_presence_matcher_test.rb @@ -19,7 +19,7 @@ class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase end should "have messages" do - assert_equal "require presence of attachment avatar", @matcher.description + assert_equal "require presence of attachment avatar", @matcher.description assert_equal "Attachment avatar should be required", @matcher.failure_message assert_equal "Attachment avatar should not be required", @matcher.negative_failure_message end diff --git a/test/matchers/validate_attachment_size_matcher_test.rb b/test/matchers/validate_attachment_size_matcher_test.rb index 5668635..7cc8c88 100644 --- a/test/matchers/validate_attachment_size_matcher_test.rb +++ b/test/matchers/validate_attachment_size_matcher_test.rb @@ -33,7 +33,7 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase end should "have messages" do - assert_equal "validate the size of attachment avatar", @matcher.description + assert_equal "validate the size of attachment avatar", @matcher.description assert_equal "Attachment avatar must be between 256 and 1024 bytes", @matcher.failure_message assert_equal "Attachment avatar cannot be between 256 and 1024 bytes", @matcher.negative_failure_message end diff --git a/test/optimizer_test.rb b/test/optimizer_test.rb index abc490f..f76ed4a 100644 --- a/test/optimizer_test.rb +++ b/test/optimizer_test.rb @@ -5,7 +5,7 @@ require 'test_helper' class OptimizerTest < Test::Unit::TestCase setup do @pixel_jpg = Base64.decode64( - "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP#{'/'*86}wgALCAABAAEBAREA/8QAFBAB#{'A'*21}P/aAAgBAQABPxA" + "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP#{'/' * 86}wgALCAABAAEBAREA/8QAFBAB#{'A' * 21}P/aAAgBAQABPxA" ) @pixel_png = Base64.decode64( "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg" diff --git a/test/paperclip_test.rb b/test/paperclip_test.rb index 8a5241a..377f5c0 100644 --- a/test/paperclip_test.rb +++ b/test/paperclip_test.rb @@ -110,7 +110,7 @@ class PaperclipTest < Test::Unit::TestCase context "a validation with an if guard clause" do setup do - Dummy.send(:validates_attachment_presence, :avatar, :if => lambda{|i| i.foo }) + Dummy.send(:validates_attachment_presence, :avatar, if: ->(i) { i.foo }) @dummy = Dummy.new end @@ -129,7 +129,7 @@ class PaperclipTest < Test::Unit::TestCase context "a validation with an unless guard clause" do setup do - Dummy.send(:validates_attachment_presence, :avatar, :unless => lambda{|i| i.foo }) + Dummy.send(:validates_attachment_presence, :avatar, unless: ->(i) { i.foo }) @dummy = Dummy.new end diff --git a/test/railtie_test.rb b/test/railtie_test.rb index 9e1d669..78ca8c9 100644 --- a/test/railtie_test.rb +++ b/test/railtie_test.rb @@ -5,7 +5,7 @@ require 'test_helper' class RailtieTest < Test::Unit::TestCase should "load processors" do FileUtils.mkdir_p('tmp/rails/lib/paperclip_processors') - File.write(Rails.root.join('lib/paperclip_processors/some_custom_processor.rb'), <<~RUBY) + Rails.root.join('lib/paperclip_processors/some_custom_processor.rb').write <<~RUBY class Paperclip::SomeCustomProcessor < Paperclip::Processor end RUBY diff --git a/test/recursive_thumbnail_test.rb b/test/recursive_thumbnail_test.rb index 55b157f..bddc184 100644 --- a/test/recursive_thumbnail_test.rb +++ b/test/recursive_thumbnail_test.rb @@ -10,13 +10,13 @@ class RecursiveThumbnailTest < Test::Unit::TestCase end should "use original when style not present" do - processor = Paperclip::RecursiveThumbnail.new(@original_file, { thumbnail: :missing, geometry: '1x1'}, @attachment) + processor = Paperclip::RecursiveThumbnail.new(@original_file, { thumbnail: :missing, geometry: '1x1' }, @attachment) assert_equal @original_file, processor.file end should "use original when style failed to download" do @attachment.expects(:to_file).with(:missing).raises("cannot haz filez") - processor = Paperclip::RecursiveThumbnail.new(@original_file, { thumbnail: :missing, geometry: '1x1'}, @attachment) + processor = Paperclip::RecursiveThumbnail.new(@original_file, { thumbnail: :missing, geometry: '1x1' }, @attachment) assert_equal @original_file, processor.file end @@ -25,7 +25,9 @@ class RecursiveThumbnailTest < Test::Unit::TestCase style_file.expects(:close!).once @original_file.expects(:close!).never @attachment.expects(:to_file).with(:existent).returns(style_file) - processor = Paperclip::RecursiveThumbnail.new(@original_file, { thumbnail: :existent, geometry: '1x1'}, @attachment) + processor = Paperclip::RecursiveThumbnail.new( + @original_file, { thumbnail: :existent, geometry: '1x1' }, @attachment + ) Paperclip.stubs run: "" assert_equal style_file, processor.file res = processor.make diff --git a/test/test_helper.rb b/test/test_helper.rb index 97252fd..36f05c2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -100,8 +100,7 @@ def rebuild_class(options = {}) end class FakeModel - def self.set_callback(...) - end + def self.set_callback(...); end include Paperclip diff --git a/test/upfile_test.rb b/test/upfile_test.rb index d6a37d2..603ff06 100644 --- a/test/upfile_test.rb +++ b/test/upfile_test.rb @@ -28,11 +28,10 @@ class UpfileTest < Test::Unit::TestCase '_.html' => 'text/html', '__.htm' => 'text/html', - "_.txt" => "text/plain", "_.liquid" => "text/x-liquid", '_.svg' => 'image/svg+xml', - '_.xls' => 'application/vnd.ms-excel', + '_.xls' => 'application/vnd.ms-excel' }.each_pair do |example, result| should "return #{result} for #{example}" do assert_equal result, Paperclip::Upfile.content_type_from_ext(example)