-
-
Save kidlab/3b4374f09b73ae168e2a to your computer and use it in GitHub Desktop.
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
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'activerecord', '4.2.4' | |
gem 'goldiloader' | |
gem 'sqlite3' | |
end | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
# 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, force: true do |t| | |
t.references :user | |
end | |
create_table :users, force: true do |t| | |
end | |
end | |
class Post < ActiveRecord::Base | |
belongs_to :user | |
scope :rank, -> do | |
all | |
end | |
end | |
class User < ActiveRecord::Base | |
has_many :posts | |
end | |
class BugTest < Minitest::Test | |
def test_eager_loading | |
user = User.create! | |
3.times { user.posts.create! } | |
scope = filter_scope(Post.where(user_id: 1)) | |
assert(!scope.loaded?) | |
end | |
def filter_scope(scope) | |
if scope == Post || (scope.is_a?(ActiveRecord::Relation) && scope.klass == Post) | |
scope = scope.rank | |
end | |
# ... | |
scope | |
end | |
end |
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
Fetching gem metadata from https://rubygems.org/........... | |
Fetching version metadata from https://rubygems.org/.. | |
Resolving dependencies... | |
Using i18n 0.7.0 | |
Using json 1.8.3 | |
Using minitest 5.8.3 | |
Using thread_safe 0.3.5 | |
Using tzinfo 1.2.2 | |
Using activesupport 4.2.4 | |
Using builder 3.2.2 | |
Using activemodel 4.2.4 | |
Using arel 6.0.3 | |
Using activerecord 4.2.4 | |
Using goldiloader 0.0.9 | |
Using sqlite3 1.3.11 | |
Using bundler 1.10.6 | |
-- create_table(:posts, {:force=>true}) | |
D, [2015-12-04T19:22:30.784491 #62783] DEBUG -- : (0.2ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer) | |
-> 0.0027s | |
-- create_table(:users, {:force=>true}) | |
D, [2015-12-04T19:22:30.784903 #62783] DEBUG -- : (0.1ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) | |
-> 0.0003s | |
Run options: --seed 31098 | |
# Running: | |
D, [2015-12-04T19:22:30.797421 #62783] DEBUG -- : (0.0ms) begin transaction | |
D, [2015-12-04T19:22:30.799380 #62783] DEBUG -- : SQL (0.0ms) INSERT INTO "users" DEFAULT VALUES | |
D, [2015-12-04T19:22:30.799670 #62783] DEBUG -- : (0.0ms) commit transaction | |
D, [2015-12-04T19:22:30.801859 #62783] DEBUG -- : (0.0ms) begin transaction | |
D, [2015-12-04T19:22:30.805206 #62783] DEBUG -- : SQL (0.1ms) INSERT INTO "posts" ("user_id") VALUES (?) [["user_id", 1]] | |
D, [2015-12-04T19:22:30.805453 #62783] DEBUG -- : (0.0ms) commit transaction | |
D, [2015-12-04T19:22:30.805605 #62783] DEBUG -- : (0.0ms) begin transaction | |
D, [2015-12-04T19:22:30.806148 #62783] DEBUG -- : SQL (0.0ms) INSERT INTO "posts" ("user_id") VALUES (?) [["user_id", 1]] | |
D, [2015-12-04T19:22:30.806360 #62783] DEBUG -- : (0.0ms) commit transaction | |
D, [2015-12-04T19:22:30.806488 #62783] DEBUG -- : (0.0ms) begin transaction | |
D, [2015-12-04T19:22:30.806988 #62783] DEBUG -- : SQL (0.0ms) INSERT INTO "posts" ("user_id") VALUES (?) [["user_id", 1]] | |
D, [2015-12-04T19:22:30.807200 #62783] DEBUG -- : (0.0ms) commit transaction | |
. | |
Finished in 0.014776s, 67.6789 runs/s, 67.6789 assertions/s. | |
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment