diff --git a/README.rdoc b/README.rdoc index f4ae68b40..c7096ef4c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -138,7 +138,7 @@ For example, assuming we had this definition: has_attached_file :scan, :styles => { :text => { :quality => :better } }, :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 or more or the processors, and they are expected to ignore it. diff --git a/Rakefile b/Rakefile index bdeb698a8..6a11036d8 100644 --- a/Rakefile +++ b/Rakefile @@ -62,13 +62,13 @@ task :manifest => :clean do puts file end end - + desc "Generate a gemspec file for GitHub" task :gemspec => :clean do File.open("#{spec.name}.gemspec", 'w') do |f| f.write spec.to_ruby end -end +end desc "Build the gem into the current directory" task :gem => :gemspec do diff --git a/generators/paperclip/USAGE b/generators/paperclip/USAGE index 2d611d7d1..4ad7e9684 100644 --- a/generators/paperclip/USAGE +++ b/generators/paperclip/USAGE @@ -1,5 +1,5 @@ Usage: script/generate paperclip Class attachment1 (attachment2 ...) - -This will create a migration that will add the proper columns to your class's table. \ No newline at end of file + +This will create a migration that will add the proper columns to your class's table. diff --git a/generators/paperclip/paperclip_generator.rb b/generators/paperclip/paperclip_generator.rb index 77ee5a212..b5d3c2236 100644 --- a/generators/paperclip/paperclip_generator.rb +++ b/generators/paperclip/paperclip_generator.rb @@ -1,12 +1,12 @@ class PaperclipGenerator < Rails::Generator::NamedBase attr_accessor :attachments, :migration_name - + def initialize(args, options = {}) super @class_name, @attachments = args[0], args[1..-1] end - - def manifest + + def manifest file_name = generate_file_name @migration_name = file_name.camelize record do |m| @@ -14,14 +14,14 @@ def manifest File.join('db', 'migrate'), :migration_file_name => file_name end - end - - private - + end + + private + def generate_file_name names = attachments.map{|a| a.underscore } names = names[0..-2] + ["and", names[-1]] if names.length > 1 "add_attachments_#{names.join("_")}_to_#{@class_name.underscore}" end - + end diff --git a/lib/paperclip.rb b/lib/paperclip.rb index 8e5cdfc08..63f9097ce 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -51,12 +51,12 @@ module Paperclip class << self # 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. # * log: Logs progress to the Rails log. Uses ActiveRecord's logger, so honors # log levels, etc. Defaults to true. # * 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. # * image_magick_path: Deprecated alias of command_path. def options @@ -99,7 +99,7 @@ def interpolates key, &block # # 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 # will only log if logging in general is set to true as well. def run cmd, *params @@ -151,7 +151,7 @@ def processor name #:nodoc: name = name.to_s.camelize processor = Paperclip.const_get(name) unless processor.ancestors.include?(Paperclip::Processor) - raise PaperclipError.new("Processor #{name} was not found") + raise PaperclipError.new("Processor #{name} was not found") end processor end @@ -193,41 +193,41 @@ class InfiniteInterpolationError < PaperclipError #:nodoc: module ClassMethods # +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 - # 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 - # 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 - # Paperclip::Attachment documentation for more specifics. There are a number of options + # 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 + # 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 + # Paperclip::Attachment documentation for more specifics. There are a number of options # 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 # 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 - # just an absolute path is sufficient. The leading slash *must* be included manually for - # absolute paths. The default value is + # just an absolute path is sufficient. The leading slash *must* be included manually for + # absolute paths. The default value is # "/system/:attachment/:id/:style/:filename". See # Paperclip::Attachment#interpolate for more information on variable interpolaton. # :url => "/:class/:attachment/:id/:style_:filename" # :url => "http://some.other.host/stuff/:class/:id_:extension" - # * +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 + # * +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 # "/:attachment/:style/missing.png" # has_attached_file :avatar, :default_url => "/images/default_:style_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 - # geometry strings at the ImageMagick website + # * +styles+: A hash of thumbnail styles and their geometries. You can find more about + # geometry strings at the ImageMagick website # (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 - # inside the dimensions and then crop the rest off (weighted at the center). The + # 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 # 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+. # has_attached_file :avatar, :styles => { :normal => "100x100#" }, # :default_style => :normal # user.avatar.url # => "/avatars/23/normal_me.png" # * +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 # deprecated. # * +convert_options+: When creating thumbnails, use this free-form options @@ -323,19 +323,19 @@ def validates_attachment_thumbnails name, options = {} # * +unless+: Same as +if+ but validates if lambda or method returns false. def validates_attachment_presence name, options = {} message = options[:message] || "must be set." - validates_presence_of :"#{name}_file_name", + validates_presence_of :"#{name}_file_name", :message => message, :if => options[:if], :unless => options[:unless] end - + # Places ActiveRecord-style validations on the content type of the file - # assigned. The possible options are: - # * +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 - # noted that Internet Explorer upload files with content_types that you - # 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 + # assigned. The possible options are: + # * +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 + # noted that Internet Explorer upload files with content_types that you + # 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 # match. Allows all by default. # * +message+: The message to display when the uploaded file has an invalid # content type. diff --git a/lib/paperclip/attachment.rb b/lib/paperclip/attachment.rb index 09ecf7b63..80c59bce5 100644 --- a/lib/paperclip/attachment.rb +++ b/lib/paperclip/attachment.rb @@ -4,7 +4,7 @@ module Paperclip # when the model saves, deletes when the model is destroyed, and processes # the file upon assignment. class Attachment - + def self.default_options @default_options ||= { :url => "/system/:attachment/:id/:style/:filename", @@ -50,7 +50,7 @@ def initialize name, instance, options = {} initialize_storage end - + def styles unless @normalized_styles @normalized_styles = {} @@ -60,7 +60,7 @@ def styles end @normalized_styles end - + def processors @processors.respond_to?(:call) ? @processors.call(instance) : @processors end @@ -69,7 +69,7 @@ def processors # errors, assigns attributes, and processes the file. It # 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 - # another Paperclip attachment: + # another Paperclip attachment: # new_user.avatar = old_user.avatar def assign uploaded_file ensure_required_accessors! @@ -95,7 +95,7 @@ def assign uploaded_file @dirty = true post_process - + # Reset the file size if the original file was reprocessed. instance_write(:file_size, @queued_for_write[:original].size.to_i) ensure @@ -179,8 +179,8 @@ def size def content_type instance_read(:content_type) 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 _updated_at attribute of the model. def updated_at time = instance_read(:updated_at) @@ -220,7 +220,7 @@ def reprocess! true end end - + # Returns true if a file has been assigned. def file? !original_filename.blank? @@ -324,4 +324,3 @@ def flush_errors #:nodoc: end end - diff --git a/lib/paperclip/geometry.rb b/lib/paperclip/geometry.rb index d6f7ab126..53b4d7164 100644 --- a/lib/paperclip/geometry.rb +++ b/lib/paperclip/geometry.rb @@ -75,12 +75,12 @@ def inspect to_s end - # Returns the scaling and cropping geometries (in string-based ImageMagick format) - # 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. - # 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 - # overhanging image would be cropped. Useful for square thumbnail images. The cropping + # Returns the scaling and cropping geometries (in string-based ImageMagick format) + # 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. + # 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 + # overhanging image would be cropped. Useful for square thumbnail images. The cropping # is weighted at the center of the Geometry. def transformation_to dst, crop = false if crop diff --git a/lib/paperclip/interpolations.rb b/lib/paperclip/interpolations.rb index fbf00b27a..1ad4e3fcc 100644 --- a/lib/paperclip/interpolations.rb +++ b/lib/paperclip/interpolations.rb @@ -78,7 +78,7 @@ def basename attachment, style_name # 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 # of the actual extension. - def extension attachment, style_name + def extension attachment, style_name ((style = attachment.styles[style_name]) && style[:format]) || File.extname(attachment.original_filename).gsub(/^\.+/, "") end diff --git a/lib/paperclip/iostream.rb b/lib/paperclip/iostream.rb index 2b6dbb4c8..bd08c207c 100644 --- a/lib/paperclip/iostream.rb +++ b/lib/paperclip/iostream.rb @@ -26,7 +26,7 @@ def stream_to path_or_file, in_blocks_of = 8192 while self.read(in_blocks_of, buffer) do dstio.write(buffer) end - dstio.rewind + dstio.rewind dstio end end diff --git a/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb b/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb index d0ff8c23a..3da00dfc1 100644 --- a/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +++ b/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb @@ -42,7 +42,7 @@ def failure_message end 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}" end @@ -72,4 +72,3 @@ def rejected_types_rejected? end end end - diff --git a/lib/paperclip/matchers/validate_attachment_presence_matcher.rb b/lib/paperclip/matchers/validate_attachment_presence_matcher.rb index aa97d80bc..37c4db061 100644 --- a/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +++ b/lib/paperclip/matchers/validate_attachment_presence_matcher.rb @@ -52,4 +52,3 @@ def no_error_when_valid? end end end - diff --git a/lib/paperclip/matchers/validate_attachment_size_matcher.rb b/lib/paperclip/matchers/validate_attachment_size_matcher.rb index 5d7abea3f..62bd67b81 100644 --- a/lib/paperclip/matchers/validate_attachment_size_matcher.rb +++ b/lib/paperclip/matchers/validate_attachment_size_matcher.rb @@ -93,4 +93,3 @@ def higher_than_high? end end end - diff --git a/lib/paperclip/processor.rb b/lib/paperclip/processor.rb index c553b91b1..8bf49a66b 100644 --- a/lib/paperclip/processor.rb +++ b/lib/paperclip/processor.rb @@ -6,7 +6,7 @@ module Paperclip # # Processors are required to be defined inside the Paperclip module and # 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 # 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 @@ -33,7 +33,7 @@ def self.make file, options = {}, attachment = nil new(file, options, attachment).make end end - + # Due to how ImageMagick handles its image format conversion and how Tempfile # 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 diff --git a/lib/paperclip/style.rb b/lib/paperclip/style.rb index 4d8d724ab..480efd8d2 100644 --- a/lib/paperclip/style.rb +++ b/lib/paperclip/style.rb @@ -3,7 +3,7 @@ module Paperclip # The Style class holds the definition of a thumbnail style, applying # whatever processing is required to normalize the definition and delaying # the evaluation of block parameters until useful context is available. - + class Style attr_reader :name, :attachment, :format @@ -25,7 +25,7 @@ def initialize name, definition, attachment end @format = nil if @format.blank? end - + # retrieves from the attachment the processors defined in the has_attached_file call # (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 @@ -33,17 +33,17 @@ def initialize name, definition, attachment def processors @processors || attachment.processors end - + # retrieves from the attachment the whiny setting def whiny attachment.whiny end - + # returns true if we're inclined to grumble def whiny? !!whiny end - + def convert_options attachment.send(:extra_options_for, name) end @@ -55,7 +55,7 @@ def geometry end # 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. def processor_options args = {} @@ -63,7 +63,7 @@ def processor_options args[k] = v.respond_to?(:call) ? v.call(attachment) : v end [:processors, :geometry, :format, :whiny, :convert_options].each do |k| - (arg = send(k)) && args[k] = arg + (arg = send(k)) && args[k] = arg end args end @@ -71,13 +71,13 @@ def processor_options # Supports getting and setting style properties with hash notation to ensure backwards-compatibility # eg. @attachment.styles[:large][:geometry]@ will still work def [](key) - if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key) + if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key) send(key) elsif defined? @other_args[key] @other_args[key] end end - + def []=(key, value) if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key) send("#{key}=".intern, value) @@ -85,6 +85,6 @@ def []=(key, value) @other_args[key] = value end end - + end -end \ No newline at end of file +end diff --git a/lib/paperclip/thumbnail.rb b/lib/paperclip/thumbnail.rb index 323e58d9f..e58e5091e 100644 --- a/lib/paperclip/thumbnail.rb +++ b/lib/paperclip/thumbnail.rb @@ -9,10 +9,10 @@ class Thumbnail < Processor # which is a "WxH"-style string. +format+ will be inferred from the +file+ # unless specified. Thumbnail creation will raise no errors unless # +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 super - + geometry = options[:geometry] @file = file @crop = geometry[-1,1] == '#' @@ -28,14 +28,14 @@ def initialize file, options = {}, attachment = nil @current_format = File.extname(@file.path) @basename = File.basename(@file.path, @current_format) - + end # Returns true if the +target_geometry+ is meant to crop. def crop? @crop end - + # Returns true if the image is meant to make use of additional convert options. def convert_options? !@convert_options.nil? && !@convert_options.empty? diff --git a/lib/paperclip/upfile.rb b/lib/paperclip/upfile.rb index 927e7f9cf..14525d548 100644 --- a/lib/paperclip/upfile.rb +++ b/lib/paperclip/upfile.rb @@ -50,4 +50,3 @@ def content_type class File #:nodoc: include Paperclip::Upfile end - diff --git a/paperclip.gemspec b/paperclip.gemspec index 5b51ca8c7..1b9bfae2f 100644 --- a/paperclip.gemspec +++ b/paperclip.gemspec @@ -8,7 +8,7 @@ exclude_files = ["test/s3.yml", "test/debug.log", "test/paperclip.db", "test/doc Dir[glob] end.flatten -spec = Gem::Specification.new do |s| +spec = Gem::Specification.new do |s| s.name = "paperclip" s.version = Paperclip::VERSION s.author = "Jon Yurek" @@ -32,4 +32,3 @@ spec = Gem::Specification.new do |s| s.add_development_dependency 'aws-s3' s.add_development_dependency 'sqlite3-ruby' end - diff --git a/shoulda_macros/paperclip.rb b/shoulda_macros/paperclip.rb index 7021793bf..d3f2fc097 100644 --- a/shoulda_macros/paperclip.rb +++ b/shoulda_macros/paperclip.rb @@ -46,7 +46,7 @@ def should_validate_attachment_content_type name, options = {} end # 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. # :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 diff --git a/test/attachment_test.rb b/test/attachment_test.rb index ebcf33a6b..1974c15da 100644 --- a/test/attachment_test.rb +++ b/test/attachment_test.rb @@ -41,7 +41,7 @@ class AttachmentTest < Test::Unit::TestCase setup do @dummy = Dummy.new end - + should "return false when asked exists?" do assert !@dummy.avatar.exists? end @@ -55,7 +55,7 @@ class AttachmentTest < Test::Unit::TestCase Paperclip::Attachment.default_options.keys.each do |key| 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}"), key end @@ -177,11 +177,11 @@ def thumb; "-thumb"; end assert_equal "-all", @dummy.avatar.send(:extra_options_for, :large) end end - + context "An attachment with :path that is a proc" do setup do rebuild_model :path => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" } - + @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb') @@ -190,31 +190,31 @@ def thumb; "-thumb"; end @dummyB = Dummy.new(:other => 'b') @dummyB.avatar = @file end - + teardown { @file.close } - + should "return correct path" do assert_equal "path/a.png", @dummyA.avatar.path assert_equal "path/b.png", @dummyB.avatar.path end end - + context "An attachment with :styles that is a proc" do setup do rebuild_model :styles => lambda{ |attachment| {:thumb => "50x50#", :large => "400x400"} } - + @attachment = Dummy.new.avatar end - + should "have the correct geometry" do assert_equal "50x50#", @attachment.styles[:thumb][:geometry] end end - + context "An attachment with :url that is a proc" do setup do rebuild_model :url => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" } - + @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb') @@ -223,16 +223,16 @@ def thumb; "-thumb"; end @dummyB = Dummy.new(:other => 'b') @dummyB.avatar = @file end - + teardown { @file.close } - + should "return correct url" do assert_equal "path/a.png", @dummyA.avatar.url(:original, false) assert_equal "path/b.png", @dummyB.avatar.url(:original, false) end end - geometry_specs = [ + geometry_specs = [ [ lambda{|z| "50x50#" }, :png ], lambda{|z| "50x50#" }, { :geometry => lambda{|z| "50x50#" } } @@ -326,12 +326,12 @@ class Paperclip::Test < Paperclip::Processor; end Paperclip::Thumbnail.expects(:make).with(any_parameters).returns(@file) Paperclip::Test.expects(:make).with(any_parameters).returns(@file) end - + 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 => ""}) Paperclip::Thumbnail.expects(:make).with(anything, expected_params, anything).returns(@file) end - + before_should "call #make with attachment passed as third argument" do Paperclip::Test.expects(:make).with(anything, anything, @dummy.avatar).returns(@file) end @@ -442,7 +442,7 @@ def do_after_all; end context "Attachment with strange letters" do setup do rebuild_model - + @not_file = mock @tempfile = mock @not_file.stubs(:nil?).returns(false) @@ -451,7 +451,7 @@ def do_after_all; end @not_file.expects(:to_tempfile).returns(@tempfile) @not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n") @not_file.expects(:content_type).returns("image/png\r\n") - + @dummy = Dummy.new @attachment = @dummy.avatar @attachment.expects(:valid_assignment?).with(@not_file).returns(true) @@ -459,7 +459,7 @@ def do_after_all; end @attachment.expects(:post_process) @dummy.avatar = @not_file end - + should "not remove strange letters" do assert_equal "sheep_say_bæ.png", @dummy.avatar.original_filename end @@ -597,7 +597,7 @@ def do_after_all; end cmd = %Q[identify -format "%w %h %b %m" "#{@attachment.path(style.first)}"] out = `#{cmd}` 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[3].to_s, format.to_s end diff --git a/test/geometry_test.rb b/test/geometry_test.rb index ef84a0471..3ae3b717e 100644 --- a/test/geometry_test.rb +++ b/test/geometry_test.rb @@ -65,7 +65,7 @@ class GeometryTest < Test::Unit::TestCase assert_equal "123x456#{mod}", @geo.to_s end end - + ['>', '<', '#', '@', '%', '^', '!', nil].each do |mod| should "ensure the modifier #{mod.inspect} is preserved with no height" do assert @geo = Paperclip::Geometry.parse("123x#{mod}") diff --git a/test/helper.rb b/test/helper.rb index aedf78590..dda8d9499 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -25,7 +25,7 @@ require 'active_support' require 'action_pack' -puts "Testing againt version #{ActiveRecord::VERSION::STRING}" +puts "Testing against version #{ActiveRecord::VERSION::STRING}" begin require 'ruby-debug' @@ -57,7 +57,7 @@ def setup 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')) ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") ActiveRecord::Base.establish_connection(config['test']) diff --git a/test/integration_test.rb b/test/integration_test.rb index e7512c9ba..abf21af2c 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -9,7 +9,7 @@ class IntegrationTest < Test::Unit::TestCase Dummy.create! :avatar => @file end end - + should "not exceed the open file limit" do assert_nothing_raised do dummies = Dummy.find(:all) @@ -157,7 +157,7 @@ class IntegrationTest < Test::Unit::TestCase end end end - + context "A model with no convert_options setting" do setup do rebuild_model :styles => { :large => "300x300>", @@ -168,7 +168,7 @@ class IntegrationTest < Test::Unit::TestCase :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension" @dummy = Dummy.new end - + should "have its definition return nil when asked about convert_options" do assert ! Dummy.attachment_definitions[:avatar][:convert_options] end @@ -189,7 +189,7 @@ class IntegrationTest < Test::Unit::TestCase end end end - + context "A model with a filesystem attachment" do setup do rebuild_model :styles => { :large => "300x300>", @@ -281,7 +281,7 @@ class IntegrationTest < Test::Unit::TestCase Dummy.validates_attachment_presence :avatar @d2 = Dummy.find(@dummy.id) @d2.avatar = @file - assert @d2.valid?, @d2.errors.full_messages.inspect + assert @d2.valid?, @d2.errors.full_messages.inspect @d2.avatar = @bad_file assert ! @d2.valid? end @@ -294,7 +294,7 @@ class IntegrationTest < Test::Unit::TestCase @dummy.reload assert_equal "5k.png", @dummy.avatar_file_name end - + context "that is assigned its file from another Paperclip attachment" do setup do @dummy2 = Dummy.new @@ -302,7 +302,7 @@ class IntegrationTest < Test::Unit::TestCase assert @dummy2.avatar = @file2 @dummy2.save end - + should "work when assigned a file" do assert_not_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`, `identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"` @@ -312,7 +312,7 @@ class IntegrationTest < Test::Unit::TestCase assert_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`, `identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"` end - end + end end diff --git a/test/paperclip_test.rb b/test/paperclip_test.rb index 5113b3180..5b9bb43b2 100644 --- a/test/paperclip_test.rb +++ b/test/paperclip_test.rb @@ -96,7 +96,7 @@ class PaperclipTest < Test::Unit::TestCase setup do File.expects(:exists?).with("/dev/null").returns(false) end - + should "return 'NUL'" do assert_equal "NUL", Paperclip.bit_bucket end @@ -106,7 +106,7 @@ class PaperclipTest < Test::Unit::TestCase setup do File.expects(:exists?).with("/dev/null").returns(true) end - + should "return '/dev/null'" do assert_equal "/dev/null", Paperclip.bit_bucket end @@ -152,7 +152,7 @@ class PaperclipTest < Test::Unit::TestCase should "not assign the avatar on mass-set" do @dummy.attributes = { :other => "I'm set!", :avatar => @file } - + assert_equal "I'm set!", @dummy.other assert ! @dummy.avatar? end @@ -160,7 +160,7 @@ class PaperclipTest < Test::Unit::TestCase should "still allow assigment on normal set" do @dummy.other = "I'm set!" @dummy.avatar = @file - + assert_equal "I'm set!", @dummy.other assert @dummy.avatar? end @@ -294,10 +294,10 @@ def self.should_validate validation, options, valid_file, invalid_file validation, options, valid_file, invalid_file = args valid_file &&= File.open(File.join(FIXTURES_DIR, valid_file), "rb") invalid_file &&= File.open(File.join(FIXTURES_DIR, invalid_file), "rb") - + should_validate validation, options, valid_file, invalid_file end - + context "with size validation and less_than 10240 option" do context "and assigned an invalid file" do setup do @@ -306,9 +306,9 @@ def self.should_validate validation, options, valid_file, invalid_file @dummy.avatar &&= File.open(File.join(FIXTURES_DIR, "12k.png"), "rb") @dummy.valid? end - + should "have a file size min/max error message" do - assert @dummy.errors[:avatar_file_size].any?{|e| e.match %r/between 0 and 10240 bytes/ } + assert @dummy.errors[:avatar_file_size] =~ %r/between 0 and 10240 bytes/ end end end diff --git a/test/style_test.rb b/test/style_test.rb index ff1fa565e..11e5d97d8 100644 --- a/test/style_test.rb +++ b/test/style_test.rb @@ -9,7 +9,7 @@ class StyleTest < Test::Unit::TestCase :styles => { :foo => {:geometry => "100x100#", :format => :png} } @style = @attachment.styles[:foo] end - + should "be held as a Style object" do assert_kind_of Paperclip::Style, @style end @@ -21,18 +21,18 @@ class StyleTest < Test::Unit::TestCase should "have the right geometry" do assert_equal "100x100#", @style.geometry end - + should "be whiny if the attachment is" do @attachment.expects(:whiny).returns(true) assert @style.whiny? end - + should "respond to hash notation" do assert_equal [:thumbnail], @style[:processors] assert_equal "100x100#", @style[:geometry] end end - + context "A style rule with properties supplied as procs" do setup do @attachment = attachment :path => ":basename.:extension", @@ -45,13 +45,13 @@ class StyleTest < Test::Unit::TestCase } } end - + 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[:bar].instance_variable_get("@geometry") assert_kind_of Proc, @attachment.instance_variable_get("@processors") end - + should "call procs when they are needed" do assert_equal "300x300#", @attachment.styles[:foo].geometry assert_equal "300x300#", @attachment.styles[:bar].geometry @@ -63,7 +63,7 @@ class StyleTest < Test::Unit::TestCase context "An attachment with style rules in various forms" do setup do @attachment = attachment :path => ":basename.:extension", - :styles => { + :styles => { :aslist => ["100x100", :png], :ashash => {:geometry => "100x100", :format => :png}, :asstring => "100x100" @@ -73,13 +73,13 @@ class StyleTest < Test::Unit::TestCase assert_kind_of Hash, @attachment.styles assert_equal 3, @attachment.styles.size end - + should "have styles as Style objects" do [:aslist, :ashash, :aslist].each do |s| assert_kind_of Paperclip::Style, @attachment.styles[s] end end - + should "have the right geometries" do [:aslist, :ashash, :aslist].each do |s| assert_equal @attachment.styles[s].geometry, "100x100" @@ -107,32 +107,32 @@ class StyleTest < Test::Unit::TestCase before_should "not have called extra_options_for(:thumb/:large) on initialization" do @attachment.expects(:extra_options_for).never end - + should "call extra_options_for(:thumb/:large) when convert options are requested" do @attachment.expects(:extra_options_for).with(:thumb) @attachment.styles[:thumb].convert_options end end - + context "A style rule with its own :processors" do setup do @attachment = attachment :path => ":basename.:extension", - :styles => { + :styles => { :foo => { - :geometry => "100x100#", + :geometry => "100x100#", :format => :png, :processors => [:test] - } + } }, :processors => [:thumbnail] @style = @attachment.styles[:foo] end - + should "not get processors from the attachment" do @attachment.expects(:processors).never assert_not_equal [:thumbnail], @style.processors end - + should "report its own processors" do assert_equal [:test], @style.processors end diff --git a/test/thumbnail_test.rb b/test/thumbnail_test.rb index 57f9811a1..9eff5591c 100644 --- a/test/thumbnail_test.rb +++ b/test/thumbnail_test.rb @@ -47,7 +47,7 @@ class ThumbnailTest < Test::Unit::TestCase end 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 end @@ -61,7 +61,7 @@ class ThumbnailTest < Test::Unit::TestCase end 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 end end @@ -85,7 +85,7 @@ class ThumbnailTest < Test::Unit::TestCase should "have whiny turned on by default" do assert @thumb.whiny end - + should "have convert_options set to nil by default" do assert_equal nil, @thumb.convert_options end @@ -102,7 +102,7 @@ class ThumbnailTest < Test::Unit::TestCase assert_match /100x50/, `identify "#{dst.path}"` end end - + context "being thumbnailed with source file options set" do setup do @thumb = Paperclip::Thumbnail.new(@file, @@ -125,7 +125,7 @@ class ThumbnailTest < Test::Unit::TestCase dst = @thumb.make assert_match /100x50/, `identify "#{dst.path}"` end - + context "redefined to have bad source_file_options setting" do setup do @thumb = Paperclip::Thumbnail.new(@file, @@ -138,7 +138,7 @@ class ThumbnailTest < Test::Unit::TestCase @thumb.make end end - end + end end context "being thumbnailed with convert options set" do @@ -163,7 +163,7 @@ class ThumbnailTest < Test::Unit::TestCase dst = @thumb.make assert_match /100x50/, `identify "#{dst.path}"` end - + context "redefined to have bad convert_options setting" do setup do @thumb = Paperclip::Thumbnail.new(@file, @@ -176,16 +176,16 @@ class ThumbnailTest < Test::Unit::TestCase @thumb.make end end - end + end end - + context "being thumbnailed with a blank geometry string" do setup do @thumb = Paperclip::Thumbnail.new(@file, :geometry => "", :convert_options => "-gravity center -crop \"300x300+0-0\"") end - + should "not get resized by default" do assert !@thumb.transformation_command.include?("-resize") end