mirror of
https://github.com/kemko/paperclip.git
synced 2026-01-01 16:05:40 +03:00
Rubocop
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -100,8 +100,7 @@ def rebuild_class(options = {})
|
||||
end
|
||||
|
||||
class FakeModel
|
||||
def self.set_callback(...)
|
||||
end
|
||||
def self.set_callback(...); end
|
||||
|
||||
include Paperclip
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user