Skip to content

Instantly share code, notes, and snippets.

@madmax
Last active January 30, 2020 08:08
Show Gist options
  • Save madmax/21069d5695ad732369433dc8986b55d0 to your computer and use it in GitHub Desktop.
Save madmax/21069d5695ad732369433dc8986b55d0 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "sqlite3"
end
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, force: true do |t|
end
end
class Post < ActiveRecord::Base
def self.show_scopes
new.show_scopes
end
def show_scopes
Post.all.to_sql
end
end
class BugTest < Minitest::Test
def test_dont_add_scope_if_class_used
scope_by_class_method = Post.where(id: 1).show_scopes
scope_called_directly = Post.where(id: 1).new.show_scopes
assert_equal scope_called_directly, scope_by_class_method
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment