Created
February 2, 2014 06:33
-
-
Save diatmpravin/8763852 to your computer and use it in GitHub Desktop.
AR bug with circular destroy: I am able to replicate this issue for later release including 4.0.0 for has_many relationship. It's fine for earlier release.
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.timestamps | |
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