Created
September 3, 2013 15:07
-
-
Save senny/6425163 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
# Activate the gem you are reporting the issue against. | |
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| | |
t.string :title | |
end | |
end | |
class Post < ActiveRecord::Base | |
def self.total_post_count | |
Post.count | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_scope_leak | |
Post.create! title: "one" | |
Post.create! title: "two" | |
Post.create! title: "three" | |
assert_equal 3, Post.total_post_count | |
assert_equal 3, Post.where(title: "one").total_post_count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fails with:
the relevant SQL is: