Permalink
Browse files

Added testing suite and plugin tests

  • Loading branch information...
1 parent 7b18d25 commit d3ee15e97ffa36a605800fbcb91b1c2777247b3d @DefV DefV committed Mar 27, 2008
View
@@ -1 +1,3 @@
+require 'deep_cloning'
+
ActiveRecord::Base.send(:include, DeepCloning)
View
@@ -0,0 +1,4 @@
+sqlite3:
+ adapter: sqlite3
+ database: ":memory:"
+
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
Binary file not shown.
View
@@ -1,8 +1,45 @@
-require 'test/unit'
+require File.dirname(__FILE__) + '/test_helper'
class DeepCloningTest < Test::Unit::TestCase
- # Replace this with your real tests.
- def test_this_plugin
- flunk
+ fixtures :pirates, :gold_pieces, :treasures, :mateys
+
+ def setup
+ @jack = Pirate.find(pirates(:jack).id)
+ end
+
+ def test_single_clone_exception
+ clone = @jack.clone(:except => :name)
+ assert clone.save
+ assert_equal @jack.name, @jack.clone.name
+ assert_nil clone.name
+ assert_equal @jack.nick_name, clone.nick_name
+ end
+
+ def test_multiple_clone_exception
+ clone = @jack.clone(:except => [:name, :nick_name])
+ assert clone.save
+ assert_nil clone.name
+ assert_equal 'no nickname', clone.nick_name
+ assert_equal @jack.age, clone.age
+ end
+
+ def test_singe_include_association
+ clone = @jack.clone(:include => :mateys)
+ assert clone.save
+ assert_equal @jack.mateys.size, clone.mateys.size
+ end
+
+ def test_multiple_include_association
+ clone = @jack.clone(:include => [:mateys, :treasures])
+ assert clone.save
+ assert_equal @jack.mateys.size, clone.mateys.size
+ assert_equal @jack.treasures.size, clone.treasures.size
+ end
+
+ def test_deep_include_association
+ clone = @jack.clone(:include => {:treasures => :gold_pieces})
+ assert clone.save
+ assert_equal @jack.treasures.size, clone.treasures.size
+ assert_equal @jack.gold_pieces.size, clone.gold_pieces.size
end
-end
+end
@@ -0,0 +1,3 @@
+class GoldPiece < ActiveRecord::Base
+ belongs_to :treasure
+end
@@ -0,0 +1,2 @@
+gold_piece1:
+ treasure: big_treasure
View
@@ -0,0 +1,3 @@
+class Matey < ActiveRecord::Base
+ belongs_to :pirate
+end
View
@@ -0,0 +1,3 @@
+john:
+ name: John
+ pirate: jack
View
@@ -0,0 +1,5 @@
+class Pirate < ActiveRecord::Base
+ has_many :mateys
+ has_many :treasures
+ has_many :gold_pieces, :through => :treasures
+end
@@ -0,0 +1,3 @@
+jack:
+ name: Jack Sparrow
+ nick_name: Captain Jack
@@ -0,0 +1,5 @@
+class Treasure < ActiveRecord::Base
+ belongs_to :pirate
+
+ has_many :gold_pieces
+end
@@ -0,0 +1,3 @@
+big_treasure:
+ found_at: Isla del Muerte
+ pirate: jack
View
@@ -0,0 +1,21 @@
+ActiveRecord::Schema.define(:version => 1) do
+ create_table :pirates, :force => true do |t|
+ t.column :name, :string
+ t.column :nick_name, :string, :default => 'no nickname'
+ t.column :age, :string
+ end
+
+ create_table :mateys, :force => true do |t|
+ t.column :name, :string
+ t.column :pirate_id, :integer
+ end
+
+ create_table :treasures, :force => true do |t|
+ t.column :found_at, :string
+ t.column :pirate_id, :integer
+ end
+
+ create_table :gold_pieces, :force => true do |t|
+ t.column :treasure_id, :integer
+ end
+end
View
@@ -0,0 +1,38 @@
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+RAILS_ROOT = File.dirname(__FILE__)
+
+require 'rubygems'
+require 'test/unit'
+require 'active_record'
+
+require 'active_record/fixtures'
+require "#{File.dirname(__FILE__)}/../init"
+
+
+config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
+ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
+ActiveRecord::Base.configurations = {'test' => config[ENV['DB'] || 'sqlite3']}
+ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
+
+load(File.dirname(__FILE__) + "/schema.rb") if File.exist?(File.dirname(__FILE__) + "/schema.rb")
+
+Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
+$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
+
+class Test::Unit::TestCase #:nodoc:
+ def create_fixtures(*table_names)
+ if block_given?
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
+ else
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
+ end
+ end
+
+ # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
+ self.use_transactional_fixtures = true
+
+ # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
+ self.use_instantiated_fixtures = false
+
+ # Add more helper methods to be used by all tests here...
+end

0 comments on commit d3ee15e

Please sign in to comment.