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

Adds Rails 7 Support #174

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@ jobs:
fail-fast: false
matrix:
ruby: ["3.0", 3.1, 3.2, 3.3]
rails: [6.1.4]
gemfile:
- gemfiles/rails_6.gemfile
- gemfiles/rails_7.gemfile
include:
- ruby: "3.0"
rails: 6.1.4
gemfile: gemfiles/rails_6.gemfile
- ruby: "3.0"
gemfile: gemfiles/rails_7.gemfile
- ruby: 3.1
gemfile: gemfiles/rails_6.gemfile
- ruby: 3.1
rails: 6.1.4
gemfile: gemfiles/rails_7.gemfile
- ruby: 3.2
rails: 6.1.4
gemfile: gemfiles/rails_6.gemfile
- ruby: 3.2
gemfile: gemfiles/rails_7.gemfile
- ruby: 3.3
gemfile: gemfiles/rails_6.gemfile
- ruby: 3.3
rails: 6.1.4
gemfile: gemfiles/rails_7.gemfile

env:
TESTING_RAILS_VERSION: ${{ matrix.rails }}
BUNDLE_GEMFILE: ${{ matrix.gemfile }}

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.config
.yardoc
Gemfile.lock
gemfiles/*.lock
InstalledFiles
_yardoc
coverage
Expand Down
10 changes: 10 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
appraise "rails-6" do
gem "rails", "6.1.4"
gem "sqlite3", "~> 1.4"
end

appraise "rails-7" do
gem "rails", "7.1.3"
gem "sqlite3", "~> 1.4"
gem "importmap-rails"
end
8 changes: 8 additions & 0 deletions gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "6.1.4"
gem "sqlite3", "~> 1.4"

gemspec path: "../"
9 changes: 9 additions & 0 deletions gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "7.1.3"
gem "sqlite3", "~> 1.4"
gem "importmap-rails"

gemspec path: "../"
14 changes: 11 additions & 3 deletions lib/raygun/middleware/javascript_exception_tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ def call(env)
end

def inject_javascript_to_response(response)
if Raygun.configuration.js_api_key.present? && response.respond_to?('[]')
response[0].gsub!('</head>', "#{js_tracker.head_html}</head>")
response[0].gsub!('</body>', "#{js_tracker.body_html}</body>")
if Raygun.configuration.js_api_key.present?
if response.respond_to?('[]')
response[0].gsub!('</head>', "#{js_tracker.head_html}</head>")
response[0].gsub!('</body>', "#{js_tracker.body_html}</body>")
end

if response.respond_to?(:body) # Rack::BodyProxy
body = response.body
body.gsub!('</head>', "#{js_tracker.head_html}</head>")
body.gsub!('</body>', "#{js_tracker.body_html}</body>")
end
end

response
Expand Down
10 changes: 3 additions & 7 deletions raygun4ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "raygun/version"

TESTING_RAILS_VERSION = ENV.fetch("TESTING_RAILS_VERSION", "6.1.4")
TESTING_RAILS_MAJOR_VERSION = TESTING_RAILS_VERSION.split(".").first.to_i

Gem::Specification.new do |spec|
spec.name = "raygun4ruby"
spec.version = Raygun::VERSION
spec.authors = ["Mindscape", "Nik Wakelin"]
spec.email = ["[email protected]"]
spec.description = %q{Ruby Adapter for Raygun}
spec.summary = %q{This gem provides support for Ruby and Ruby on Rails for the Raygun error reporter}
spec.summary = %q{This gem provides support for Ruby and Ruby on Rails for the Raygun.com error reporter}
spec.homepage = "https://raygun.com"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.0"
Expand All @@ -30,6 +27,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", ">= 2.3"
spec.add_development_dependency "rake", ">= 12.3.3"
spec.add_development_dependency "appraisal"
spec.add_development_dependency "timecop"
spec.add_development_dependency "minitest", "~> 5.11"
spec.add_development_dependency "redis-namespace", ">= 1.3.1"
Expand All @@ -39,10 +37,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "pry"
spec.add_development_dependency "webmock"

spec.add_development_dependency "rails", "= #{TESTING_RAILS_VERSION}"
spec.add_development_dependency "sqlite3", "~> #{TESTING_RAILS_MAJOR_VERSION <= 5 ? "1.3.13" : "1.4"}"
spec.add_development_dependency "capybara"
spec.add_development_dependency "rspec-rails", "~> 3.9"
spec.add_development_dependency "rspec-rails"
spec.add_development_dependency "launchy"
spec.add_development_dependency "simplecov"
end
37 changes: 37 additions & 0 deletions spec/rails_applications/7.1.3/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.

# Ignore git directory.
/.git/

# Ignore bundler config.
/.bundle

# Ignore all environment files (except templates).
/.env*
!/.env*.erb

# Ignore all default key files.
/config/master.key
/config/credentials/*.key

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/.keep

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
sumitramanga marked this conversation as resolved.
Show resolved Hide resolved
/tmp/storage/*
!/tmp/storage/.keep

# Ignore assets.
/node_modules/
/app/assets/builds/*
!/app/assets/builds/.keep
/public/assets
9 changes: 9 additions & 0 deletions spec/rails_applications/7.1.3/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# See https://git-scm.com/docs/gitattributes for more about git attribute files.

# Mark the database schema as having been generated.
db/schema.rb linguist-generated

# Mark any vendored files as having been vendored.
vendor/* linguist-vendored
config/credentials/*.yml.enc diff=rails_credentials
config/credentials.yml.enc diff=rails_credentials
35 changes: 35 additions & 0 deletions spec/rails_applications/7.1.3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all environment files (except templates).
/.env*
!/.env*.erb

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

/public/assets

# Ignore master key for decrypting credentials and more.
/config/master.key
1 change: 1 addition & 0 deletions spec/rails_applications/7.1.3/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.0
62 changes: 62 additions & 0 deletions spec/rails_applications/7.1.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.3.0
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build gems
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential git libvips pkg-config

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile


# Final stage for app image
FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN useradd rails --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp
USER rails:rails

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]
67 changes: 67 additions & 0 deletions spec/rails_applications/7.1.3/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
source "https://rubygems.org"

ruby "3.3.0"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.1.3", ">= 7.1.3.2"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
gem "redis", ">= 4.0.1"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ windows jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ]
end

group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"

# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"

# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
end
24 changes: 24 additions & 0 deletions spec/rails_applications/7.1.3/README.md
sumitramanga marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...
6 changes: 6 additions & 0 deletions spec/rails_applications/7.1.3/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative "config/application"

Rails.application.load_tasks
4 changes: 4 additions & 0 deletions spec/rails_applications/7.1.3/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
sumitramanga marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
Loading