Commit 3ba8fcba by Mike Burns

Merge pull request #664 from thoughtbot/options-is-a-hash

Remove the Options class, replacing it with a hash.
parents 2c08152b 5a7769b6
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
require 'erb' require 'erb'
require 'digest' require 'digest'
require 'tempfile' require 'tempfile'
require 'paperclip/options'
require 'paperclip/version' require 'paperclip/version'
require 'paperclip/upfile' require 'paperclip/upfile'
require 'paperclip/iostream' require 'paperclip/iostream'
......
...@@ -33,6 +33,7 @@ module Paperclip ...@@ -33,6 +33,7 @@ module Paperclip
end end
attr_reader :name, :instance, :default_style, :convert_options, :queued_for_write, :whiny, :options, :interpolator attr_reader :name, :instance, :default_style, :convert_options, :queued_for_write, :whiny, :options, :interpolator
attr_reader :source_file_options, :whiny
attr_accessor :post_processing attr_accessor :post_processing
# Creates an Attachment object. +name+ is the name of the attachment, # Creates an Attachment object. +name+ is the name of the attachment,
...@@ -66,7 +67,7 @@ module Paperclip ...@@ -66,7 +67,7 @@ module Paperclip
options = self.class.default_options.merge(options) options = self.class.default_options.merge(options)
@options = Paperclip::Options.new(self, options) @options = options
@post_processing = true @post_processing = true
@queued_for_delete = [] @queued_for_delete = []
@queued_for_write = {} @queued_for_write = {}
...@@ -74,18 +75,12 @@ module Paperclip ...@@ -74,18 +75,12 @@ module Paperclip
@dirty = false @dirty = false
@interpolator = options[:interpolator] @interpolator = options[:interpolator]
@url_generator = options[:url_generator].new(self, @options) @url_generator = options[:url_generator].new(self, @options)
@source_file_options = options[:source_file_options]
@whiny = options[:whiny]
initialize_storage initialize_storage
end end
# [:url, :path, :only_process, :normalized_styles, :default_url, :default_style,
# :storage, :use_timestamp, :whiny, :use_default_time_zone, :hash_digest, :hash_secret,
# :convert_options, :preserve_files].each do |field|
# define_method field do
# @options.send(field)
# end
# end
# What gets called when you call instance.attachment = File. It clears # What gets called when you call instance.attachment = File. It clears
# errors, assigns attributes, and processes the file. It # errors, assigns attributes, and processes the file. It
# also queues up the previous file for deletion, to be flushed away on # also queues up the previous file for deletion, to be flushed away on
...@@ -120,7 +115,7 @@ module Paperclip ...@@ -120,7 +115,7 @@ module Paperclip
@dirty = true @dirty = true
post_process(*@options.only_process) if post_processing post_process(*@options[:only_process]) if post_processing
# Reset the file size if the original file was reprocessed. # Reset the file size if the original file was reprocessed.
instance_write(:file_size, @queued_for_write[:original].size.to_i) instance_write(:file_size, @queued_for_write[:original].size.to_i)
...@@ -149,10 +144,10 @@ module Paperclip ...@@ -149,10 +144,10 @@ module Paperclip
# As mentioned just above, the object that generates this URL can be passed # As mentioned just above, the object that generates this URL can be passed
# in, for finer control. This object must respond to two methods: # in, for finer control. This object must respond to two methods:
# #
# +#new(Paperclip::Attachment, Paperclip::Options)+ # +#new(Paperclip::Attachment, options_hash)+
# +#for(style_name, options_hash)+ # +#for(style_name, options_hash)+
def url(style_name = default_style, options = {}) def url(style_name = default_style, options = {})
default_options = {:timestamp => @options.use_timestamp, :escape => true} default_options = {:timestamp => @options[:use_timestamp], :escape => true}
if options == true || options == false # Backwards compatibility. if options == true || options == false # Backwards compatibility.
@url_generator.for(style_name, default_options.merge(:timestamp => options)) @url_generator.for(style_name, default_options.merge(:timestamp => options))
...@@ -166,7 +161,7 @@ module Paperclip ...@@ -166,7 +161,7 @@ module Paperclip
# on disk. If the file is stored in S3, the path is the "key" part of the # on disk. If the file is stored in S3, the path is the "key" part of the
# URL, and the :bucket option refers to the S3 bucket. # URL, and the :bucket option refers to the S3 bucket.
def path(style_name = default_style) def path(style_name = default_style)
path = original_filename.nil? ? nil : interpolate(@options.path, style_name) path = original_filename.nil? ? nil : interpolate(path_option, style_name)
path.respond_to?(:unescape) ? path.unescape : path path.respond_to?(:unescape) ? path.unescape : path
end end
...@@ -176,11 +171,28 @@ module Paperclip ...@@ -176,11 +171,28 @@ module Paperclip
end end
def default_style def default_style
@options.default_style @options[:default_style]
end end
def styles def styles
@options.styles styling_option = @options[:styles]
if styling_option.respond_to?(:call) || !@normalized_styles
@normalized_styles = ActiveSupport::OrderedHash.new
(styling_option.respond_to?(:call) ? styling_option.call(self) : styling_option).each do |name, args|
@normalized_styles[name] = Paperclip::Style.new(name, args.dup, self)
end
end
@normalized_styles
end
def processors
processing_option = @options[:processors]
if processing_option.respond_to?(:call)
processing_option.call(instance)
else
processing_option
end
end end
# Returns an array containing the errors on this attachment. # Returns an array containing the errors on this attachment.
...@@ -215,7 +227,7 @@ module Paperclip ...@@ -215,7 +227,7 @@ module Paperclip
# nil to the attachment *and saving*. This is permanent. If you wish to # nil to the attachment *and saving*. This is permanent. If you wish to
# wipe out the existing attachment but not save, use #clear. # wipe out the existing attachment but not save, use #clear.
def destroy def destroy
unless @options.preserve_files unless @options[:preserve_files]
clear clear
save save
end end
...@@ -260,16 +272,16 @@ module Paperclip ...@@ -260,16 +272,16 @@ module Paperclip
# The time zone to use for timestamp interpolation. Using the default # The time zone to use for timestamp interpolation. Using the default
# time zone ensures that results are consistent across all threads. # time zone ensures that results are consistent across all threads.
def time_zone def time_zone
@options.use_default_time_zone ? Time.zone_default : Time.zone @options[:use_default_time_zone] ? Time.zone_default : Time.zone
end end
# Returns a unique hash suitable for obfuscating the URL of an otherwise # Returns a unique hash suitable for obfuscating the URL of an otherwise
# publicly viewable attachment. # publicly viewable attachment.
def hash(style_name = default_style) def hash(style_name = default_style)
raise ArgumentError, "Unable to generate hash without :hash_secret" unless @options.hash_secret raise ArgumentError, "Unable to generate hash without :hash_secret" unless @options[:hash_secret]
require 'openssl' unless defined?(OpenSSL) require 'openssl' unless defined?(OpenSSL)
data = interpolate(@options.hash_data, style_name) data = interpolate(@options[:hash_data], style_name)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@options.hash_digest).new, @options.hash_secret, data) OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@options[:hash_digest]).new, @options[:hash_secret], data)
end end
def generate_fingerprint(source) def generate_fingerprint(source)
...@@ -350,6 +362,10 @@ module Paperclip ...@@ -350,6 +362,10 @@ module Paperclip
private private
def path_option
@options[:path].respond_to?(:call) ? @options[:path].call(self) : @options[:path]
end
def ensure_required_accessors! #:nodoc: def ensure_required_accessors! #:nodoc:
%w(file_name).each do |field| %w(file_name).each do |field|
unless @instance.respond_to?("#{name}_#{field}") && @instance.respond_to?("#{name}_#{field}=") unless @instance.respond_to?("#{name}_#{field}") && @instance.respond_to?("#{name}_#{field}=")
...@@ -367,7 +383,7 @@ module Paperclip ...@@ -367,7 +383,7 @@ module Paperclip
end end
def initialize_storage #:nodoc: def initialize_storage #:nodoc:
storage_class_name = @options.storage.to_s.downcase.camelize storage_class_name = @options[:storage].to_s.downcase.camelize
begin begin
storage_module = Paperclip::Storage.const_get(storage_class_name) storage_module = Paperclip::Storage.const_get(storage_class_name)
rescue NameError rescue NameError
...@@ -377,18 +393,18 @@ module Paperclip ...@@ -377,18 +393,18 @@ module Paperclip
end end
def extra_options_for(style) #:nodoc: def extra_options_for(style) #:nodoc:
all_options = @options.convert_options[:all] all_options = @options[:convert_options][:all]
all_options = all_options.call(instance) if all_options.respond_to?(:call) all_options = all_options.call(instance) if all_options.respond_to?(:call)
style_options = @options.convert_options[style] style_options = @options[:convert_options][style]
style_options = style_options.call(instance) if style_options.respond_to?(:call) style_options = style_options.call(instance) if style_options.respond_to?(:call)
[ style_options, all_options ].compact.join(" ") [ style_options, all_options ].compact.join(" ")
end end
def extra_source_file_options_for(style) #:nodoc: def extra_source_file_options_for(style) #:nodoc:
all_options = @options.source_file_options[:all] all_options = @options[:source_file_options][:all]
all_options = all_options.call(instance) if all_options.respond_to?(:call) all_options = all_options.call(instance) if all_options.respond_to?(:call)
style_options = @options.source_file_options[style] style_options = @options[:source_file_options][style]
style_options = style_options.call(instance) if style_options.respond_to?(:call) style_options = style_options.call(instance) if style_options.respond_to?(:call)
[ style_options, all_options ].compact.join(" ") [ style_options, all_options ].compact.join(" ")
...@@ -404,7 +420,7 @@ module Paperclip ...@@ -404,7 +420,7 @@ module Paperclip
end end
def post_process_styles(*style_args) #:nodoc: def post_process_styles(*style_args) #:nodoc:
@options.styles.each do |name, style| styles.each do |name, style|
begin begin
if style_args.empty? || style_args.include?(name) if style_args.empty? || style_args.include?(name)
raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank? raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
...@@ -414,7 +430,7 @@ module Paperclip ...@@ -414,7 +430,7 @@ module Paperclip
end end
rescue PaperclipError => e rescue PaperclipError => e
log("An error was received while processing: #{e.inspect}") log("An error was received while processing: #{e.inspect}")
(@errors[:processing] ||= []) << e.message if @options.whiny (@errors[:processing] ||= []) << e.message if @options[:whiny]
end end
end end
end end
...@@ -424,8 +440,8 @@ module Paperclip ...@@ -424,8 +440,8 @@ module Paperclip
end end
def queue_existing_for_delete #:nodoc: def queue_existing_for_delete #:nodoc:
return if @options.preserve_files || !file? return if @options[:preserve_files] || !file?
@queued_for_delete += [:original, *@options.styles.keys].uniq.map do |style| @queued_for_delete += [:original, *styles.keys].uniq.map do |style|
path(style) if exists?(style) path(style) if exists?(style)
end.compact end.compact
instance_write(:file_name, nil) instance_write(:file_name, nil)
......
module Paperclip
class Options
attr_accessor :url, :path, :only_process, :normalized_styles, :default_url, :default_style,
:storage, :use_timestamp, :whiny, :use_default_time_zone, :hash_digest, :hash_secret,
:convert_options, :source_file_options, :preserve_files, :http_proxy
attr_accessor :s3_credentials, :s3_host_name, :s3_options, :s3_permissions, :s3_protocol,
:s3_headers, :s3_host_alias, :bucket
attr_accessor :fog_directory, :fog_credentials, :fog_host, :fog_public, :fog_file
def initialize(attachment, hash)
@attachment = attachment
@url = hash[:url]
@url = @url.call(@attachment) if @url.is_a?(Proc)
@path = hash[:path]
@path = @path.call(@attachment) if @path.is_a?(Proc)
@styles = hash[:styles]
@only_process = hash[:only_process]
@normalized_styles = nil
@default_url = hash[:default_url]
@default_style = hash[:default_style]
@storage = hash[:storage]
@use_timestamp = hash[:use_timestamp]
@whiny = hash[:whiny_thumbnails] || hash[:whiny]
@use_default_time_zone = hash[:use_default_time_zone]
@hash_digest = hash[:hash_digest]
@hash_data = hash[:hash_data]
@hash_secret = hash[:hash_secret]
@convert_options = hash[:convert_options]
@source_file_options = hash[:source_file_options]
@processors = hash[:processors]
@preserve_files = hash[:preserve_files]
@http_proxy = hash[:http_proxy]
@interpolator = hash[:interpolator]
@escape = hash[:escape]
@url_generator = hash[:url_generator]
#s3 options
@s3_credentials = hash[:s3_credentials]
@s3_host_name = hash[:s3_host_name]
@bucket = hash[:bucket]
@s3_options = hash[:s3_options]
@s3_permissions = hash[:s3_permissions]
@s3_protocol = hash[:s3_protocol]
@s3_headers = hash[:s3_headers]
@s3_host_alias = hash[:s3_host_alias]
#fog options
@fog_directory = hash[:fog_directory]
@fog_credentials = hash[:fog_credentials]
@fog_host = hash[:fog_host]
@fog_public = hash[:fog_public]
@fog_file = hash[:fog_file]
end
def method_missing(method, *args, &blk)
if method.to_s[-1,1] == "="
instance_variable_set("@#{method[0..-2]}", args[0])
else
instance_variable_get("@#{method}")
end
end
def processors
@processors.respond_to?(:call) ? @processors.call(@attachment.instance) : @processors
end
def styles
if @styles.respond_to?(:call) || !@normalized_styles
@normalized_styles = ActiveSupport::OrderedHash.new
(@styles.respond_to?(:call) ? @styles.call(@attachment) : @styles).each do |name, args|
normalized_styles[name] = Paperclip::Style.new(name, args.dup, @attachment)
end
end
@normalized_styles
end
end
end
...@@ -41,9 +41,9 @@ module Paperclip ...@@ -41,9 +41,9 @@ module Paperclip
end unless defined?(Fog) end unless defined?(Fog)
base.instance_eval do base.instance_eval do
unless @options.url.to_s.match(/^:fog.*url$/) unless @options[:url].to_s.match(/^:fog.*url$/)
@options.path = @options.path.gsub(/:url/, @options.url) @options[:path] = @options[:path].gsub(/:url/, @options[:url])
@options.url = ':fog_public_url' @options[:url] = ':fog_public_url'
end end
Paperclip.interpolates(:fog_public_url) do |attachment, style| Paperclip.interpolates(:fog_public_url) do |attachment, style|
attachment.public_url(style) attachment.public_url(style)
...@@ -60,16 +60,16 @@ module Paperclip ...@@ -60,16 +60,16 @@ module Paperclip
end end
def fog_credentials def fog_credentials
@fog_credentials ||= parse_credentials(@options.fog_credentials) @fog_credentials ||= parse_credentials(@options[:fog_credentials])
end end
def fog_file def fog_file
@fog_file ||= @options.fog_file || {} @fog_file ||= @options[:fog_file] || {}
end end
def fog_public def fog_public
return @fog_public if defined?(@fog_public) return @fog_public if defined?(@fog_public)
@fog_public = defined?(@options.fog_public) ? @options.fog_public : true @fog_public = defined?(@options[:fog_public]) ? @options[:fog_public] : true
end end
def flush_writes def flush_writes
...@@ -122,8 +122,8 @@ module Paperclip ...@@ -122,8 +122,8 @@ module Paperclip
end end
def public_url(style = default_style) def public_url(style = default_style)
if @options.fog_host if @options[:fog_host]
host = (@options.fog_host =~ /%d/) ? @options.fog_host % (path(style).hash % 4) : @options.fog_host host = (@options[:fog_host] =~ /%d/) ? @options[:fog_host] % (path(style).hash % 4) : @options[:fog_host]
"#{host}/#{path(style)}" "#{host}/#{path(style)}"
else else
directory.files.new(:key => path(style)).public_url directory.files.new(:key => path(style)).public_url
...@@ -156,7 +156,7 @@ module Paperclip ...@@ -156,7 +156,7 @@ module Paperclip
end end
def directory def directory
@directory ||= connection.directories.new(:key => @options.fog_directory) @directory ||= connection.directories.new(:key => @options[:fog_directory])
end end
end end
end end
......
...@@ -77,23 +77,23 @@ module Paperclip ...@@ -77,23 +77,23 @@ module Paperclip
end unless defined?(AWS::S3) end unless defined?(AWS::S3)
base.instance_eval do base.instance_eval do
@s3_options = @options.s3_options || {} @s3_options = @options[:s3_options] || {}
@s3_permissions = set_permissions(@options.s3_permissions) @s3_permissions = set_permissions(@options[:s3_permissions])
@s3_protocol = @options.s3_protocol || @s3_protocol = @options[:s3_protocol] ||
Proc.new do |style, attachment| Proc.new do |style, attachment|
permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default]) permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default])
permission = permission.call(attachment, style) if permission.is_a?(Proc) permission = permission.call(attachment, style) if permission.is_a?(Proc)
(permission == :public_read) ? 'http' : 'https' (permission == :public_read) ? 'http' : 'https'
end end
@s3_headers = @options.s3_headers || {} @s3_headers = @options[:s3_headers] || {}
unless @options.url.to_s.match(/^:s3.*url$/) || @options.url == ":asset_host" unless @options[:url].to_s.match(/^:s3.*url$/) || @options[:url] == ":asset_host"
@options.path = @options.path.gsub(/:url/, @options.url).gsub(/^:rails_root\/public\/system/, '') @options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/^:rails_root\/public\/system/, '')
@options.url = ":s3_path_url" @options[:url] = ":s3_path_url"
end end
@options.url = @options.url.inspect if @options.url.is_a?(Symbol) @options[:url] = @options[:url].inspect if @options[:url].is_a?(Symbol)
@http_proxy = @options.http_proxy || nil @http_proxy = @options[:http_proxy] || nil
if @http_proxy if @http_proxy
@s3_options.merge!({:proxy => @http_proxy}) @s3_options.merge!({:proxy => @http_proxy})
end end
...@@ -117,21 +117,21 @@ module Paperclip ...@@ -117,21 +117,21 @@ module Paperclip
end end
def s3_credentials def s3_credentials
@s3_credentials ||= parse_credentials(@options.s3_credentials) @s3_credentials ||= parse_credentials(@options[:s3_credentials])
end end
def s3_host_name def s3_host_name
@options.s3_host_name || s3_credentials[:s3_host_name] || "s3.amazonaws.com" @options[:s3_host_name] || s3_credentials[:s3_host_name] || "s3.amazonaws.com"
end end
def s3_host_alias def s3_host_alias
@s3_host_alias = @options.s3_host_alias @s3_host_alias = @options[:s3_host_alias]
@s3_host_alias = @s3_host_alias.call(self) if @s3_host_alias.is_a?(Proc) @s3_host_alias = @s3_host_alias.call(self) if @s3_host_alias.is_a?(Proc)
@s3_host_alias @s3_host_alias
end end
def bucket_name def bucket_name
@bucket = @options.bucket || s3_credentials[:bucket] @bucket = @options[:bucket] || s3_credentials[:bucket]
@bucket = @bucket.call(self) if @bucket.is_a?(Proc) @bucket = @bucket.call(self) if @bucket.is_a?(Proc)
@bucket @bucket
end end
......
...@@ -38,12 +38,12 @@ module Paperclip ...@@ -38,12 +38,12 @@ module Paperclip
# by default we behave as before, though. # by default we behave as before, though.
# if a proc has been supplied, we call it here # if a proc has been supplied, we call it here
def processors def processors
@processors.respond_to?(:call) ? @processors.call(attachment.instance) : (@processors || attachment.options.processors) @processors.respond_to?(:call) ? @processors.call(attachment.instance) : (@processors || attachment.processors)
end end
# retrieves from the attachment the whiny setting # retrieves from the attachment the whiny setting
def whiny def whiny
attachment.options.whiny attachment.whiny
end end
# returns true if we're inclined to grumble # returns true if we're inclined to grumble
...@@ -82,7 +82,7 @@ module Paperclip ...@@ -82,7 +82,7 @@ module Paperclip
end end
# Supports getting and setting style properties with hash notation to ensure backwards-compatibility # Supports getting and setting style properties with hash notation to ensure backwards-compatibility
# eg. @attachment.options.styles[:large][:geometry]@ will still work # eg. @attachment.styles[:large][:geometry]@ will still work
def [](key) def [](key)
if [:name, :convert_options, :whiny, :processors, :geometry, :format, :animated, :source_file_options].include?(key) if [:name, :convert_options, :whiny, :processors, :geometry, :format, :animated, :source_file_options].include?(key)
send(key) send(key)
......
...@@ -10,7 +10,7 @@ module Paperclip ...@@ -10,7 +10,7 @@ module Paperclip
def for(style_name, options) def for(style_name, options)
escape_url_as_needed( escape_url_as_needed(
timestamp_as_needed( timestamp_as_needed(
@attachment_options.interpolator.interpolate(most_appropriate_url, @attachment, style_name), @attachment_options[:interpolator].interpolate(most_appropriate_url, @attachment, style_name),
options options
), options) ), options)
end end
...@@ -19,12 +19,12 @@ module Paperclip ...@@ -19,12 +19,12 @@ module Paperclip
# This method is all over the place. # This method is all over the place.
def default_url def default_url
if @attachment_options.default_url.respond_to?(:call) if @attachment_options[:default_url].respond_to?(:call)
@attachment_options.default_url.call(@attachment) @attachment_options[:default_url].call(@attachment)
elsif @attachment_options.default_url.is_a?(Symbol) elsif @attachment_options[:default_url].is_a?(Symbol)
@attachment.instance.send(@attachment_options.default_url) @attachment.instance.send(@attachment_options[:default_url])
else else
@attachment_options.default_url @attachment_options[:default_url]
end end
end end
...@@ -32,7 +32,7 @@ module Paperclip ...@@ -32,7 +32,7 @@ module Paperclip
if @attachment.original_filename.nil? if @attachment.original_filename.nil?
default_url default_url
else else
@attachment_options.url @attachment_options[:url]
end end
end end
......
...@@ -131,7 +131,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -131,7 +131,7 @@ class AttachmentTest < Test::Unit::TestCase
Paperclip::Attachment.default_options.keys.each do |key| Paperclip::Attachment.default_options.keys.each do |key|
should "be the default_options for #{key}" do should "be the default_options for #{key}" do
assert_equal @old_default_options[key], assert_equal @old_default_options[key],
@attachment.options.send(key), @attachment.instance_variable_get("@options")[key],
key key
end end
end end
...@@ -146,7 +146,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -146,7 +146,7 @@ class AttachmentTest < Test::Unit::TestCase
Paperclip::Attachment.default_options.keys.each do |key| Paperclip::Attachment.default_options.keys.each do |key|
should "be the new default_options for #{key}" do should "be the new default_options for #{key}" do
assert_equal @new_default_options[key], assert_equal @new_default_options[key],
@attachment.options.send(key), @attachment.instance_variable_get("@options")[key],
key key
end end
end end
...@@ -230,12 +230,12 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -230,12 +230,12 @@ class AttachmentTest < Test::Unit::TestCase
end end
should "interpolate the hash data" do should "interpolate the hash data" do
@attachment.expects(:interpolate).with(@attachment.options.hash_data,anything).returns("interpolated_stuff") @attachment.expects(:interpolate).with(@attachment.options[:hash_data],anything).returns("interpolated_stuff")
@attachment.hash @attachment.hash
end end
should "result in the correct interpolation" do should "result in the correct interpolation" do
assert_equal "fake_models/avatars/1234/original/1234567890", @attachment.send(:interpolate,@attachment.options.hash_data) assert_equal "fake_models/avatars/1234/original/1234567890", @attachment.send(:interpolate,@attachment.options[:hash_data])
end end
should "result in a correct hash" do should "result in a correct hash" do
...@@ -318,7 +318,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -318,7 +318,7 @@ class AttachmentTest < Test::Unit::TestCase
end end
should "report the correct options when sent #extra_source_file_options_for(:thumb)" do should "report the correct options when sent #extra_source_file_options_for(:thumb)" do
assert_equal "-depth 8 -density 400", @dummy.avatar.send(:extra_source_file_options_for, :thumb), @dummy.avatar.options.source_file_options.inspect assert_equal "-depth 8 -density 400", @dummy.avatar.send(:extra_source_file_options_for, :thumb), @dummy.avatar.source_file_options.inspect
end end
should "report the correct options when sent #extra_source_file_options_for(:large)" do should "report the correct options when sent #extra_source_file_options_for(:large)" do
...@@ -400,10 +400,10 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -400,10 +400,10 @@ class AttachmentTest < Test::Unit::TestCase
end end
should "have the correct geometry" do should "have the correct geometry" do
assert_equal "50x50#", @attachment.options.styles[:thumb][:geometry] assert_equal "50x50#", @attachment.styles[:thumb][:geometry]
end end
end end
context "An attachment with conditional :styles that is a proc" do context "An attachment with conditional :styles that is a proc" do
setup do setup do
rebuild_model :styles => lambda{ |attachment| attachment.instance.other == 'a' ? {:thumb => "50x50#"} : {:large => "400x400"} } rebuild_model :styles => lambda{ |attachment| attachment.instance.other == 'a' ? {:thumb => "50x50#"} : {:large => "400x400"} }
...@@ -412,13 +412,13 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -412,13 +412,13 @@ class AttachmentTest < Test::Unit::TestCase
end end
should "have the correct styles for the assigned instance values" do should "have the correct styles for the assigned instance values" do
assert_equal "50x50#", @dummy.avatar.options.styles[:thumb][:geometry] assert_equal "50x50#", @dummy.avatar.styles[:thumb][:geometry]
assert_nil @dummy.avatar.options.styles[:large] assert_nil @dummy.avatar.styles[:large]
@dummy.other = 'b' @dummy.other = 'b'
assert_equal "400x400", @dummy.avatar.options.styles[:large][:geometry] assert_equal "400x400", @dummy.avatar.styles[:large][:geometry]
assert_nil @dummy.avatar.options.styles[:thumb] assert_nil @dummy.avatar.styles[:thumb]
end end
end end
...@@ -441,7 +441,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -441,7 +441,7 @@ class AttachmentTest < Test::Unit::TestCase
end end
should "have the correct geometry" do should "have the correct geometry" do
assert_equal "50x50#", @attachment.options.styles[:normal][:geometry] assert_equal "50x50#", @attachment.styles[:normal][:geometry]
end end
end end
end end
...@@ -459,7 +459,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -459,7 +459,7 @@ class AttachmentTest < Test::Unit::TestCase
[:processors, :whiny, :convert_options, :geometry, :format].each do |field| [:processors, :whiny, :convert_options, :geometry, :format].each do |field|
should "have the same #{field} field" do should "have the same #{field} field" do
assert_equal @attachment.options.styles[:normal][field], @attachment.options.styles[:hash][field] assert_equal @attachment.styles[:normal][field], @attachment.styles[:hash][field]
end end
end end
end end
...@@ -480,7 +480,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -480,7 +480,7 @@ class AttachmentTest < Test::Unit::TestCase
end end
should "have the correct processors" do should "have the correct processors" do
assert_equal [ :test ], @attachment.options.styles[:normal][:processors] assert_equal [ :test ], @attachment.styles[:normal][:processors]
end end
end end
end end
...@@ -860,7 +860,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -860,7 +860,7 @@ class AttachmentTest < Test::Unit::TestCase
context "and trying to delete" do context "and trying to delete" do
setup do setup do
@existing_names = @attachment.options.styles.keys.collect do |style| @existing_names = @attachment.styles.keys.collect do |style|
@attachment.path(style) @attachment.path(style)
end end
end end
......
# encoding: utf-8
require './test/helper'
class DSO < Struct.new(:one, :two)
def instance
self
end
end
class OptionsTest < Test::Unit::TestCase
should "be able to set a value" do
@options = Paperclip::Options.new(nil, {})
assert_nil @options.path
@options.path = "this/is/a/path"
assert_equal "this/is/a/path", @options.path
end
context "#styles with a plain hash" do
setup do
@attachment = DSO.new(nil, nil)
@options = Paperclip::Options.new(@attachment,
:styles => {
:something => ["400x400", :png]
})
end
should "return the right data for the style's geometry" do
assert_equal "400x400", @options.styles[:something][:geometry]
end
should "return the right data for the style's format" do
assert_equal :png, @options.styles[:something][:format]
end
end
context "#styles is a proc" do
setup do
@attachment = DSO.new("123x456", :doc)
@options = Paperclip::Options.new(@attachment,
:styles => lambda {|att|
{:something => {:geometry => att.one, :format => att.two}}
})
end
should "return the right data for the style's geometry" do
assert_equal "123x456", @options.styles[:something][:geometry]
end
should "return the right data for the style's format" do
assert_equal :doc, @options.styles[:something][:format]
end
should "run the proc each time, giving dynamic results" do
assert_equal :doc, @options.styles[:something][:format]
@attachment.two = :pdf
assert_equal :pdf, @options.styles[:something][:format]
end
end
context "#processors" do
setup do
@attachment = DSO.new(nil, nil)
end
should "return processors if not a proc" do
@options = Paperclip::Options.new(@attachment, :processors => [:one])
assert_equal [:one], @options.processors
end
should "return processors if it is a proc" do
@options = Paperclip::Options.new(@attachment, :processors => lambda{|att| [att.one]})
assert_equal [nil], @options.processors
@attachment.one = :other
assert_equal [:other], @options.processors
end
end
end
...@@ -181,7 +181,7 @@ class FogTest < Test::Unit::TestCase ...@@ -181,7 +181,7 @@ class FogTest < Test::Unit::TestCase
end end
should 'set the @fog_public instance variable to false' do should 'set the @fog_public instance variable to false' do
assert_equal false, @dummy.avatar.options.fog_public assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
assert_equal false, @dummy.avatar.fog_public assert_equal false, @dummy.avatar.fog_public
end end
end end
......
...@@ -8,7 +8,7 @@ class StyleTest < Test::Unit::TestCase ...@@ -8,7 +8,7 @@ class StyleTest < Test::Unit::TestCase
@attachment = attachment :path => ":basename.:extension", @attachment = attachment :path => ":basename.:extension",
:styles => { :foo => {:geometry => "100x100#", :format => :png} }, :styles => { :foo => {:geometry => "100x100#", :format => :png} },
:whiny => true :whiny => true
@style = @attachment.options.styles[:foo] @style = @attachment.styles[:foo]
end end
should "be held as a Style object" do should "be held as a Style object" do
...@@ -49,12 +49,12 @@ class StyleTest < Test::Unit::TestCase ...@@ -49,12 +49,12 @@ class StyleTest < Test::Unit::TestCase
end end
should "call procs when they are needed" do should "call procs when they are needed" do
assert_equal "300x300#", @attachment.options.styles[:foo].geometry assert_equal "300x300#", @attachment.styles[:foo].geometry
assert_equal "300x300#", @attachment.options.styles[:bar].geometry assert_equal "300x300#", @attachment.styles[:bar].geometry
assert_equal [:test], @attachment.options.styles[:foo].processors assert_equal [:test], @attachment.styles[:foo].processors
assert_equal [:test], @attachment.options.styles[:bar].processors assert_equal [:test], @attachment.styles[:bar].processors
assert_equal "-do_stuff", @attachment.options.styles[:bar].convert_options assert_equal "-do_stuff", @attachment.styles[:bar].convert_options
assert_equal "-do_extra_stuff", @attachment.options.styles[:bar].source_file_options assert_equal "-do_extra_stuff", @attachment.styles[:bar].source_file_options
end end
end end
...@@ -68,30 +68,30 @@ class StyleTest < Test::Unit::TestCase ...@@ -68,30 +68,30 @@ class StyleTest < Test::Unit::TestCase
:styles => styles :styles => styles
end end
should "have the right number of styles" do should "have the right number of styles" do
assert_kind_of Hash, @attachment.options.styles assert_kind_of Hash, @attachment.styles
assert_equal 3, @attachment.options.styles.size assert_equal 3, @attachment.styles.size
end end
should "have styles as Style objects" do should "have styles as Style objects" do
[:aslist, :ashash, :aslist].each do |s| [:aslist, :ashash, :aslist].each do |s|
assert_kind_of Paperclip::Style, @attachment.options.styles[s] assert_kind_of Paperclip::Style, @attachment.styles[s]
end end
end end
should "have the right geometries" do should "have the right geometries" do
[:aslist, :ashash, :aslist].each do |s| [:aslist, :ashash, :aslist].each do |s|
assert_equal @attachment.options.styles[s].geometry, "100x100" assert_equal @attachment.styles[s].geometry, "100x100"
end end
end end
should "have the right formats" do should "have the right formats" do
assert_equal @attachment.options.styles[:aslist].format, :png assert_equal @attachment.styles[:aslist].format, :png
assert_equal @attachment.options.styles[:ashash].format, :png assert_equal @attachment.styles[:ashash].format, :png
assert_nil @attachment.options.styles[:asstring].format assert_nil @attachment.styles[:asstring].format
end end
should "retain order" do should "retain order" do
assert_equal [:aslist, :ashash, :asstring], @attachment.options.styles.keys assert_equal [:aslist, :ashash, :asstring], @attachment.styles.keys
end end
end end
...@@ -100,7 +100,7 @@ class StyleTest < Test::Unit::TestCase ...@@ -100,7 +100,7 @@ class StyleTest < Test::Unit::TestCase
@attachment = attachment :path => ":basename.:extension", @attachment = attachment :path => ":basename.:extension",
:styles => {:thumb => "100x100", :large => "400x400"}, :styles => {:thumb => "100x100", :large => "400x400"},
:convert_options => {:all => "-do_stuff", :thumb => "-thumbnailize"} :convert_options => {:all => "-do_stuff", :thumb => "-thumbnailize"}
@style = @attachment.options.styles[:thumb] @style = @attachment.styles[:thumb]
@file = StringIO.new("...") @file = StringIO.new("...")
@file.stubs(:original_filename).returns("file.jpg") @file.stubs(:original_filename).returns("file.jpg")
end end
...@@ -111,7 +111,7 @@ class StyleTest < Test::Unit::TestCase ...@@ -111,7 +111,7 @@ class StyleTest < Test::Unit::TestCase
should "call extra_options_for(:thumb/:large) when convert options are requested" do should "call extra_options_for(:thumb/:large) when convert options are requested" do
@attachment.expects(:extra_options_for).with(:thumb) @attachment.expects(:extra_options_for).with(:thumb)
@attachment.options.styles[:thumb].convert_options @attachment.styles[:thumb].convert_options
end end
end end
...@@ -120,7 +120,7 @@ class StyleTest < Test::Unit::TestCase ...@@ -120,7 +120,7 @@ class StyleTest < Test::Unit::TestCase
@attachment = attachment :path => ":basename.:extension", @attachment = attachment :path => ":basename.:extension",
:styles => {:thumb => "100x100", :large => "400x400"}, :styles => {:thumb => "100x100", :large => "400x400"},
:source_file_options => {:all => "-density 400", :thumb => "-depth 8"} :source_file_options => {:all => "-density 400", :thumb => "-depth 8"}
@style = @attachment.options.styles[:thumb] @style = @attachment.styles[:thumb]
@file = StringIO.new("...") @file = StringIO.new("...")
@file.stubs(:original_filename).returns("file.jpg") @file.stubs(:original_filename).returns("file.jpg")
end end
...@@ -131,7 +131,7 @@ class StyleTest < Test::Unit::TestCase ...@@ -131,7 +131,7 @@ class StyleTest < Test::Unit::TestCase
should "call extra_options_for(:thumb/:large) when convert options are requested" do should "call extra_options_for(:thumb/:large) when convert options are requested" do
@attachment.expects(:extra_source_file_options_for).with(:thumb) @attachment.expects(:extra_source_file_options_for).with(:thumb)
@attachment.options.styles[:thumb].source_file_options @attachment.styles[:thumb].source_file_options
end end
end end
...@@ -146,7 +146,7 @@ class StyleTest < Test::Unit::TestCase ...@@ -146,7 +146,7 @@ class StyleTest < Test::Unit::TestCase
} }
}, },
:processors => [:thumbnail] :processors => [:thumbnail]
@style = @attachment.options.styles[:foo] @style = @attachment.styles[:foo]
end end
should "not get processors from the attachment" do should "not get processors from the attachment" do
...@@ -174,11 +174,11 @@ class StyleTest < Test::Unit::TestCase ...@@ -174,11 +174,11 @@ class StyleTest < Test::Unit::TestCase
end end
should "defer processing of procs until they are needed" do should "defer processing of procs until they are needed" do
assert_kind_of Proc, @attachment.options.styles[:foo].instance_variable_get("@processors") assert_kind_of Proc, @attachment.styles[:foo].instance_variable_get("@processors")
end end
should "call procs when they are needed" do should "call procs when they are needed" do
assert_equal [:test], @attachment.options.styles[:foo].processors assert_equal [:test], @attachment.styles[:foo].processors
end end
end end
...@@ -186,7 +186,7 @@ class StyleTest < Test::Unit::TestCase ...@@ -186,7 +186,7 @@ class StyleTest < Test::Unit::TestCase
setup do setup do
@attachment = attachment :path => ":basename.:extension", @attachment = attachment :path => ":basename.:extension",
:styles => { :styles => {
:thumb => "100x100", :thumb => "100x100",
:large => {:geometry => "400x400", :large => {:geometry => "400x400",
:convert_options => "-do_stuff", :convert_options => "-do_stuff",
:source_file_options => "-do_extra_stuff" :source_file_options => "-do_extra_stuff"
...@@ -197,13 +197,13 @@ class StyleTest < Test::Unit::TestCase ...@@ -197,13 +197,13 @@ class StyleTest < Test::Unit::TestCase
end end
should "have empty options for :thumb style" do should "have empty options for :thumb style" do
assert_equal "", @attachment.options.styles[:thumb].processor_options[:convert_options] assert_equal "", @attachment.styles[:thumb].processor_options[:convert_options]
assert_equal "", @attachment.options.styles[:thumb].processor_options[:source_file_options] assert_equal "", @attachment.styles[:thumb].processor_options[:source_file_options]
end end
should "have the right options for :large style" do should "have the right options for :large style" do
assert_equal "-do_stuff", @attachment.options.styles[:large].processor_options[:convert_options] assert_equal "-do_stuff", @attachment.styles[:large].processor_options[:convert_options]
assert_equal "-do_extra_stuff", @attachment.options.styles[:large].processor_options[:source_file_options] assert_equal "-do_extra_stuff", @attachment.styles[:large].processor_options[:source_file_options]
end end
end end
end end
# encoding: utf-8 # encoding: utf-8
require './test/helper' require './test/helper'
require 'paperclip/url_generator' require 'paperclip/url_generator'
require 'paperclip/options'
class UrlGeneratorTest < Test::Unit::TestCase class UrlGeneratorTest < Test::Unit::TestCase
should "use the given interpolator" do should "use the given interpolator" do
...@@ -10,7 +9,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -10,7 +9,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
url_generator = Paperclip::UrlGenerator.new(mock_attachment, url_generator = Paperclip::UrlGenerator.new(mock_attachment,
Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator)) { :interpolator => mock_interpolator })
result = url_generator.for(:style_name, {}) result = url_generator.for(:style_name, {})
assert_equal expected, result assert_equal expected, result
...@@ -22,9 +21,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -22,9 +21,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new mock_interpolator = MockInterpolator.new
default_url = "the default url" default_url = "the default url"
options = Paperclip::Options.new(mock_attachment, options = { :interpolator => mock_interpolator, :default_url => default_url}
:interpolator => mock_interpolator,
:default_url => default_url)
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {}) url_generator.for(:style_name, {})
...@@ -37,9 +34,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -37,9 +34,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new mock_interpolator = MockInterpolator.new
default_url = lambda {|attachment| "the #{attachment.class.name} default url" } default_url = lambda {|attachment| "the #{attachment.class.name} default url" }
options = Paperclip::Options.new(mock_attachment, options = { :interpolator => mock_interpolator, :default_url => default_url}
:interpolator => mock_interpolator,
:default_url => default_url)
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {}) url_generator.for(:style_name, {})
...@@ -53,9 +48,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -53,9 +48,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
mock_attachment = MockAttachment.new(:model => mock_model) mock_attachment = MockAttachment.new(:model => mock_model)
mock_interpolator = MockInterpolator.new mock_interpolator = MockInterpolator.new
default_url = :to_s default_url = :to_s
options = Paperclip::Options.new(mock_attachment, options = { :interpolator => mock_interpolator, :default_url => default_url}
:interpolator => mock_interpolator,
:default_url => default_url)
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {}) url_generator.for(:style_name, {})
...@@ -68,7 +61,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -68,7 +61,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
expected = "the expected result" expected = "the expected result"
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator) options = { :interpolator => mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:escape => true}) result = url_generator.for(:style_name, {:escape => true})
...@@ -84,7 +77,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -84,7 +77,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
end.new end.new
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator) options = { :interpolator => mock_interpolator}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:escape => true}) result = url_generator.for(:style_name, {:escape => true})
...@@ -96,7 +89,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -96,7 +89,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
expected = "the expected result" expected = "the expected result"
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator) options = { :interpolator => mock_interpolator}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:escape => false}) result = url_generator.for(:style_name, {:escape => false})
...@@ -108,7 +101,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -108,7 +101,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
expected = "the expected result" expected = "the expected result"
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator) options = { :interpolator => mock_interpolator}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {}) result = url_generator.for(:style_name, {})
...@@ -120,7 +113,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -120,7 +113,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
expected = "the expected result" expected = "the expected result"
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
mock_attachment = MockAttachment.new(:responds_to_updated_at => false) mock_attachment = MockAttachment.new(:responds_to_updated_at => false)
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator) options = { :interpolator => mock_interpolator}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => true}) result = url_generator.for(:style_name, {:timestamp => true})
...@@ -132,7 +125,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -132,7 +125,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
expected = "the expected result" expected = "the expected result"
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
mock_attachment = MockAttachment.new(:responds_to_updated_at => true, :updated_at => nil) mock_attachment = MockAttachment.new(:responds_to_updated_at => true, :updated_at => nil)
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator) options = { :interpolator => mock_interpolator}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => true}) result = url_generator.for(:style_name, {:timestamp => true})
...@@ -145,7 +138,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -145,7 +138,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
updated_at = 1231231234 updated_at = 1231231234
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
mock_attachment = MockAttachment.new(:updated_at => updated_at) mock_attachment = MockAttachment.new(:updated_at => updated_at)
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator) options = { :interpolator => mock_interpolator}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => true}) result = url_generator.for(:style_name, {:timestamp => true})
...@@ -158,7 +151,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -158,7 +151,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
updated_at = 1231231234 updated_at = 1231231234
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
mock_attachment = MockAttachment.new(:updated_at => updated_at) mock_attachment = MockAttachment.new(:updated_at => updated_at)
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator) options = { :interpolator => mock_interpolator}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => true}) result = url_generator.for(:style_name, {:timestamp => true})
...@@ -171,7 +164,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -171,7 +164,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
updated_at = 1231231234 updated_at = 1231231234
mock_interpolator = MockInterpolator.new(:result => expected) mock_interpolator = MockInterpolator.new(:result => expected)
mock_attachment = MockAttachment.new(:updated_at => updated_at) mock_attachment = MockAttachment.new(:updated_at => updated_at)
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator) options = { :interpolator => mock_interpolator}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => false}) result = url_generator.for(:style_name, {:timestamp => false})
...@@ -183,7 +176,7 @@ class UrlGeneratorTest < Test::Unit::TestCase ...@@ -183,7 +176,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
expected = "the expected result" expected = "the expected result"
mock_attachment = MockAttachment.new(:original_filename => 'exists') mock_attachment = MockAttachment.new(:original_filename => 'exists')
mock_interpolator = MockInterpolator.new mock_interpolator = MockInterpolator.new
options = Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator, :url => expected) options = { :interpolator => mock_interpolator, :url => expected}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options) url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {}) url_generator.for(:style_name, {})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment