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

Upgrade to Rails 7.2, switch to system specs, and add PWA and devcontainers support #1589

Merged
merged 16 commits into from
Oct 15, 2024

Conversation

MrSerth
Copy link
Member

@MrSerth MrSerth commented Aug 16, 2024

With this PR, we are upgrading CodeHarbor to Rails 7.2 and making use of all the great features the new version provides. Therefore, this PR looks rather big at a first glance, but the commits are intended to provide a meaningful grouping of the changes. All commits are required to complete the upgrade and the activation of current best-practices for Rails application.

From a high-level point of view, the following changes are relevant:

  • CodeHarbor is running Rails 7.2 (instead of Rails 7.1)
  • Remove deprecated secrets.yml, require setting environment variable SECRET_KEY_BASE for production
  • Add brakeman as security scanner
  • Rspec feature specs are migrated to system specs, which allows the usage of advanced features (automatic screenshots in case of failures, easier management of Capybara, no need to use the DatabaseCleaner gem any longer)
  • Applying best-practices for Rails and Rspec, reordering some files
  • Adding a webmanifest for CodeHarbor, which allows to install CodeHarbor as a PWA
  • Chrome is used as a new default browser for system specs (rather than Firefox)
  • A production-ready Dockerfile and a pre-configured devcontainer for local development are provided
  • GitHub Codespaces is officially supported
Screenshots of enhanced PWA support

Shortcuts with native app experience:
Bildschirmfoto 2024-08-16 um 14 17 42

Screenshots of GitHub Codespaces running CodeHarbor

Codespaces Editor:
Bildschirmfoto 2024-08-16 um 14 03 46
Remote Access:
Bildschirmfoto 2024-08-16 um 14 03 51

List of commits

Specifically, this PR adds the following commits:

  • Upgrade to Rails 7.2 and apply new framework defaults
  • Remove outdated reference to node_modules folder
  • Add brakeman with GitHub action pipeline
  • Add production-ready Docker image
  • Add webmanifest and basic PWA support
  • Apply current config for Rspec and move extensions to support directory
  • Move ungrouped specs to a dedicated folder other
  • Fix warning about stubbing a method on nil
  • Ensure select2 is initialized regardless of page load events
  • Migrate feature specs to system specs
  • Switch to Rspec native transactional fixtures to replace database cleaner
  • Add support for devcontainers
  • Add support for GitHub Codespaces and port forwarding
  • Add recent changes to Local Setup Guides

@MrSerth MrSerth added enhancement dependencies Pull requests that update a dependency file ruby Pull requests that update Ruby code docker Pull requests that update Docker dependencies devcontainers Pull requests that update devcontainer dependencies labels Aug 16, 2024
@MrSerth MrSerth requested a review from Dome-GER August 16, 2024 12:24
@MrSerth MrSerth self-assigned this Aug 16, 2024
Copy link

codecov bot commented Aug 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.78%. Comparing base (4f4f3d7) to head (0f23d64).
Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1589      +/-   ##
==========================================
+ Coverage   94.77%   94.78%   +0.01%     
==========================================
  Files         130      133       +3     
  Lines        3330     3338       +8     
==========================================
+ Hits         3156     3164       +8     
  Misses        174      174              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* Use new syntax for enums
* Fix usage of incorrect queue adapter for test environment
* Adjust boilerplate code to match default for new Rails apps
* Lint binstubs and remove outdated `yarn` stub
The prefix `~` was used to refer to a package in the `node_modules` folder and thus specify the search path. By today, this syntax is still supported, but unnecessary (the search path nowadays includes `node_modules`) and thus the usage is not recommended any longer.
For new Rails apps, brakeman is enabled by default
The docker image is not meant for local development, but for a production-level deployment. It is based on the Docker setup added by default for new Rails apps.

As part of this change, we had to rethink our integration of JavaScript and CSS compressors. Without the change in `production.rb`, an ExecJS runtime would be needed to run the Rails app. Since we require a JavaScript runtime only for the asset compilation (but not when serving the application), this would bloat the Docker image unnecessarily.
For new Rails apps, a suitable webmanifest is added by default
Further, this commit also configures custom groups for SimpleCov, enriching the report generated with further details.
Previously, select2 was only loaded successfully, if first the page was loaded (turbolinks:load) and then all select2 locales (select2:locales:loaded). However, if the order was different, select2 wouldn't be initialized.

Fixes #1476
System tests are natively supported by Rails and come with nice features, such as automatic screenshots in case of failures. Since a few years already, Rspec recommends system specs over feature specs.
…aner

With the previous change to system specs and the new framework defaults, we can drop the database cleaner entirely. All tests will only be executed as part of a transaction, and nothing is stored in the database.
For new Rails apps, a suitable devcontainer is enabled by default. The setup provided has been tested and confirmed to work with a singe click in Visual Studio Code.
GitHub Codespaces is a commercial offering for devcontainers. While our setup mostly works out-of-the-box, the host and port forwarding required further adjustments to work as expected.
Otherwise, only the `id` is shown by default (in contrast to `full_inspect`). This behavior has changed with Rails 7.2, and previously showed all information by default.

Since we often use `inspect` within the application to get details about unexpected errors, we want to keep the previous behavior.
spec/system/authentication_system_spec.rb Show resolved Hide resolved
spec/system/tasks_system_spec.rb Show resolved Hide resolved
@MrSerth MrSerth merged commit b292878 into master Oct 15, 2024
10 checks passed
@MrSerth MrSerth deleted the rails_72 branch October 15, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file devcontainers Pull requests that update devcontainer dependencies docker Pull requests that update Docker dependencies enhancement ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants