Commit 550129b1 by jyurek

Changing the tests around

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@238 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent fdd71b36
test:
adapter: sqlite3
dbfile: paperclip.db
#database: ":memory:"
\ No newline at end of file
#dbfile: paperclip.db
database: ":memory:"
\ No newline at end of file
require 'test/unit'
require 'uri'
require File.dirname(__FILE__) + "/test_helper.rb"
require File.dirname(__FILE__) + "/../init.rb"
require File.join(File.dirname(__FILE__), "models.rb")
class PaperclipImagesTest < Test::Unit::TestCase
def setup
assert @foo = Foo.new
assert @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', 'test_image.jpg'))
assert @document = File.new(File.join(File.dirname(__FILE__), 'fixtures', 'test_document.doc'))
assert @foo.image = @file
end
def test_should_supply_all_attachment_names
assert_equal %w( image ), Foo.attachment_names.map{|a| a.to_s }.sort
end
def test_should_validate_before_save
assert @foo.image_valid?
assert @foo.valid?
end
def test_should_save_the_file_and_its_thumbnails
assert @foo.save, @foo.errors.full_messages.inspect
assert File.exists?( @foo.image_file_name(:original) ), @foo.image_file_name(:original)
assert File.exists?( @foo.image_file_name(:medium) ), @foo.image_file_name(:medium)
assert File.exists?( @foo.image_file_name(:thumb) ), @foo.image_file_name(:thumb)
assert File.size?( @foo.image_file_name(:original) )
assert File.size?( @foo.image_file_name(:medium) )
assert File.size?( @foo.image_file_name(:thumb) )
out = `identify '#{@foo.image_file_name(:original)}'`; assert out.match("405x375"); assert $?.exitstatus == 0
out = `identify '#{@foo.image_file_name(:medium)}'`; assert out.match("300x278"); assert $?.exitstatus == 0
out = `identify '#{@foo.image_file_name(:thumb)}'`; assert out.match("100x93"); assert $?.exitstatus == 0
end
def test_should_validate_to_make_sure_the_thumbnails_exist
assert @foo.save
assert @foo.image_valid?
assert @foo.valid?
end
def test_should_ensure_that_file_are_accessible_after_reload
assert @foo.save
assert @foo.image_valid?
assert @foo.valid?, @foo.errors.full_messages.inspect
@foo2 = Foo.find @foo.id
assert @foo.image_valid?
assert File.exists?( @foo.image_file_name(:original) ), @foo.image_file_name(:original)
assert File.exists?( @foo.image_file_name(:medium) ), @foo.image_file_name(:medium)
assert File.exists?( @foo.image_file_name(:thumb) ), @foo.image_file_name(:thumb)
out = `identify '#{@foo.image_file_name(:original)}'`; assert out.match("405x375"); assert $?.exitstatus == 0
out = `identify '#{@foo.image_file_name(:medium)}'`; assert out.match("300x278"); assert $?.exitstatus == 0
out = `identify '#{@foo.image_file_name(:thumb)}'`; assert out.match("100x93"); assert $?.exitstatus == 0
end
def test_should_delete_all_thumbnails_on_destroy
assert @foo.save
names = [:original, :medium, :thumb].map{|style| @foo.image_file_name(style) }
assert @foo.destroy
names.each {|path| assert !File.exists?( path ), path }
end
def test_should_ensure_file_names_and_urls_are_empty_if_no_file_set
assert @foo.save
assert @foo.image_valid?
mappings = [:original, :medium, :thumb].map do |style|
assert @foo.image_file_name(style)
assert @foo.image_url(style)
[style, @foo.image_file_name(style), @foo.image_url(style)]
end
assert @foo.destroy_image
assert @foo.save, @foo.errors.full_messages.inspect
mappings.each do |style, file, url|
assert_not_equal file, @foo.image_file_name(style)
assert_equal "", @foo.image_file_name(style)
assert_not_equal url, @foo.image_url(style)
assert_equal "", @foo.image_url(style)
end
assert @foo2 = Foo.find(@foo.id)
mappings.each do |style, file, url|
assert_not_equal file, @foo2.image_file_name(style)
assert_equal "", @foo2.image_file_name(style)
assert_not_equal url, @foo2.image_url(style)
assert_equal "", @foo2.image_url(style)
end
assert @foo3 = Foo.new
mappings.each do |style, file, url|
assert_equal "", @foo3.image_file_name(style), @foo3["image_file_name"]
assert_equal "", @foo3.image_url(style)
end
end
def test_should_save_image_from_uri
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 40404,
:DocumentRoot => File.dirname(__FILE__),
:AccessLog => [],
:Logger => WEBrick::Log.new(nil, WEBrick::Log::WARN))
Thread.new do
server.start
end
while server.status != :Running
sleep 0.1
print "!"; $stdout.flush
end
uri = URI.parse("http://127.0.0.1:40404/fixtures/test_image.jpg")
@foo.image = uri
@foo.save
@foo.image_valid?
assert File.exists?( @foo.image_file_name(:original) ), @foo.image_file_name(:original)
assert File.exists?( @foo.image_file_name(:medium) ), @foo.image_file_name(:medium)
assert File.exists?( @foo.image_file_name(:thumb) ), @foo.image_file_name(:thumb)
out = `identify '#{@foo.image_file_name(:original)}'`; assert_match "405x375", out; assert $?.exitstatus == 0
out = `identify '#{@foo.image_file_name(:medium)}'`; assert_match "300x278", out; assert $?.exitstatus == 0
out = `identify '#{@foo.image_file_name(:thumb)}'`; assert_match "100x93", out; assert $?.exitstatus == 0
ensure
server.stop if server
end
def test_should_put_errors_on_object_if_convert_does_not_exist
old_path = Thoughtbot::Paperclip.options[:image_magick_path]
Thoughtbot::Paperclip.options[:image_magick_path] = "/does/not/exist"
assert_nothing_raised{ @foo.image = @file }
assert !@foo.valid?
assert !@foo.save, @foo.errors.full_messages.inspect
assert @foo.errors.length > 0
assert @foo.errors.on(:image)
[@foo.errors.on(:image)].flatten.each do |err|
assert_match /could not/, err, err
end
ensure
Thoughtbot::Paperclip.options[:image_magick_path] = old_path
end
def test_should_put_errors_on_object_if_convert_fails
assert_nothing_raised{ @foo.image = @document }
assert !@foo.save
assert !@foo.valid?
assert @foo.errors.length > 0
assert @foo.errors.on(:image)
[@foo.errors.on(:image)].flatten.each do |err|
assert_match /could not/, err, err
end
end
end
\ No newline at end of file
require 'test/unit'
require File.dirname(__FILE__) + "/test_helper.rb"
require File.dirname(__FILE__) + "/../init.rb"
require File.join(File.dirname(__FILE__), "models.rb")
class PaperclipNonStandardTest < Test::Unit::TestCase
def setup
assert @ns = NonStandard.new
assert @resume = File.new(File.join(File.dirname(__FILE__), 'fixtures', 'test_document.doc'))
assert @avatar = File.new(File.join(File.dirname(__FILE__), 'fixtures', 'test_image.jpg'))
assert @ns.resume = @resume
assert @ns.avatar = @avatar
end
def test_should_supply_all_attachment_names
assert_equal %w( avatar resume ), NonStandard.attachment_names.map{|a| a.to_s }.sort
end
def test_should_validate_before_save
assert @ns.avatar_valid?
assert @ns.valid?
end
def test_should_save_the_created_file_to_the_final_asset_directory
assert @ns.save
assert File.exists?( @ns.resume_file_name ), @ns.resume_file_name
assert File.exists?( @ns.avatar_file_name(:original) ), @ns.avatar_file_name(:original)
assert File.exists?( @ns.avatar_file_name(:bigger) )
assert File.exists?( @ns.avatar_file_name(:cropped) )
assert File.size?( @ns.avatar_file_name(:original) )
assert File.size?( @ns.avatar_file_name(:bigger) )
assert File.size?( @ns.avatar_file_name(:cropped) )
out = `identify '#{@ns.avatar_file_name(:original)}'`; assert_match /405x375/, out, out; assert $?.exitstatus == 0
out = `identify '#{@ns.avatar_file_name(:bigger)}'`; assert_match /1000x926/, out, out; assert $?.exitstatus == 0
out = `identify '#{@ns.avatar_file_name(:cropped)}'`; assert_match /200x10/, out, out; assert $?.exitstatus == 0
end
def test_should_validate
assert @ns.save
assert @ns.resume_valid?
assert @ns.avatar_valid?
assert @ns.valid?
end
def test_should_default_to_the_assigned_default_style_for_path_and_url
assert_equal @ns.resume_file_name(:original), @ns.resume_file_name
assert_equal @ns.resume_url(:original), @ns.resume_url
assert_equal @ns.avatar_file_name(:square), @ns.avatar_file_name
assert_equal @ns.avatar_url(:square), @ns.avatar_url
end
def test_should_delete_files_on_destroy
assert @ns.save
assert File.exists?( @ns.resume_file_name ), @ns.resume_file_name
[:original, :bigger, :cropped].each do |style|
assert File.exists?( @ns.avatar_file_name(style) ), @ns.avatar_file_name(style)
end
resume_file_name = @ns.resume_file_name
avatar_file_names = [:original, :bigger, :cropped].map{|style| @ns.avatar_file_name(style) }
assert @ns.destroy
assert !File.exists?( resume_file_name ), resume_file_name
avatar_file_names.each do |name|
assert !File.exists?(name), name
end
end
def test_should_return_missing_url_interpolated_when_no_attachment_exists
assert @ns.save
assert @ns.destroy_resume
assert @ns.destroy_avatar
assert_equal "/non_standards/original/resumes/404.txt", @ns.resume_url
assert_equal "/non_standards/bigger/avatars/404.png", @ns.avatar_url(:bigger)
assert_equal "/non_standards/original/avatars/404.png", @ns.avatar_url(:original)
assert_equal "/non_standards/square/avatars/404.png", @ns.avatar_url
end
end
\ No newline at end of file
require 'test/unit'
require File.dirname(__FILE__) + "/test_helper.rb"
require File.dirname(__FILE__) + "/../init.rb"
require File.join(File.dirname(__FILE__), "models.rb")
class PaperclipS3Test < Test::Unit::TestCase
def setup
end
def test_truth
assert true
end
end
\ No newline at end of file
require 'test/unit'
require File.dirname(__FILE__) + "/test_helper.rb"
require File.dirname(__FILE__) + "/../init.rb"
require File.join(File.dirname(__FILE__), "models.rb")
class PaperclipTest < Test::Unit::TestCase
def setup
assert @bar = Bar.new
assert @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', 'test_document.doc'))
assert @bar.document = @file
end
def test_should_supply_all_attachment_names
assert_equal %w( document ), Bar.attachment_names.map{|a| a.to_s }.sort
end
def test_should_validate_before_save
assert @bar.document_valid?, @bar.errors.full_messages.inspect
assert @bar.valid?, @bar.errors.full_messages.inspect
end
def test_should_save_the_created_file_to_the_final_asset_directory
assert @bar.save
assert File.exists?( @bar.document_file_name )
end
def test_should_validate
assert @bar.save, @bar.errors.full_messages.inspect
assert @bar.document_valid?, @bar.errors.full_messages.inspect
assert @bar.valid?, @bar.errors.full_messages.inspect
end
def test_should_default_to_original_for_path_and_url
assert_equal @bar.document_file_name(:original), @bar.document_file_name
assert_equal @bar.document_url(:original), @bar.document_url
end
def test_should_delete_files_on_destroy
assert @bar.save
assert File.exists?( @bar.document_file_name ), @bar.document_file_name
document_file_name = @bar.document_file_name
assert @bar.destroy
assert !File.exists?( document_file_name ), document_file_name
end
def test_should_put_on_errors_if_no_file_exists
assert @bar.save
@bar.document = nil
assert !@bar.document_valid?, @bar.errors.full_messages.inspect
assert !@bar.save
assert @bar.errors.length > 0
assert @bar.errors.on(:document)
assert_match /requires a valid/, @bar.errors.on(:document), @bar.errors.on(:document)
end
def test_should_raise_if_table_missing_columns
assert_raises Thoughtbot::Paperclip::PaperclipError do
Negative.send(:has_attached_file, :missing)
end
end
end
\ No newline at end of file
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