Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changing out the paperclip plugin for the vendored gem, updating envi…

…ronment.rb to reflect that
  • Loading branch information...
commit 959cb0f5f5033c3ce7e7d94a177724df53ac9226 1 parent 2e6d46a
Matthew Peychich authored
Showing with 3,376 additions and 4,403 deletions.
  1. +2 −1  CHANGELOG
  2. +1 −0  config/environment.rb
  3. 0  vendor/{plugins/paperclip → gems/paperclip-2.1.2}/LICENSE
  4. +48 −0 vendor/gems/paperclip-2.1.2/README
  5. +22 −37 vendor/{plugins/paperclip → gems/paperclip-2.1.2}/Rakefile
  6. +5 −0 vendor/gems/paperclip-2.1.2/generators/paperclip/USAGE
  7. +2 −2 vendor/{plugins/paperclip → gems/paperclip-2.1.2}/generators/paperclip/paperclip_generator.rb
  8. +0 −2  ...perclip_migration.rb.erb → gems/paperclip-2.1.2/generators/paperclip/templates/paperclip_migration.rb}
  9. 0  vendor/{plugins/paperclip → gems/paperclip-2.1.2}/init.rb
  10. +244 −0 vendor/gems/paperclip-2.1.2/lib/paperclip.rb
  11. +243 −0 vendor/gems/paperclip-2.1.2/lib/paperclip/attachment.rb
  12. +11 −17 vendor/{plugins/paperclip → gems/paperclip-2.1.2}/lib/paperclip/geometry.rb
  13. +2 −17 vendor/{plugins/paperclip → gems/paperclip-2.1.2}/lib/paperclip/iostream.rb
  14. +132 −0 vendor/gems/paperclip-2.1.2/lib/paperclip/storage.rb
  15. +80 −0 vendor/gems/paperclip-2.1.2/lib/paperclip/thumbnail.rb
  16. +33 −0 vendor/gems/paperclip-2.1.2/lib/paperclip/upfile.rb
  17. +38 −0 vendor/gems/paperclip-2.1.2/tasks/paperclip_tasks.rake
  18. +1 −0  vendor/{plugins/paperclip → gems/paperclip-2.1.2}/test/database.yml
  19. +1,745 −0 vendor/gems/paperclip-2.1.2/test/debug.log
  20. 0  vendor/{plugins/paperclip → gems/paperclip-2.1.2}/test/fixtures/12k.png
  21. 0  vendor/{plugins/paperclip → gems/paperclip-2.1.2}/test/fixtures/50x50.png
  22. 0  vendor/{plugins/paperclip → gems/paperclip-2.1.2}/test/fixtures/5k.png
  23. 0  vendor/{plugins/paperclip → gems/paperclip-2.1.2}/test/fixtures/bad.png
  24. 0  vendor/{plugins/paperclip → gems/paperclip-2.1.2}/test/fixtures/text.txt
  25. +44 −0 vendor/gems/paperclip-2.1.2/test/helper.rb
  26. +2 −0  vendor/gems/paperclip-2.1.2/test/s3.yml
  27. +230 −0 vendor/gems/paperclip-2.1.2/test/test_attachment.rb
  28. +19 −54 vendor/{plugins/paperclip/test/geometry_test.rb → gems/paperclip-2.1.2/test/test_geometry.rb}
  29. +46 −198 vendor/{plugins/paperclip/test/integration_test.rb → gems/paperclip-2.1.2/test/test_integration.rb}
  30. +60 −0 vendor/gems/paperclip-2.1.2/test/test_iostream.rb
  31. +123 −0 vendor/gems/paperclip-2.1.2/test/test_paperclip.rb
  32. +136 −0 vendor/gems/paperclip-2.1.2/test/test_storage.rb
  33. +107 −0 vendor/gems/paperclip-2.1.2/test/test_thumbnail.rb
  34. +0 −5 vendor/plugins/paperclip/.gitignore
  35. +0 −174 vendor/plugins/paperclip/README.rdoc
  36. +0 −6 vendor/plugins/paperclip/cucumber/paperclip_steps.rb
  37. +0 −5 vendor/plugins/paperclip/generators/paperclip/USAGE
  38. +0 −353 vendor/plugins/paperclip/lib/paperclip.rb
  39. +0 −414 vendor/plugins/paperclip/lib/paperclip/attachment.rb
  40. +0 −33 vendor/plugins/paperclip/lib/paperclip/callback_compatability.rb
  41. +0 −108 vendor/plugins/paperclip/lib/paperclip/interpolations.rb
  42. +0 −4 vendor/plugins/paperclip/lib/paperclip/matchers.rb
  43. +0 −49 vendor/plugins/paperclip/lib/paperclip/matchers/have_attached_file_matcher.rb
  44. +0 −66 vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
  45. +0 −48 vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_presence_matcher.rb
  46. +0 −83 vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb
  47. +0 −49 vendor/plugins/paperclip/lib/paperclip/processor.rb
  48. +0 −243 vendor/plugins/paperclip/lib/paperclip/storage.rb
  49. +0 −73 vendor/plugins/paperclip/lib/paperclip/thumbnail.rb
  50. +0 −48 vendor/plugins/paperclip/lib/paperclip/upfile.rb
  51. +0 −37 vendor/plugins/paperclip/paperclip.gemspec
  52. +0 −117 vendor/plugins/paperclip/shoulda_macros/paperclip.rb
  53. +0 −79 vendor/plugins/paperclip/tasks/paperclip_tasks.rake
  54. +0 −1  vendor/plugins/paperclip/test/.gitignore
  55. +0 −780 vendor/plugins/paperclip/test/attachment_test.rb
  56. +0 −8 vendor/plugins/paperclip/test/fixtures/s3.yml
  57. BIN  vendor/plugins/paperclip/test/fixtures/twopage.pdf
  58. +0 −108 vendor/plugins/paperclip/test/helper.rb
  59. +0 −124 vendor/plugins/paperclip/test/interpolations_test.rb
  60. +0 −71 vendor/plugins/paperclip/test/iostream_test.rb
  61. +0 −21 vendor/plugins/paperclip/test/matchers/have_attached_file_matcher_test.rb
  62. +0 −30 vendor/plugins/paperclip/test/matchers/validate_attachment_content_type_matcher_test.rb
  63. +0 −21 vendor/plugins/paperclip/test/matchers/validate_attachment_presence_matcher_test.rb
  64. +0 −50 vendor/plugins/paperclip/test/matchers/validate_attachment_size_matcher_test.rb
  65. +0 −327 vendor/plugins/paperclip/test/paperclip_test.rb
  66. +0 −10 vendor/plugins/paperclip/test/processor_test.rb
  67. +0 −303 vendor/plugins/paperclip/test/storage_test.rb
  68. +0 −227 vendor/plugins/paperclip/test/thumbnail_test.rb
View
3  CHANGELOG
@@ -1,4 +1,5 @@
-
+2009-10-07
+ Upgraded from file_column to paperclip
2008-04-17
Fixed bug in less_captcha
View
1  config/environment.rb
@@ -34,6 +34,7 @@
config.gem 'mocha', :version=> '0.9.3'
config.gem 'redgreen', :version=> '1.2.2' unless ENV['TM_MODE']
config.gem 'gcnovus-avatar', :version=> '0.0.7', :lib => 'avatar'
+ config.gem 'paperclip', :version=> '2.1.2'
View
0  vendor/plugins/paperclip/LICENSE → vendor/gems/paperclip-2.1.2/LICENSE
File renamed without changes
View
48 vendor/gems/paperclip-2.1.2/README
@@ -0,0 +1,48 @@
+=Paperclip
+
+Paperclip is intended as an easy file attachment library for ActiveRecord. The intent behind it was to keep setup as easy as possible and to treat files as much like other attributes as possible. This means they aren't saved to their final locations on disk, nor are they deleted if set to nil, until ActiveRecord::Base#save is called. It manages validations based on size and presence, if required. It can transform its assigned image into thumbnails if needed, and the prerequisites are as simple as installing ImageMagick (which, for most modern Unix-based systems, is as easy as installing the right packages). Attached files are saved to the filesystem and referenced in the browser by an easily understandable specification, which has sensible and useful defaults.
+
+See the documentation for the +has_attached_file+ method for options.
+
+==Usage
+
+In your model:
+
+ class User < ActiveRecord::Base
+ has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
+ end
+
+In your migrations:
+
+ class AddAvatarColumsToUser < ActiveRecord::Migration
+ def self.up
+ add_column :users, :avatar_file_name, :string
+ add_column :users, :avatar_content_type, :string
+ add_column :users, :avatar_file_size, :integer
+ end
+
+ def self.down
+ remove_column :users, :avatar_file_name
+ remove_column :users, :avatar_content_type
+ remove_column :users, :avatar_file_size
+ end
+ end
+
+In your edit and new views:
+
+ <% form_for :user, @user, :url => user_path, :html => { :multipart => true } do |form| %>
+ <%= form.file_field :avatar %>
+ <% end %>
+
+In your controller:
+
+ def create
+ @user = User.create( params[:user] )
+ end
+
+In your show view:
+
+ <%= image_tag @user.avatar.url %>
+ <%= image_tag @user.avatar.url(:medium) %>
+ <%= image_tag @user.avatar.url(:thumb) %>
+
View
59 vendor/plugins/paperclip/Rakefile → vendor/gems/paperclip-2.1.2/Rakefile
@@ -1,6 +1,7 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
+require 'rake/gempackagetask'
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require 'paperclip'
@@ -11,7 +12,7 @@ task :default => [:clean, :test]
desc 'Test the paperclip plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib' << 'profile'
- t.pattern = 'test/**/*_test.rb'
+ t.pattern = 'test/**/test_*.rb'
t.verbose = true
end
@@ -26,7 +27,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = 'Paperclip'
rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
@@ -42,58 +43,42 @@ task :clean do |t|
FileUtils.rm_rf "pkg"
FileUtils.rm "test/debug.log" rescue nil
FileUtils.rm "test/paperclip.db" rescue nil
- Dir.glob("paperclip-*.gem").each{|f| FileUtils.rm f }
end
-include_file_globs = ["README*",
- "LICENSE",
- "Rakefile",
- "init.rb",
- "{generators,lib,tasks,test,shoulda_macros}/**/*"]
-exclude_file_globs = ["test/s3.yml",
- "test/debug.log",
- "test/paperclip.db",
- "test/doc",
- "test/doc/*",
- "test/pkg",
- "test/pkg/*",
- "test/tmp",
- "test/tmp/*"]
spec = Gem::Specification.new do |s|
s.name = "paperclip"
s.version = Paperclip::VERSION
s.author = "Jon Yurek"
s.email = "jyurek@thoughtbot.com"
- s.homepage = "http://www.thoughtbot.com/projects/paperclip"
+ s.homepage = "http://www.thoughtbot.com/"
s.platform = Gem::Platform::RUBY
s.summary = "File attachments as attributes for ActiveRecord"
- s.files = FileList[include_file_globs].to_a - FileList[exclude_file_globs].to_a
+ s.files = FileList["README",
+ "LICENSE",
+ "Rakefile",
+ "init.rb",
+ "{generators,lib,tasks,test}/**/*"].to_a
s.require_path = "lib"
s.test_files = FileList["test/**/test_*.rb"].to_a
s.rubyforge_project = "paperclip"
s.has_rdoc = true
- s.extra_rdoc_files = FileList["README*"].to_a
+ s.extra_rdoc_files = ["README"]
s.rdoc_options << '--line-numbers' << '--inline-source'
s.requirements << "ImageMagick"
- s.add_development_dependency 'thoughtbot-shoulda'
- s.add_development_dependency 'mocha'
-end
-
-desc "Print a list of the files to be put into the gem"
-task :manifest => :clean do
- spec.files.each do |file|
- 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
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_tar = true
end
-desc "Build the gem into the current directory"
-task :gem => :gemspec do
- `gem build #{spec.name}.gemspec`
+desc "Release new version"
+task :release => [:test, :sync_docs, :gem] do
+ require 'rubygems'
+ require 'rubyforge'
+ r = RubyForge.new
+ r.login
+ r.add_release spec.rubyforge_project,
+ spec.name,
+ spec.version,
+ File.join("pkg", "#{spec.name}-#{spec.version}.gem")
end
View
5 vendor/gems/paperclip-2.1.2/generators/paperclip/USAGE
@@ -0,0 +1,5 @@
+Usage:
+
+ script/generate attachment Class attachment1 attachment2
+
+This will create a migration that will add the proper columns to your class's table.
View
4 ...rclip/generators/paperclip/paperclip_generator.rb → ...2.1.2/generators/paperclip/paperclip_generator.rb
@@ -10,7 +10,7 @@ def manifest
file_name = generate_file_name
@migration_name = file_name.camelize
record do |m|
- m.migration_template "paperclip_migration.rb.erb",
+ m.migration_template "paperclip_migration.rb",
File.join('db', 'migrate'),
:migration_file_name => file_name
end
@@ -24,4 +24,4 @@ def generate_file_name
"add_attachments_#{names.join("_")}_to_#{@class_name.underscore}"
end
-end
+end
View
2  ...rs/paperclip/templates/paperclip_migration.rb.erb → ...rators/paperclip/templates/paperclip_migration.rb
@@ -4,7 +4,6 @@ def self.up
add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name, :string
add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type, :string
add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size, :integer
- add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at, :datetime
<% end -%>
end
@@ -13,7 +12,6 @@ def self.down
remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name
remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type
remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size
- remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at
<% end -%>
end
end
View
0  vendor/plugins/paperclip/init.rb → vendor/gems/paperclip-2.1.2/init.rb
File renamed without changes
View
244 vendor/gems/paperclip-2.1.2/lib/paperclip.rb
@@ -0,0 +1,244 @@
+# Paperclip allows file attachments that are stored in the filesystem. All graphical
+# transformations are done using the Graphics/ImageMagick command line utilities and
+# are stored in Tempfiles until the record is saved. Paperclip does not require a
+# separate model for storing the attachment's information, instead adding a few simple
+# columns to your table.
+#
+# Author:: Jon Yurek
+# Copyright:: Copyright (c) 2008 thoughtbot, inc.
+# License:: MIT License (http://www.opensource.org/licenses/mit-license.php)
+#
+# Paperclip defines an attachment as any file, though it makes special considerations
+# for image files. You can declare that a model has an attached file with the
+# +has_attached_file+ method:
+#
+# class User < ActiveRecord::Base
+# has_attached_file :avatar, :styles => { :thumb => "100x100" }
+# end
+#
+# user = User.new
+# user.avatar = params[:user][:avatar]
+# user.avatar.url
+# # => "/users/avatars/4/original_me.jpg"
+# user.avatar.url(:thumb)
+# # => "/users/avatars/4/thumb_me.jpg"
+#
+# See the +has_attached_file+ documentation for more details.
+
+require 'tempfile'
+require 'paperclip/upfile'
+require 'paperclip/iostream'
+require 'paperclip/geometry'
+require 'paperclip/thumbnail'
+require 'paperclip/storage'
+require 'paperclip/attachment'
+
+# The base module that gets included in ActiveRecord::Base.
+module Paperclip
+
+ VERSION = "2.1.2"
+
+ class << self
+ # Provides configurability to Paperclip. There are a number of options available, such as:
+ # * whiny_thumbnails: Will raise an error if Paperclip cannot process thumbnails of
+ # an uploaded image. Defaults to true.
+ # * image_magick_path: Defines the path at which to find the +convert+ and +identify+
+ # programs if they are not visible to Rails the system's search path. Defaults to
+ # nil, which uses the first executable found in the search path.
+ def options
+ @options ||= {
+ :whiny_thumbnails => true,
+ :image_magick_path => nil
+ }
+ end
+
+ def path_for_command command #:nodoc:
+ path = [options[:image_magick_path], command].compact
+ File.join(*path)
+ end
+
+ def included base #:nodoc:
+ base.extend ClassMethods
+ end
+ end
+
+ class PaperclipError < StandardError #:nodoc:
+ end
+
+ class NotIdentifiedByImageMagickError < PaperclipError #:nodoc:
+ end
+
+ 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.
+ # 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
+ # 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 "/:class/:attachment/:id/:style_:filename". See
+ # Paperclip::Attachment#interpolate for more information on variable interpolaton.
+ # :url => "/:attachment/:id/:style_:basename:extension"
+ # :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
+ # "/:class/:attachment/missing_:style.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
+ # (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
+ # default value is to generate no thumbnails.
+ # * +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"
+ # * +path+: The location of the repository of attachments on disk. This can be coordinated
+ # with the value of the +url+ option to allow files to be saved into a place where Apache
+ # can serve them without hitting your app. Defaults to
+ # ":rails_root/public/:class/:attachment/:id/:style_:filename".
+ # By default this places the files in the app's public directory which can be served
+ # directly. If you are using capistrano for deployment, a good idea would be to
+ # make a symlink to the capistrano-created system directory from inside your app's
+ # public directory.
+ # See Paperclip::Attachment#interpolate for more information on variable interpolaton.
+ # :path => "/var/app/attachments/:class/:id/:style/:filename"
+ # * +whiny_thumbnails+: Will raise an error if Paperclip cannot process thumbnails of an
+ # uploaded image. This will ovrride the global setting for this attachment.
+ # Defaults to true.
+ def has_attached_file name, options = {}
+ include InstanceMethods
+
+ write_inheritable_attribute(:attachment_definitions, {}) if attachment_definitions.nil?
+ attachment_definitions[name] = {:validations => []}.merge(options)
+
+ after_save :save_attached_files
+ before_destroy :destroy_attached_files
+
+ define_method name do |*args|
+ a = attachment_for(name)
+ (args.length > 0) ? a.to_s(args.first) : a
+ end
+
+ define_method "#{name}=" do |file|
+ attachment_for(name).assign(file)
+ end
+
+ define_method "#{name}?" do
+ ! attachment_for(name).original_filename.blank?
+ end
+
+ validates_each(name) do |record, attr, value|
+ value.send(:flush_errors)
+ end
+ end
+
+ # Places ActiveRecord-style validations on the size of the file assigned. The
+ # possible options are:
+ # * +in+: a Range of bytes (i.e. +1..1.megabyte+),
+ # * +less_than+: equivalent to :in => 0..options[:less_than]
+ # * +greater_than+: equivalent to :in => options[:greater_than]..Infinity
+ # * +message+: error message to display, use :min and :max as replacements
+ def validates_attachment_size name, options = {}
+ attachment_definitions[name][:validations] << lambda do |attachment, instance|
+ unless options[:greater_than].nil?
+ options[:in] = (options[:greater_than]..(1/0)) # 1/0 => Infinity
+ end
+ unless options[:less_than].nil?
+ options[:in] = (0..options[:less_than])
+ end
+ unless attachment.original_filename.blank? || options[:in].include?(instance[:"#{name}_file_size"].to_i)
+ min = options[:in].first
+ max = options[:in].last
+
+ if options[:message]
+ options[:message].gsub(/:min/, min.to_s).gsub(/:max/, max.to_s)
+ else
+ "file size is not between #{min} and #{max} bytes."
+ end
+ end
+ end
+ end
+
+ # Adds errors if thumbnail creation fails. The same as specifying :whiny_thumbnails => true.
+ def validates_attachment_thumbnails name, options = {}
+ attachment_definitions[name][:whiny_thumbnails] = true
+ end
+
+ # Places ActiveRecord-style validations on the presence of a file.
+ def validates_attachment_presence name, options = {}
+ attachment_definitions[name][:validations] << lambda do |attachment, instance|
+ if attachment.original_filename.blank?
+ options[:message] || "must be set."
+ end
+ end
+ 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. Allows all by default.
+ # * +message+: The message to display when the uploaded file has an invalid content type.
+ def validates_attachment_content_type name, options = {}
+ attachment_definitions[name][:validations] << lambda do |attachment, instance|
+ valid_types = [options[:content_type]].flatten
+
+ unless attachment.original_filename.nil?
+ unless options[:content_type].blank?
+ content_type = instance[:"#{name}_content_type"]
+ unless valid_types.any?{|t| t === content_type }
+ options[:message] || ActiveRecord::Errors.default_error_messages[:inclusion]
+ end
+ end
+ end
+ end
+ end
+
+ # Returns the attachment definitions defined by each call to has_attached_file.
+ def attachment_definitions
+ read_inheritable_attribute(:attachment_definitions)
+ end
+
+ end
+
+ module InstanceMethods #:nodoc:
+ def attachment_for name
+ @attachments ||= {}
+ @attachments[name] ||= Attachment.new(name, self, self.class.attachment_definitions[name])
+ end
+
+ def each_attachment
+ self.class.attachment_definitions.each do |name, definition|
+ yield(name, attachment_for(name))
+ end
+ end
+
+ def save_attached_files
+ each_attachment do |name, attachment|
+ attachment.send(:save)
+ end
+ end
+
+ def destroy_attached_files
+ each_attachment do |name, attachment|
+ attachment.send(:queue_existing_for_delete)
+ attachment.send(:flush_deletes)
+ end
+ end
+ end
+
+end
+
+# Set it all up.
+if Object.const_defined?("ActiveRecord")
+ ActiveRecord::Base.send(:include, Paperclip)
+ File.send(:include, Paperclip::Upfile)
+end
View
243 vendor/gems/paperclip-2.1.2/lib/paperclip/attachment.rb
@@ -0,0 +1,243 @@
+module Paperclip
+ # The Attachment class manages the files for a given attachment. It saves 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 => "/:attachment/:id/:style/:basename.:extension",
+ :path => ":rails_root/public/:attachment/:id/:style/:basename.:extension",
+ :styles => {},
+ :default_url => "/:attachment/:style/missing.png",
+ :default_style => :original,
+ :validations => [],
+ :storage => :filesystem
+ }
+ end
+
+ attr_reader :name, :instance, :styles, :default_style
+
+ # Creates an Attachment object. +name+ is the name of the attachment, +instance+ is the
+ # ActiveRecord object instance it's attached to, and +options+ is the same as the hash
+ # passed to +has_attached_file+.
+ def initialize name, instance, options = {}
+ @name = name
+ @instance = instance
+
+ options = self.class.default_options.merge(options)
+
+ @url = options[:url]
+ @path = options[:path]
+ @styles = options[:styles]
+ @default_url = options[:default_url]
+ @validations = options[:validations]
+ @default_style = options[:default_style]
+ @storage = options[:storage]
+ @whiny_thumbnails = options[:whiny_thumbnails]
+ @options = options
+ @queued_for_delete = []
+ @queued_for_write = {}
+ @errors = []
+ @validation_errors = nil
+ @dirty = false
+
+ normalize_style_definition
+ initialize_storage
+ end
+
+ # What gets called when you call instance.attachment = File. It clears errors,
+ # assigns attributes, processes the file, and runs validations. It also queues up
+ # the previous file for deletion, to be flushed away on #save of its host.
+ def assign uploaded_file
+ return nil unless valid_assignment?(uploaded_file)
+
+ queue_existing_for_delete
+ @errors = []
+ @validation_errors = nil
+
+ return nil if uploaded_file.nil?
+
+ @queued_for_write[:original] = uploaded_file.to_tempfile
+ @instance[:"#{@name}_file_name"] = uploaded_file.original_filename
+ @instance[:"#{@name}_content_type"] = uploaded_file.content_type
+ @instance[:"#{@name}_file_size"] = uploaded_file.size
+
+ @dirty = true
+
+ post_process
+ ensure
+ validate
+ end
+
+ # Returns the public URL of the attachment, with a given style. Note that this
+ # does not necessarily need to point to a file that your web server can access
+ # and can point to an action in your app, if you need fine grained security.
+ # This is not recommended if you don't need the security, however, for
+ # performance reasons.
+ def url style = default_style
+ original_filename.nil? ? interpolate(@default_url, style) : interpolate(@url, style)
+ end
+
+ # Returns the path of the attachment as defined by the :path optionn. If the
+ # file is stored in the filesystem the path refers to the path of the file on
+ # disk. If the file is stored in S3, the path is the "key" part of th URL,
+ # and the :bucket option refers to the S3 bucket.
+ def path style = nil #:nodoc:
+ interpolate(@path, style)
+ end
+
+ # Alias to +url+
+ def to_s style = nil
+ url(style)
+ end
+
+ # Returns true if there are any errors on this attachment.
+ def valid?
+ errors.length == 0
+ end
+
+ # Returns an array containing the errors on this attachment.
+ def errors
+ @errors.compact.uniq
+ end
+
+ # Returns true if there are changes that need to be saved.
+ def dirty?
+ @dirty
+ end
+
+ # Saves the file, if there are no errors. If there are, it flushes them to
+ # the instance's errors and returns false, cancelling the save.
+ def save
+ if valid?
+ flush_deletes
+ flush_writes
+ @dirty = false
+ true
+ else
+ flush_errors
+ false
+ end
+ end
+
+ # Returns the name of the file as originally assigned, and as lives in the
+ # <attachment>_file_name attribute of the model.
+ def original_filename
+ instance[:"#{name}_file_name"]
+ end
+
+ # A hash of procs that are run during the interpolation of a path or url.
+ # A variable of the format :name will be replaced with the return value of
+ # the proc named ":name". Each lambda takes the attachment and the current
+ # style as arguments. This hash can be added to with your own proc if
+ # necessary.
+ def self.interpolations
+ @interpolations ||= {
+ :rails_root => lambda{|attachment,style| RAILS_ROOT },
+ :class => lambda do |attachment,style|
+ attachment.instance.class.name.underscore.pluralize
+ end,
+ :basename => lambda do |attachment,style|
+ attachment.original_filename.gsub(File.extname(attachment.original_filename), "")
+ end,
+ :extension => lambda do |attachment,style|
+ ((style = attachment.styles[style]) && style.last) ||
+ File.extname(attachment.original_filename).gsub(/^\.+/, "")
+ end,
+ :id => lambda{|attachment,style| attachment.instance.id },
+ :id_partition => lambda do |attachment, style|
+ ("%09d" % attachment.instance.id).scan(/\d{3}/).join("/")
+ end,
+ :attachment => lambda{|attachment,style| attachment.name.to_s.downcase.pluralize },
+ :style => lambda{|attachment,style| style || attachment.default_style },
+ }
+ end
+
+ # This method really shouldn't be called that often. It's expected use is in the
+ # paperclip:refresh rake task and that's it. It will regenerate all thumbnails
+ # forcefully, by reobtaining the original file and going through the post-process
+ # again.
+ def reprocess!
+ new_original = Tempfile.new("paperclip-reprocess")
+ old_original = to_file(:original)
+ new_original.write( old_original.read )
+ new_original.rewind
+
+ @queued_for_write = { :original => new_original }
+ post_process
+
+ old_original.close if old_original.respond_to?(:close)
+ end
+
+ private
+
+ def valid_assignment? file #:nodoc:
+ file.nil? || (file.respond_to?(:original_filename) && file.respond_to?(:content_type))
+ end
+
+ def validate #:nodoc:
+ unless @validation_errors
+ @validation_errors = @validations.collect do |v|
+ v.call(self, instance)
+ end.flatten.compact.uniq
+ @errors += @validation_errors
+ end
+ end
+
+ def normalize_style_definition
+ @styles.each do |name, args|
+ dimensions, format = [args, nil].flatten[0..1]
+ format = nil if format == ""
+ @styles[name] = [dimensions, format]
+ end
+ end
+
+ def initialize_storage
+ @storage_module = Paperclip::Storage.const_get(@storage.to_s.capitalize)
+ self.extend(@storage_module)
+ end
+
+ def post_process #:nodoc:
+ return if @queued_for_write[:original].nil?
+ @styles.each do |name, args|
+ begin
+ dimensions, format = args
+ @queued_for_write[name] = Thumbnail.make(@queued_for_write[:original],
+ dimensions,
+ format,
+ @whiny_thumnails)
+ rescue PaperclipError => e
+ @errors << e.message if @whiny_thumbnails
+ end
+ end
+ end
+
+ def interpolate pattern, style = default_style #:nodoc:
+ interpolations = self.class.interpolations.sort{|a,b| a.first.to_s <=> b.first.to_s }
+ interpolations.reverse.inject( pattern.dup ) do |result, interpolation|
+ tag, blk = interpolation
+ result.gsub(/:#{tag}/) do |match|
+ blk.call( self, style )
+ end
+ end
+ end
+
+ def queue_existing_for_delete #:nodoc:
+ return if original_filename.blank?
+ @queued_for_delete += [:original, *@styles.keys].uniq.map do |style|
+ path(style) if exists?(style)
+ end.compact
+ @instance[:"#{@name}_file_name"] = nil
+ @instance[:"#{@name}_content_type"] = nil
+ @instance[:"#{@name}_file_size"] = nil
+ end
+
+ def flush_errors #:nodoc:
+ @errors.each do |error|
+ instance.errors.add(name, error)
+ end
+ end
+
+ end
+end
+
View
28 vendor/plugins/paperclip/lib/paperclip/geometry.rb → ...or/gems/paperclip-2.1.2/lib/paperclip/geometry.rb
@@ -1,13 +1,15 @@
module Paperclip
-
+
# Defines the geometry of an image.
class Geometry
attr_accessor :height, :width, :modifier
# Gives a Geometry representing the given height and width
def initialize width = nil, height = nil, modifier = nil
- @height = height.to_f
- @width = width.to_f
+ height = nil if height == ""
+ width = nil if width == ""
+ @height = (height || width).to_f
+ @width = (width || height).to_f
@modifier = modifier
end
@@ -15,18 +17,13 @@ def initialize width = nil, height = nil, modifier = nil
# File or path.
def self.from_file file
file = file.path if file.respond_to? "path"
- geometry = begin
- Paperclip.run("identify", %Q[-format "%wx%h" "#{file}"[0]])
- rescue PaperclipCommandLineError
- ""
- end
- parse(geometry) ||
+ parse(`#{Paperclip.path_for_command('identify')} "#{file}"`) ||
raise(NotIdentifiedByImageMagickError.new("#{file} is not recognized by the 'identify' command."))
end
# Parses a "WxH" formatted string, where W is the width and H is the height.
def self.parse string
- if match = (string && string.match(/\b(\d*)x?(\d*)\b([\>\<\#\@\%^!])?/i))
+ if match = (string && string.match(/\b(\d*)x(\d*)\b([\>\<\#\@\%^!])?/))
Geometry.new(*match[1,3])
end
end
@@ -63,11 +60,7 @@ def smaller
# Returns the width and height in a format suitable to be passed to Geometry.parse
def to_s
- s = ""
- s << width.to_i.to_s if width > 0
- s << "x#{height.to_i}" if height > 0
- s << modifier.to_s
- s
+ "%dx%d%s" % [width, height, modifier]
end
# Same as to_s
@@ -83,14 +76,15 @@ def inspect
# 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
+ ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
+
if crop
- ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
scale_geometry, scale = scaling(dst, ratio)
crop_geometry = cropping(dst, ratio, scale)
else
scale_geometry = dst.to_s
end
-
+
[ scale_geometry, crop_geometry ]
end
View
19 vendor/plugins/paperclip/lib/paperclip/iostream.rb → ...or/gems/paperclip-2.1.2/lib/paperclip/iostream.rb
@@ -11,7 +11,7 @@ def to_tempfile
# Copies one read-able object from one place to another in blocks, obviating the need to load
# the whole thing into memory. Defaults to 8k blocks. If this module is included in both
- # StringIO and Tempfile, then either can have its data copied anywhere else without typing
+ # both StringIO and Tempfile, then either can have its data copied anywhere else without typing
# worries or memory overhead worries. Returns a File if a String is passed in as the destination
# and returns the IO or Tempfile as passed in if one is sent as the destination.
def stream_to path_or_file, in_blocks_of = 8192
@@ -30,7 +30,7 @@ def stream_to path_or_file, in_blocks_of = 8192
end
end
-class IO #:nodoc:
+class IO
include IOStream
end
@@ -41,18 +41,3 @@ class IO #:nodoc:
end
end
end
-
-# Corrects a bug in Windows when asking for Tempfile size.
-if defined? Tempfile
- class Tempfile
- def size
- if @tmpfile
- @tmpfile.fsync
- @tmpfile.flush
- @tmpfile.stat.size
- else
- 0
- end
- end
- end
-end
View
132 vendor/gems/paperclip-2.1.2/lib/paperclip/storage.rb
@@ -0,0 +1,132 @@
+module Paperclip
+ module Storage
+
+ module Filesystem
+ def self.extended base
+ end
+
+ def exists?(style = default_style)
+ if original_filename
+ File.exist?(path(style))
+ else
+ false
+ end
+ end
+
+ # Returns representation of the data of the file assigned to the given
+ # style, in the format most representative of the current storage.
+ def to_file style = default_style
+ @queued_for_write[style] || (File.new(path(style)) if exists?(style))
+ end
+ alias_method :to_io, :to_file
+
+ def flush_writes #:nodoc:
+ @queued_for_write.each do |style, file|
+ FileUtils.mkdir_p(File.dirname(path(style)))
+ result = file.stream_to(path(style))
+ file.close
+ result.close
+ end
+ @queued_for_write = {}
+ end
+
+ def flush_deletes #:nodoc:
+ @queued_for_delete.each do |path|
+ begin
+ FileUtils.rm(path) if File.exist?(path)
+ rescue Errno::ENOENT => e
+ # ignore file-not-found, let everything else pass
+ end
+ end
+ @queued_for_delete = []
+ end
+ end
+
+ module S3
+ def self.extended base
+ require 'right_aws'
+ base.instance_eval do
+ @bucket = @options[:bucket]
+ @s3_credentials = parse_credentials(@options[:s3_credentials])
+ @s3_options = @options[:s3_options] || {}
+ @s3_permissions = @options[:s3_permissions] || 'public-read'
+ @url = ":s3_url"
+ end
+ base.class.interpolations[:s3_url] = lambda do |attachment, style|
+ "https://s3.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
+ end
+ end
+
+ def s3
+ @s3 ||= RightAws::S3.new(@s3_credentials[:access_key_id],
+ @s3_credentials[:secret_access_key],
+ @s3_options)
+ end
+
+ def s3_bucket
+ @s3_bucket ||= s3.bucket(@bucket, true, @s3_permissions)
+ end
+
+ def bucket_name
+ @bucket
+ end
+
+ def parse_credentials creds
+ creds = find_credentials(creds).stringify_keys
+ (creds[ENV['RAILS_ENV']] || creds).symbolize_keys
+ end
+
+ def exists?(style = default_style)
+ s3_bucket.key(path(style)) ? true : false
+ end
+
+ # Returns representation of the data of the file assigned to the given
+ # style, in the format most representative of the current storage.
+ def to_file style = default_style
+ @queued_for_write[style] || s3_bucket.key(path(style))
+ end
+ alias_method :to_io, :to_file
+
+ def flush_writes #:nodoc:
+ @queued_for_write.each do |style, file|
+ begin
+ key = s3_bucket.key(path(style))
+ key.data = file
+ key.put(nil, @s3_permissions)
+ rescue RightAws::AwsError => e
+ raise
+ end
+ end
+ @queued_for_write = {}
+ end
+
+ def flush_deletes #:nodoc:
+ @queued_for_delete.each do |path|
+ begin
+ if file = s3_bucket.key(path)
+ file.delete
+ end
+ rescue RightAws::AwsError
+ # Ignore this.
+ end
+ end
+ @queued_for_delete = []
+ end
+
+ def find_credentials creds
+ case creds
+ when File:
+ YAML.load_file(creds.path)
+ when String:
+ YAML.load_file(creds)
+ when Hash:
+ creds
+ else
+ raise ArgumentError, "Credentials are not a path, file, or hash."
+ end
+ end
+ private :find_credentials
+
+ end
+ end
+end
View
80 vendor/gems/paperclip-2.1.2/lib/paperclip/thumbnail.rb
@@ -0,0 +1,80 @@
+module Paperclip
+ # Handles thumbnailing images that are uploaded.
+ class Thumbnail
+
+ attr_accessor :file, :current_geometry, :target_geometry, :format, :whiny_thumbnails
+
+ # Creates a Thumbnail object set to work on the +file+ given. It
+ # will attempt to transform the image into one defined by +target_geometry+
+ # which is a "WxH"-style string. +format+ will be inferred from the +file+
+ # unless specified. Thumbnail creation will raise no errors unless
+ # +whiny_thumbnails+ is true (which it is, by default.
+ def initialize file, target_geometry, format = nil, whiny_thumbnails = true
+ @file = file
+ @crop = target_geometry[-1,1] == '#'
+ @target_geometry = Geometry.parse target_geometry
+ @current_geometry = Geometry.from_file file
+ @whiny_thumbnails = whiny_thumbnails
+
+ @current_format = File.extname(@file.path)
+ @basename = File.basename(@file.path, @current_format)
+
+ @format = format
+ end
+
+ # Creates a thumbnail, as specified in +initialize+, +make+s it, and returns the
+ # resulting Tempfile.
+ def self.make file, dimensions, format = nil, whiny_thumbnails = true
+ new(file, dimensions, format, whiny_thumbnails).make
+ end
+
+ # Returns true if the +target_geometry+ is meant to crop.
+ def crop?
+ @crop
+ end
+
+ # Performs the conversion of the +file+ into a thumbnail. Returns the Tempfile
+ # that contains the new image.
+ def make
+ src = @file
+ dst = Tempfile.new([@basename, @format].compact.join("."))
+ dst.binmode
+
+ command = <<-end_command
+ #{ Paperclip.path_for_command('convert') }
+ "#{ File.expand_path(src.path) }"
+ #{ transformation_command }
+ "#{ File.expand_path(dst.path) }"
+ end_command
+ success = system(command.gsub(/\s+/, " "))
+
+ if success && $?.exitstatus != 0 && @whiny_thumbnails
+ raise PaperclipError, "There was an error processing this thumbnail"
+ end
+
+ dst
+ end
+
+ # Returns the command ImageMagick's +convert+ needs to transform the image
+ # into the thumbnail.
+ def transformation_command
+ scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
+ trans = "-scale \"#{scale}\""
+ trans << " -crop \"#{crop}\" +repage" if crop
+ trans
+ 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
+ # on this blog post:
+ # http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
+ class Tempfile < ::Tempfile
+ # Replaces Tempfile's +make_tmpname+ with one that honors file extensions.
+ def make_tmpname(basename, n)
+ extension = File.extname(basename)
+ sprintf("%s,%d,%d%s", File.basename(basename, extension), $$, n, extension)
+ end
+ end
+end
View
33 vendor/gems/paperclip-2.1.2/lib/paperclip/upfile.rb
@@ -0,0 +1,33 @@
+module Paperclip
+ # The Upfile module is a convenience module for adding uploaded-file-type methods
+ # to the +File+ class. Useful for testing.
+ # user.avatar = File.new("test/test_avatar.jpg")
+ module Upfile
+
+ # Infer the MIME-type of the file from the extension.
+ def content_type
+ type = self.path.match(/\.(\w+)$/)[1] rescue "octet-stream"
+ case type
+ when "jpg", "png", "gif" then "image/#{type}"
+ when "txt" then "text/plain"
+ when "csv", "xml", "html", "htm", "css", "js" then "text/#{type}"
+ else "x-application/#{type}"
+ end
+ end
+
+ # Returns the file's normal name.
+ def original_filename
+ File.basename(self.path)
+ end
+
+ # Returns the size of the file.
+ def size
+ File.size(self)
+ end
+ end
+
+end
+
+class File #:nodoc:
+ include Paperclip::Upfile
+end
View
38 vendor/gems/paperclip-2.1.2/tasks/paperclip_tasks.rake
@@ -0,0 +1,38 @@
+def obtain_class
+ class_name = ENV['CLASS'] || ENV['class']
+ raise "Must specify CLASS" unless class_name
+ @klass = Object.const_get(class_name)
+end
+
+def obtain_attachments
+ name = ENV['ATTACHMENT'] || ENV['attachment']
+ raise "Class #{@klass.name} has no attachments specified" unless @klass.respond_to?(:attachment_definitions)
+ if !name.blank? && @klass.attachment_definitions.keys.include?(name)
+ [ name ]
+ else
+ @klass.attachment_definitions.keys
+ end
+end
+
+namespace :paperclip do
+ desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
+ task :refresh => :environment do
+ klass = obtain_class
+ names = obtain_attachments
+ instances = klass.find(:all)
+
+ puts "Regenerating thumbnails for #{instances.length} instances of #{klass.name}:"
+ instances.each do |instance|
+ names.each do |name|
+ result = if instance.send("#{ name }?")
+ instance.send(name).reprocess!
+ instance.send(name).save
+ else
+ true
+ end
+ print result ? "." : "x"; $stdout.flush
+ end
+ end
+ puts " Done."
+ end
+end
View
1  vendor/plugins/paperclip/test/database.yml → vendor/gems/paperclip-2.1.2/test/database.yml
@@ -1,4 +1,5 @@
test:
adapter: sqlite3
+ #dbfile: paperclip.db
database: ":memory:"
View
1,745 vendor/gems/paperclip-2.1.2/test/debug.log
1,745 additions, 0 deletions not shown
View
0  vendor/plugins/paperclip/test/fixtures/12k.png → vendor/gems/paperclip-2.1.2/test/fixtures/12k.png
File renamed without changes
View
0  vendor/plugins/paperclip/test/fixtures/50x50.png → vendor/gems/paperclip-2.1.2/test/fixtures/50x50.png
File renamed without changes
View
0  vendor/plugins/paperclip/test/fixtures/5k.png → vendor/gems/paperclip-2.1.2/test/fixtures/5k.png
File renamed without changes
View
0  vendor/plugins/paperclip/test/fixtures/bad.png → vendor/gems/paperclip-2.1.2/test/fixtures/bad.png
File renamed without changes
View
0  vendor/plugins/paperclip/test/fixtures/text.txt → vendor/gems/paperclip-2.1.2/test/fixtures/text.txt
File renamed without changes
View
44 vendor/gems/paperclip-2.1.2/test/helper.rb
@@ -0,0 +1,44 @@
+require 'rubygems'
+require 'test/unit'
+require 'shoulda'
+require 'mocha'
+require 'tempfile'
+
+require 'active_record'
+begin
+ require 'ruby-debug'
+rescue LoadError
+ puts "ruby-debug not loaded"
+end
+
+ROOT = File.join(File.dirname(__FILE__), '..')
+RAILS_ROOT = ROOT
+
+$LOAD_PATH << File.join(ROOT, 'lib')
+$LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
+
+require File.join(ROOT, 'lib', 'paperclip.rb')
+
+ENV['RAILS_ENV'] ||= 'test'
+
+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[ENV['RAILS_ENV'] || 'test'])
+
+def rebuild_model options = {}
+ ActiveRecord::Base.connection.create_table :dummies, :force => true do |table|
+ table.column :other, :string
+ table.column :avatar_file_name, :string
+ table.column :avatar_content_type, :string
+ table.column :avatar_file_size, :integer
+ end
+
+ ActiveRecord::Base.send(:include, Paperclip)
+ Object.send(:remove_const, "Dummy") rescue nil
+ Object.const_set("Dummy", Class.new(ActiveRecord::Base))
+ Dummy.class_eval do
+ include Paperclip
+ has_attached_file :avatar, options
+ end
+end
View
2  vendor/gems/paperclip-2.1.2/test/s3.yml
@@ -0,0 +1,2 @@
+access_key_id: 11196XQ35WGRKEVQN782
+secret_access_key: TczVRadcH5sealaWUMpbY/Hnex90iCmJ3LDM5w74
View
230 vendor/gems/paperclip-2.1.2/test/test_attachment.rb
@@ -0,0 +1,230 @@
+require 'test/helper'
+
+class Dummy
+ # This is a dummy class
+end
+
+class AttachmentTest < Test::Unit::TestCase
+ context "Attachment default_options" do
+ setup do
+ rebuild_model
+ @old_default_options = Paperclip::Attachment.default_options.dup
+ @new_default_options = @old_default_options.merge({
+ :path => "argle/bargle",
+ :url => "fooferon",
+ :default_url => "not here.png"
+ })
+ end
+
+ teardown do
+ Paperclip::Attachment.default_options.merge! @old_default_options
+ end
+
+ should "be overrideable" do
+ Paperclip::Attachment.default_options.merge!(@new_default_options)
+ @new_default_options.keys.each do |key|
+ assert_equal @new_default_options[key],
+ Paperclip::Attachment.default_options[key]
+ end
+ end
+
+ context "without an Attachment" do
+ setup do
+ @dummy = Dummy.new
+ end
+
+ should "return false when asked exists?" do
+ assert !@dummy.avatar.exists?
+ end
+ end
+
+ context "on an Attachment" do
+ setup do
+ @dummy = Dummy.new
+ @attachment = @dummy.avatar
+ end
+
+ Paperclip::Attachment.default_options.keys.each do |key|
+ should "be the default_options for #{key}" do
+ assert_equal @old_default_options[key],
+ @attachment.instance_variable_get("@#{key}"),
+ key
+ end
+ end
+
+ context "when redefined" do
+ setup do
+ Paperclip::Attachment.default_options.merge!(@new_default_options)
+ @dummy = Dummy.new
+ @attachment = @dummy.avatar
+ end
+
+ Paperclip::Attachment.default_options.keys.each do |key|
+ should "be the new default_options for #{key}" do
+ assert_equal @new_default_options[key],
+ @attachment.instance_variable_get("@#{key}"),
+ key
+ end
+ end
+ end
+ end
+ end
+
+ context "An attachment with similarly named interpolations" do
+ setup do
+ rebuild_model :path => ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
+ @dummy = Dummy.new
+ @dummy.stubs(:id).returns(1024)
+ @file = File.new(File.join(File.dirname(__FILE__),
+ "fixtures",
+ "5k.png"))
+ @dummy.avatar = @file
+ end
+
+ should "make sure that they are interpolated correctly" do
+ assert_equal "1024.omg/1024-bbq/1024what/000/001/024.wtf", @dummy.avatar.path
+ end
+ end
+
+ context "An attachment" do
+ setup do
+ Paperclip::Attachment.default_options.merge!({
+ :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
+ })
+ FileUtils.rm_rf("tmp")
+ @instance = stub
+ @instance.stubs(:id).returns(41)
+ @instance.stubs(:class).returns(Dummy)
+ @instance.stubs(:[]).with(:test_file_name).returns(nil)
+ @instance.stubs(:[]).with(:test_content_type).returns(nil)
+ @instance.stubs(:[]).with(:test_file_size).returns(nil)
+ @attachment = Paperclip::Attachment.new(:test,
+ @instance)
+ @file = File.new(File.join(File.dirname(__FILE__),
+ "fixtures",
+ "5k.png"))
+ end
+
+ should "return its default_url when no file assigned" do
+ assert @attachment.to_file.nil?
+ assert_equal "/tests/original/missing.png", @attachment.url
+ assert_equal "/tests/blah/missing.png", @attachment.url(:blah)
+ end
+
+ context "with a file assigned in the database" do
+ setup do
+ @instance.stubs(:[]).with(:test_file_name).returns("5k.png")
+ @instance.stubs(:[]).with(:test_content_type).returns("image/png")
+ @instance.stubs(:[]).with(:test_file_size).returns(12345)
+ end
+
+ should "return a correct url even if the file does not exist" do
+ assert_nil @attachment.to_file
+ assert_equal "/tests/41/blah/5k.png", @attachment.url(:blah)
+ end
+
+ should "return the proper path when filename has a single .'s" do
+ assert_equal "./test/../tmp/tests/dummies/original/41/5k.png", @attachment.path
+ end
+
+ should "return the proper path when filename has multiple .'s" do
+ @instance.stubs(:[]).with(:test_file_name).returns("5k.old.png")
+ assert_equal "./test/../tmp/tests/dummies/original/41/5k.old.png", @attachment.path
+ end
+
+ context "when expecting three styles" do
+ setup do
+ styles = {:styles => { :large => ["400x400", :png],
+ :medium => ["100x100", :gif],
+ :small => ["32x32#", :jpg]}}
+ @attachment = Paperclip::Attachment.new(:test,
+ @instance,
+ styles)
+ end
+
+ context "and assigned a file" do
+ setup do
+ @instance.expects(:[]=).with(:test_file_name,
+ File.basename(@file.path))
+ @instance.expects(:[]=).with(:test_content_type, "image/png")
+ @instance.expects(:[]=).with(:test_file_size, @file.size)
+ @instance.expects(:[]=).with(:test_file_name, nil)
+ @instance.expects(:[]=).with(:test_content_type, nil)
+ @instance.expects(:[]=).with(:test_file_size, nil)
+ @attachment.assign(@file)
+ end
+
+ should "be dirty" do
+ assert @attachment.dirty?
+ end
+
+ context "and saved" do
+ setup do
+ @attachment.save
+ end
+
+ should "return the real url" do
+ assert @attachment.to_file
+ assert_equal "/tests/41/original/5k.png", @attachment.url
+ assert_equal "/tests/41/small/5k.jpg", @attachment.url(:small)
+ end
+
+ should "commit the files to disk" do
+ [:large, :medium, :small].each do |style|
+ io = @attachment.to_io(style)
+ assert File.exists?(io)
+ assert ! io.is_a?(::Tempfile)
+ end
+ end
+
+ should "save the files as the right formats and sizes" do
+ [[:large, 400, 61, "PNG"],
+ [:medium, 100, 15, "GIF"],
+ [:small, 32, 32, "JPEG"]].each do |style|
+ cmd = "identify -format '%w %h %b %m' " +
+ "#{@attachment.to_io(style.first).path}"
+ out = `#{cmd}`
+ width, height, size, format = out.split(" ")
+ 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
+ end
+
+ should "still have its #file attribute not be nil" do
+ assert ! @attachment.to_file.nil?
+ end
+
+ context "and deleted" do
+ setup do
+ @existing_names = @attachment.styles.keys.collect do |style|
+ @attachment.path(style)
+ end
+ @instance.expects(:[]=).with(:test_file_name, nil)
+ @instance.expects(:[]=).with(:test_content_type, nil)
+ @instance.expects(:[]=).with(:test_file_size, nil)
+ @attachment.assign nil
+ @attachment.save
+ end
+
+ should "delete the files" do
+ @existing_names.each{|f| assert ! File.exists?(f) }
+ end
+ end
+ end
+ end
+ end
+
+ end
+
+ context "when trying a nonexistant storage type" do
+ setup do
+ rebuild_model :storage => :not_here
+ end
+
+ should "not be able to find the module" do
+ assert_raise(NameError){ Dummy.new.avatar }
+ end
+ end
+ end
+end
View
73 vendor/plugins/paperclip/test/geometry_test.rb → vendor/gems/paperclip-2.1.2/test/test_geometry.rb
@@ -1,4 +1,8 @@
-require 'test/helper'
+require 'rubygems'
+require 'test/unit'
+require 'shoulda'
+
+require File.join(File.dirname(__FILE__), '..', 'lib', 'paperclip', 'geometry.rb')
class GeometryTest < Test::Unit::TestCase
context "Paperclip::Geometry" do
@@ -8,15 +12,15 @@ class GeometryTest < Test::Unit::TestCase
assert_equal 768, @geo.height
end
- should "set height to 0 if height dimension is missing" do
+ should "correctly create a square if the height dimension is missing" do
assert @geo = Paperclip::Geometry.new(1024)
assert_equal 1024, @geo.width
- assert_equal 0, @geo.height
+ assert_equal 1024, @geo.height
end
- should "set width to 0 if width dimension is missing" do
+ should "correctly create a square if the width dimension is missing" do
assert @geo = Paperclip::Geometry.new(nil, 768)
- assert_equal 0, @geo.width
+ assert_equal 768, @geo.width
assert_equal 768, @geo.height
end
@@ -28,20 +32,19 @@ class GeometryTest < Test::Unit::TestCase
should "be generated from a xH-formatted string" do
assert @geo = Paperclip::Geometry.parse("x600")
- assert_equal 0, @geo.width
+ assert_equal 600, @geo.width
assert_equal 600, @geo.height
end
-
+
should "be generated from a Wx-formatted string" do
assert @geo = Paperclip::Geometry.parse("800x")
assert_equal 800, @geo.width
- assert_equal 0, @geo.height
+ assert_equal 800, @geo.height
end
- should "be generated from a W-formatted string" do
- assert @geo = Paperclip::Geometry.parse("800")
- assert_equal 800, @geo.width
- assert_equal 0, @geo.height
+ should "ensure the modifier is nil if only one dimension present" do
+ assert @geo = Paperclip::Geometry.parse("123x")
+ assert_nil @geo.modifier
end
should "ensure the modifier is nil if not present" do
@@ -49,60 +52,22 @@ class GeometryTest < Test::Unit::TestCase
assert_nil @geo.modifier
end
- should "treat x and X the same in geometries" do
- @lower = Paperclip::Geometry.parse("123x456")
- @upper = Paperclip::Geometry.parse("123X456")
- assert_equal 123, @lower.width
- assert_equal 123, @upper.width
- assert_equal 456, @lower.height
- assert_equal 456, @upper.height
- end
-
- ['>', '<', '#', '@', '%', '^', '!', nil].each do |mod|
- should "ensure the modifier #{mod.inspect} is preserved" do
+ ['>', '<', '#', '@', '%', '^', '!'].each do |mod|
+ should "ensure the modifier #{mod} is preserved" do
assert @geo = Paperclip::Geometry.parse("123x456#{mod}")
assert_equal mod, @geo.modifier
- 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}")
- assert_equal mod, @geo.modifier
- assert_equal "123#{mod}", @geo.to_s
end
end
should "make sure the modifier gets passed during transformation_to" do
assert @src = Paperclip::Geometry.parse("123x456")
assert @dst = Paperclip::Geometry.parse("123x456>")
- assert_equal ["123x456>", nil], @src.transformation_to(@dst)
- end
-
- should "generate correct ImageMagick formatting string for W-formatted string" do
- assert @geo = Paperclip::Geometry.parse("800")
- assert_equal "800", @geo.to_s
- end
-
- should "generate correct ImageMagick formatting string for Wx-formatted string" do
- assert @geo = Paperclip::Geometry.parse("800x")
- assert_equal "800", @geo.to_s
- end
-
- should "generate correct ImageMagick formatting string for xH-formatted string" do
- assert @geo = Paperclip::Geometry.parse("x600")
- assert_equal "x600", @geo.to_s
- end
-
- should "generate correct ImageMagick formatting string for WxH-formatted string" do
- assert @geo = Paperclip::Geometry.parse("800x600")
- assert_equal "800x600", @geo.to_s
+ assert_equal "123x456>", @src.transformation_to(@dst).to_s
end
should "be generated from a file" do
file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
- file = File.new(file, 'rb')
+ file = File.new(file)
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
assert @geo.height > 0
assert @geo.width > 0
View
244 vendor/plugins/paperclip/test/integration_test.rb → vendor/gems/paperclip-2.1.2/test/test_integration.rb
@@ -1,10 +1,10 @@
-require 'test/helper'
+require 'test/helper.rb'
class IntegrationTest < Test::Unit::TestCase
context "Many models at once" do
setup do
rebuild_model
- @file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
+ @file = File.new(File.join(FIXTURES_DIR, "5k.png"))
300.times do |i|
Dummy.create! :avatar => @file
end
@@ -24,22 +24,19 @@ class IntegrationTest < Test::Unit::TestCase
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
- "5k.png"), 'rb')
+ "5k.png"))
@dummy.avatar = @file
assert @dummy.save
end
- teardown { @file.close }
-
should "create its thumbnails properly" do
- assert_match /\b50x50\b/, `identify "#{@dummy.avatar.path(:thumb)}"`
+ assert_match /\b50x50\b/, `identify '#{@dummy.avatar.path(:thumb)}'`
end
context "redefining its attachment styles" do
setup do
Dummy.class_eval do
has_attached_file :avatar, :styles => { :thumb => "150x25#" }
- has_attached_file :avatar, :styles => { :thumb => "150x25#", :dynamic => lambda { |a| '50x50#' } }
end
@d2 = Dummy.find(@dummy.id)
@d2.avatar.reprocess!
@@ -47,71 +44,7 @@ class IntegrationTest < Test::Unit::TestCase
end
should "create its thumbnails properly" do
- assert_match /\b150x25\b/, `identify "#{@dummy.avatar.path(:thumb)}"`
- assert_match /\b50x50\b/, `identify "#{@dummy.avatar.path(:dynamic)}"`
- end
- end
- end
-
- context "A model that modifies its original" do
- setup do
- rebuild_model :styles => { :original => "2x2#" }
- @dummy = Dummy.new
- @file = File.new(File.join(File.dirname(__FILE__),
- "fixtures",
- "5k.png"), 'rb')
- @dummy.avatar = @file
- end
-
- should "report the file size of the processed file and not the original" do
- assert_not_equal @file.size, @dummy.avatar.size
- end
-
- teardown { @file.close }
- end
-
- context "A model with attachments scoped under an id" do
- setup do
- rebuild_model :styles => { :large => "100x100",
- :medium => "50x50" },
- :path => ":rails_root/tmp/:id/:attachments/:style.:extension"
- @dummy = Dummy.new
- @file = File.new(File.join(File.dirname(__FILE__),
- "fixtures",
- "5k.png"), 'rb')
- @dummy.avatar = @file
- end
-
- teardown { @file.close }
-
- context "when saved" do
- setup do
- @dummy.save
- @saved_path = @dummy.avatar.path(:large)
- end
-
- should "have a large file in the right place" do
- assert File.exists?(@dummy.avatar.path(:large))
- end
-
- context "and deleted" do
- setup do
- @dummy.avatar.clear
- @dummy.save
- end
-
- should "not have a large file in the right place anymore" do
- assert ! File.exists?(@saved_path)
- end
-
- should "not have its next two parent directories" do
- assert ! File.exists?(File.dirname(@saved_path))
- assert ! File.exists?(File.dirname(File.dirname(@saved_path)))
- end
-
- before_should "not die if an unexpected SystemCallError happens" do
- FileUtils.stubs(:rmdir).raises(Errno::EPIPE)
- end
+ assert_match /\b150x25\b/, `identify '#{@dummy.avatar.path(:thumb)}'`
end
end
end
@@ -158,38 +91,6 @@ class IntegrationTest < Test::Unit::TestCase
end
end
- context "A model with no convert_options setting" do
- setup do
- rebuild_model :styles => { :large => "300x300>",
- :medium => "100x100",
- :thumb => ["32x32#", :gif] },
- :default_style => :medium,
- :url => "/:attachment/:class/:style/:id/:basename.:extension",
- :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
-
- context "redefined to have convert_options setting" do
- setup do
- rebuild_model :styles => { :large => "300x300>",
- :medium => "100x100",
- :thumb => ["32x32#", :gif] },
- :convert_options => "-strip -depth 8",
- :default_style => :medium,
- :url => "/:attachment/:class/:style/:id/:basename.:extension",
- :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
- end
-
- should "have its definition return convert_options value when asked about convert_options" do
- assert_equal "-strip -depth 8", Dummy.attachment_definitions[:avatar][:convert_options]
- end
- end
- end
-
context "A model with a filesystem attachment" do
setup do
rebuild_model :styles => { :large => "300x300>",
@@ -200,8 +101,8 @@ class IntegrationTest < Test::Unit::TestCase
:url => "/:attachment/:class/:style/:id/:basename.:extension",
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@dummy = Dummy.new
- @file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
- @bad_file = File.new(File.join(FIXTURES_DIR, "bad.png"), 'rb')
+ @file = File.new(File.join(FIXTURES_DIR, "5k.png"))
+ @bad_file = File.new(File.join(FIXTURES_DIR, "bad.png"))
assert @dummy.avatar = @file
assert @dummy.valid?
@@ -213,18 +114,18 @@ class IntegrationTest < Test::Unit::TestCase
["300x46", :large],
["100x15", :medium],
["32x32", :thumb]].each do |geo, style|
- cmd = %Q[identify -format "%wx%h" "#{@dummy.avatar.path(style)}"]
+ cmd = %Q[identify -format "%wx%h" #{@dummy.avatar.to_file(style).path}]
assert_equal geo, `#{cmd}`.chomp, cmd
end
- saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.path(s) }
+ saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.to_file(s).path }
@d2 = Dummy.find(@dummy.id)
- assert_equal "100x15", `identify -format "%wx%h" "#{@d2.avatar.path}"`.chomp
- assert_equal "434x66", `identify -format "%wx%h" "#{@d2.avatar.path(:original)}"`.chomp
- assert_equal "300x46", `identify -format "%wx%h" "#{@d2.avatar.path(:large)}"`.chomp
- assert_equal "100x15", `identify -format "%wx%h" "#{@d2.avatar.path(:medium)}"`.chomp
- assert_equal "32x32", `identify -format "%wx%h" "#{@d2.avatar.path(:thumb)}"`.chomp
+ assert_equal "100x15", `identify -format "%wx%h" #{@d2.avatar.to_file.path}`.chomp
+ assert_equal "434x66", `identify -format "%wx%h" #{@d2.avatar.to_file(:original).path}`.chomp
+ assert_equal "300x46", `identify -format "%wx%h" #{@d2.avatar.to_file(:large).path}`.chomp
+ assert_equal "100x15", `identify -format "%wx%h" #{@d2.avatar.to_file(:medium).path}`.chomp
+ assert_equal "32x32", `identify -format "%wx%h" #{@d2.avatar.to_file(:thumb).path}`.chomp
@dummy.avatar = "not a valid file but not nil"
assert_equal File.basename(@file.path), @dummy.avatar_file_name
@@ -235,7 +136,7 @@ class IntegrationTest < Test::Unit::TestCase
assert File.exists?(p)
end
- @dummy.avatar.clear
+ @dummy.avatar = nil
assert_nil @dummy.avatar_file_name
assert @dummy.valid?
assert @dummy.save
@@ -253,12 +154,12 @@ class IntegrationTest < Test::Unit::TestCase
assert_equal @dummy.avatar_file_name, @d2.avatar_file_name
[:thumb, :medium, :large, :original].each do |style|
- assert_equal @dummy.avatar.path(style), @d2.avatar.path(style)
+ assert_equal @dummy.avatar.to_file(style).path, @d2.avatar.to_file(style).path
end
- saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.path(s) }
+ saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.to_file(s).path }
- @d2.avatar.clear
+ @d2.avatar = nil
assert @d2.save
saved_paths.each do |p|
@@ -266,81 +167,44 @@ class IntegrationTest < Test::Unit::TestCase
end
end
- should "know the difference between good files, bad files, and not files" do
+ should "know the difference between good files, bad files, not files, and nil" do
expected = @dummy.avatar.to_file
@dummy.avatar = "not a file"
assert @dummy.valid?
- assert_equal expected.path, @dummy.avatar.path
- expected.close
+ assert_equal expected.path, @dummy.avatar.to_file.path
@dummy.avatar = @bad_file
assert ! @dummy.valid?
+ @dummy.avatar = nil
+ assert @dummy.valid?
end
- should "know the difference between good files, bad files, and not files when validating" do
+ should "know the difference between good files, bad files, not files, and nil when validating" do
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.avatar = @bad_file
assert ! @d2.valid?
+ @d2.avatar = nil
+ assert ! @d2.valid?
end
- should "be able to reload without saving and not have the file disappear" do
+ should "be able to reload without saving an not have the file disappear" do
@dummy.avatar = @file
assert @dummy.save
- @dummy.avatar.clear
+ @dummy.avatar = nil
assert_nil @dummy.avatar_file_name
@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
- @file2 = File.new(File.join(FIXTURES_DIR, "12k.png"), 'rb')
- 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)}"`
-
- assert @dummy.avatar = @dummy2.avatar
- @dummy.save
- assert_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
- `identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
- end
- end
-
- end
-
- context "A model with an attachments association and a Paperclip attachment" do
- setup do
- Dummy.class_eval do
- has_many :attachments, :class_name => 'Dummy'
- end
-
- @dummy = Dummy.new
- @dummy.avatar = File.new(File.join(File.dirname(__FILE__),
- "fixtures",
- "5k.png"), 'rb')
- end
-
- should "should not error when saving" do
- assert_nothing_raised do
- @dummy.save!
- end
- end
end
if ENV['S3_TEST_BUCKET']
def s3_files_for attachment
[:thumb, :medium, :large, :original].inject({}) do |files, style|
- data = `curl "#{attachment.url(style)}" 2>/dev/null`.chomp
+ data = `curl '#{attachment.url(style)}' 2>/dev/null`.chomp
t = Tempfile.new("paperclip-test")
- t.binmode
t.write(data)
t.rewind
files[style] = t
@@ -348,14 +212,6 @@ def s3_files_for attachment
end
end
- def s3_headers_for attachment, style
- `curl --head "#{attachment.url(style)}" 2>/dev/null`.split("\n").inject({}) do |h,head|
- split_head = head.chomp.split(/\s*:\s*/, 2)
- h[split_head.first.downcase] = split_head.last unless split_head.empty?
- h
- end
- end
-
context "A model with an S3 attachment" do
setup do
rebuild_model :styles => { :large => "300x300>",
@@ -369,8 +225,8 @@ def s3_headers_for attachment, style
:bucket => ENV['S3_TEST_BUCKET'],
:path => ":class/:attachment/:id/:style/:basename.:extension"
@dummy = Dummy.new
- @file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
- @bad_file = File.new(File.join(FIXTURES_DIR, "bad.png"), 'rb')
+ @file = File.new(File.join(FIXTURES_DIR, "5k.png"))
+ @bad_file = File.new(File.join(FIXTURES_DIR, "bad.png"))
assert @dummy.avatar = @file
assert @dummy.valid?
@@ -379,17 +235,12 @@ def s3_headers_for attachment, style
@files_on_s3 = s3_files_for @dummy.avatar
end
- should "have the same contents as the original" do
- @file.rewind
- assert_equal @file.read, @files_on_s3[:original].read
- end
-
should "write and delete its files" do
[["434x66", :original],
["300x46", :large],
["100x15", :medium],
["32x32", :thumb]].each do |geo, style|
- cmd = %Q[identify -format "%wx%h" "#{@files_on_s3[style].path}"]
+ cmd = %Q[identify -format "%wx%h" #{@files_on_s3[style].path}]
assert_equal geo, `#{cmd}`.chomp, cmd
end
@@ -399,7 +250,7 @@ def s3_headers_for attachment, style
["300x46", :large],
["100x15", :medium],
["32x32", :thumb]].each do |geo, style|
- cmd = %Q[identify -format "%wx%h" "#{@d2_files[style].path}"]
+ cmd = %Q[identify -format "%wx%h" #{@d2_files[style].path}]
assert_equal geo, `#{cmd}`.chomp, cmd
end
@@ -408,17 +259,19 @@ def s3_headers_for attachment, style
assert @dummy.valid?
assert @dummy.save
- [:thumb, :medium, :large, :original].each do |style|
- assert @dummy.avatar.exists?(style)
+ saved_keys = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.to_file(s) }
+
+ saved_keys.each do |key|
+ assert key.exists?
end
- @dummy.avatar.clear
+ @dummy.avatar = nil
assert_nil @dummy.avatar_file_name
assert @dummy.valid?
assert @dummy.save
- [:thumb, :medium, :large, :original].each do |style|
- assert ! @dummy.avatar.exists?(style)
+ saved_keys.each do |key|
+ assert ! key.exists?
end
@d2 = Dummy.find(@dummy.id)
@@ -430,16 +283,16 @@ def s3_headers_for attachment, style
assert_equal @dummy.avatar_file_name, @d2.avatar_file_name
[:thumb, :medium, :large, :original].each do |style|
- assert_equal @dummy.avatar.to_file(style).read, @d2.avatar.to_file(style).read
+ assert_equal @dummy.avatar.to_file(style).to_s, @d2.avatar.to_file(style).to_s
end
saved_keys = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.to_file(s) }
- @d2.avatar.clear
+ @d2.avatar =