Sha256: efe1fb1a31c4b2d9fbc90b22631b4909d4f31520a1be05f44d38781a4f2df15b

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

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

class HasAndBelongsToManyMigration < ActiveRecord::Migration
  def self.up
	create_table :habtm_parents do |t|
		t.column :field, :string
	end	
	create_table :habtm_children do |t|
		t.column :field, :string
	end	
	create_table :habtm_children_habtm_parents do |t|
		t.column :habtm_parent_id, :integer
		t.column :habtm_child_id, :integer
	end	
  end

  def self.down
	drop_table :habtm_parents
	drop_table :habtm_children
	drop_table :habtm_children_habtm_parents
  end
end

class HabtmParent < ActiveRecord::Base
	has_and_belongs_to_many :habtm_children
end

class HabtmChild < ActiveRecord::Base
end

class HabtmChildrenHabtmParent < ActiveRecord::Base
end

class HasAndBelongsToManyTest < Test::Unit::TestCase
	fixtures :habtm_parents, :habtm_children, :habtm_children_habtm_parents

	def test_habtm
		setup_fixtures(
:habtm_parents => %Q{
parent_entry:
  field: parent value
  habtm_children:
    - child_one: 
        field: one
    - child_two:
        field: two},
:habtm_children => "",
:habtm_children_habtm_parents => "")

		assert_fixtures(
:habtm_parents => %Q{
parent_entry:
  id: 1
  field: parent value},
:habtm_children => %Q{
child_one:
  id: 1
  field: one
child_two:
  id: 2
  field: two},
:habtm_children_habtm_parents => %Q{
child_one_parent_entry:
  id: 1
  habtm_parent_id: 1
  habtm_child_id: 1 
child_two_parent_entry:
  id: 2
  habtm_parent_id: 1
  habtm_child_id: 2  })
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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