diff options
Diffstat (limited to 'guides/bug_report_templates')
-rw-r--r-- | guides/bug_report_templates/action_controller_gem.rb | 52 | ||||
-rw-r--r-- | guides/bug_report_templates/action_controller_master.rb | 50 | ||||
-rw-r--r-- | guides/bug_report_templates/active_job_gem.rb | 29 | ||||
-rw-r--r-- | guides/bug_report_templates/active_job_master.rb | 28 | ||||
-rw-r--r-- | guides/bug_report_templates/active_record_gem.rb | 49 | ||||
-rw-r--r-- | guides/bug_report_templates/active_record_master.rb | 48 | ||||
-rw-r--r-- | guides/bug_report_templates/active_record_migrations_gem.rb | 60 | ||||
-rw-r--r-- | guides/bug_report_templates/active_record_migrations_master.rb | 59 | ||||
-rw-r--r-- | guides/bug_report_templates/benchmark.rb | 49 | ||||
-rw-r--r-- | guides/bug_report_templates/generic_gem.rb | 23 | ||||
-rw-r--r-- | guides/bug_report_templates/generic_master.rb | 22 |
11 files changed, 469 insertions, 0 deletions
diff --git a/guides/bug_report_templates/action_controller_gem.rb b/guides/bug_report_templates/action_controller_gem.rb new file mode 100644 index 0000000000..6c74200761 --- /dev/null +++ b/guides/bug_report_templates/action_controller_gem.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require "bundler/inline" + +gemfile(true) do + source "https://rubygems.org" + + git_source(:github) { |repo| "https://github.com/#{repo}.git" } + + # Activate the gem you are reporting the issue against. + gem "rails", "5.2.0" +end + +require "rack/test" +require "action_controller/railtie" + +class TestApp < Rails::Application + config.root = __dir__ + config.session_store :cookie_store, key: "cookie_store_key" + secrets.secret_key_base = "secret_key_base" + + config.logger = Logger.new($stdout) + Rails.logger = config.logger + + routes.draw do + get "/" => "test#index" + end +end + +class TestController < ActionController::Base + include Rails.application.routes.url_helpers + + def index + render plain: "Home" + end +end + +require "minitest/autorun" + +class BugTest < Minitest::Test + include Rack::Test::Methods + + def test_returns_success + get "/" + assert last_response.ok? + end + + private + def app + Rails.application + end +end diff --git a/guides/bug_report_templates/action_controller_master.rb b/guides/bug_report_templates/action_controller_master.rb new file mode 100644 index 0000000000..6d53e957d9 --- /dev/null +++ b/guides/bug_report_templates/action_controller_master.rb @@ -0,0 +1,50 @@ +# 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" +end + +require "action_controller/railtie" + +class TestApp < Rails::Application + config.root = __dir__ + secrets.secret_key_base = "secret_key_base" + + config.logger = Logger.new($stdout) + Rails.logger = config.logger + + routes.draw do + get "/" => "test#index" + end +end + +class TestController < ActionController::Base + include Rails.application.routes.url_helpers + + def index + render plain: "Home" + end +end + +require "minitest/autorun" +require "rack/test" + +class BugTest < Minitest::Test + include Rack::Test::Methods + + def test_returns_success + get "/" + assert last_response.ok? + end + + private + def app + Rails.application + end +end diff --git a/guides/bug_report_templates/active_job_gem.rb b/guides/bug_report_templates/active_job_gem.rb new file mode 100644 index 0000000000..eb9d1316e9 --- /dev/null +++ b/guides/bug_report_templates/active_job_gem.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require "bundler/inline" + +gemfile(true) do + source "https://rubygems.org" + + git_source(:github) { |repo| "https://github.com/#{repo}.git" } + + # Activate the gem you are reporting the issue against. + gem "activejob", "5.2.0" +end + +require "minitest/autorun" +require "active_job" + +class BuggyJob < ActiveJob::Base + def perform + puts "performed" + end +end + +class BuggyJobTest < ActiveJob::TestCase + def test_stuff + assert_enqueued_with(job: BuggyJob) do + BuggyJob.perform_later + end + end +end diff --git a/guides/bug_report_templates/active_job_master.rb b/guides/bug_report_templates/active_job_master.rb new file mode 100644 index 0000000000..ae3ef7752f --- /dev/null +++ b/guides/bug_report_templates/active_job_master.rb @@ -0,0 +1,28 @@ +# 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" +end + +require "active_job" +require "minitest/autorun" + +class BuggyJob < ActiveJob::Base + def perform + puts "performed" + end +end + +class BuggyJobTest < ActiveJob::TestCase + def test_stuff + assert_enqueued_with(job: BuggyJob) do + BuggyJob.perform_later + end + end +end diff --git a/guides/bug_report_templates/active_record_gem.rb b/guides/bug_report_templates/active_record_gem.rb new file mode 100644 index 0000000000..d88304a219 --- /dev/null +++ b/guides/bug_report_templates/active_record_gem.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require "bundler/inline" + +gemfile(true) do + source "https://rubygems.org" + + git_source(:github) { |repo| "https://github.com/#{repo}.git" } + + # Activate the gem you are reporting the issue against. + gem "activerecord", "5.2.0" + 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 + + create_table :comments, force: true do |t| + t.integer :post_id + end +end + +class Post < ActiveRecord::Base + has_many :comments +end + +class Comment < ActiveRecord::Base + belongs_to :post +end + +class BugTest < Minitest::Test + def test_association_stuff + post = Post.create! + post.comments << Comment.create! + + assert_equal 1, post.comments.count + assert_equal 1, Comment.count + assert_equal post.id, Comment.first.post.id + end +end diff --git a/guides/bug_report_templates/active_record_master.rb b/guides/bug_report_templates/active_record_master.rb new file mode 100644 index 0000000000..780456b7b6 --- /dev/null +++ b/guides/bug_report_templates/active_record_master.rb @@ -0,0 +1,48 @@ +# 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 + + create_table :comments, force: true do |t| + t.integer :post_id + end +end + +class Post < ActiveRecord::Base + has_many :comments +end + +class Comment < ActiveRecord::Base + belongs_to :post +end + +class BugTest < Minitest::Test + def test_association_stuff + post = Post.create! + post.comments << Comment.create! + + assert_equal 1, post.comments.count + assert_equal 1, Comment.count + assert_equal post.id, Comment.first.post.id + end +end diff --git a/guides/bug_report_templates/active_record_migrations_gem.rb b/guides/bug_report_templates/active_record_migrations_gem.rb new file mode 100644 index 0000000000..5dfd49fb38 --- /dev/null +++ b/guides/bug_report_templates/active_record_migrations_gem.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require "bundler/inline" + +gemfile(true) do + source "https://rubygems.org" + + git_source(:github) { |repo| "https://github.com/#{repo}.git" } + + # Activate the gem you are reporting the issue against. + gem "activerecord", "5.2.0" + 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 :payments, force: true do |t| + t.decimal :amount, precision: 10, scale: 0, default: 0, null: false + end +end + +class Payment < ActiveRecord::Base +end + +class ChangeAmountToAddScale < ActiveRecord::Migration[5.2] + def change + reversible do |dir| + dir.up do + change_column :payments, :amount, :decimal, precision: 10, scale: 2, default: 0, null: false + end + + dir.down do + change_column :payments, :amount, :decimal, precision: 10, scale: 0, default: 0, null: false + end + end + end +end + +class BugTest < Minitest::Test + def test_migration_up + ChangeAmountToAddScale.migrate(:up) + Payment.reset_column_information + + assert_equal "decimal(10,2)", Payment.columns.last.sql_type + end + + def test_migration_down + ChangeAmountToAddScale.migrate(:down) + Payment.reset_column_information + + assert_equal "decimal(10,0)", Payment.columns.last.sql_type + end +end diff --git a/guides/bug_report_templates/active_record_migrations_master.rb b/guides/bug_report_templates/active_record_migrations_master.rb new file mode 100644 index 0000000000..b0fe3bc660 --- /dev/null +++ b/guides/bug_report_templates/active_record_migrations_master.rb @@ -0,0 +1,59 @@ +# 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 :payments, force: true do |t| + t.decimal :amount, precision: 10, scale: 0, default: 0, null: false + end +end + +class Payment < ActiveRecord::Base +end + +class ChangeAmountToAddScale < ActiveRecord::Migration[6.0] + def change + reversible do |dir| + dir.up do + change_column :payments, :amount, :decimal, precision: 10, scale: 2, default: 0, null: false + end + + dir.down do + change_column :payments, :amount, :decimal, precision: 10, scale: 0, default: 0, null: false + end + end + end +end + +class BugTest < Minitest::Test + def test_migration_up + ChangeAmountToAddScale.migrate(:up) + Payment.reset_column_information + + assert_equal "decimal(10,2)", Payment.columns.last.sql_type + end + + def test_migration_down + ChangeAmountToAddScale.migrate(:down) + Payment.reset_column_information + + assert_equal "decimal(10,0)", Payment.columns.last.sql_type + end +end diff --git a/guides/bug_report_templates/benchmark.rb b/guides/bug_report_templates/benchmark.rb new file mode 100644 index 0000000000..4a8ce787c7 --- /dev/null +++ b/guides/bug_report_templates/benchmark.rb @@ -0,0 +1,49 @@ +# 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 "benchmark-ips" +end + +require "active_support" +require "active_support/core_ext/object/blank" + +# Your patch goes here. +class String + def fast_blank? + true + end +end + +# Enumerate some representative scenarios here. +# +# It is very easy to make an optimization that improves performance for a +# specific scenario you care about but regresses on other common cases. +# Therefore, you should test your change against a list of representative +# scenarios. Ideally, they should be based on real-world scenarios extracted +# from production applications. +SCENARIOS = { + "Empty" => "", + "Single Space" => " ", + "Two Spaces" => " ", + "Mixed Whitspaces" => " \t\r\n", + "Very Long String" => " " * 100 +} + +SCENARIOS.each_pair do |name, value| + puts + puts " #{name} ".center(80, "=") + puts + + Benchmark.ips do |x| + x.report("blank?") { value.blank? } + x.report("fast_blank?") { value.fast_blank? } + x.compare! + end +end diff --git a/guides/bug_report_templates/generic_gem.rb b/guides/bug_report_templates/generic_gem.rb new file mode 100644 index 0000000000..3fd54437f7 --- /dev/null +++ b/guides/bug_report_templates/generic_gem.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "bundler/inline" + +gemfile(true) do + source "https://rubygems.org" + + git_source(:github) { |repo| "https://github.com/#{repo}.git" } + + # Activate the gem you are reporting the issue against. + gem "activesupport", "5.2.0" +end + +require "active_support" +require "active_support/core_ext/object/blank" +require "minitest/autorun" + +class BugTest < Minitest::Test + def test_stuff + assert "zomg".present? + refute "".present? + end +end diff --git a/guides/bug_report_templates/generic_master.rb b/guides/bug_report_templates/generic_master.rb new file mode 100644 index 0000000000..ec65fee292 --- /dev/null +++ b/guides/bug_report_templates/generic_master.rb @@ -0,0 +1,22 @@ +# 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" +end + +require "active_support" +require "active_support/core_ext/object/blank" +require "minitest/autorun" + +class BugTest < Minitest::Test + def test_stuff + assert "zomg".present? + refute "".present? + end +end |