Sha256: 5f0e81240b486cd8afdd0da1762cab78799b9d31744245be3787e2e03820f077

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

require  File.dirname(__FILE__) + '/joinfix_test_helper'

class NestedMigration < ActiveRecord::Migration
  def self.up
	create_table :nested_parents do |t|
		t.column :field, :string
		t.column :inner_child_id, :integer
	end	
	create_table :nested_children do |t|
		t.column :field, :string
		t.column :nested_parent_id, :integer
	end	
	create_table :inner_children do |t|
		t.column :field, :string
		t.column :nested_child_id, :integer
	end	
  end

  def self.down
	drop_table :nested_parents
	drop_table :nested_children
	drop_table :inner_children
  end
end

class NestedParent < ActiveRecord::Base
	belongs_to :inner_child
	has_many :nested_children
end

class NestedChild < ActiveRecord::Base
	belongs_to :nested_parent
	has_many :inner_children
end

class InnerChild < ActiveRecord::Base
	belongs_to :nested_child
	has_many :nested_parents
end

class NestedTest < Test::Unit::TestCase
	fixtures :nested_parents, :nested_children, :inner_children
	
	def setup
	end
	
	def teardown
	end
	
	def test_nested_fixtures
		database_test(NestedMigration) do 
			parent_one= nested_parents(:parent_one)
			parent_two = nested_parents(:parent_two)
			parent_three = nested_parents(:parent_three)
			parent_four = nested_parents(:parent_four)
			
			query_result = NestedChild.find_by_field(1).nested_parent
			assert_equal parent_one, query_result
			
			query_result = NestedParent.find_by_field(1).nested_children.first.inner_children.first.nested_parents
			assert_equal [parent_two, parent_three], query_result
			
			query_result = NestedParent.find_by_field(1).inner_child.nested_child.nested_parent
			assert_equal parent_two, query_result
			
			query_result = InnerChild.find_by_field(3).nested_parents.first
			assert_equal parent_four, query_result
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
joinfix-0.1.0 test/nested_test.rb