Commit d840a1ef by Jon Yurek

We can't work with isolated attachment objects anymore

parent f1db7d7b
...@@ -346,11 +346,12 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -346,11 +346,12 @@ class AttachmentTest < Test::Unit::TestCase
context "An attachment with :hash interpolations" do context "An attachment with :hash interpolations" do
setup do setup do
@file = StringIO.new("...") @file = StringIO.new("...\n")
end end
should "raise if no secret is provided" do should "raise if no secret is provided" do
@attachment = attachment :path => ":hash" rebuild_model :path => ":hash"
@attachment = Dummy.new.avatar
@attachment.assign @file @attachment.assign @file
assert_raise ArgumentError do assert_raise ArgumentError do
...@@ -360,29 +361,23 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -360,29 +361,23 @@ class AttachmentTest < Test::Unit::TestCase
context "when secret is set" do context "when secret is set" do
setup do setup do
@attachment = attachment :path => ":hash", :hash_secret => "w00t" rebuild_model :path => ":hash",
@attachment.stubs(:instance_read).with(:updated_at).returns(Time.at(1234567890)) :hash_secret => "w00t",
@attachment.stubs(:instance_read).with(:file_name).returns("bla.txt") :hash_data => ":class/:attachment/:style/:filename"
@attachment.instance.id = 1234 @attachment = Dummy.new.avatar
@attachment.assign @file @attachment.assign @file
end end
should "interpolate the hash data" do
@attachment.expects(:interpolate).with(@attachment.options[:hash_data],anything).returns("interpolated_stuff")
@attachment.hash_key
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 "dummies/avatars/original/data.txt",
@attachment.send(:interpolate, @attachment.options[:hash_data])
assert_equal "dummies/avatars/thumb/data.txt",
@attachment.send(:interpolate, @attachment.options[:hash_data], :thumb)
end end
should "result in a correct hash" do should "result in a correct hash" do
assert_equal "d22b617d1bf10016aa7d046d16427ae203f39fce", @attachment.path assert_equal "e1079a5c34ddbd197ebd0280d07952d98a57fb30", @attachment.path
end assert_equal "d740189bd3e49ef226fab84c8d45f7ae4126d043", @attachment.path(:thumb)
should "generate a hash digest with the correct style" do
OpenSSL::HMAC.expects(:hexdigest).with(anything, anything, "fake_models/avatars/1234/medium/1234567890")
@attachment.path("medium")
end end
end end
end end
...@@ -406,15 +401,16 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -406,15 +401,16 @@ class AttachmentTest < Test::Unit::TestCase
context "An attachment with a default style and an extension interpolation" do context "An attachment with a default style and an extension interpolation" do
setup do setup do
@attachment = attachment :path => ":basename.:extension", rebuild_model :path => ":basename.:extension",
:styles => { :default => ["100x100", :png] }, :styles => { :default => ["100x100", :jpg] },
:default_style => :default :default_style => :default
@file = StringIO.new("...") @attachment = Dummy.new.avatar
@file.stubs(:original_filename).returns("file.jpg") @file = File.open(fixture_file("5k.png"))
@file.stubs(:original_filename).returns("file.png")
end end
should "return the right extension for the path" do should "return the right extension for the path" do
@attachment.assign(@file) @attachment.assign(@file)
assert_equal "file.png", @attachment.path assert_equal "file.jpg", @attachment.path
end end
end end
...@@ -1091,11 +1087,14 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -1091,11 +1087,14 @@ class AttachmentTest < Test::Unit::TestCase
context "when expecting three styles" do context "when expecting three styles" do
setup do setup do
rebuild_model :styles => { rebuild_class :styles => {
:large => ["400x400", :png], :large => ["400x400", :png],
:medium => ["100x100", :gif], :medium => ["100x100", :gif],
:small => ["32x32#", :jpg] :small => ["32x32#", :jpg]
} }
@instance = Dummy.new
@instance.stubs(:id).returns 123
@file = File.new(fixture_file("5k.png"), 'rb')
@attachment = @instance.avatar @attachment = @instance.avatar
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