Last active
August 29, 2015 13:55
-
-
Save diatmpravin/8763535 to your computer and use it in GitHub Desktop.
Rails Bug - https://github.com/rails/rails/issues/13609
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', '3.2.12' | |
gem 'arel' | |
gem 'mysql2' | |
GEMFILE | |
system 'bundle' | |
end | |
require 'bundler' | |
Bundler.setup(:default) | |
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.establish_connection(adapter: 'mysql2', host: 'localhost', port: '3306', database: 'testing_test') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
unless ActiveRecord::Base.connection.table_exists? 'physicians' | |
create_table :physicians do |t| | |
t.string :name | |
t.timestamps | |
end | |
end | |
unless ActiveRecord::Base.connection.table_exists? 'patients' | |
create_table :patients do |t| | |
t.string :name | |
t.timestamps | |
end | |
end | |
unless ActiveRecord::Base.connection.table_exists? 'appointments' | |
create_table :appointments do |t| | |
t.references :patient | |
t.references :physician | |
t.datetime :appointment_date | |
t.timestampshttp://gathers.us/events/hosting-rails-apps | |
end | |
end | |
end | |
class Physician < ActiveRecord::Base | |
has_many :appointments, dependent: :destroy | |
has_many :patient, through: :appointment | |
end | |
class Appointment < ActiveRecord::Base | |
belongs_to :physician | |
belongs_to :patient, dependent: :destroy | |
end | |
class Patient < ActiveRecord::Base | |
has_many :appointments, dependent: :destroy | |
has_many :physician, through: :appointment | |
end | |
class BugTest < MiniTest::Unit::TestCase | |
def test_save_failed | |
physician = Physician.create! | |
patient = Patient.create! | |
appointment = Appointment.create!(physician: physician, patient: patient, appointment_date: Date.today) | |
#puts physician.appointments.inspect | |
#puts physician.appointments.size.inspect | |
#puts physician.appointments(true).empty?.inspect | |
physician.destroy # here we get a stack level too deep error | |
assert physician.destroyed? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment