diff --git a/guides/bug_report_templates/action_controller_gem.rb b/guides/bug_report_templates/action_controller.rb similarity index 85% rename from guides/bug_report_templates/action_controller_gem.rb rename to guides/bug_report_templates/action_controller.rb index 2d02c37247..8062d67293 100644 --- a/guides/bug_report_templates/action_controller_gem.rb +++ b/guides/bug_report_templates/action_controller.rb @@ -7,17 +7,16 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } - # Activate the gem you are reporting the issue against. - gem "rails", "~> 7.1.0" + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" end -require "rack/test" require "action_controller/railtie" class TestApp < Rails::Application config.root = __dir__ config.hosts << "example.org" - config.session_store :cookie_store, key: "cookie_store_key" config.secret_key_base = "secret_key_base" config.logger = Logger.new($stdout) @@ -37,6 +36,7 @@ def index end require "minitest/autorun" +require "rack/test" class BugTest < Minitest::Test include Rack::Test::Methods diff --git a/guides/bug_report_templates/action_controller_main.rb b/guides/bug_report_templates/action_controller_main.rb deleted file mode 100644 index c9d8bee95e..0000000000 --- a/guides/bug_report_templates/action_controller_main.rb +++ /dev/null @@ -1,51 +0,0 @@ -# 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", branch: "main" -end - -require "action_controller/railtie" - -class TestApp < Rails::Application - config.root = __dir__ - config.hosts << "example.org" - config.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/action_mailbox_gem.rb b/guides/bug_report_templates/action_mailbox.rb similarity index 92% rename from guides/bug_report_templates/action_mailbox_gem.rb rename to guides/bug_report_templates/action_mailbox.rb index 34a46c26f2..50e6b57e25 100644 --- a/guides/bug_report_templates/action_mailbox_gem.rb +++ b/guides/bug_report_templates/action_mailbox.rb @@ -7,9 +7,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } - # Activate the gem you are reporting the issue against. - gem "rails", "~> 7.1.0" - gem "sqlite3" + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" end require "active_record/railtie" diff --git a/guides/bug_report_templates/action_mailbox_main.rb b/guides/bug_report_templates/action_mailbox_main.rb deleted file mode 100644 index e24c327e4e..0000000000 --- a/guides/bug_report_templates/action_mailbox_main.rb +++ /dev/null @@ -1,76 +0,0 @@ -# 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", branch: "main" - gem "sqlite3" -end - -require "active_record/railtie" -require "active_storage/engine" -require "action_mailbox/engine" -require "tmpdir" - -class TestApp < Rails::Application - config.load_defaults Rails::VERSION::STRING.to_f - - config.root = __dir__ - config.hosts << "example.org" - config.eager_load = false - config.session_store :cookie_store, key: "cookie_store_key" - config.secret_key_base = "secret_key_base" - - config.logger = Logger.new($stdout) - Rails.logger = config.logger - - config.active_storage.service = :local - config.active_storage.service_configurations = { - local: { - root: Dir.tmpdir, - service: "Disk" - } - } - - config.action_mailbox.ingress = :relay -end - -ENV["DATABASE_URL"] = "sqlite3::memory:" - -Rails.application.initialize! - -require ActiveStorage::Engine.root.join("db/migrate/20170806125915_create_active_storage_tables.rb").to_s -require ActionMailbox::Engine.root.join("db/migrate/20180917164000_create_action_mailbox_tables.rb").to_s - -ActiveRecord::Schema.define do - CreateActiveStorageTables.new.change - CreateActionMailboxTables.new.change -end - -class ApplicationMailbox < ActionMailbox::Base - routing (/^replies@/i) => :replies -end - -class RepliesMailbox < ActionMailbox::Base - def process - $processed = mail.subject - end -end - -require "minitest/autorun" - -class RepliesMailboxTest < ActionMailbox::TestCase - setup do - $processed = false - @inbound_email = receive_inbound_email_from_mail \ - to: "replies@example.com", subject: "Here is a reply" - end - - test "successful mailbox processing" do - assert_equal "Here is a reply", $processed - end -end diff --git a/guides/bug_report_templates/action_mailer_gem.rb b/guides/bug_report_templates/action_mailer.rb similarity index 84% rename from guides/bug_report_templates/action_mailer_gem.rb rename to guides/bug_report_templates/action_mailer.rb index ad6415d7a7..5d97c231c2 100644 --- a/guides/bug_report_templates/action_mailer_gem.rb +++ b/guides/bug_report_templates/action_mailer.rb @@ -7,8 +7,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } - # Activate the gem you are reporting the issue against. - gem "rails", "~> 7.1.0" + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" end require "action_mailer/railtie" diff --git a/guides/bug_report_templates/action_mailer_main.rb b/guides/bug_report_templates/action_mailer_main.rb deleted file mode 100644 index af12a45f57..0000000000 --- a/guides/bug_report_templates/action_mailer_main.rb +++ /dev/null @@ -1,39 +0,0 @@ -# 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", branch: "main" -end - -require "action_mailer/railtie" - -class TestMailer < ActionMailer::Base - def hello_world - @message = "Hello, world" - - mail from: "test@example.com", to: "user@example.com" do |format| - format.html { render inline: "

