Skip to content

Instantly share code, notes, and snippets.

@trushkevich
Created April 24, 2020 09:56
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 trushkevich/9d8cdc3c7466e7bc793ae7075534db4f to your computer and use it in GitHub Desktop.
Save trushkevich/9d8cdc3c7466e7bc793ae7075534db4f 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
end
class BugTest < Minitest::Test
def test_ok
posts = (0..10).to_a.map { |i| Post.where(id: i) }.inject { |res, scope| res.or(scope) }
assert_equal posts.count, 0
end
def test_parser_stack_overflow
posts = (0..100).to_a.map { |i| Post.where(id: i) }.inject { |res, scope| res.or(scope) }
assert_equal posts.count, 0
end
def test_stack_level_too_deep
posts = (0..1000).to_a.map { |i| Post.where(id: i) }.inject { |res, scope| res.or(scope) }
assert_equal posts.count, 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment