Skip to content

Instantly share code, notes, and snippets.

@chasballew
Created January 13, 2014 15:35
Show Gist options
  • Save chasballew/8402375 to your computer and use it in GitHub Desktop.
Save chasballew/8402375 to your computer and use it in GitHub Desktop.
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 :admin_posts do |t|
end
create_table :admin_comments do |t|
end
create_join_table :admin_comments, :admin_posts
end
class AdminPost < ActiveRecord::Base
has_and_belongs_to_many :admin_comments
end
class AdminComment < ActiveRecord::Base
has_and_belongs_to_many :admin_posts
end
class BugTest < Minitest::Test
def test_association_stuff
post = AdminPost.create!
comment = AdminComment.create!
comment.admin_posts << post
end
end
@senny
Copy link

senny commented Jan 13, 2014

fails with:

  1) Error:
BugTest#test_association_stuff:
ActiveRecord::StatementInvalid: Could not find table 'admin_comments_posts'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:496:in `table_structure'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:383:in `columns'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/schema_cache.rb:93:in `block in prepare_default_proc'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/schema_cache.rb:44:in `yield'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/schema_cache.rb:44:in `columns'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/schema_cache.rb:97:in `block in prepare_default_proc'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/schema_cache.rb:50:in `yield'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/schema_cache.rb:50:in `columns_hash'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association_scope.rb:25:in `column_for'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association_scope.rb:37:in `bind'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association_scope.rb:61:in `block in add_constraints'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association_scope.rb:44:in `each'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association_scope.rb:44:in `each_with_index'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association_scope.rb:44:in `add_constraints'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association_scope.rb:19:in `scope'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association.rb:97:in `association_scope'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association.rb:86:in `scope'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/collection_association.rb:384:in `scope'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/collection_proxy.rb:36:in `initialize'
    /Users/senny/Projects/rails/activerecord/lib/active_record/relation/delegation.rb:106:in `new'
    /Users/senny/Projects/rails/activerecord/lib/active_record/relation/delegation.rb:106:in `create'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/collection_association.rb:36:in `reader'
    /Users/senny/Projects/rails/activerecord/lib/active_record/associations/builder/association.rb:104:in `admin_posts'
    test.rb:33:in `test_association_stuff'

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment