Sha256: b198209c4a0b10c1b7ac68cf2d472c1d735213fe143610b6fcf2e73838e17cbf

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

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

#
#  hm through
#

class HasManyThroughMigration < ActiveRecord::Migration
  def self.up
	create_table :hm_through_parents do |t|
		t.column :field, :string
	end	
	create_table :hm_through_children do |t|
		t.column :field, :string
	end	
	create_table :hm_through_joins do |t|
		t.column :hm_through_parent_id, :integer
		t.column :hm_through_child_id, :integer
	end	
  end

  def self.down
	drop_table :hm_through_parents
	drop_table :hm_through_children
	drop_table :hm_through_joins
  end
end


class HmThroughParent < ActiveRecord::Base 
	has_many :hm_through_joins
	has_many :hm_through_children, :through => :hm_through_joins
end
	
class HmThroughChild < ActiveRecord::Base
end
	
class HmThroughJoin < ActiveRecord::Base
	belongs_to :hm_through_child
end

class HasManyThroughTest < Test::Unit::TestCase
	fixtures :hm_through_parents, :hm_through_children, :hm_through_joins

	def test_has_many_through
		setup_fixtures(
:hm_through_parents  => %Q{
parent_entry:
 field: parent value
 hm_through_children:
   - child_one:
       field: one
   - child_two:
       field: two},
:hm_through_children => "",
:hm_through_joins => "")

		assert_fixtures(
:hm_through_parents  => %Q{
parent_entry:
  id: 1
  field: parent value},
:hm_through_children => %Q{
child_one:
  id: 1
  field: one
child_two:
  id: 2
  field: two},
:hm_through_joins => %Q{
child_one_parent_entry:
  id: 1
  hm_through_parent_id: 1
  hm_through_child_id: 1
child_two_parent_entry:
  id: 2
  hm_through_parent_id: 1
  hm_through_child_id: 2})
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
joinfix-1.0.0 test/has_many_through_test.rb
joinfix-0.1.1 test/has_many_through_test.rb
joinfix-1.0.1 test/has_many_through_test.rb