Skip to content

Instantly share code, notes, and snippets.

@senny
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senny/40408a0b048ee31f6268 to your computer and use it in GitHub Desktop.
Save senny/40408a0b048ee31f6268 to your computer and use it in GitHub Desktop.
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
end
class Post < ActiveRecord::Base
scope :one, -> { order(id: :asc).first }
end
class BugTest < Minitest::Test
def test_scope_stuff
post1 = Post.create!
post2 = Post.create!
post3 = Post.create!
post4 = Post.create!
assert_equal post1, Post.one
end
end
-- create_table(:posts)
D, [2014-12-03T10:16:11.177162 #90023] DEBUG -- : (0.6ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
-> 0.0062s
Run options: --seed 5055
# Running:
D, [2014-12-03T10:16:11.212085 #90023] DEBUG -- : (0.1ms) begin transaction
D, [2014-12-03T10:16:11.216655 #90023] DEBUG -- : SQL (0.2ms) INSERT INTO "posts" DEFAULT VALUES
D, [2014-12-03T10:16:11.217220 #90023] DEBUG -- : (0.1ms) commit transaction
D, [2014-12-03T10:16:11.217506 #90023] DEBUG -- : (0.1ms) begin transaction
D, [2014-12-03T10:16:11.218027 #90023] DEBUG -- : SQL (0.1ms) INSERT INTO "posts" DEFAULT VALUES
D, [2014-12-03T10:16:11.218317 #90023] DEBUG -- : (0.1ms) commit transaction
D, [2014-12-03T10:16:11.218626 #90023] DEBUG -- : (0.1ms) begin transaction
D, [2014-12-03T10:16:11.219029 #90023] DEBUG -- : SQL (0.1ms) INSERT INTO "posts" DEFAULT VALUES
D, [2014-12-03T10:16:11.219338 #90023] DEBUG -- : (0.0ms) commit transaction
D, [2014-12-03T10:16:11.219569 #90023] DEBUG -- : (0.1ms) begin transaction
D, [2014-12-03T10:16:11.219942 #90023] DEBUG -- : SQL (0.1ms) INSERT INTO "posts" DEFAULT VALUES
D, [2014-12-03T10:16:11.220253 #90023] DEBUG -- : (0.1ms) commit transaction
D, [2014-12-03T10:16:11.223953 #90023] DEBUG -- : Post Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT 1
.
Finished in 0.022305s, 44.8330 runs/s, 44.8330 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