Skip to content

Instantly share code, notes, and snippets.

@msbit
Created March 4, 2016 02:10
Show Gist options
  • Save msbit/a56285c870f66a1c0a08 to your computer and use it in GitHub Desktop.
Save msbit/a56285c870f66a1c0a08 to your computer and use it in GitHub Desktop.
ActiveRecord::QueryMethods#includes has_many through with conditions on destination model
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.4
Using thread_safe 0.3.5
Using builder 3.2.2
Using arel 6.0.3
Using sqlite3 1.3.11
Using bundler 1.11.2
Using tzinfo 1.2.2
Using activesupport 4.2.5.2
Using activemodel 4.2.5.2
Using activerecord 4.2.5.2
-- create_table(:users, {:force=>true})
D, [2016-03-04T13:08:15.263241 #36845] DEBUG -- :  (0.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) 
-> 0.0046s
-- create_table(:participations, {:force=>true})
D, [2016-03-04T13:08:15.263727 #36845] DEBUG -- :  (0.1ms) CREATE TABLE "participations" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer)
-> 0.0004s
-- create_table(:attempts, {:force=>true})
D, [2016-03-04T13:08:15.264138 #36845] DEBUG -- :  (0.1ms) CREATE TABLE "attempts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "completed" boolean, "participation_id" integer) 
-> 0.0004s
Run options: --seed 11313
# Running:
D, [2016-03-04T13:08:15.291722 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.293320 #36845] DEBUG -- : SQL (0.1ms) INSERT INTO "users" DEFAULT VALUES
D, [2016-03-04T13:08:15.293570 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.299650 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.304017 #36845] DEBUG -- : SQL (0.1ms) INSERT INTO "participations" ("user_id") VALUES (?) [["user_id", 1]]
D, [2016-03-04T13:08:15.304267 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.305302 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.308372 #36845] DEBUG -- : SQL (0.1ms) INSERT INTO "attempts" ("participation_id", "completed") VALUES (?, ?) [["participation_id", 1], ["completed", "t"]]
D, [2016-03-04T13:08:15.308607 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.308743 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.309269 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "attempts" ("participation_id", "completed") VALUES (?, ?) [["participation_id", 1], ["completed", "f"]]
D, [2016-03-04T13:08:15.309453 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.311743 #36845] DEBUG -- : User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
D, [2016-03-04T13:08:15.319519 #36845] DEBUG -- : Participation Load (0.2ms) SELECT "participations".* FROM "participations" WHERE "attempts"."completed" = ? AND "participations"."user_id" IN (1) [["completed", "t"]]
ED, [2016-03-04T13:08:15.320021 #36845] DEBUG -- :  (0.1ms) begin transaction
D, [2016-03-04T13:08:15.320621 #36845] DEBUG -- : SQL (0.1ms) INSERT INTO "users" DEFAULT VALUES
D, [2016-03-04T13:08:15.320951 #36845] DEBUG -- :  (0.1ms) commit transaction
D, [2016-03-04T13:08:15.321446 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.322397 #36845] DEBUG -- : SQL (0.1ms) INSERT INTO "participations" ("user_id") VALUES (?) [["user_id", 2]]
D, [2016-03-04T13:08:15.322704 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.323102 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.323836 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "attempts" ("participation_id", "completed") VALUES (?, ?) [["participation_id", 2], ["completed", "t"]]
D, [2016-03-04T13:08:15.324068 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.324209 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.324838 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "attempts" ("participation_id", "completed") VALUES (?, ?) [["participation_id", 2], ["completed", "f"]]
D, [2016-03-04T13:08:15.325064 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.326300 #36845] DEBUG -- : User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
D, [2016-03-04T13:08:15.330448 #36845] DEBUG -- : Attempt Load (0.1ms) SELECT "attempts".* FROM "attempts" INNER JOIN "participations" ON "attempts"."participation_id" = "participations"."id" WHERE "participations"."user_id" = ? AND "attempts"."completed" = ? [["user_id", 2], ["completed", "t"]]
.D, [2016-03-04T13:08:15.330928 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.331407 #36845] DEBUG -- : SQL (0.1ms) INSERT INTO "users" DEFAULT VALUES
D, [2016-03-04T13:08:15.331660 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.332071 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.332800 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "participations" ("user_id") VALUES (?) [["user_id", 3]]
D, [2016-03-04T13:08:15.333039 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.333394 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.334015 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "attempts" ("participation_id", "completed") VALUES (?, ?) [["participation_id", 3], ["completed", "t"]]
D, [2016-03-04T13:08:15.334218 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.334346 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.334896 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "attempts" ("participation_id", "completed") VALUES (?, ?) [["participation_id", 3], ["completed", "f"]]
D, [2016-03-04T13:08:15.335097 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.337151 #36845] DEBUG -- : SQL (0.1ms) SELECT DISTINCT "users"."id" FROM "users" LEFT OUTER JOIN "participations" ON "participations"."user_id" = "users"."id" LEFT OUTER JOIN "attempts" ON "attempts"."participation_id" = "participations"."id" AND "attempts"."completed" = ? WHERE "users"."id" = ? LIMIT 1 [["completed", "t"], ["id", 3]]
D, [2016-03-04T13:08:15.338387 #36845] DEBUG -- : SQL (0.2ms) SELECT "users"."id" AS t0_r0, "attempts"."id" AS t1_r0, "attempts"."completed" AS t1_r1, "attempts"."participation_id" AS t1_r2 FROM "users" LEFT OUTER JOIN "participations" ON "participations"."user_id" = "users"."id" LEFT OUTER JOIN "attempts" ON "attempts"."participation_id" = "participations"."id" AND "attempts"."completed" = ? WHERE "users"."id" = ? AND "users"."id" IN (3) [["completed", "t"], ["id", 3]]
.D, [2016-03-04T13:08:15.339208 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.339567 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "users" DEFAULT VALUES
D, [2016-03-04T13:08:15.339787 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.340083 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.340674 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "participations" ("user_id") VALUES (?) [["user_id", 4]]
D, [2016-03-04T13:08:15.340879 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.341170 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.341754 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "attempts" ("participation_id", "completed") VALUES (?, ?) [["participation_id", 4], ["completed", "t"]]
D, [2016-03-04T13:08:15.341960 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.342075 #36845] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:08:15.342573 #36845] DEBUG -- : SQL (0.0ms) INSERT INTO "attempts" ("participation_id", "completed") VALUES (?, ?) [["participation_id", 4], ["completed", "f"]]
D, [2016-03-04T13:08:15.342758 #36845] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:08:15.343061 #36845] DEBUG -- : User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 4]]
D, [2016-03-04T13:08:15.343893 #36845] DEBUG -- : Participation Load (0.2ms) SELECT "participations".* FROM "participations" WHERE "attempts"."completed" = ? AND "participations"."user_id" IN (4) [["completed", "t"]]
E
Finished in 0.056283s, 71.0692 runs/s, 35.5346 assertions/s.
1) Error:
BugTest#test_included_through:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: attempts.completed: SELECT "participations".* FROM "participations" WHERE "attempts"."completed" = ? AND "participations"."user_id" IN (1)
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `new'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `prepare'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:306:in `block in exec_query'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:293:in `exec_query'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/database_statements.rb:355:in `select'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/querying.rb:39:in `find_by_sql'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:639:in `exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:515:in `load'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:243:in `to_a'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:46:in `to_ary'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `each_slice'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `load_slices'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:91:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/collection_association.rb:13:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:20:in `run'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:146:in `block (2 levels) in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `block in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:115:in `preloaders_on'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:103:in `block in preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/through_association.rb:14:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/has_many_through.rb:8:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/collection_association.rb:13:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:20:in `run'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:146:in `block (2 levels) in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `block in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:115:in `preloaders_on'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:103:in `block in preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:645:in `block in exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:644:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:644:in `exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:515:in `load'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:243:in `to_a'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:475:in `find_take'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:105:in `take'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:442:in `find_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:423:in `find_with_ids'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:71:in `find'
active_record_gem.rb:84:in `test_included_through'
2) Error:
BugTest#test_preloaded_through:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: attempts.completed: SELECT "participations".* FROM "participations" WHERE "attempts"."completed" = ? AND "participations"."user_id" IN (4)
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `new'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `prepare'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:306:in `block in exec_query'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:293:in `exec_query'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/database_statements.rb:355:in `select'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/querying.rb:39:in `find_by_sql'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:639:in `exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:515:in `load'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:243:in `to_a'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/delegation.rb:46:in `to_ary'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `each_slice'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:115:in `load_slices'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:91:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/collection_association.rb:13:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:20:in `run'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:146:in `block (2 levels) in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `block in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:115:in `preloaders_on'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:103:in `block in preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/through_association.rb:14:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/has_many_through.rb:8:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/collection_association.rb:13:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader/association.rb:20:in `run'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:146:in `block (2 levels) in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:144:in `block in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:143:in `preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:115:in `preloaders_on'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:103:in `block in preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/associations/preloader.rb:102:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:645:in `block in exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:644:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:644:in `exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:515:in `load'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation.rb:243:in `to_a'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:475:in `find_take'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:105:in `take'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:442:in `find_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:423:in `find_with_ids'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/relation/finder_methods.rb:71:in `find'
active_record_gem.rb:79:in `test_preloaded_through'
4 runs, 2 assertions, 0 failures, 2 errors, 0 skips
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'
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.2.5.2'
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 :users, force: true do |t|
end
create_table :participations, force: true do |t|
t.integer :user_id
end
create_table :attempts, force: true do |t|
t.boolean :completed
t.integer :participation_id
end
end
class User < ActiveRecord::Base
has_many :participations
has_many :attempts, through: :participations
has_many :completed_attempts, -> { completed }, through: :participations, source: :attempts
end
class Participation < ActiveRecord::Base
belongs_to :user
has_many :attempts
end
class Attempt < ActiveRecord::Base
belongs_to :participation
scope :completed, -> { where(completed: true) }
end
class BugTest < Minitest::Test
def setup
@user = User.create
@participation = @user.participations.create
@completed_attempt = @participation.attempts.create do |attempt|
attempt.completed = true
end
@uncompleted_attempt = @participation.attempts.create do |attempt|
attempt.completed = false
end
end
def test_lazy_loaded_through
lazy_loaded_completed_attempts = User.find(@user.id).completed_attempts
assert_equal([@completed_attempt], lazy_loaded_completed_attempts.to_a)
end
def test_eager_loaded_through
eager_loaded_completed_attempts = User.eager_load(:completed_attempts).find(@user.id).completed_attempts
assert_equal([@completed_attempt], eager_loaded_completed_attempts.to_a)
end
def test_preloaded_through
preloaded_completed_attempts = User.preload(:completed_attempts).find(@user.id).completed_attempts
assert_equal([@completed_attempt], preloaded_completed_attempts.to_a)
end
def test_included_through
included_completed_attempts = User.includes(:completed_attempts).find(@user.id).completed_attempts
assert_equal([@completed_attempt], included_completed_attempts.to_a)
end
end
Fetching git://github.com/rails/rails.git
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/..
Resolving dependencies....
Using rake 10.5.0
Using concurrent-ruby 1.0.1
Using i18n 0.7.0
Using minitest 5.8.4
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using json 1.8.3
Using nio4r 1.2.1
Using websocket-extensions 0.1.2
Using mime-types 2.99.1
Using arel 7.0.0
Using bundler 1.11.2
Using method_source 0.8.2
Using thor 0.19.1
Using sqlite3 1.3.11
Using tzinfo 1.2.2
Using nokogiri 1.6.7.2
Using rack 2.0.0.alpha
Using websocket-driver 0.6.3
Using mail 2.6.3
Using activesupport 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
Using loofah 2.0.3
Using rack-test 0.6.3
Using sprockets 3.5.2
Using rails-deprecated_sanitizer 1.0.3
Using globalid 0.3.6
Using activemodel 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
Using rails-html-sanitizer 1.0.3
Using rails-dom-testing 1.0.7
Using activejob 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
Using activerecord 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
Using actionview 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
Using actionpack 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
Using actioncable 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
Using actionmailer 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
Using railties 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
Using sprockets-rails 3.0.4
Using rails 5.0.0.beta3 from git://github.com/rails/rails.git (at master@f8ec3a1)
-- create_table(:users, {:force=>true})
D, [2016-03-04T13:09:12.298318 #36860] DEBUG -- :  (0.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) 
-> 0.0169s
-- create_table(:participations, {:force=>true})
D, [2016-03-04T13:09:12.299050 #36860] DEBUG -- :  (0.1ms) CREATE TABLE "participations" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer) 
-> 0.0006s
-- create_table(:attempts, {:force=>true})
D, [2016-03-04T13:09:12.299574 #36860] DEBUG -- :  (0.1ms) CREATE TABLE "attempts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "completed" boolean, "participation_id" integer) 
-> 0.0005s
D, [2016-03-04T13:09:12.302734 #36860] DEBUG -- :  (0.1ms) CREATE TABLE "ar_internal_metadata" ("key" varchar PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
D, [2016-03-04T13:09:12.309427 #36860] DEBUG -- : ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" ORDER BY "ar_internal_metadata"."key" ASC LIMIT ? [["LIMIT", 1]]
D, [2016-03-04T13:09:12.314527 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.315428 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "development"], ["created_at", 2016-03-04 02:09:12 UTC], ["updated_at", 2016-03-04 02:09:12 UTC]]
D, [2016-03-04T13:09:12.315578 #36860] DEBUG -- :  (0.0ms) commit transaction
Run options: --seed 23337
# Running:
D, [2016-03-04T13:09:12.342719 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.343374 #36860] DEBUG -- : SQL (0.0ms) INSERT INTO "users" DEFAULT VALUES
D, [2016-03-04T13:09:12.343580 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.352576 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.356983 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "participations" ("user_id") VALUES (?) [["user_id", 1]]
D, [2016-03-04T13:09:12.357201 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.358858 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.362034 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "attempts" ("completed", "participation_id") VALUES (?, ?) [["completed", true], ["participation_id", 1]]
D, [2016-03-04T13:09:12.362196 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.362331 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.362992 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "attempts" ("completed", "participation_id") VALUES (?, ?) [["completed", false], ["participation_id", 1]]
D, [2016-03-04T13:09:12.363137 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.368425 #36860] DEBUG -- : SQL (0.1ms) SELECT DISTINCT "users"."id" FROM "users" LEFT OUTER JOIN "participations" ON "participations"."user_id" = "users"."id" LEFT OUTER JOIN "attempts" ON "attempts"."participation_id" = "participations"."id" AND "attempts"."completed" = ? WHERE "users"."id" = ? LIMIT ? [["completed", true], ["id", 1], ["LIMIT", 1]]
D, [2016-03-04T13:09:12.369885 #36860] DEBUG -- : SQL (0.2ms) SELECT "users"."id" AS t0_r0, "attempts"."id" AS t1_r0, "attempts"."completed" AS t1_r1, "attempts"."participation_id" AS t1_r2 FROM "users" LEFT OUTER JOIN "participations" ON "participations"."user_id" = "users"."id" LEFT OUTER JOIN "attempts" ON "attempts"."participation_id" = "participations"."id" AND "attempts"."completed" = ? WHERE "users"."id" = ? AND "users"."id" = 1 [["completed", true], ["id", 1]]
.D, [2016-03-04T13:09:12.373114 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.373604 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "users" DEFAULT VALUES
D, [2016-03-04T13:09:12.373793 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.374314 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.375153 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "participations" ("user_id") VALUES (?) [["user_id", 2]]
D, [2016-03-04T13:09:12.375326 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.375784 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.376546 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "attempts" ("completed", "participation_id") VALUES (?, ?) [["completed", true], ["participation_id", 2]]
D, [2016-03-04T13:09:12.376707 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.376825 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.377468 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "attempts" ("completed", "participation_id") VALUES (?, ?) [["completed", false], ["participation_id", 2]]
D, [2016-03-04T13:09:12.377618 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.378711 #36860] DEBUG -- : User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
D, [2016-03-04T13:09:12.380028 #36860] DEBUG -- : Attempt Load (0.1ms) SELECT "attempts".* FROM "attempts" INNER JOIN "participations" ON "attempts"."participation_id" = "participations"."id" WHERE "participations"."user_id" = ? AND "attempts"."completed" = ? [["user_id", 2], ["completed", true]]
.D, [2016-03-04T13:09:12.380347 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.380744 #36860] DEBUG -- : SQL (0.0ms) INSERT INTO "users" DEFAULT VALUES
D, [2016-03-04T13:09:12.380913 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.381367 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.382126 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "participations" ("user_id") VALUES (?) [["user_id", 3]]
D, [2016-03-04T13:09:12.382293 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.382739 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.383436 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "attempts" ("completed", "participation_id") VALUES (?, ?) [["completed", true], ["participation_id", 3]]
D, [2016-03-04T13:09:12.383587 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.383705 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.384310 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "attempts" ("completed", "participation_id") VALUES (?, ?) [["completed", false], ["participation_id", 3]]
D, [2016-03-04T13:09:12.384455 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.384802 #36860] DEBUG -- : User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]]
D, [2016-03-04T13:09:12.387956 #36860] DEBUG -- : Participation Load (0.2ms) SELECT "participations".* FROM "participations" WHERE "attempts"."completed" = ? AND "participations"."user_id" = 3 [["completed", true]]
ED, [2016-03-04T13:09:12.388263 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.388657 #36860] DEBUG -- : SQL (0.0ms) INSERT INTO "users" DEFAULT VALUES
D, [2016-03-04T13:09:12.388819 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.389278 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.389991 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "participations" ("user_id") VALUES (?) [["user_id", 4]]
D, [2016-03-04T13:09:12.390146 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.390600 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.391311 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "attempts" ("completed", "participation_id") VALUES (?, ?) [["completed", true], ["participation_id", 4]]
D, [2016-03-04T13:09:12.391458 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.391576 #36860] DEBUG -- :  (0.0ms) begin transaction
D, [2016-03-04T13:09:12.392182 #36860] DEBUG -- : SQL (0.1ms) INSERT INTO "attempts" ("completed", "participation_id") VALUES (?, ?) [["completed", false], ["participation_id", 4]]
D, [2016-03-04T13:09:12.392322 #36860] DEBUG -- :  (0.0ms) commit transaction
D, [2016-03-04T13:09:12.392660 #36860] DEBUG -- : User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 4], ["LIMIT", 1]]
D, [2016-03-04T13:09:12.393634 #36860] DEBUG -- : Participation Load (0.2ms) SELECT "participations".* FROM "participations" WHERE "attempts"."completed" = ? AND "participations"."user_id" = 4 [["completed", true]]
E
Finished in 0.054200s, 73.8009 runs/s, 36.9005 assertions/s.
1) Error:
BugTest#test_included_through:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: attempts.completed: SELECT "participations".* FROM "participations" WHERE "attempts"."completed" = ? AND "participations"."user_id" = 3
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `new'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `prepare'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:243:in `block in exec_query'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:526:in `block in log'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activesupport/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:520:in `log'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:227:in `exec_query'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:381:in `select_prepared'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:39:in `select_all'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/querying.rb:39:in `find_by_sql'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:699:in `exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:580:in `load'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:260:in `records'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/delegation.rb:39:in `to_ary'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `each_slice'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `load_records'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:65:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/collection_association.rb:8:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:19:in `run'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:151:in `block (2 levels) in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `block in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:115:in `preloaders_on'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:102:in `block in preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/through_association.rb:14:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/has_many_through.rb:8:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/collection_association.rb:8:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:19:in `run'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:151:in `block (2 levels) in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `block in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:115:in `preloaders_on'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:102:in `block in preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:705:in `block in exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:704:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:704:in `exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:580:in `load'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:260:in `records'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:525:in `find_take'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:100:in `take'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:475:in `find_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:456:in `find_with_ids'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:66:in `find'
active_record_master.rb:84:in `test_included_through'
2) Error:
BugTest#test_preloaded_through:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: attempts.completed: SELECT "participations".* FROM "participations" WHERE "attempts"."completed" = ? AND "participations"."user_id" = 4
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `new'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `prepare'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:243:in `block in exec_query'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:526:in `block in log'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activesupport/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:520:in `log'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:227:in `exec_query'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:381:in `select_prepared'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:39:in `select_all'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/querying.rb:39:in `find_by_sql'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:699:in `exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:580:in `load'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:260:in `records'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/delegation.rb:39:in `to_ary'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `each_slice'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:107:in `load_records'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:65:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/collection_association.rb:8:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:19:in `run'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:151:in `block (2 levels) in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `block in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:115:in `preloaders_on'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:102:in `block in preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/through_association.rb:14:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/has_many_through.rb:8:in `associated_records_by_owner'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/collection_association.rb:8:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader/association.rb:19:in `run'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:151:in `block (2 levels) in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:149:in `block in preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:148:in `preloaders_for_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:115:in `preloaders_on'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:102:in `block in preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `flat_map'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/associations/preloader.rb:101:in `preload'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:705:in `block in exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:704:in `each'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:704:in `exec_queries'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:580:in `load'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation.rb:260:in `records'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:525:in `find_take'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:100:in `take'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:475:in `find_one'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:456:in `find_with_ids'
/Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/rails-f8ec3a142fbf/activerecord/lib/active_record/relation/finder_methods.rb:66:in `find'
active_record_master.rb:79:in `test_preloaded_through'
4 runs, 2 assertions, 0 failures, 2 errors, 0 skips
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'
# Activate the gem you are reporting the issue against.
gem 'rails', github: 'rails/rails'
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 :users, force: true do |t|
end
create_table :participations, force: true do |t|
t.integer :user_id
end
create_table :attempts, force: true do |t|
t.boolean :completed
t.integer :participation_id
end
end
class User < ActiveRecord::Base
has_many :participations
has_many :attempts, through: :participations
has_many :completed_attempts, -> { completed }, through: :participations, source: :attempts
end
class Participation < ActiveRecord::Base
belongs_to :user
has_many :attempts
end
class Attempt < ActiveRecord::Base
belongs_to :participation
scope :completed, -> { where(completed: true) }
end
class BugTest < Minitest::Test
def setup
@user = User.create
@participation = @user.participations.create
@completed_attempt = @participation.attempts.create do |attempt|
attempt.completed = true
end
@uncompleted_attempt = @participation.attempts.create do |attempt|
attempt.completed = false
end
end
def test_lazy_loaded_through
lazy_loaded_completed_attempts = User.find(@user.id).completed_attempts
assert_equal([@completed_attempt], lazy_loaded_completed_attempts.to_a)
end
def test_eager_loaded_through
eager_loaded_completed_attempts = User.eager_load(:completed_attempts).find(@user.id).completed_attempts
assert_equal([@completed_attempt], eager_loaded_completed_attempts.to_a)
end
def test_preloaded_through
preloaded_completed_attempts = User.preload(:completed_attempts).find(@user.id).completed_attempts
assert_equal([@completed_attempt], preloaded_completed_attempts.to_a)
end
def test_included_through
included_completed_attempts = User.includes(:completed_attempts).find(@user.id).completed_attempts
assert_equal([@completed_attempt], included_completed_attempts.to_a)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment