Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove the Options class, replacing it with a hash.

  • Loading branch information...
commit 5a7769b61f403b4598fa905d20e5da083dc96df2 1 parent 2c08152
@mike-burns mike-burns authored
View
1  lib/paperclip.rb
@@ -28,7 +28,6 @@
require 'erb'
require 'digest'
require 'tempfile'
-require 'paperclip/options'
require 'paperclip/version'
require 'paperclip/upfile'
require 'paperclip/iostream'
View
74 lib/paperclip/attachment.rb
@@ -33,6 +33,7 @@ def self.default_options
end
attr_reader :name, :instance, :default_style, :convert_options, :queued_for_write, :whiny, :options, :interpolator
+ attr_reader :source_file_options, :whiny
attr_accessor :post_processing
# Creates an Attachment object. +name+ is the name of the attachment,
@@ -66,7 +67,7 @@ def initialize(name, instance, options = {})
options = self.class.default_options.merge(options)
- @options = Paperclip::Options.new(self, options)
+ @options = options
@post_processing = true
@queued_for_delete = []
@queued_for_write = {}
@@ -74,18 +75,12 @@ def initialize(name, instance, options = {})
@dirty = false
@interpolator = options[:interpolator]
@url_generator = options[:url_generator].new(self, @options)
+ @source_file_options = options[:source_file_options]
+ @whiny = options[:whiny]
initialize_storage
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
# errors, assigns attributes, and processes the file. It
# also queues up the previous file for deletion, to be flushed away on
@@ -120,7 +115,7 @@ def assign uploaded_file
@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.
instance_write(:file_size, @queued_for_write[:original].size.to_i)
@@ -149,10 +144,10 @@ def assign uploaded_file
# As mentioned just above, the object that generates this URL can be passed
# 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)+
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.
@url_generator.for(style_name, default_options.merge(:timestamp => options))
@@ -166,7 +161,7 @@ def url(style_name = default_style, options = {})
# 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.
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
end
@@ -176,11 +171,28 @@ def to_s style_name = default_style
end
def default_style
- @options.default_style
+ @options[:default_style]
end
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
# Returns an array containing the errors on this attachment.
@@ -215,7 +227,7 @@ def clear
# nil to the attachment *and saving*. This is permanent. If you wish to
# wipe out the existing attachment but not save, use #clear.
def destroy
- unless @options.preserve_files
+ unless @options[:preserve_files]
clear
save
end
@@ -260,16 +272,16 @@ def updated_at
# The time zone to use for timestamp interpolation. Using the default
# time zone ensures that results are consistent across all threads.
def time_zone
- @options.use_default_time_zone ? Time.zone_default : Time.zone
+ @options[:use_default_time_zone] ? Time.zone_default : Time.zone
end
# Returns a unique hash suitable for obfuscating the URL of an otherwise
# publicly viewable attachment.
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)
- data = interpolate(@options.hash_data, style_name)
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@options.hash_digest).new, @options.hash_secret, data)
+ data = interpolate(@options[:hash_data], style_name)
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@options[:hash_digest]).new, @options[:hash_secret], data)
end
def generate_fingerprint(source)
@@ -350,6 +362,10 @@ def instance_read(attr)
private
+ def path_option
+ @options[:path].respond_to?(:call) ? @options[:path].call(self) : @options[:path]
+ end
+
def ensure_required_accessors! #:nodoc:
%w(file_name).each do |field|
unless @instance.respond_to?("#{name}_#{field}") && @instance.respond_to?("#{name}_#{field}=")
@@ -367,7 +383,7 @@ def valid_assignment? file #:nodoc:
end
def initialize_storage #:nodoc:
- storage_class_name = @options.storage.to_s.downcase.camelize
+ storage_class_name = @options[:storage].to_s.downcase.camelize
begin
storage_module = Paperclip::Storage.const_get(storage_class_name)
rescue NameError
@@ -377,18 +393,18 @@ def initialize_storage #:nodoc:
end
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)
- 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, all_options ].compact.join(" ")
end
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)
- 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, all_options ].compact.join(" ")
@@ -404,7 +420,7 @@ def post_process(*style_args) #:nodoc:
end
def post_process_styles(*style_args) #:nodoc:
- @options.styles.each do |name, style|
+ styles.each do |name, style|
begin
if style_args.empty? || style_args.include?(name)
raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
@@ -414,7 +430,7 @@ def post_process_styles(*style_args) #:nodoc:
end
rescue PaperclipError => e
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
@@ -424,8 +440,8 @@ def interpolate(pattern, style_name = default_style) #:nodoc:
end
def queue_existing_for_delete #:nodoc:
- return if @options.preserve_files || !file?
- @queued_for_delete += [:original, *@options.styles.keys].uniq.map do |style|
+ return if @options[:preserve_files] || !file?
+ @queued_for_delete += [:original, *styles.keys].uniq.map do |style|
path(style) if exists?(style)
end.compact
instance_write(:file_name, nil)
View
81 lib/paperclip/options.rb
@@ -1,81 +0,0 @@
-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
View
18 lib/paperclip/storage/fog.rb
@@ -41,9 +41,9 @@ def self.extended base
end unless defined?(Fog)
base.instance_eval do
- unless @options.url.to_s.match(/^:fog.*url$/)
- @options.path = @options.path.gsub(/:url/, @options.url)
- @options.url = ':fog_public_url'
+ unless @options[:url].to_s.match(/^:fog.*url$/)
+ @options[:path] = @options[:path].gsub(/:url/, @options[:url])
+ @options[:url] = ':fog_public_url'
end
Paperclip.interpolates(:fog_public_url) do |attachment, style|
attachment.public_url(style)
@@ -60,16 +60,16 @@ def exists?(style = default_style)
end
def fog_credentials
- @fog_credentials ||= parse_credentials(@options.fog_credentials)
+ @fog_credentials ||= parse_credentials(@options[:fog_credentials])
end
def fog_file
- @fog_file ||= @options.fog_file || {}
+ @fog_file ||= @options[:fog_file] || {}
end
def 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
def flush_writes
@@ -122,8 +122,8 @@ def to_file(style = default_style)
end
def public_url(style = default_style)
- if @options.fog_host
- host = (@options.fog_host =~ /%d/) ? @options.fog_host % (path(style).hash % 4) : @options.fog_host
+ if @options[:fog_host]
+ host = (@options[:fog_host] =~ /%d/) ? @options[:fog_host] % (path(style).hash % 4) : @options[:fog_host]
"#{host}/#{path(style)}"
else
directory.files.new(:key => path(style)).public_url
@@ -156,7 +156,7 @@ def connection
end
def directory
- @directory ||= connection.directories.new(:key => @options.fog_directory)
+ @directory ||= connection.directories.new(:key => @options[:fog_directory])
end
end
end
View
26 lib/paperclip/storage/s3.rb
@@ -77,23 +77,23 @@ def self.extended base
end unless defined?(AWS::S3)
base.instance_eval do
- @s3_options = @options.s3_options || {}
- @s3_permissions = set_permissions(@options.s3_permissions)
- @s3_protocol = @options.s3_protocol ||
+ @s3_options = @options[:s3_options] || {}
+ @s3_permissions = set_permissions(@options[:s3_permissions])
+ @s3_protocol = @options[:s3_protocol] ||
Proc.new do |style, attachment|
permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default])
permission = permission.call(attachment, style) if permission.is_a?(Proc)
(permission == :public_read) ? 'http' : 'https'
end
- @s3_headers = @options.s3_headers || {}
+ @s3_headers = @options[:s3_headers] || {}
- 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.url = ":s3_path_url"
+ 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[:url] = ":s3_path_url"
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
@s3_options.merge!({:proxy => @http_proxy})
end
@@ -117,21 +117,21 @@ def expiring_url(time = 3600, style_name = default_style)
end
def s3_credentials
- @s3_credentials ||= parse_credentials(@options.s3_credentials)
+ @s3_credentials ||= parse_credentials(@options[:s3_credentials])
end
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
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
end
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
end
View
6 lib/paperclip/style.rb
@@ -38,12 +38,12 @@ def initialize name, definition, attachment
# by default we behave as before, though.
# if a proc has been supplied, we call it here
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
# retrieves from the attachment the whiny setting
def whiny
- attachment.options.whiny
+ attachment.whiny
end
# returns true if we're inclined to grumble
@@ -82,7 +82,7 @@ def processor_options
end
# 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)
if [:name, :convert_options, :whiny, :processors, :geometry, :format, :animated, :source_file_options].include?(key)
send(key)
View
14 lib/paperclip/url_generator.rb
@@ -10,7 +10,7 @@ def initialize(attachment, attachment_options)
def for(style_name, options)
escape_url_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)
end
@@ -19,12 +19,12 @@ def for(style_name, options)
# This method is all over the place.
def default_url
- if @attachment_options.default_url.respond_to?(:call)
- @attachment_options.default_url.call(@attachment)
- elsif @attachment_options.default_url.is_a?(Symbol)
- @attachment.instance.send(@attachment_options.default_url)
+ if @attachment_options[:default_url].respond_to?(:call)
+ @attachment_options[:default_url].call(@attachment)
+ elsif @attachment_options[:default_url].is_a?(Symbol)
+ @attachment.instance.send(@attachment_options[:default_url])
else
- @attachment_options.default_url
+ @attachment_options[:default_url]
end
end
@@ -32,7 +32,7 @@ def most_appropriate_url
if @attachment.original_filename.nil?
default_url
else
- @attachment_options.url
+ @attachment_options[:url]
end
end
View
32 test/attachment_test.rb
@@ -131,7 +131,7 @@ class AttachmentTest < Test::Unit::TestCase
Paperclip::Attachment.default_options.keys.each do |key|
should "be the default_options for #{key}" do
assert_equal @old_default_options[key],
- @attachment.options.send(key),
+ @attachment.instance_variable_get("@options")[key],
key
end
end
@@ -146,7 +146,7 @@ class AttachmentTest < Test::Unit::TestCase
Paperclip::Attachment.default_options.keys.each do |key|
should "be the new default_options for #{key}" do
assert_equal @new_default_options[key],
- @attachment.options.send(key),
+ @attachment.instance_variable_get("@options")[key],
key
end
end
@@ -230,12 +230,12 @@ class AttachmentTest < Test::Unit::TestCase
end
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
end
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
should "result in a correct hash" do
@@ -318,7 +318,7 @@ class AttachmentTest < Test::Unit::TestCase
end
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
should "report the correct options when sent #extra_source_file_options_for(:large)" do
@@ -400,10 +400,10 @@ def thumb; "-thumb"; end
end
should "have the correct geometry" do
- assert_equal "50x50#", @attachment.options.styles[:thumb][:geometry]
+ assert_equal "50x50#", @attachment.styles[:thumb][:geometry]
end
end
-
+
context "An attachment with conditional :styles that is a proc" do
setup do
rebuild_model :styles => lambda{ |attachment| attachment.instance.other == 'a' ? {:thumb => "50x50#"} : {:large => "400x400"} }
@@ -412,13 +412,13 @@ def thumb; "-thumb"; end
end
should "have the correct styles for the assigned instance values" do
- assert_equal "50x50#", @dummy.avatar.options.styles[:thumb][:geometry]
- assert_nil @dummy.avatar.options.styles[:large]
+ assert_equal "50x50#", @dummy.avatar.styles[:thumb][:geometry]
+ assert_nil @dummy.avatar.styles[:large]
@dummy.other = 'b'
-
- assert_equal "400x400", @dummy.avatar.options.styles[:large][:geometry]
- assert_nil @dummy.avatar.options.styles[:thumb]
+
+ assert_equal "400x400", @dummy.avatar.styles[:large][:geometry]
+ assert_nil @dummy.avatar.styles[:thumb]
end
end
@@ -441,7 +441,7 @@ def thumb; "-thumb"; end
end
should "have the correct geometry" do
- assert_equal "50x50#", @attachment.options.styles[:normal][:geometry]
+ assert_equal "50x50#", @attachment.styles[:normal][:geometry]
end
end
end
@@ -459,7 +459,7 @@ def thumb; "-thumb"; end
[:processors, :whiny, :convert_options, :geometry, :format].each do |field|
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
@@ -480,7 +480,7 @@ class Paperclip::Test < Paperclip::Processor; end
end
should "have the correct processors" do
- assert_equal [ :test ], @attachment.options.styles[:normal][:processors]
+ assert_equal [ :test ], @attachment.styles[:normal][:processors]
end
end
end
@@ -860,7 +860,7 @@ def do_after_all; end
context "and trying to delete" do
setup do
- @existing_names = @attachment.options.styles.keys.collect do |style|
+ @existing_names = @attachment.styles.keys.collect do |style|
@attachment.path(style)
end
end
View
75 test/options_test.rb
@@ -1,75 +0,0 @@
-# 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
View
2  test/storage/fog_test.rb
@@ -181,7 +181,7 @@ class FogTest < Test::Unit::TestCase
end
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
end
end
View
54 test/style_test.rb
@@ -8,7 +8,7 @@ class StyleTest < Test::Unit::TestCase
@attachment = attachment :path => ":basename.:extension",
:styles => { :foo => {:geometry => "100x100#", :format => :png} },
:whiny => true
- @style = @attachment.options.styles[:foo]
+ @style = @attachment.styles[:foo]
end
should "be held as a Style object" do
@@ -49,12 +49,12 @@ class StyleTest < Test::Unit::TestCase
end
should "call procs when they are needed" do
- assert_equal "300x300#", @attachment.options.styles[:foo].geometry
- assert_equal "300x300#", @attachment.options.styles[:bar].geometry
- assert_equal [:test], @attachment.options.styles[:foo].processors
- assert_equal [:test], @attachment.options.styles[:bar].processors
- assert_equal "-do_stuff", @attachment.options.styles[:bar].convert_options
- assert_equal "-do_extra_stuff", @attachment.options.styles[:bar].source_file_options
+ assert_equal "300x300#", @attachment.styles[:foo].geometry
+ assert_equal "300x300#", @attachment.styles[:bar].geometry
+ assert_equal [:test], @attachment.styles[:foo].processors
+ assert_equal [:test], @attachment.styles[:bar].processors
+ assert_equal "-do_stuff", @attachment.styles[:bar].convert_options
+ assert_equal "-do_extra_stuff", @attachment.styles[:bar].source_file_options
end
end
@@ -68,30 +68,30 @@ class StyleTest < Test::Unit::TestCase
:styles => styles
end
should "have the right number of styles" do
- assert_kind_of Hash, @attachment.options.styles
- assert_equal 3, @attachment.options.styles.size
+ assert_kind_of Hash, @attachment.styles
+ assert_equal 3, @attachment.styles.size
end
should "have styles as Style objects" do
[:aslist, :ashash, :aslist].each do |s|
- assert_kind_of Paperclip::Style, @attachment.options.styles[s]
+ assert_kind_of Paperclip::Style, @attachment.styles[s]
end
end
should "have the right geometries" do
[:aslist, :ashash, :aslist].each do |s|
- assert_equal @attachment.options.styles[s].geometry, "100x100"
+ assert_equal @attachment.styles[s].geometry, "100x100"
end
end
should "have the right formats" do
- assert_equal @attachment.options.styles[:aslist].format, :png
- assert_equal @attachment.options.styles[:ashash].format, :png
- assert_nil @attachment.options.styles[:asstring].format
+ assert_equal @attachment.styles[:aslist].format, :png
+ assert_equal @attachment.styles[:ashash].format, :png
+ assert_nil @attachment.styles[:asstring].format
end
should "retain order" do
- assert_equal [:aslist, :ashash, :asstring], @attachment.options.styles.keys
+ assert_equal [:aslist, :ashash, :asstring], @attachment.styles.keys
end
end
@@ -100,7 +100,7 @@ class StyleTest < Test::Unit::TestCase
@attachment = attachment :path => ":basename.:extension",
:styles => {:thumb => "100x100", :large => "400x400"},
:convert_options => {:all => "-do_stuff", :thumb => "-thumbnailize"}
- @style = @attachment.options.styles[:thumb]
+ @style = @attachment.styles[:thumb]
@file = StringIO.new("...")
@file.stubs(:original_filename).returns("file.jpg")
end
@@ -111,7 +111,7 @@ class StyleTest < Test::Unit::TestCase
should "call extra_options_for(:thumb/:large) when convert options are requested" do
@attachment.expects(:extra_options_for).with(:thumb)
- @attachment.options.styles[:thumb].convert_options
+ @attachment.styles[:thumb].convert_options
end
end
@@ -120,7 +120,7 @@ class StyleTest < Test::Unit::TestCase
@attachment = attachment :path => ":basename.:extension",
:styles => {:thumb => "100x100", :large => "400x400"},
:source_file_options => {:all => "-density 400", :thumb => "-depth 8"}
- @style = @attachment.options.styles[:thumb]
+ @style = @attachment.styles[:thumb]
@file = StringIO.new("...")
@file.stubs(:original_filename).returns("file.jpg")
end
@@ -131,7 +131,7 @@ class StyleTest < Test::Unit::TestCase
should "call extra_options_for(:thumb/:large) when convert options are requested" do
@attachment.expects(:extra_source_file_options_for).with(:thumb)
- @attachment.options.styles[:thumb].source_file_options
+ @attachment.styles[:thumb].source_file_options
end
end
@@ -146,7 +146,7 @@ class StyleTest < Test::Unit::TestCase
}
},
:processors => [:thumbnail]
- @style = @attachment.options.styles[:foo]
+ @style = @attachment.styles[:foo]
end
should "not get processors from the attachment" do
@@ -174,11 +174,11 @@ class StyleTest < Test::Unit::TestCase
end
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
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
@@ -186,7 +186,7 @@ class StyleTest < Test::Unit::TestCase
setup do
@attachment = attachment :path => ":basename.:extension",
:styles => {
- :thumb => "100x100",
+ :thumb => "100x100",
:large => {:geometry => "400x400",
:convert_options => "-do_stuff",
:source_file_options => "-do_extra_stuff"
@@ -197,13 +197,13 @@ class StyleTest < Test::Unit::TestCase
end
should "have empty options for :thumb style" do
- assert_equal "", @attachment.options.styles[:thumb].processor_options[:convert_options]
- assert_equal "", @attachment.options.styles[:thumb].processor_options[:source_file_options]
+ assert_equal "", @attachment.styles[:thumb].processor_options[:convert_options]
+ assert_equal "", @attachment.styles[:thumb].processor_options[:source_file_options]
end
should "have the right options for :large style" do
- assert_equal "-do_stuff", @attachment.options.styles[:large].processor_options[:convert_options]
- assert_equal "-do_extra_stuff", @attachment.options.styles[:large].processor_options[:source_file_options]
+ assert_equal "-do_stuff", @attachment.styles[:large].processor_options[:convert_options]
+ assert_equal "-do_extra_stuff", @attachment.styles[:large].processor_options[:source_file_options]
end
end
end
View
35 test/url_generator_test.rb
@@ -1,7 +1,6 @@
# encoding: utf-8
require './test/helper'
require 'paperclip/url_generator'
-require 'paperclip/options'
class UrlGeneratorTest < Test::Unit::TestCase
should "use the given interpolator" do
@@ -10,7 +9,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
mock_interpolator = MockInterpolator.new(:result => expected)
url_generator = Paperclip::UrlGenerator.new(mock_attachment,
- Paperclip::Options.new(mock_attachment, :interpolator => mock_interpolator))
+ { :interpolator => mock_interpolator })
result = url_generator.for(:style_name, {})
assert_equal expected, result
@@ -22,9 +21,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new
default_url = "the default url"
- options = Paperclip::Options.new(mock_attachment,
- :interpolator => mock_interpolator,
- :default_url => default_url)
+ options = { :interpolator => mock_interpolator, :default_url => default_url}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {})
@@ -37,9 +34,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new
default_url = lambda {|attachment| "the #{attachment.class.name} default url" }
- options = Paperclip::Options.new(mock_attachment,
- :interpolator => mock_interpolator,
- :default_url => default_url)
+ options = { :interpolator => mock_interpolator, :default_url => default_url}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {})
@@ -53,9 +48,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
mock_attachment = MockAttachment.new(:model => mock_model)
mock_interpolator = MockInterpolator.new
default_url = :to_s
- options = Paperclip::Options.new(mock_attachment,
- :interpolator => mock_interpolator,
- :default_url => default_url)
+ options = { :interpolator => mock_interpolator, :default_url => default_url}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {})
@@ -68,7 +61,7 @@ class UrlGeneratorTest < Test::Unit::TestCase
expected = "the expected result"
mock_attachment = MockAttachment.new
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)
result = url_generator.for(:style_name, {:escape => true})
@@ -84,7 +77,7 @@ def escape
end.new
mock_attachment = MockAttachment.new
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)
result = url_generator.for(:style_name, {:escape => true})
@@ -96,7 +89,7 @@ def escape
expected = "the expected result"
mock_attachment = MockAttachment.new
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)
result = url_generator.for(:style_name, {:escape => false})
@@ -108,7 +101,7 @@ def escape
expected = "the expected result"
mock_attachment = MockAttachment.new
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)
result = url_generator.for(:style_name, {})
@@ -120,7 +113,7 @@ def escape
expected = "the expected result"
mock_interpolator = MockInterpolator.new(:result => expected)
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)
result = url_generator.for(:style_name, {:timestamp => true})
@@ -132,7 +125,7 @@ def escape
expected = "the expected result"
mock_interpolator = MockInterpolator.new(:result => expected)
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)
result = url_generator.for(:style_name, {:timestamp => true})
@@ -145,7 +138,7 @@ def escape
updated_at = 1231231234
mock_interpolator = MockInterpolator.new(:result => expected)
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)
result = url_generator.for(:style_name, {:timestamp => true})
@@ -158,7 +151,7 @@ def escape
updated_at = 1231231234
mock_interpolator = MockInterpolator.new(:result => expected)
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)
result = url_generator.for(:style_name, {:timestamp => true})
@@ -171,7 +164,7 @@ def escape
updated_at = 1231231234
mock_interpolator = MockInterpolator.new(:result => expected)
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)
result = url_generator.for(:style_name, {:timestamp => false})
@@ -183,7 +176,7 @@ def escape
expected = "the expected result"
mock_attachment = MockAttachment.new(:original_filename => 'exists')
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.for(:style_name, {})
Please sign in to comment.
Something went wrong with that request. Please try again.