Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create executable bug report Rails application #593

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
rubygems: latest
bundler-cache: true

- name: Run Bug Template Tests
run: ruby bug_report_template.rb || ruby bug_report_template.rb
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first execution fails with:

/opt/hostedtoolcache/Ruby/3.0.6/x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:304:in `check_for_activated_spec!': You have already activated stringio 3.0.1, but your Gemfile requires stringio 3.1.0. Since stringio is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports stringio as a default gem. (Gem::LoadError)

I'm not sure why, but executing a second time resolves that problem.


- name: Run tests
id: test
run: bundle exec rake TESTOPT=-vdc
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ The [`Turbo::Broadcastable::TestHelper`](./lib/turbo/broadcastable/test_helper.r

Run the tests with `./bin/test`.

## Contributing

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 an [executable bug report Rails application](./bug_report_template.rb) for you to use as a starting point.

This template includes the boilerplate code to set up a System Test case. Copy the content of the template into a `.rb` file and make the necessary changes to demonstrate the issue. You can execute it by running `ruby the_file.rb` in your terminal. If all goes well, you should see your test case failing.

You can then share your executable test case as a gist or paste the content into the issue description.

## License

Turbo is released under the [MIT License](https://opensource.org/licenses/MIT).
111 changes: 111 additions & 0 deletions bug_report_template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
require "bundler/inline"

gemfile(true) do
source "https://rubygems.org"

gem "rails"
gem "propshaft"
gem "puma"
gem "sqlite3", "~> 1.4"
gem "turbo-rails"

gem "capybara"
gem "cuprite", require: "capybara/cuprite"
end

ENV["DATABASE_URL"] = "sqlite3::memory:"
ENV["RAILS_ENV"] = "test"

require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_view/railtie"
# require "action_mailer/railtie"
# require "active_job/railtie"
require "action_cable/engine"
# require "action_mailbox/engine"
# require "action_text/engine"
require "rails/test_unit/railtie"

class App < 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.consider_all_requests_local = true
config.action_cable.cable = {"adapter" => "async"}
config.turbo.draw_routes = false

Rails.logger = config.logger = Logger.new($stdout)

routes.append do
root to: "application#index"
end
end

Rails.application.initialize!

ActiveRecord::Schema.define do
create_table :messages, force: true do |t|
t.text :body, null: false
end
end

class Message < ActiveRecord::Base
end

class ApplicationController < ActionController::Base
include Rails.application.routes.url_helpers

class_attribute :template, default: DATA.read

def index
render inline: template, formats: :html
end
end

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :cuprite, using: :chrome, screen_size: [1400, 1400], options: {js_errors: true}
end

Capybara.configure do |config|
config.server = :puma, {Silent: true}
config.default_normalize_ws = true
end

require "rails/test_help"

class TurboSystemTest < ApplicationSystemTestCase
test "reproduces bug" do
visit root_path

assert_text "Loaded with Turbo"
end
end

__END__
<!DOCTYPE html>
<html>
<head>
<%= csrf_meta_tags %>

<script type="importmap">
{
"imports": {
"@hotwired/turbo-rails": "<%= asset_path("turbo.js") %>"
}
}
</script>

<script type="module">
import "@hotwired/turbo-rails"

addEventListener("turbo:load", () => document.body.innerHTML = "Loaded with Turbo")
</script>
</head>

<body>Loaded without Turbo</body>
</html>