Commit 31cc0d6e by jyurek

Formatting a bit

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@433 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 8cceb0ea
...@@ -19,7 +19,7 @@ module Paperclip ...@@ -19,7 +19,7 @@ module Paperclip
# Creates an Attachment object. +name+ is the name of the attachment, +instance+ is the # 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 # ActiveRecord object instance it's attached to, and +options+ is the same as the hash
# passed to +has_attached_file+. # passed to +has_attached_file+.
def initialize name, instance, options def initialize name, instance, options = {}
@name = name @name = name
@instance = instance @instance = instance
......
...@@ -19,7 +19,8 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -19,7 +19,8 @@ class AttachmentTest < Test::Unit::TestCase
should "be overrideable" do should "be overrideable" do
Paperclip::Attachment.default_options.merge!(@new_default_options) Paperclip::Attachment.default_options.merge!(@new_default_options)
@new_default_options.keys.each do |key| @new_default_options.keys.each do |key|
assert_equal @new_default_options[key], Paperclip::Attachment.default_options[key] assert_equal @new_default_options[key],
Paperclip::Attachment.default_options[key]
end end
end end
...@@ -29,9 +30,11 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -29,9 +30,11 @@ class AttachmentTest < Test::Unit::TestCase
@attachment = @dummy.avatar @attachment = @dummy.avatar
end end
should "be the default_options" do Paperclip::Attachment.default_options.keys.each do |key|
@old_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 assert_equal @old_default_options[key],
@attachment.instance_variable_get("@#{key}"),
key
end end
end end
...@@ -42,9 +45,11 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -42,9 +45,11 @@ class AttachmentTest < Test::Unit::TestCase
@attachment = @dummy.avatar @attachment = @dummy.avatar
end end
should "be the new default_options" do Paperclip::Attachment.default_options.keys.each do |key|
@new_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 assert_equal @new_default_options[key],
@attachment.instance_variable_get("@#{key}"),
key
end end
end end
end end
...@@ -53,17 +58,20 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -53,17 +58,20 @@ class AttachmentTest < Test::Unit::TestCase
context "An attachment" do context "An attachment" do
setup do setup do
@default_options = { Paperclip::Attachment.default_options.merge!({
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension" :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
} })
@instance = stub @instance = stub
@instance.stubs(:id).returns(41) @instance.stubs(:id).returns(41)
@instance.stubs(:class).returns(Dummy) @instance.stubs(:class).returns(Dummy)
@instance.stubs(:[]).with(:test_file_name).returns("5k.png") @instance.stubs(:[]).with(:test_file_name).returns("5k.png")
@instance.stubs(:[]).with(:test_content_type).returns("image/png") @instance.stubs(:[]).with(:test_content_type).returns("image/png")
@instance.stubs(:[]).with(:test_file_size).returns(12345) @instance.stubs(:[]).with(:test_file_size).returns(12345)
@attachment = Paperclip::Attachment.new(:test, @instance, @default_options) @attachment = Paperclip::Attachment.new(:test,
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png")) @instance)
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"))
end end
should "return its default_url when no file assigned" do should "return its default_url when no file assigned" do
...@@ -74,16 +82,18 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -74,16 +82,18 @@ class AttachmentTest < Test::Unit::TestCase
context "when expecting three styles" do context "when expecting three styles" do
setup do setup do
@attachment = Paperclip::Attachment.new(:test, @instance, @default_options.merge({ styles = {:styles => { :large => ["400x400", :png],
:styles => { :large => ["400x400", :png], :medium => ["100x100", :gif],
:medium => ["100x100", :gif], :small => ["32x32#", :jpg]}}
:small => ["32x32#", :jpg]} @attachment = Paperclip::Attachment.new(:test,
})) @instance,
styles)
end end
context "and assigned a file" do context "and assigned a file" do
setup do setup do
@instance.expects(:[]=).with(:test_file_name, File.basename(@file.path)) @instance.expects(:[]=).with(:test_file_name,
File.basename(@file.path))
@instance.expects(:[]=).with(:test_content_type, "image/png") @instance.expects(:[]=).with(:test_content_type, "image/png")
@instance.expects(:[]=).with(:test_file_size, @file.size) @instance.expects(:[]=).with(:test_file_size, @file.size)
@instance.expects(:[]=).with(:test_file_name, nil) @instance.expects(:[]=).with(:test_file_name, nil)
...@@ -122,8 +132,12 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -122,8 +132,12 @@ class AttachmentTest < Test::Unit::TestCase
end end
should "save the files as the right formats and sizes" do 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| [[:large, 400, 61, "PNG"],
out = `identify -format "%w %h %b %m" #{@attachment.to_io(style.first).path}` [: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(" ") width, height, size, format = out.split(" ")
assert_equal style[1].to_s, width.to_s assert_equal style[1].to_s, width.to_s
assert_equal style[2].to_s, height.to_s assert_equal style[2].to_s, height.to_s
......
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