Commit 27727359 by Henrik N

Fix old tests to pass. Still need to write tests for new functionality.

parent 8697826a
...@@ -154,6 +154,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -154,6 +154,7 @@ class AttachmentTest < Test::Unit::TestCase
@instance.stubs(:[]).with(:test_file_name).returns(nil) @instance.stubs(:[]).with(:test_file_name).returns(nil)
@instance.stubs(:[]).with(:test_content_type).returns(nil) @instance.stubs(:[]).with(:test_content_type).returns(nil)
@instance.stubs(:[]).with(:test_file_size).returns(nil) @instance.stubs(:[]).with(:test_file_size).returns(nil)
@instance.stubs(:[]).with(:test_updated_at).returns(nil)
@attachment = Paperclip::Attachment.new(:test, @attachment = Paperclip::Attachment.new(:test,
@instance) @instance)
@file = File.new(File.join(File.dirname(__FILE__), @file = File.new(File.join(File.dirname(__FILE__),
...@@ -172,11 +173,12 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -172,11 +173,12 @@ class AttachmentTest < Test::Unit::TestCase
@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)
@instance.stubs(:[]).with(:test_updated_at).returns(Time.now)
end end
should "return a correct url even if the file does not exist" do should "return a correct url even if the file does not exist" do
assert_nil @attachment.to_file assert_nil @attachment.to_file
assert_equal "/tests/41/blah/5k.png", @attachment.url(:blah) assert_match %r{^/tests/41/blah/5k\.png}, @attachment.url(:blah)
end end
should "return the proper path when filename has a single .'s" do should "return the proper path when filename has a single .'s" do
...@@ -200,6 +202,8 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -200,6 +202,8 @@ class AttachmentTest < Test::Unit::TestCase
context "and assigned a file" do context "and assigned a file" do
setup do setup do
now = Time.mktime(2008)
Time.stubs(:now).returns(now)
@instance.expects(:[]=).with(:test_file_name, @instance.expects(:[]=).with(:test_file_name,
File.basename(@file.path)) File.basename(@file.path))
@instance.expects(:[]=).with(:test_content_type, "image/png") @instance.expects(:[]=).with(:test_content_type, "image/png")
...@@ -207,6 +211,8 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -207,6 +211,8 @@ class AttachmentTest < Test::Unit::TestCase
@instance.expects(:[]=).with(:test_file_name, nil) @instance.expects(:[]=).with(:test_file_name, nil)
@instance.expects(:[]=).with(:test_content_type, nil) @instance.expects(:[]=).with(:test_content_type, nil)
@instance.expects(:[]=).with(:test_file_size, nil) @instance.expects(:[]=).with(:test_file_size, nil)
@instance.expects(:[]=).with(:test_updated_at, nil)
@instance.expects(:[]=).with(:test_updated_at, now)
@attachment.assign(@file) @attachment.assign(@file)
end end
...@@ -221,8 +227,8 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -221,8 +227,8 @@ class AttachmentTest < Test::Unit::TestCase
should "return the real url" do should "return the real url" do
assert @attachment.to_file assert @attachment.to_file
assert_equal "/tests/41/original/5k.png", @attachment.url assert_match %r{^/tests/41/original/5k\.png}, @attachment.url
assert_equal "/tests/41/small/5k.jpg", @attachment.url(:small) assert_match %r{^/tests/41/small/5k\.jpg}, @attachment.url(:small)
end end
should "commit the files to disk" do should "commit the files to disk" do
...@@ -259,6 +265,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -259,6 +265,7 @@ class AttachmentTest < Test::Unit::TestCase
@instance.expects(:[]=).with(:test_file_name, nil) @instance.expects(:[]=).with(:test_file_name, nil)
@instance.expects(:[]=).with(:test_content_type, nil) @instance.expects(:[]=).with(:test_content_type, nil)
@instance.expects(:[]=).with(:test_file_size, nil) @instance.expects(:[]=).with(:test_file_size, nil)
@instance.expects(:[]=).with(:test_updated_at, nil)
@attachment.assign nil @attachment.assign nil
@attachment.save @attachment.save
end end
......
...@@ -71,7 +71,7 @@ class StorageTest < Test::Unit::TestCase ...@@ -71,7 +71,7 @@ class StorageTest < Test::Unit::TestCase
should "not get a bucket to get a URL" do should "not get a bucket to get a URL" do
@dummy.avatar.expects(:s3).never @dummy.avatar.expects(:s3).never
@dummy.avatar.expects(:s3_bucket).never @dummy.avatar.expects(:s3_bucket).never
assert_equal "https://s3.amazonaws.com/testing/avatars/original/5k.png", @dummy.avatar.url assert_match %r{^https://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
end end
context "and saved" do context "and saved" do
......
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