Skip to content

Instantly share code, notes, and snippets.

@maurogeorge
Created February 2, 2014 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maurogeorge/8776223 to your computer and use it in GitHub Desktop.
Save maurogeorge/8776223 to your computer and use it in GitHub Desktop.
Self executable gist to show the error of issue https://github.com/rails/rails/issues/13923 on Rails
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
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.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :people do |t|
t.string :name
end
create_table :relatives do |t|
t.boolean :adopted
end
create_table :people_relatives do |t|
t.integer :person_id
t.integer :relative_id
end
end
class Person < ActiveRecord::Base
has_and_belongs_to_many :relatives, :autosave => true
end
class Relative < ActiveRecord::Base
end
class PeopleRelative < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_association_stuff
person = Person.create!
relative = Relative.create!
person.relatives << relative
person.name = 'John Doe'
relative.adopted = false
person.save!
person.reload
relative.reload
assert_equal 'John Doe', person.name
assert_equal false, relative.adopted
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment