Commit 3e6d9333 by Jon Yurek

Flesh out the tests for the options class to ensure future refactorings

parent b948f968
......@@ -62,17 +62,17 @@ module Paperclip
end
def processors
@processors.respond_to?(:call) ? @processors.call(instance) : @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
@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
@normalized_styles
end
end
end
# encoding: utf-8
require './test/helper'
class MockAttachment < Struct.new(:one, :two)
def instance
self
end
end
class OptionsTest < Test::Unit::TestCase
context "#styles with a plain hash" do
setup do
@attachment = MockAttachment.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 = MockAttachment.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 = MockAttachment.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
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