Skip to content

Instantly share code, notes, and snippets.

@alexdean
Forked from senny/scope_leak.rb
Created December 8, 2015 16:28
Show Gist options
  • Save alexdean/acd6d81da86d1dd507b1 to your computer and use it in GitHub Desktop.
Save alexdean/acd6d81da86d1dd507b1 to your computer and use it in GitHub Desktop.
# 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