This commit is contained in:
Vasily Fedoseyev
2024-04-10 19:27:24 +03:00
parent 6647c5fa9c
commit 7cef86bb49
13 changed files with 33 additions and 21 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -29,8 +29,16 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
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(
"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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -100,8 +100,7 @@ def rebuild_class(options = {})
end
class FakeModel
def self.set_callback(...)
end
def self.set_callback(...); end
include Paperclip

View File

@@ -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)