Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New testing structure

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@239 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
commit eba59dac2928f2873be823f4fd83a58ec173aef4 1 parent 550129b
jyurek authored
Showing with 92 additions and 0 deletions.
  1. +59 −0 test/paperclip_test.rb
  2. +33 −0 test/simply_shoulda.rb
View
59 test/paperclip_test.rb
@@ -0,0 +1,59 @@
+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
View
33 test/simply_shoulda.rb
@@ -0,0 +1,33 @@
+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
Please sign in to comment.
Something went wrong with that request. Please try again.