Last active
August 29, 2015 14:07
-
-
Save codeodor/ba07e1dd00a5c831822f to your computer and use it in GitHub Desktop.
A bug report script to reproduce issue #17119 in rails/rails
This file contains 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', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
gem 'rack', github: 'rack/rack' | |
gem 'i18n', github: 'svenfuchs/i18n' | |
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 :posts do |t| | |
end | |
create_table :authors do |t| | |
end | |
create_table :authors_posts do |t| | |
t.integer :author_id | |
t.integer :post_id | |
end | |
end | |
class Author < ActiveRecord::Base | |
end | |
class Post < ActiveRecord::Base | |
has_and_belongs_to_many :writers, class_name: "Author" | |
end | |
class BugTest < Minitest::Test | |
def test_habtm_reflections_with_nonstandard_name_and_class_name_option_work_correctly | |
post = Post.create! | |
post.writers << Author.create! | |
# proof that it works at the macro level of using the association | |
assert_equal 1, post.writers.count | |
# proof that it does not work when using reflections API, as Fixtures do | |
Post._reflections.values.each do |association| | |
assert Kernel.const_defined?(association.class_name), "'#{association.class_name}' expected to be a defined constant, but was not." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment