0
@@ -148,40 +148,40 @@ class AttachmentTest < Test::Unit::TestCase
0
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
0
- @instance.stubs(:id).returns(41)
0
- @instance.stubs(:class).returns(Dummy)
0
- @instance.stubs(:[]).with(:test_file_name).returns(nil)
0
- @instance.stubs(:[]).with(:test_content_type).returns(nil)
0
- @instance.stubs(:[]).with(:test_file_size).returns(nil)
0
- @instance.stubs(:[]).with(:test_updated_at).returns(nil)
0
- @instance.stubs(:logger).returns(ActiveRecord::Base.logger)
0
- @attachment = Paperclip::Attachment.new(:test,
0
+ @attachment = Paperclip::Attachment.new(:avatar, @instance)
0
@file = File.new(File.join(File.dirname(__FILE__),
0
+ should "raise if there are not the correct columns when you try to assign" do
0
+ @other_attachment = Paperclip::Attachment.new(:not_here, @instance)
0
+ assert_raises(Paperclip::PaperclipError) do
0
+ @other_attachment.assign(@file)
0
should "return its default_url when no file assigned" do
0
assert @attachment.to_file.nil?
0
- assert_equal "/tests/original/missing.png", @attachment.url
0
- assert_equal "/tests/blah/missing.png", @attachment.url(:blah)
0
+ assert_equal "/avatars/original/missing.png", @attachment.url
0
+ assert_equal "/avatars/blah/missing.png", @attachment.url(:blah)
0
context "with a file assigned in the database" do
0
- @instance.stubs(:[]).with(:test_file_name).returns("5k.png")
0
- @instance.stubs(:[]).with(:test_content_type).returns("image/png")
0
- @instance.stubs(:[]).with(:test_file_size).returns(12345)
0
+ @instance.stubs(:[]).with(:avatar_file_name).returns("5k.png")
0
+ @instance.stubs(:[]).with(:avatar_content_type).returns("image/png")
0
+ @instance.stubs(:[]).with(:avatar_file_size).returns(12345)
0
Time.stubs(:now).returns(now)
0
- @instance.stubs(:[]).with(:
test_updated_at).returns(Time.now)
0
+ @instance.stubs(:[]).with(:
avatar_updated_at).returns(Time.now)
0
should "return a correct url even if the file does not exist" do
0
assert_nil @attachment.to_file
0
- assert_match %r{^/
tests/41/blah/5k\.png}, @attachment.url(:blah)
0
+ assert_match %r{^/
avatars/#{@instance.id}/blah/5k\.png}, @attachment.url(:blah)
0
should "make sure the updated_at mtime is in the url if it is defined" do
0
@@ -190,21 +190,21 @@ class AttachmentTest < Test::Unit::TestCase
0
context "with the updated_at field removed" do
0
- @instance.stubs(:[]).with(:
test_updated_at).returns(nil)
0
+ @instance.stubs(:[]).with(:
avatar_updated_at).returns(nil)
0
should "only return the url without the updated_at when sent #url" do
0
- assert_match "/
tests/41/blah/5k.png", @attachment.url(:blah)
0
+ assert_match "/
avatars/#{@instance.id}/blah/5k.png", @attachment.url(:blah)
0
should "return the proper path when filename has a single .'s" do
0
- assert_equal "./test/../tmp/
tests/dummies/original/41/5k.png", @attachment.path
0
+ assert_equal "./test/../tmp/
avatars/dummies/original/#{@instance.id}/5k.png", @attachment.path
0
should "return the proper path when filename has multiple .'s" do
0
- @instance.stubs(:[]).with(:test_file_name).returns("5k.old.png")
0
- assert_equal "./test/../tmp/tests/dummies/original/41/5k.old.png", @attachment.path
0
+ @instance.stubs(:[]).with(:avatar_file_name).returns("5k.old.png")
0
+ assert_equal "./test/../tmp/avatars/dummies/original/#{@instance.id}/5k.old.png", @attachment.path
0
context "when expecting three styles" do
0
@@ -212,7 +212,7 @@ class AttachmentTest < Test::Unit::TestCase
0
styles = {:styles => { :large => ["400x400", :png],
0
:medium => ["100x100", :gif],
0
:small => ["32x32#", :jpg]}}
0
- @attachment = Paperclip::Attachment.new(:
test,
0
+ @attachment = Paperclip::Attachment.new(:
avatar,
0
@@ -221,15 +221,6 @@ class AttachmentTest < Test::Unit::TestCase
0
Time.stubs(:now).returns(now)
0
- @instance.expects(:[]=).with(:test_file_name,
0
- File.basename(@file.path))
0
- @instance.expects(:[]=).with(:test_content_type, "image/png")
0
- @instance.expects(:[]=).with(:test_file_size, @file.size)
0
- @instance.expects(:[]=).with(:test_file_name, nil)
0
- @instance.expects(:[]=).with(:test_content_type, nil)
0
- @instance.expects(:[]=).with(:test_file_size, nil)
0
- @instance.expects(:[]=).with(:test_updated_at, nil)
0
- @instance.expects(:[]=).with(:test_updated_at, now)
0
@attachment.assign(@file)
0
@@ -244,8 +235,8 @@ class AttachmentTest < Test::Unit::TestCase
0
should "return the real url" do
0
assert @attachment.to_file
0
- assert_match %r{^/tests/41/original/5k\.png}, @attachment.url
0
- assert_match %r{^/tests/41/small/5k\.jpg}, @attachment.url(:small)
0
+ assert_match %r{^/avatars/#{@instance.id}/original/5k\.png}, @attachment.url
0
+ assert_match %r{^/avatars/#{@instance.id}/small/5k\.jpg}, @attachment.url(:small)
0
should "commit the files to disk" do
0
@@ -279,10 +270,10 @@ class AttachmentTest < Test::Unit::TestCase
0
@existing_names = @attachment.styles.keys.collect do |style|
0
@attachment.path(style)
0
- @instance.expects(:[]=).with(:test_file_name, nil)
0
- @instance.expects(:[]=).with(:test_content_type, nil)
0
- @instance.expects(:[]=).with(:test_file_size, nil)
0
- @instance.expects(:[]=).with(:test_updated_at, nil)
0
+ @instance.expects(:[]=).with(:avatar_file_name, nil)
0
+ @instance.expects(:[]=).with(:avatar_content_type, nil)
0
+ @instance.expects(:[]=).with(:avatar_file_size, nil)
0
+ @instance.expects(:[]=).with(:avatar_updated_at, nil)
Comments
No one has commented yet.