<%= @message %>

" } - format.text { render inline: "<%= @message %>" } - end - end -end - -require "minitest/autorun" - -class BugTest < ActionMailer::TestCase - test "renders HTML and Text body" do - email = TestMailer.hello_world - - email.deliver_now - - assert_dom_email do - assert_dom "h1", text: "Hello, world" - end - assert_includes email.text_part.body, "Hello, world" - end -end diff --git a/guides/bug_report_templates/active_job_gem.rb b/guides/bug_report_templates/active_job.rb similarity index 75% rename from guides/bug_report_templates/active_job_gem.rb rename to guides/bug_report_templates/active_job.rb index 34c30776ae..8b551cc392 100644 --- a/guides/bug_report_templates/active_job_gem.rb +++ b/guides/bug_report_templates/active_job.rb @@ -7,12 +7,13 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } - # Activate the gem you are reporting the issue against. - gem "activejob", "~> 7.1.0" + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" end -require "minitest/autorun" require "active_job" +require "minitest/autorun" class BuggyJob < ActiveJob::Base def perform diff --git a/guides/bug_report_templates/active_job_main.rb b/guides/bug_report_templates/active_job_main.rb deleted file mode 100644 index 335a78f392..0000000000 --- a/guides/bug_report_templates/active_job_main.rb +++ /dev/null @@ -1,28 +0,0 @@ -# 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", branch: "main" -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.rb similarity index 86% rename from guides/bug_report_templates/active_record_gem.rb rename to guides/bug_report_templates/active_record.rb index 89e00cb8c3..5ade95ccdf 100644 --- a/guides/bug_report_templates/active_record_gem.rb +++ b/guides/bug_report_templates/active_record.rb @@ -7,9 +7,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } - # Activate the gem you are reporting the issue against. - gem "activerecord", "~> 7.1.0" - gem "sqlite3" + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" end require "active_record" diff --git a/guides/bug_report_templates/active_record_main.rb b/guides/bug_report_templates/active_record_main.rb deleted file mode 100644 index f8acbabfa3..0000000000 --- a/guides/bug_report_templates/active_record_main.rb +++ /dev/null @@ -1,48 +0,0 @@ -# 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", branch: "main" - 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_main.rb b/guides/bug_report_templates/active_record_migrations.rb similarity index 90% rename from guides/bug_report_templates/active_record_migrations_main.rb rename to guides/bug_report_templates/active_record_migrations.rb index 49f7272447..7aa989d3a4 100644 --- a/guides/bug_report_templates/active_record_migrations_main.rb +++ b/guides/bug_report_templates/active_record_migrations.rb @@ -7,8 +7,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } - gem "rails", github: "rails/rails", branch: "main" - gem "sqlite3" + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" end require "active_record" diff --git a/guides/bug_report_templates/active_record_migrations_gem.rb b/guides/bug_report_templates/active_record_migrations_gem.rb deleted file mode 100644 index 092fbddc36..0000000000 --- a/guides/bug_report_templates/active_record_migrations_gem.rb +++ /dev/null @@ -1,60 +0,0 @@ -# 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", "~> 7.1.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[7.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/active_storage_main.rb b/guides/bug_report_templates/active_storage.rb similarity index 90% rename from guides/bug_report_templates/active_storage_main.rb rename to guides/bug_report_templates/active_storage.rb index 7ec906dee3..d646cf57d5 100644 --- a/guides/bug_report_templates/active_storage_main.rb +++ b/guides/bug_report_templates/active_storage.rb @@ -7,8 +7,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } - gem "rails", github: "rails/rails", branch: "main" - gem "sqlite3" + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" end require "active_record/railtie" diff --git a/guides/bug_report_templates/active_storage_gem.rb b/guides/bug_report_templates/active_storage_gem.rb deleted file mode 100644 index 2e2e512d7a..0000000000 --- a/guides/bug_report_templates/active_storage_gem.rb +++ /dev/null @@ -1,70 +0,0 @@ -# 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", "~> 7.1.0" - gem "sqlite3" -end - -require "active_record/railtie" -require "active_storage/engine" -require "tmpdir" - -class TestApp < Rails::Application - config.load_defaults Rails::VERSION::STRING.to_f - - config.root = __dir__ - config.hosts << "example.org" - config.eager_load = false - config.session_store :cookie_store, key: "cookie_store_key" - config.secret_key_base = "secret_key_base" - - config.logger = Logger.new($stdout) - Rails.logger = config.logger - - config.active_storage.service = :local - config.active_storage.service_configurations = { - local: { - root: Dir.tmpdir, - service: "Disk" - } - } -end - -ENV["DATABASE_URL"] = "sqlite3::memory:" - -Rails.application.initialize! - -require ActiveStorage::Engine.root.join("db/migrate/20170806125915_create_active_storage_tables.rb").to_s - -ActiveRecord::Schema.define do - CreateActiveStorageTables.new.change - - create_table :users, force: true -end - -class User < ActiveRecord::Base - has_one_attached :profile -end - -require "minitest/autorun" - -class BugTest < Minitest::Test - def test_upload_and_download - user = User.create!( - profile: { - content_type: "text/plain", - filename: "dummy.txt", - io: ::StringIO.new("dummy"), - } - ) - - assert_equal "dummy", user.profile.download - end -end diff --git a/guides/bug_report_templates/benchmark.rb b/guides/bug_report_templates/benchmark.rb index f00a7de5f5..dcfa9c3d1a 100644 --- a/guides/bug_report_templates/benchmark.rb +++ b/guides/bug_report_templates/benchmark.rb @@ -7,7 +7,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } - gem "rails", github: "rails/rails", branch: "main" + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" gem "benchmark-ips" end diff --git a/guides/bug_report_templates/generic_main.rb b/guides/bug_report_templates/generic.rb similarity index 72% rename from guides/bug_report_templates/generic_main.rb rename to guides/bug_report_templates/generic.rb index 576b95e108..92d082e9d2 100644 --- a/guides/bug_report_templates/generic_main.rb +++ b/guides/bug_report_templates/generic.rb @@ -7,7 +7,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } - gem "rails", github: "rails/rails", branch: "main" + gem "rails" + # If you want to test against edge Rails replace the previous line with this: + # gem "rails", github: "rails/rails", branch: "main" end require "active_support" diff --git a/guides/bug_report_templates/generic_gem.rb b/guides/bug_report_templates/generic_gem.rb deleted file mode 100644 index 25d34ae2aa..0000000000 --- a/guides/bug_report_templates/generic_gem.rb +++ /dev/null @@ -1,23 +0,0 @@ -# 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", "~> 7.1.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/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md index 227728dfca..dfa0553e6c 100644 --- a/guides/source/contributing_to_ruby_on_rails.md +++ b/guides/source/contributing_to_ruby_on_rails.md @@ -39,14 +39,14 @@ Once you open an issue, it may or may not see activity right away unless it is a Having a way to reproduce your issue will help people confirm, investigate, and ultimately fix your issue. You can do this by providing an executable test case. To make this process easier, we have prepared several bug report templates for you to use as a starting point: -* Template for Active Record (models, database) issues: [gem](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_gem.rb) / [main](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_main.rb) -* Template for testing Active Record (migration) issues: [gem](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_migrations_gem.rb) / [main](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_migrations_main.rb) -* Template for Action Pack (controllers, routing) issues: [gem](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_controller_gem.rb) / [main](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_controller_main.rb) -* Template for Active Job issues: [gem](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_job_gem.rb) / [main](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_job_main.rb) -* Template for Active Storage issues: [gem](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_storage_gem.rb) / [main](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_storage_main.rb) -* Template for Action Mailer issues: [gem](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailer_gem.rb) / [main](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailer_main.rb) -* Template for Action Mailbox issues: [gem](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailbox_gem.rb) / [main](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailbox_main.rb) -* Generic template for other issues: [gem](https://github.com/rails/rails/blob/main/guides/bug_report_templates/generic_gem.rb) / [main](https://github.com/rails/rails/blob/main/guides/bug_report_templates/generic_main.rb) +* Template for Active Record (models, database) issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record.rb) +* Template for testing Active Record (migration) issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_migrations.rb) +* Template for Action Pack (controllers, routing) issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_controller.rb) +* Template for Active Job issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_job.rb) +* Template for Active Storage issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_storage.rb) +* Template for Action Mailer issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailer.rb) +* Template for Action Mailbox issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailbox.rb) +* Generic template for other issues: [link](https://github.com/rails/rails/blob/main/guides/bug_report_templates/generic.rb) These templates include the boilerplate code to set up a test case against either a released version of Rails (`*_gem.rb`) or edge Rails (`*_main.rb`).