Commit 3be55fc8 by Joshua Clayton

Clean up whitespace

parent 980c9b93
...@@ -138,7 +138,7 @@ For example, assuming we had this definition: ...@@ -138,7 +138,7 @@ For example, assuming we had this definition:
has_attached_file :scan, :styles => { :text => { :quality => :better } }, has_attached_file :scan, :styles => { :text => { :quality => :better } },
:processors => [:rotator, :ocr] :processors => [:rotator, :ocr]
then both the :rotator processor and the :ocr processor would receive the then both the :rotator processor and the :ocr processor would receive the
options "{ :quality => :better }". This parameter may not mean anything to one options "{ :quality => :better }". This parameter may not mean anything to one
or more or the processors, and they are expected to ignore it. or more or the processors, and they are expected to ignore it.
......
...@@ -62,13 +62,13 @@ task :manifest => :clean do ...@@ -62,13 +62,13 @@ task :manifest => :clean do
puts file puts file
end end
end end
desc "Generate a gemspec file for GitHub" desc "Generate a gemspec file for GitHub"
task :gemspec => :clean do task :gemspec => :clean do
File.open("#{spec.name}.gemspec", 'w') do |f| File.open("#{spec.name}.gemspec", 'w') do |f|
f.write spec.to_ruby f.write spec.to_ruby
end end
end end
desc "Build the gem into the current directory" desc "Build the gem into the current directory"
task :gem => :gemspec do task :gem => :gemspec do
......
Usage: Usage:
script/generate paperclip Class attachment1 (attachment2 ...) script/generate paperclip Class attachment1 (attachment2 ...)
This will create a migration that will add the proper columns to your class's table. This will create a migration that will add the proper columns to your class's table.
\ No newline at end of file
class PaperclipGenerator < Rails::Generator::NamedBase class PaperclipGenerator < Rails::Generator::NamedBase
attr_accessor :attachments, :migration_name attr_accessor :attachments, :migration_name
def initialize(args, options = {}) def initialize(args, options = {})
super super
@class_name, @attachments = args[0], args[1..-1] @class_name, @attachments = args[0], args[1..-1]
end end
def manifest def manifest
file_name = generate_file_name file_name = generate_file_name
@migration_name = file_name.camelize @migration_name = file_name.camelize
record do |m| record do |m|
...@@ -14,14 +14,14 @@ class PaperclipGenerator < Rails::Generator::NamedBase ...@@ -14,14 +14,14 @@ class PaperclipGenerator < Rails::Generator::NamedBase
File.join('db', 'migrate'), File.join('db', 'migrate'),
:migration_file_name => file_name :migration_file_name => file_name
end end
end end
private private
def generate_file_name def generate_file_name
names = attachments.map{|a| a.underscore } names = attachments.map{|a| a.underscore }
names = names[0..-2] + ["and", names[-1]] if names.length > 1 names = names[0..-2] + ["and", names[-1]] if names.length > 1
"add_attachments_#{names.join("_")}_to_#{@class_name.underscore}" "add_attachments_#{names.join("_")}_to_#{@class_name.underscore}"
end end
end end
...@@ -52,12 +52,12 @@ module Paperclip ...@@ -52,12 +52,12 @@ module Paperclip
class << self class << self
# Provides configurability to Paperclip. There are a number of options available, such as: # Provides configurability to Paperclip. There are a number of options available, such as:
# * whiny: Will raise an error if Paperclip cannot process thumbnails of # * whiny: Will raise an error if Paperclip cannot process thumbnails of
# an uploaded image. Defaults to true. # an uploaded image. Defaults to true.
# * log: Logs progress to the Rails log. Uses ActiveRecord's logger, so honors # * log: Logs progress to the Rails log. Uses ActiveRecord's logger, so honors
# log levels, etc. Defaults to true. # log levels, etc. Defaults to true.
# * command_path: Defines the path at which to find the command line # * command_path: Defines the path at which to find the command line
# programs if they are not visible to Rails the system's search path. Defaults to # programs if they are not visible to Rails the system's search path. Defaults to
# nil, which uses the first executable found in the user's search path. # nil, which uses the first executable found in the user's search path.
# * image_magick_path: Deprecated alias of command_path. # * image_magick_path: Deprecated alias of command_path.
def options def options
...@@ -100,7 +100,7 @@ module Paperclip ...@@ -100,7 +100,7 @@ module Paperclip
# #
# Paperclip.run("echo", "something", :expected_outcodes => [0,1,2,3]) # Paperclip.run("echo", "something", :expected_outcodes => [0,1,2,3])
# #
# This method can log the command being run when # This method can log the command being run when
# Paperclip.options[:log_command] is set to true (defaults to false). This # Paperclip.options[:log_command] is set to true (defaults to false). This
# will only log if logging in general is set to true as well. # will only log if logging in general is set to true as well.
def run cmd, *params def run cmd, *params
...@@ -152,7 +152,7 @@ module Paperclip ...@@ -152,7 +152,7 @@ module Paperclip
name = name.to_s.camelize name = name.to_s.camelize
processor = Paperclip.const_get(name) processor = Paperclip.const_get(name)
unless processor.ancestors.include?(Paperclip::Processor) unless processor.ancestors.include?(Paperclip::Processor)
raise PaperclipError.new("Processor #{name} was not found") raise PaperclipError.new("Processor #{name} was not found")
end end
processor processor
end end
...@@ -194,41 +194,41 @@ module Paperclip ...@@ -194,41 +194,41 @@ module Paperclip
module ClassMethods module ClassMethods
# +has_attached_file+ gives the class it is called on an attribute that maps to a file. This # +has_attached_file+ gives the class it is called on an attribute that maps to a file. This
# is typically a file stored somewhere on the filesystem and has been uploaded by a user. # is typically a file stored somewhere on the filesystem and has been uploaded by a user.
# The attribute returns a Paperclip::Attachment object which handles the management of # The attribute returns a Paperclip::Attachment object which handles the management of
# that file. The intent is to make the attachment as much like a normal attribute. The # that file. The intent is to make the attachment as much like a normal attribute. The
# thumbnails will be created when the new file is assigned, but they will *not* be saved # thumbnails will be created when the new file is assigned, but they will *not* be saved
# until +save+ is called on the record. Likewise, if the attribute is set to +nil+ is # until +save+ is called on the record. Likewise, if the attribute is set to +nil+ is
# called on it, the attachment will *not* be deleted until +save+ is called. See the # called on it, the attachment will *not* be deleted until +save+ is called. See the
# Paperclip::Attachment documentation for more specifics. There are a number of options # Paperclip::Attachment documentation for more specifics. There are a number of options
# you can set to change the behavior of a Paperclip attachment: # you can set to change the behavior of a Paperclip attachment:
# * +url+: The full URL of where the attachment is publically accessible. This can just # * +url+: The full URL of where the attachment is publically accessible. This can just
# as easily point to a directory served directly through Apache as it can to an action # as easily point to a directory served directly through Apache as it can to an action
# that can control permissions. You can specify the full domain and path, but usually # that can control permissions. You can specify the full domain and path, but usually
# just an absolute path is sufficient. The leading slash *must* be included manually for # just an absolute path is sufficient. The leading slash *must* be included manually for
# absolute paths. The default value is # absolute paths. The default value is
# "/system/:attachment/:id/:style/:filename". See # "/system/:attachment/:id/:style/:filename". See
# Paperclip::Attachment#interpolate for more information on variable interpolaton. # Paperclip::Attachment#interpolate for more information on variable interpolaton.
# :url => "/:class/:attachment/:id/:style_:filename" # :url => "/:class/:attachment/:id/:style_:filename"
# :url => "http://some.other.host/stuff/:class/:id_:extension" # :url => "http://some.other.host/stuff/:class/:id_:extension"
# * +default_url+: The URL that will be returned if there is no attachment assigned. # * +default_url+: The URL that will be returned if there is no attachment assigned.
# This field is interpolated just as the url is. The default value is # This field is interpolated just as the url is. The default value is
# "/:attachment/:style/missing.png" # "/:attachment/:style/missing.png"
# has_attached_file :avatar, :default_url => "/images/default_:style_avatar.png" # has_attached_file :avatar, :default_url => "/images/default_:style_avatar.png"
# User.new.avatar_url(:small) # => "/images/default_small_avatar.png" # User.new.avatar_url(:small) # => "/images/default_small_avatar.png"
# * +styles+: A hash of thumbnail styles and their geometries. You can find more about # * +styles+: A hash of thumbnail styles and their geometries. You can find more about
# geometry strings at the ImageMagick website # geometry strings at the ImageMagick website
# (http://www.imagemagick.org/script/command-line-options.php#resize). Paperclip # (http://www.imagemagick.org/script/command-line-options.php#resize). Paperclip
# also adds the "#" option (e.g. "50x50#"), which will resize the image to fit maximally # also adds the "#" option (e.g. "50x50#"), which will resize the image to fit maximally
# inside the dimensions and then crop the rest off (weighted at the center). The # inside the dimensions and then crop the rest off (weighted at the center). The
# default value is to generate no thumbnails. # default value is to generate no thumbnails.
# * +default_style+: The thumbnail style that will be used by default URLs. # * +default_style+: The thumbnail style that will be used by default URLs.
# Defaults to +original+. # Defaults to +original+.
# has_attached_file :avatar, :styles => { :normal => "100x100#" }, # has_attached_file :avatar, :styles => { :normal => "100x100#" },
# :default_style => :normal # :default_style => :normal
# user.avatar.url # => "/avatars/23/normal_me.png" # user.avatar.url # => "/avatars/23/normal_me.png"
# * +whiny+: Will raise an error if Paperclip cannot post_process an uploaded file due # * +whiny+: Will raise an error if Paperclip cannot post_process an uploaded file due
# to a command line error. This will override the global setting for this attachment. # to a command line error. This will override the global setting for this attachment.
# Defaults to true. This option used to be called :whiny_thumbanils, but this is # Defaults to true. This option used to be called :whiny_thumbanils, but this is
# deprecated. # deprecated.
# * +convert_options+: When creating thumbnails, use this free-form options # * +convert_options+: When creating thumbnails, use this free-form options
...@@ -324,19 +324,19 @@ module Paperclip ...@@ -324,19 +324,19 @@ module Paperclip
# * +unless+: Same as +if+ but validates if lambda or method returns false. # * +unless+: Same as +if+ but validates if lambda or method returns false.
def validates_attachment_presence name, options = {} def validates_attachment_presence name, options = {}
message = options[:message] || "must be set." message = options[:message] || "must be set."
validates_presence_of :"#{name}_file_name", validates_presence_of :"#{name}_file_name",
:message => message, :message => message,
:if => options[:if], :if => options[:if],
:unless => options[:unless] :unless => options[:unless]
end end
# Places ActiveRecord-style validations on the content type of the file # Places ActiveRecord-style validations on the content type of the file
# assigned. The possible options are: # assigned. The possible options are:
# * +content_type+: Allowed content types. Can be a single content type # * +content_type+: Allowed content types. Can be a single content type
# or an array. Each type can be a String or a Regexp. It should be # or an array. Each type can be a String or a Regexp. It should be
# noted that Internet Explorer upload files with content_types that you # noted that Internet Explorer upload files with content_types that you
# may not expect. For example, JPEG images are given image/pjpeg and # may not expect. For example, JPEG images are given image/pjpeg and
# PNGs are image/x-png, so keep that in mind when determining how you # PNGs are image/x-png, so keep that in mind when determining how you
# match. Allows all by default. # match. Allows all by default.
# * +message+: The message to display when the uploaded file has an invalid # * +message+: The message to display when the uploaded file has an invalid
# content type. # content type.
......
...@@ -4,7 +4,7 @@ module Paperclip ...@@ -4,7 +4,7 @@ module Paperclip
# when the model saves, deletes when the model is destroyed, and processes # when the model saves, deletes when the model is destroyed, and processes
# the file upon assignment. # the file upon assignment.
class Attachment class Attachment
def self.default_options def self.default_options
@default_options ||= { @default_options ||= {
:url => "/system/:attachment/:id/:style/:filename", :url => "/system/:attachment/:id/:style/:filename",
...@@ -50,7 +50,7 @@ module Paperclip ...@@ -50,7 +50,7 @@ module Paperclip
initialize_storage initialize_storage
end end
def styles def styles
unless @normalized_styles unless @normalized_styles
@normalized_styles = {} @normalized_styles = {}
...@@ -60,7 +60,7 @@ module Paperclip ...@@ -60,7 +60,7 @@ module Paperclip
end end
@normalized_styles @normalized_styles
end end
def processors def processors
@processors.respond_to?(:call) ? @processors.call(instance) : @processors @processors.respond_to?(:call) ? @processors.call(instance) : @processors
end end
...@@ -69,7 +69,7 @@ module Paperclip ...@@ -69,7 +69,7 @@ module Paperclip
# errors, assigns attributes, and processes the file. It # errors, assigns attributes, and processes the file. It
# also queues up the previous file for deletion, to be flushed away on # also queues up the previous file for deletion, to be flushed away on
# #save of its host. In addition to form uploads, you can also assign # #save of its host. In addition to form uploads, you can also assign
# another Paperclip attachment: # another Paperclip attachment:
# new_user.avatar = old_user.avatar # new_user.avatar = old_user.avatar
def assign uploaded_file def assign uploaded_file
ensure_required_accessors! ensure_required_accessors!
...@@ -95,7 +95,7 @@ module Paperclip ...@@ -95,7 +95,7 @@ module Paperclip
@dirty = true @dirty = true
post_process post_process
# Reset the file size if the original file was reprocessed. # Reset the file size if the original file was reprocessed.
instance_write(:file_size, @queued_for_write[:original].size.to_i) instance_write(:file_size, @queued_for_write[:original].size.to_i)
ensure ensure
...@@ -179,8 +179,8 @@ module Paperclip ...@@ -179,8 +179,8 @@ module Paperclip
def content_type def content_type
instance_read(:content_type) instance_read(:content_type)
end end
# Returns the last modified time of the file as originally assigned, and # Returns the last modified time of the file as originally assigned, and
# lives in the <attachment>_updated_at attribute of the model. # lives in the <attachment>_updated_at attribute of the model.
def updated_at def updated_at
time = instance_read(:updated_at) time = instance_read(:updated_at)
...@@ -220,7 +220,7 @@ module Paperclip ...@@ -220,7 +220,7 @@ module Paperclip
true true
end end
end end
# Returns true if a file has been assigned. # Returns true if a file has been assigned.
def file? def file?
!original_filename.blank? !original_filename.blank?
...@@ -324,4 +324,3 @@ module Paperclip ...@@ -324,4 +324,3 @@ module Paperclip
end end
end end
...@@ -75,12 +75,12 @@ module Paperclip ...@@ -75,12 +75,12 @@ module Paperclip
to_s to_s
end end
# Returns the scaling and cropping geometries (in string-based ImageMagick format) # Returns the scaling and cropping geometries (in string-based ImageMagick format)
# neccessary to transform this Geometry into the Geometry given. If crop is true, # neccessary to transform this Geometry into the Geometry given. If crop is true,
# then it is assumed the destination Geometry will be the exact final resolution. # then it is assumed the destination Geometry will be the exact final resolution.
# In this case, the source Geometry is scaled so that an image containing the # In this case, the source Geometry is scaled so that an image containing the
# destination Geometry would be completely filled by the source image, and any # destination Geometry would be completely filled by the source image, and any
# overhanging image would be cropped. Useful for square thumbnail images. The cropping # overhanging image would be cropped. Useful for square thumbnail images. The cropping
# is weighted at the center of the Geometry. # is weighted at the center of the Geometry.
def transformation_to dst, crop = false def transformation_to dst, crop = false
if crop if crop
......
...@@ -78,7 +78,7 @@ module Paperclip ...@@ -78,7 +78,7 @@ module Paperclip
# Returns the extension of the file. e.g. "jpg" for "file.jpg" # Returns the extension of the file. e.g. "jpg" for "file.jpg"
# If the style has a format defined, it will return the format instead # If the style has a format defined, it will return the format instead
# of the actual extension. # of the actual extension.
def extension attachment, style_name def extension attachment, style_name
((style = attachment.styles[style_name]) && style[:format]) || ((style = attachment.styles[style_name]) && style[:format]) ||
File.extname(attachment.original_filename).gsub(/^\.+/, "") File.extname(attachment.original_filename).gsub(/^\.+/, "")
end end
......
...@@ -26,7 +26,7 @@ module IOStream ...@@ -26,7 +26,7 @@ module IOStream
while self.read(in_blocks_of, buffer) do while self.read(in_blocks_of, buffer) do
dstio.write(buffer) dstio.write(buffer)
end end
dstio.rewind dstio.rewind
dstio dstio
end end
end end
......
...@@ -42,7 +42,7 @@ module Paperclip ...@@ -42,7 +42,7 @@ module Paperclip
end end
def negative_failure_message def negative_failure_message
"Content types #{@allowed_types.join(", ")} should be rejected" + "Content types #{@allowed_types.join(", ")} should be rejected" +
" and #{@rejected_types.join(", ")} accepted by #{@attachment_name}" " and #{@rejected_types.join(", ")} accepted by #{@attachment_name}"
end end
...@@ -72,4 +72,3 @@ module Paperclip ...@@ -72,4 +72,3 @@ module Paperclip
end end
end end
end end
...@@ -52,4 +52,3 @@ module Paperclip ...@@ -52,4 +52,3 @@ module Paperclip
end end
end end
end end
...@@ -93,4 +93,3 @@ module Paperclip ...@@ -93,4 +93,3 @@ module Paperclip
end end
end end
end end
...@@ -6,7 +6,7 @@ module Paperclip ...@@ -6,7 +6,7 @@ module Paperclip
# #
# Processors are required to be defined inside the Paperclip module and # Processors are required to be defined inside the Paperclip module and
# are also required to be a subclass of Paperclip::Processor. There is # are also required to be a subclass of Paperclip::Processor. There is
# only one method you *must* implement to properly be a subclass: # only one method you *must* implement to properly be a subclass:
# #make, but #initialize may also be of use. Both methods accept 3 # #make, but #initialize may also be of use. Both methods accept 3
# arguments: the file that will be operated on (which is an instance of # arguments: the file that will be operated on (which is an instance of
# File), a hash of options that were defined in has_attached_file's # File), a hash of options that were defined in has_attached_file's
...@@ -33,7 +33,7 @@ module Paperclip ...@@ -33,7 +33,7 @@ module Paperclip
new(file, options, attachment).make new(file, options, attachment).make
end end
end end
# Due to how ImageMagick handles its image format conversion and how Tempfile # Due to how ImageMagick handles its image format conversion and how Tempfile
# handles its naming scheme, it is necessary to override how Tempfile makes # handles its naming scheme, it is necessary to override how Tempfile makes
# its names so as to allow for file extensions. Idea taken from the comments # its names so as to allow for file extensions. Idea taken from the comments
......
...@@ -3,7 +3,7 @@ module Paperclip ...@@ -3,7 +3,7 @@ module Paperclip
# The Style class holds the definition of a thumbnail style, applying # The Style class holds the definition of a thumbnail style, applying
# whatever processing is required to normalize the definition and delaying # whatever processing is required to normalize the definition and delaying
# the evaluation of block parameters until useful context is available. # the evaluation of block parameters until useful context is available.
class Style class Style
attr_reader :name, :attachment, :format attr_reader :name, :attachment, :format
...@@ -25,7 +25,7 @@ module Paperclip ...@@ -25,7 +25,7 @@ module Paperclip
end end
@format = nil if @format.blank? @format = nil if @format.blank?
end end
# retrieves from the attachment the processors defined in the has_attached_file call # retrieves from the attachment the processors defined in the has_attached_file call
# (which method (in the attachment) will call any supplied procs) # (which method (in the attachment) will call any supplied procs)
# There is an important change of interface here: a style rule can set its own processors # There is an important change of interface here: a style rule can set its own processors
...@@ -33,17 +33,17 @@ module Paperclip ...@@ -33,17 +33,17 @@ module Paperclip
def processors def processors
@processors || attachment.processors @processors || attachment.processors
end end
# retrieves from the attachment the whiny setting # retrieves from the attachment the whiny setting
def whiny def whiny
attachment.whiny attachment.whiny
end end
# returns true if we're inclined to grumble # returns true if we're inclined to grumble
def whiny? def whiny?
!!whiny !!whiny
end end
def convert_options def convert_options
attachment.send(:extra_options_for, name) attachment.send(:extra_options_for, name)
end end
...@@ -55,7 +55,7 @@ module Paperclip ...@@ -55,7 +55,7 @@ module Paperclip
end end
# Supplies the hash of options that processors expect to receive as their second argument # Supplies the hash of options that processors expect to receive as their second argument
# Arguments other than the standard geometry, format etc are just passed through from # Arguments other than the standard geometry, format etc are just passed through from
# initialization and any procs are called here, just before post-processing. # initialization and any procs are called here, just before post-processing.
def processor_options def processor_options
args = {} args = {}
...@@ -63,7 +63,7 @@ module Paperclip ...@@ -63,7 +63,7 @@ module Paperclip
args[k] = v.respond_to?(:call) ? v.call(attachment) : v args[k] = v.respond_to?(:call) ? v.call(attachment) : v
end end
[:processors, :geometry, :format, :whiny, :convert_options].each do |k| [:processors, :geometry, :format, :whiny, :convert_options].each do |k|
(arg = send(k)) && args[k] = arg (arg = send(k)) && args[k] = arg
end end
args args
end end
...@@ -71,13 +71,13 @@ module Paperclip ...@@ -71,13 +71,13 @@ module Paperclip
# Supports getting and setting style properties with hash notation to ensure backwards-compatibility # Supports getting and setting style properties with hash notation to ensure backwards-compatibility
# eg. @attachment.styles[:large][:geometry]@ will still work # eg. @attachment.styles[:large][:geometry]@ will still work
def [](key) def [](key)
if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key) if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key)
send(key) send(key)
elsif defined? @other_args[key] elsif defined? @other_args[key]
@other_args[key] @other_args[key]
end end
end end
def []=(key, value) def []=(key, value)
if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key) if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key)
send("#{key}=".intern, value) send("#{key}=".intern, value)
...@@ -85,6 +85,6 @@ module Paperclip ...@@ -85,6 +85,6 @@ module Paperclip
@other_args[key] = value @other_args[key] = value
end end
end end
end end
end end
\ No newline at end of file
...@@ -9,10 +9,10 @@ module Paperclip ...@@ -9,10 +9,10 @@ module Paperclip
# which is a "WxH"-style string. +format+ will be inferred from the +file+ # which is a "WxH"-style string. +format+ will be inferred from the +file+
# unless specified. Thumbnail creation will raise no errors unless # unless specified. Thumbnail creation will raise no errors unless
# +whiny+ is true (which it is, by default. If +convert_options+ is # +whiny+ is true (which it is, by default. If +convert_options+ is
# set, the options will be appended to the convert command upon image conversion # set, the options will be appended to the convert command upon image conversion
def initialize file, options = {}, attachment = nil def initialize file, options = {}, attachment = nil
super super
geometry = options[:geometry] geometry = options[:geometry]
@file = file @file = file
@crop = geometry[-1,1] == '#' @crop = geometry[-1,1] == '#'
...@@ -28,14 +28,14 @@ module Paperclip ...@@ -28,14 +28,14 @@ module Paperclip
@current_format = File.extname(@file.path) @current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format) @basename = File.basename(@file.path, @current_format)
end end
# Returns true if the +target_geometry+ is meant to crop. # Returns true if the +target_geometry+ is meant to crop.
def crop? def crop?
@crop @crop
end end
# Returns true if the image is meant to make use of additional convert options. # Returns true if the image is meant to make use of additional convert options.
def convert_options? def convert_options?
!@convert_options.nil? && !@convert_options.empty? !@convert_options.nil? && !@convert_options.empty?
......
...@@ -50,4 +50,3 @@ end ...@@ -50,4 +50,3 @@ end
class File #:nodoc: class File #:nodoc:
include Paperclip::Upfile include Paperclip::Upfile
end end
...@@ -8,7 +8,7 @@ exclude_files = ["test/s3.yml", "test/debug.log", "test/paperclip.db", "test/doc ...@@ -8,7 +8,7 @@ exclude_files = ["test/s3.yml", "test/debug.log", "test/paperclip.db", "test/doc
Dir[glob] Dir[glob]
end.flatten end.flatten
spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
s.name = "paperclip" s.name = "paperclip"
s.version = Paperclip::VERSION s.version = Paperclip::VERSION
s.author = "Jon Yurek" s.author = "Jon Yurek"
...@@ -32,4 +32,3 @@ spec = Gem::Specification.new do |s| ...@@ -32,4 +32,3 @@ spec = Gem::Specification.new do |s|
s.add_development_dependency 'aws-s3' s.add_development_dependency 'aws-s3'
s.add_development_dependency 'sqlite3-ruby' s.add_development_dependency 'sqlite3-ruby'
end end
...@@ -46,7 +46,7 @@ module Paperclip ...@@ -46,7 +46,7 @@ module Paperclip
end end
# Tests to ensure that you have file size validations turned on. You # Tests to ensure that you have file size validations turned on. You
# can pass the same options to this that you can to # can pass the same options to this that you can to
# validate_attachment_file_size - :less_than, :greater_than, and :in. # validate_attachment_file_size - :less_than, :greater_than, and :in.
# :less_than checks that a file is less than a certain size, :greater_than # :less_than checks that a file is less than a certain size, :greater_than
# checks that a file is more than a certain size, and :in takes a Range or # checks that a file is more than a certain size, and :in takes a Range or
......
...@@ -41,7 +41,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -41,7 +41,7 @@ class AttachmentTest < Test::Unit::TestCase
setup do setup do
@dummy = Dummy.new @dummy = Dummy.new
end end
should "return false when asked exists?" do should "return false when asked exists?" do
assert !@dummy.avatar.exists? assert !@dummy.avatar.exists?
end end
...@@ -55,7 +55,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -55,7 +55,7 @@ class AttachmentTest < Test::Unit::TestCase
Paperclip::Attachment.default_options.keys.each do |key| Paperclip::Attachment.default_options.keys.each do |key|
should "be the default_options for #{key}" do should "be the default_options for #{key}" do
assert_equal @old_default_options[key], assert_equal @old_default_options[key],
@attachment.instance_variable_get("@#{key}"), @attachment.instance_variable_get("@#{key}"),
key key
end end
...@@ -177,11 +177,11 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -177,11 +177,11 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal "-all", @dummy.avatar.send(:extra_options_for, :large) assert_equal "-all", @dummy.avatar.send(:extra_options_for, :large)
end end
end end
context "An attachment with :path that is a proc" do context "An attachment with :path that is a proc" do
setup do setup do
rebuild_model :path => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" } rebuild_model :path => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
@file = File.new(File.join(File.dirname(__FILE__), @file = File.new(File.join(File.dirname(__FILE__),
"fixtures", "fixtures",
"5k.png"), 'rb') "5k.png"), 'rb')
...@@ -190,31 +190,31 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -190,31 +190,31 @@ class AttachmentTest < Test::Unit::TestCase
@dummyB = Dummy.new(:other => 'b') @dummyB = Dummy.new(:other => 'b')
@dummyB.avatar = @file @dummyB.avatar = @file
end end
teardown { @file.close } teardown { @file.close }
should "return correct path" do should "return correct path" do
assert_equal "path/a.png", @dummyA.avatar.path assert_equal "path/a.png", @dummyA.avatar.path
assert_equal "path/b.png", @dummyB.avatar.path assert_equal "path/b.png", @dummyB.avatar.path
end end
end end
context "An attachment with :styles that is a proc" do context "An attachment with :styles that is a proc" do
setup do setup do
rebuild_model :styles => lambda{ |attachment| {:thumb => "50x50#", :large => "400x400"} } rebuild_model :styles => lambda{ |attachment| {:thumb => "50x50#", :large => "400x400"} }
@attachment = Dummy.new.avatar @attachment = Dummy.new.avatar
end end
should "have the correct geometry" do should "have the correct geometry" do
assert_equal "50x50#", @attachment.styles[:thumb][:geometry] assert_equal "50x50#", @attachment.styles[:thumb][:geometry]
end end
end end
context "An attachment with :url that is a proc" do context "An attachment with :url that is a proc" do
setup do setup do
rebuild_model :url => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" } rebuild_model :url => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
@file = File.new(File.join(File.dirname(__FILE__), @file = File.new(File.join(File.dirname(__FILE__),
"fixtures", "fixtures",
"5k.png"), 'rb') "5k.png"), 'rb')
...@@ -223,16 +223,16 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -223,16 +223,16 @@ class AttachmentTest < Test::Unit::TestCase
@dummyB = Dummy.new(:other => 'b') @dummyB = Dummy.new(:other => 'b')
@dummyB.avatar = @file @dummyB.avatar = @file
end end
teardown { @file.close } teardown { @file.close }
should "return correct url" do should "return correct url" do
assert_equal "path/a.png", @dummyA.avatar.url(:original, false) assert_equal "path/a.png", @dummyA.avatar.url(:original, false)
assert_equal "path/b.png", @dummyB.avatar.url(:original, false) assert_equal "path/b.png", @dummyB.avatar.url(:original, false)
end end
end end
geometry_specs = [ geometry_specs = [
[ lambda{|z| "50x50#" }, :png ], [ lambda{|z| "50x50#" }, :png ],
lambda{|z| "50x50#" }, lambda{|z| "50x50#" },
{ :geometry => lambda{|z| "50x50#" } } { :geometry => lambda{|z| "50x50#" } }
...@@ -326,12 +326,12 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -326,12 +326,12 @@ class AttachmentTest < Test::Unit::TestCase
Paperclip::Thumbnail.expects(:make).with(any_parameters).returns(@file) Paperclip::Thumbnail.expects(:make).with(any_parameters).returns(@file)
Paperclip::Test.expects(:make).with(any_parameters).returns(@file) Paperclip::Test.expects(:make).with(any_parameters).returns(@file)
end end
before_should "call #make with the right parameters passed as second argument" do before_should "call #make with the right parameters passed as second argument" do
expected_params = @style_params[:once].merge({:processors => [:thumbnail, :test], :whiny => true, :convert_options => ""}) expected_params = @style_params[:once].merge({:processors => [:thumbnail, :test], :whiny => true, :convert_options => ""})
Paperclip::Thumbnail.expects(:make).with(anything, expected_params, anything).returns(@file) Paperclip::Thumbnail.expects(:make).with(anything, expected_params, anything).returns(@file)
end end
before_should "call #make with attachment passed as third argument" do before_should "call #make with attachment passed as third argument" do
Paperclip::Test.expects(:make).with(anything, anything, @dummy.avatar).returns(@file) Paperclip::Test.expects(:make).with(anything, anything, @dummy.avatar).returns(@file)
end end
...@@ -442,7 +442,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -442,7 +442,7 @@ class AttachmentTest < Test::Unit::TestCase
context "Attachment with strange letters" do context "Attachment with strange letters" do
setup do setup do
rebuild_model rebuild_model
@not_file = mock @not_file = mock
@tempfile = mock @tempfile = mock
@not_file.stubs(:nil?).returns(false) @not_file.stubs(:nil?).returns(false)
...@@ -451,7 +451,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -451,7 +451,7 @@ class AttachmentTest < Test::Unit::TestCase
@not_file.expects(:to_tempfile).returns(@tempfile) @not_file.expects(:to_tempfile).returns(@tempfile)
@not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n") @not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n")
@not_file.expects(:content_type).returns("image/png\r\n") @not_file.expects(:content_type).returns("image/png\r\n")
@dummy = Dummy.new @dummy = Dummy.new
@attachment = @dummy.avatar @attachment = @dummy.avatar
@attachment.expects(:valid_assignment?).with(@not_file).returns(true) @attachment.expects(:valid_assignment?).with(@not_file).returns(true)
...@@ -459,7 +459,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -459,7 +459,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:post_process) @attachment.expects(:post_process)
@dummy.avatar = @not_file @dummy.avatar = @not_file
end end
should "not remove strange letters" do should "not remove strange letters" do
assert_equal "sheep_say_bæ.png", @dummy.avatar.original_filename assert_equal "sheep_say_bæ.png", @dummy.avatar.original_filename
end end
...@@ -597,7 +597,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -597,7 +597,7 @@ class AttachmentTest < Test::Unit::TestCase
cmd = %Q[identify -format "%w %h %b %m" "#{@attachment.path(style.first)}"] cmd = %Q[identify -format "%w %h %b %m" "#{@attachment.path(style.first)}"]
out = `#{cmd}` out = `#{cmd}`
width, height, size, format = out.split(" ") width, height, size, format = out.split(" ")
assert_equal style[1].to_s, width.to_s assert_equal style[1].to_s, width.to_s
assert_equal style[2].to_s, height.to_s assert_equal style[2].to_s, height.to_s
assert_equal style[3].to_s, format.to_s assert_equal style[3].to_s, format.to_s
end end
......
...@@ -65,7 +65,7 @@ class GeometryTest < Test::Unit::TestCase ...@@ -65,7 +65,7 @@ class GeometryTest < Test::Unit::TestCase
assert_equal "123x456#{mod}", @geo.to_s assert_equal "123x456#{mod}", @geo.to_s
end end
end end
['>', '<', '#', '@', '%', '^', '!', nil].each do |mod| ['>', '<', '#', '@', '%', '^', '!', nil].each do |mod|
should "ensure the modifier #{mod.inspect} is preserved with no height" do should "ensure the modifier #{mod.inspect} is preserved with no height" do
assert @geo = Paperclip::Geometry.parse("123x#{mod}") assert @geo = Paperclip::Geometry.parse("123x#{mod}")
......
...@@ -57,7 +57,7 @@ require File.join(ROOT, 'lib', 'paperclip.rb') ...@@ -57,7 +57,7 @@ require File.join(ROOT, 'lib', 'paperclip.rb')
require 'shoulda_macros/paperclip' require 'shoulda_macros/paperclip'
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
ActiveRecord::Base.establish_connection(config['test']) ActiveRecord::Base.establish_connection(config['test'])
......
...@@ -9,7 +9,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -9,7 +9,7 @@ class IntegrationTest < Test::Unit::TestCase
Dummy.create! :avatar => @file Dummy.create! :avatar => @file
end end
end end
should "not exceed the open file limit" do should "not exceed the open file limit" do
assert_nothing_raised do assert_nothing_raised do
dummies = Dummy.find(:all) dummies = Dummy.find(:all)
...@@ -157,7 +157,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -157,7 +157,7 @@ class IntegrationTest < Test::Unit::TestCase
end end
end end
end end
context "A model with no convert_options setting" do context "A model with no convert_options setting" do
setup do setup do
rebuild_model :styles => { :large => "300x300>", rebuild_model :styles => { :large => "300x300>",
...@@ -168,7 +168,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -168,7 +168,7 @@ class IntegrationTest < Test::Unit::TestCase
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension" :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@dummy = Dummy.new @dummy = Dummy.new
end end
should "have its definition return nil when asked about convert_options" do should "have its definition return nil when asked about convert_options" do
assert ! Dummy.attachment_definitions[:avatar][:convert_options] assert ! Dummy.attachment_definitions[:avatar][:convert_options]
end end
...@@ -189,7 +189,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -189,7 +189,7 @@ class IntegrationTest < Test::Unit::TestCase
end end
end end
end end
context "A model with a filesystem attachment" do context "A model with a filesystem attachment" do
setup do setup do
rebuild_model :styles => { :large => "300x300>", rebuild_model :styles => { :large => "300x300>",
...@@ -281,7 +281,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -281,7 +281,7 @@ class IntegrationTest < Test::Unit::TestCase
Dummy.validates_attachment_presence :avatar Dummy.validates_attachment_presence :avatar
@d2 = Dummy.find(@dummy.id) @d2 = Dummy.find(@dummy.id)
@d2.avatar = @file @d2.avatar = @file
assert @d2.valid?, @d2.errors.full_messages.inspect assert @d2.valid?, @d2.errors.full_messages.inspect
@d2.avatar = @bad_file @d2.avatar = @bad_file
assert ! @d2.valid? assert ! @d2.valid?
end end
...@@ -294,7 +294,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -294,7 +294,7 @@ class IntegrationTest < Test::Unit::TestCase
@dummy.reload @dummy.reload
assert_equal "5k.png", @dummy.avatar_file_name assert_equal "5k.png", @dummy.avatar_file_name
end end
context "that is assigned its file from another Paperclip attachment" do context "that is assigned its file from another Paperclip attachment" do
setup do setup do
@dummy2 = Dummy.new @dummy2 = Dummy.new
...@@ -302,7 +302,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -302,7 +302,7 @@ class IntegrationTest < Test::Unit::TestCase
assert @dummy2.avatar = @file2 assert @dummy2.avatar = @file2
@dummy2.save @dummy2.save
end end
should "work when assigned a file" do should "work when assigned a file" do
assert_not_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`, assert_not_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
`identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"` `identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
...@@ -312,7 +312,7 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -312,7 +312,7 @@ class IntegrationTest < Test::Unit::TestCase
assert_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`, assert_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
`identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"` `identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
end end
end end
end end
......
...@@ -96,7 +96,7 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -96,7 +96,7 @@ class PaperclipTest < Test::Unit::TestCase
setup do setup do
File.expects(:exists?).with("/dev/null").returns(false) File.expects(:exists?).with("/dev/null").returns(false)
end end
should "return 'NUL'" do should "return 'NUL'" do
assert_equal "NUL", Paperclip.bit_bucket assert_equal "NUL", Paperclip.bit_bucket
end end
...@@ -106,7 +106,7 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -106,7 +106,7 @@ class PaperclipTest < Test::Unit::TestCase
setup do setup do
File.expects(:exists?).with("/dev/null").returns(true) File.expects(:exists?).with("/dev/null").returns(true)
end end
should "return '/dev/null'" do should "return '/dev/null'" do
assert_equal "/dev/null", Paperclip.bit_bucket assert_equal "/dev/null", Paperclip.bit_bucket
end end
...@@ -152,7 +152,7 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -152,7 +152,7 @@ class PaperclipTest < Test::Unit::TestCase
should "not assign the avatar on mass-set" do should "not assign the avatar on mass-set" do
@dummy.attributes = { :other => "I'm set!", @dummy.attributes = { :other => "I'm set!",
:avatar => @file } :avatar => @file }
assert_equal "I'm set!", @dummy.other assert_equal "I'm set!", @dummy.other
assert ! @dummy.avatar? assert ! @dummy.avatar?
end end
...@@ -160,7 +160,7 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -160,7 +160,7 @@ class PaperclipTest < Test::Unit::TestCase
should "still allow assigment on normal set" do should "still allow assigment on normal set" do
@dummy.other = "I'm set!" @dummy.other = "I'm set!"
@dummy.avatar = @file @dummy.avatar = @file
assert_equal "I'm set!", @dummy.other assert_equal "I'm set!", @dummy.other
assert @dummy.avatar? assert @dummy.avatar?
end end
...@@ -294,10 +294,10 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -294,10 +294,10 @@ class PaperclipTest < Test::Unit::TestCase
validation, options, valid_file, invalid_file = args validation, options, valid_file, invalid_file = args
valid_file &&= File.open(File.join(FIXTURES_DIR, valid_file), "rb") valid_file &&= File.open(File.join(FIXTURES_DIR, valid_file), "rb")
invalid_file &&= File.open(File.join(FIXTURES_DIR, invalid_file), "rb") invalid_file &&= File.open(File.join(FIXTURES_DIR, invalid_file), "rb")
should_validate validation, options, valid_file, invalid_file should_validate validation, options, valid_file, invalid_file
end end
context "with size validation and less_than 10240 option" do context "with size validation and less_than 10240 option" do
context "and assigned an invalid file" do context "and assigned an invalid file" do
setup do setup do
...@@ -306,7 +306,7 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -306,7 +306,7 @@ class PaperclipTest < Test::Unit::TestCase
@dummy.avatar &&= File.open(File.join(FIXTURES_DIR, "12k.png"), "rb") @dummy.avatar &&= File.open(File.join(FIXTURES_DIR, "12k.png"), "rb")
@dummy.valid? @dummy.valid?
end end
should "have a file size min/max error message" do should "have a file size min/max error message" do
assert @dummy.errors[:avatar_file_size] =~ %r/between 0 and 10240 bytes/ assert @dummy.errors[:avatar_file_size] =~ %r/between 0 and 10240 bytes/
end end
......
...@@ -9,7 +9,7 @@ class StyleTest < Test::Unit::TestCase ...@@ -9,7 +9,7 @@ class StyleTest < Test::Unit::TestCase
:styles => { :foo => {:geometry => "100x100#", :format => :png} } :styles => { :foo => {:geometry => "100x100#", :format => :png} }
@style = @attachment.styles[:foo] @style = @attachment.styles[:foo]
end end
should "be held as a Style object" do should "be held as a Style object" do
assert_kind_of Paperclip::Style, @style assert_kind_of Paperclip::Style, @style
end end
...@@ -21,18 +21,18 @@ class StyleTest < Test::Unit::TestCase ...@@ -21,18 +21,18 @@ class StyleTest < Test::Unit::TestCase
should "have the right geometry" do should "have the right geometry" do
assert_equal "100x100#", @style.geometry assert_equal "100x100#", @style.geometry
end end
should "be whiny if the attachment is" do should "be whiny if the attachment is" do
@attachment.expects(:whiny).returns(true) @attachment.expects(:whiny).returns(true)
assert @style.whiny? assert @style.whiny?
end end
should "respond to hash notation" do should "respond to hash notation" do
assert_equal [:thumbnail], @style[:processors] assert_equal [:thumbnail], @style[:processors]
assert_equal "100x100#", @style[:geometry] assert_equal "100x100#", @style[:geometry]
end end
end end
context "A style rule with properties supplied as procs" do context "A style rule with properties supplied as procs" do
setup do setup do
@attachment = attachment :path => ":basename.:extension", @attachment = attachment :path => ":basename.:extension",
...@@ -45,13 +45,13 @@ class StyleTest < Test::Unit::TestCase ...@@ -45,13 +45,13 @@ class StyleTest < Test::Unit::TestCase
} }
} }
end end
should "defer processing of procs until they are needed" do should "defer processing of procs until they are needed" do
assert_kind_of Proc, @attachment.styles[:foo].instance_variable_get("@geometry") assert_kind_of Proc, @attachment.styles[:foo].instance_variable_get("@geometry")
assert_kind_of Proc, @attachment.styles[:bar].instance_variable_get("@geometry") assert_kind_of Proc, @attachment.styles[:bar].instance_variable_get("@geometry")
assert_kind_of Proc, @attachment.instance_variable_get("@processors") assert_kind_of Proc, @attachment.instance_variable_get("@processors")
end end
should "call procs when they are needed" do should "call procs when they are needed" do
assert_equal "300x300#", @attachment.styles[:foo].geometry assert_equal "300x300#", @attachment.styles[:foo].geometry
assert_equal "300x300#", @attachment.styles[:bar].geometry assert_equal "300x300#", @attachment.styles[:bar].geometry
...@@ -63,7 +63,7 @@ class StyleTest < Test::Unit::TestCase ...@@ -63,7 +63,7 @@ class StyleTest < Test::Unit::TestCase
context "An attachment with style rules in various forms" do context "An attachment with style rules in various forms" do
setup do setup do
@attachment = attachment :path => ":basename.:extension", @attachment = attachment :path => ":basename.:extension",
:styles => { :styles => {
:aslist => ["100x100", :png], :aslist => ["100x100", :png],
:ashash => {:geometry => "100x100", :format => :png}, :ashash => {:geometry => "100x100", :format => :png},
:asstring => "100x100" :asstring => "100x100"
...@@ -73,13 +73,13 @@ class StyleTest < Test::Unit::TestCase ...@@ -73,13 +73,13 @@ class StyleTest < Test::Unit::TestCase
assert_kind_of Hash, @attachment.styles assert_kind_of Hash, @attachment.styles
assert_equal 3, @attachment.styles.size assert_equal 3, @attachment.styles.size
end end
should "have styles as Style objects" do should "have styles as Style objects" do
[:aslist, :ashash, :aslist].each do |s| [:aslist, :ashash, :aslist].each do |s|
assert_kind_of Paperclip::Style, @attachment.styles[s] assert_kind_of Paperclip::Style, @attachment.styles[s]
end end
end end
should "have the right geometries" do should "have the right geometries" do
[:aslist, :ashash, :aslist].each do |s| [:aslist, :ashash, :aslist].each do |s|
assert_equal @attachment.styles[s].geometry, "100x100" assert_equal @attachment.styles[s].geometry, "100x100"
...@@ -107,32 +107,32 @@ class StyleTest < Test::Unit::TestCase ...@@ -107,32 +107,32 @@ class StyleTest < Test::Unit::TestCase
before_should "not have called extra_options_for(:thumb/:large) on initialization" do before_should "not have called extra_options_for(:thumb/:large) on initialization" do
@attachment.expects(:extra_options_for).never @attachment.expects(:extra_options_for).never
end end
should "call extra_options_for(:thumb/:large) when convert options are requested" do should "call extra_options_for(:thumb/:large) when convert options are requested" do
@attachment.expects(:extra_options_for).with(:thumb) @attachment.expects(:extra_options_for).with(:thumb)
@attachment.styles[:thumb].convert_options @attachment.styles[:thumb].convert_options
end end
end end
context "A style rule with its own :processors" do context "A style rule with its own :processors" do
setup do setup do
@attachment = attachment :path => ":basename.:extension", @attachment = attachment :path => ":basename.:extension",
:styles => { :styles => {
:foo => { :foo => {
:geometry => "100x100#", :geometry => "100x100#",
:format => :png, :format => :png,
:processors => [:test] :processors => [:test]
} }
}, },
:processors => [:thumbnail] :processors => [:thumbnail]
@style = @attachment.styles[:foo] @style = @attachment.styles[:foo]
end end
should "not get processors from the attachment" do should "not get processors from the attachment" do
@attachment.expects(:processors).never @attachment.expects(:processors).never
assert_not_equal [:thumbnail], @style.processors assert_not_equal [:thumbnail], @style.processors
end end
should "report its own processors" do should "report its own processors" do
assert_equal [:test], @style.processors assert_equal [:test], @style.processors
end end
......
...@@ -47,7 +47,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -47,7 +47,7 @@ class ThumbnailTest < Test::Unit::TestCase
end end
should "start with dimensions of 434x66" do should "start with dimensions of 434x66" do
cmd = %Q[identify -format "%wx%h" "#{@file.path}"] cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
assert_equal "434x66", `#{cmd}`.chomp assert_equal "434x66", `#{cmd}`.chomp
end end
...@@ -61,7 +61,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -61,7 +61,7 @@ class ThumbnailTest < Test::Unit::TestCase
end end
should "be the size we expect it to be" do should "be the size we expect it to be" do
cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"] cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
assert_equal args[1], `#{cmd}`.chomp assert_equal args[1], `#{cmd}`.chomp
end end
end end
...@@ -85,7 +85,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -85,7 +85,7 @@ class ThumbnailTest < Test::Unit::TestCase
should "have whiny turned on by default" do should "have whiny turned on by default" do
assert @thumb.whiny assert @thumb.whiny
end end
should "have convert_options set to nil by default" do should "have convert_options set to nil by default" do
assert_equal nil, @thumb.convert_options assert_equal nil, @thumb.convert_options
end end
...@@ -102,7 +102,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -102,7 +102,7 @@ class ThumbnailTest < Test::Unit::TestCase
assert_match /100x50/, `identify "#{dst.path}"` assert_match /100x50/, `identify "#{dst.path}"`
end end
end end
context "being thumbnailed with source file options set" do context "being thumbnailed with source file options set" do
setup do setup do
@thumb = Paperclip::Thumbnail.new(@file, @thumb = Paperclip::Thumbnail.new(@file,
...@@ -125,7 +125,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -125,7 +125,7 @@ class ThumbnailTest < Test::Unit::TestCase
dst = @thumb.make dst = @thumb.make
assert_match /100x50/, `identify "#{dst.path}"` assert_match /100x50/, `identify "#{dst.path}"`
end end
context "redefined to have bad source_file_options setting" do context "redefined to have bad source_file_options setting" do
setup do setup do
@thumb = Paperclip::Thumbnail.new(@file, @thumb = Paperclip::Thumbnail.new(@file,
...@@ -138,7 +138,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -138,7 +138,7 @@ class ThumbnailTest < Test::Unit::TestCase
@thumb.make @thumb.make
end end
end end
end end
end end
context "being thumbnailed with convert options set" do context "being thumbnailed with convert options set" do
...@@ -163,7 +163,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -163,7 +163,7 @@ class ThumbnailTest < Test::Unit::TestCase
dst = @thumb.make dst = @thumb.make
assert_match /100x50/, `identify "#{dst.path}"` assert_match /100x50/, `identify "#{dst.path}"`
end end
context "redefined to have bad convert_options setting" do context "redefined to have bad convert_options setting" do
setup do setup do
@thumb = Paperclip::Thumbnail.new(@file, @thumb = Paperclip::Thumbnail.new(@file,
...@@ -176,16 +176,16 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -176,16 +176,16 @@ class ThumbnailTest < Test::Unit::TestCase
@thumb.make @thumb.make
end end
end end
end end
end end
context "being thumbnailed with a blank geometry string" do context "being thumbnailed with a blank geometry string" do
setup do setup do
@thumb = Paperclip::Thumbnail.new(@file, @thumb = Paperclip::Thumbnail.new(@file,
:geometry => "", :geometry => "",
:convert_options => "-gravity center -crop \"300x300+0-0\"") :convert_options => "-gravity center -crop \"300x300+0-0\"")
end end
should "not get resized by default" do should "not get resized by default" do
assert !@thumb.transformation_command.include?("-resize") assert !@thumb.transformation_command.include?("-resize")
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment