Skip to content

Instantly share code, notes, and snippets.

@tigris
Forked from neerajsingh0101/with_published_versions.rb
Last active December 15, 2015 06:49
Show Gist options
  • Save tigris/5218844 to your computer and use it in GitHub Desktop.
Save tigris/5218844 to your computer and use it in GitHub Desktop.
-- create_table(:players, {:force=>true})
-> 0.0088s
-- create_table(:player_totals, {:force=>true})
-> 0.0009s
Run options: --seed 39528
# Running tests:
E
Fabulous tests in 0.104982s, 9.5254 tests/s, 0.0000 assertions/s.
1) Error:
HasManyBugTest#test_complex_association:
ActiveRecord::StatementInvalid: Could not find table 'previous_totals_players'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/sqlite3_adapter.rb:509:in `table_structure'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/sqlite3_adapter.rb:396:in `columns'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/schema_cache.rb:86:in `block in prepare_default_proc'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/schema_cache.rb:90:in `yield'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/schema_cache.rb:90:in `block in prepare_default_proc'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/schema_cache.rb:46:in `yield'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/schema_cache.rb:46:in `columns_hash'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/predicate_builder.rb:104:in `build'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/predicate_builder.rb:51:in `expand'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/predicate_builder.rb:28:in `block in build_from_hash'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/predicate_builder.rb:6:in `each'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/predicate_builder.rb:6:in `build_from_hash'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/query_methods.rb:800:in `build_where'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/query_methods.rb:478:in `where!'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/query_methods.rb:468:in `where'
bar.rb:22:in `block in <class:Player>'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/associations/builder/association.rb:31:in `instance_exec'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/associations/builder/association.rb:31:in `block in initialize'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/associations/join_dependency/join_association.rb:106:in `instance_exec'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/associations/join_dependency/join_association.rb:106:in `block (2 levels) in join_to'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/associations/join_dependency/join_association.rb:104:in `each'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/associations/join_dependency/join_association.rb:104:in `block in join_to'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/associations/join_dependency/join_association.rb:69:in `each'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/associations/join_dependency/join_association.rb:69:in `each_with_index'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/associations/join_dependency/join_association.rb:69:in `join_to'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/query_methods.rb:854:in `block in build_joins'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/query_methods.rb:853:in `each'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/query_methods.rb:853:in `build_joins'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/query_methods.rb:736:in `build_arel'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/query_methods.rb:729:in `arel'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/delegation.rb:110:in `respond_to?'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/abstract/database_statements.rb:11:in `to_sql'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_all'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/finder_methods.rb:184:in `find_with_associations'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation.rb:555:in `exec_queries'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation.rb:447:in `load'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation.rb:197:in `to_a'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/finder_methods.rb:312:in `find_first'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/relation/finder_methods.rb:90:in `first'
/home/danial/git/foo/gems/ruby/2.0.0/gems/activerecord-deprecated_finders-0.0.3/lib/active_record/deprecated_finders/relation.rb:129:in `first'
bar.rb:38:in `test_complex_association'
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
source 'http://rubygems.org'
gem 'rails', '4.0.0.beta1'
gem 'sqlite3'
#!/usr/bin/env ruby
require 'bundler/setup'
require 'active_record'
require 'minitest/autorun'
require 'minitest/pride'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :players, force: true
create_table :player_totals, force: true do |t|
t.integer :player_id
t.integer :year
t.integer :total
end
end
class Player < ActiveRecord::Base
has_many :totals, class_name: 'PlayerTotal'
has_one :current_total, -> { where(year: 2013) }, class_name: 'PlayerTotal'
has_one :previous_total, -> { where(year: 2012) }, class_name: 'PlayerTotal'
# Rails 3.2.13 version of associations
# has_many :totals, class_name: 'PlayerTotal'
# has_one :current_total, conditions: { year: 2013 }, class_name: 'PlayerTotal'
# has_one :previous_total, conditions: { year: 2012 }, class_name: 'PlayerTotal'
end
class PlayerTotal < ActiveRecord::Base
belongs_to :player
end
class HasManyBugTest < MiniTest::Unit::TestCase
def setup
@player = Player.create!
@player.totals.create!(year: 2013, total: 110)
@player.totals.create!(year: 2012, total: 120)
@player.totals.create!(year: 2011, total: 130)
end
def test_complex_association
assert @player.current_total, Player.includes(:current_total, :previous_total).where('player_totals.total > ?', 100).references(:current_total).first.current_total
# Rails 3.2.13 version of the same test
#
assert @player.current_total, Player.includes(:current_total, :previous_total).where('player_totals.total > ?', 100).first.current_total
end
def teardown
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment