Sha256: b5ee64ded83f9d5b117e393c477bb9abaf355d1eaef0e1769cfe921f04614200

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

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

#
# Habtm with options
#

class HasAndBelongsToManyWithOptionsMigration < ActiveRecord::Migration
  def self.up
	create_table :habtm_with_options_parents do |t|
		t.column :field, :string
	end	
	create_table :habtm_with_options_children do |t|
		t.column :field, :string
	end	
	create_table :habtm_joins do |t|
		t.column :field, :string
		t.column :alternate_parent, :integer
		t.column :alternate_child, :integer
	end	
  end

  def self.down
	drop_table :habtm_with_options_parents
	drop_table :habtm_with_options_children
	drop_table :habtm_joins
  end
end

class HabtmWithOptionsParent < ActiveRecord::Base
	has_and_belongs_to_many :children,
		:foreign_key => "alternate_parent",
		:association_foreign_key => "alternate_child",
		:class_name => "HabtmWithOptionsChild",
		:join_table => :habtm_joins
end

class HabtmWithOptionsChild < ActiveRecord::Base
end

class HabtmJoin < ActiveRecord::Base
end

class HasAndBelongsToManyWithOptionsTest < Test::Unit::TestCase
	fixtures :habtm_with_options_parents, :habtm_with_options_children, :habtm_joins

	def test_habtm_with_options
		setup_fixtures(
:habtm_with_options_parents => %Q{
parent_entry:
  field: parent value
  children:
    - child_one: 
        field: one
    - child_two:
        field: two},
:habtm_with_options_children => "",
:habtm_joins => "
child_one_parent_entry:
  field: one value")

		assert_fixtures(
:habtm_with_options_parents => %Q{
parent_entry:
  id: 1
  field: parent value},
:habtm_with_options_children => %Q{
child_one:
  id: 1
  field: one
child_two:
  id: 2
  field: two},
:habtm_joins => %Q{
child_one_parent_entry:
  id: 1
  field: one value
  alternate_parent: 1
  alternate_child: 1 
child_two_parent_entry:
  id: 2
  alternate_parent: 1
  alternate_child: 2  })
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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