pftg
6/27/2013 - 7:07 AM

gynecologic_examinations_test.rb

# Activate the gem you are reporting the issue against.
gem 'activerecord', '3.2.13'
require 'active_record'
require 'minitest/autorun'
require 'logger'

# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table :gynecologic_examination_uterine_boundaries do |t|
    t.string :value

    t.timestamps
  end

  create_table :gynecologic_examinations do |t|
    t.date :date
    t.integer :uterine_boundary_id
    t.timestamps
  end
end

class GynecologicExamination < ActiveRecord::Base
  belongs_to :uterine_boundary
  attr_accessible :date, :uterine_boundary_id, :uterine_boundary
end

class GynecologicExamination::UterineBoundary < ActiveRecord::Base
  has_many :gynecologic_examination
  attr_accessible :value
end


class BugTest < MiniTest::Unit::TestCase
  def test_association_stuff
    boundary = GynecologicExamination::UterineBoundary.create value: 'test'
    exam     = GynecologicExamination.create(:date => Date.today, uterine_boundary_id: boundary.id)
    assert exam.uterine_boundary, 'should be associated'

    exam     = GynecologicExamination.create(:date => Date.today, uterine_boundary: boundary)
    assert exam.uterine_boundary, 'should be associated'
  end
end