Commit eba59dac by jyurek

New testing structure

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@239 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 550129b1
require 'test/unit'
require File.dirname(__FILE__) + "/test_helper.rb"
require File.dirname(__FILE__) + "/simply_shoulda.rb"
require File.dirname(__FILE__) + "/../lib/paperclip-c.rb"
class PaperclipTest < Test::Unit::TestCase
context "Paperclip" do
should "allow overriding options" do
not_expected = Paperclip.options[:image_magick_path]
Paperclip.options[:image_magick_path] = "123"
assert_equal "123", Paperclip.options[:image_magick_path]
end
should "give the correct path for a command" do
expected = "/usr/bin/wtf"
Paperclip.options[:image_magick_path] = "/usr/bin"
assert_equal expected, Paperclip.path_for_command("wtf")
end
context "being used on class Foo" do
setup do
ActiveRecord::Base.connection.create_table :foos, :force => true do |table|
table.column :image_file_name, :string
table.column :image_content_type, :string
table.column :image_file_size, :integer
table.column :document_file_name, :string
table.column :document_content_type, :string
table.column :document_file_size, :integer
end
class ::Foo < ActiveRecord::Base; end
end
should "be able to assign a default attachment" do
assert Foo.has_attached_file(:image)
assert_equal [:image], Foo.attached_files
end
should "be able to assign two attachments separately" do
assert Foo.has_attached_file(:image)
assert Foo.has_attached_file(:document)
assert_equal [:image, :document], Foo.attached_files
end
should "be able to assign two attachments simultaneously" do
assert Foo.has_attached_file(:image, :document)
assert_equal [:image, :document], Foo.attached_files
end
should "be able to set options on attachments" do
assert Foo.has_attached_file :image, :thumbnails => {:thumb => "100x100"}
assert_equal [:image], Foo.attached_files
end
end
end
end
\ No newline at end of file
class << Test::Unit::TestCase
def context name, &block
(@contexts ||= []) << name
(@context_blocks ||= []) << block
saved_setups = (@context_setups ||= []).dup
saved_teardowns = (@context_teardowns ||= []).dup
self.instance_eval(&block)
@context_setups = saved_setups
@context_teardowns = saved_teardowns
@contexts.pop
@context_blocks.pop
end
def setup &block
@context_setups << block
end
def teardown &block
@context_teardowns << block
end
def should name, &test
context_setups = @context_setups.dup
context_teardowns = @context_teardowns.dup
define_method(["test:", @contexts, "should", name].join(" ")) do
context_setups.each { |setup| self.instance_eval(&setup) }
self.instance_eval(&test)
context_teardowns.each { |teardown| self.instance_eval(&teardown) }
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