Skip to content

Instantly share code, notes, and snippets.

@equivalent
Last active April 8, 2020 05:44
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 equivalent/52e3713ec9c35aed26a463ccc28d0617 to your computer and use it in GitHub Desktop.
Save equivalent/52e3713ec9c35aed26a463ccc28d0617 to your computer and use it in GitHub Desktop.
rails reproduce template
# 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 'active_support/test_case'
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
create_table :comments, force: true do |t|
t.integer :post_id
t.string :source
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
SOURCE_INTERFACE='interface'
belongs_to :post
scope :interface, -> { where(source: Comment::SOURCE_INTERFACE) }
end
class BugTest < Minitest::Test
include ActiveSupport::Testing::Deprecation
def test_association_stuff
post = Post.create!
assert_deprecated do
post.comments.interface.create!
end
end
end
# 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 'active_support/test_case'
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
create_table :comments, force: true do |t|
t.integer :post_id
t.string :type
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
SOURCE_INTERFACE='interface'
belongs_to :post
self.inheritance_column = :_type_disabled
scope :interface, -> { where(type: BusinessLogic::SomeBusinessLogic) }
end
module BusinessLogic
class SomeBusinessLogic
end
end
class BugTest < Minitest::Test
include ActiveSupport::Testing::Deprecation
def test_association_stuff
post = Post.create!
assert_deprecated do
post.comments.interface.create!
end
end
end
@equivalent
Copy link
Author

equivalent commented Apr 7, 2020

Screenshot from 2020-04-07 11-02-55

I've runned it on Rails 6.0.2.2 and 6.0.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment