diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 14bb44f..18a8cb0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/.gitignore b/.gitignore index 70dc5c6..d84a66c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .config .yardoc Gemfile.lock +gemfiles/*.lock InstalledFiles _yardoc coverage diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..f388b16 --- /dev/null +++ b/Appraisals @@ -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 \ No newline at end of file diff --git a/gemfiles/rails_6.gemfile b/gemfiles/rails_6.gemfile new file mode 100644 index 0000000..044af8f --- /dev/null +++ b/gemfiles/rails_6.gemfile @@ -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: "../" diff --git a/gemfiles/rails_7.gemfile b/gemfiles/rails_7.gemfile new file mode 100644 index 0000000..7268342 --- /dev/null +++ b/gemfiles/rails_7.gemfile @@ -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: "../" diff --git a/lib/raygun/middleware/javascript_exception_tracking.rb b/lib/raygun/middleware/javascript_exception_tracking.rb index 504ac76..9691a4c 100644 --- a/lib/raygun/middleware/javascript_exception_tracking.rb +++ b/lib/raygun/middleware/javascript_exception_tracking.rb @@ -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!('', "#{js_tracker.head_html}") - response[0].gsub!('
+ <%= yield %> +', "#{js_tracker.body_html}") + if Raygun.configuration.js_api_key.present? + if response.respond_to?('[]') + response[0].gsub!('', "#{js_tracker.head_html}") + response[0].gsub!('', "#{js_tracker.body_html}") + end + + if response.respond_to?(:body) # Rack::BodyProxy + body = response.body + body.gsub!('', "#{js_tracker.head_html}") + body.gsub!('', "#{js_tracker.body_html}") + end end response diff --git a/raygun4ruby.gemspec b/raygun4ruby.gemspec index e1ef03b..1a5ab39 100644 --- a/raygun4ruby.gemspec +++ b/raygun4ruby.gemspec @@ -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 = ["hello@raygun.com"] 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" @@ -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" @@ -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 diff --git a/spec/rails_applications/7.1.3/.dockerignore b/spec/rails_applications/7.1.3/.dockerignore new file mode 100644 index 0000000..9612375 --- /dev/null +++ b/spec/rails_applications/7.1.3/.dockerignore @@ -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 +/tmp/storage/* +!/tmp/storage/.keep + +# Ignore assets. +/node_modules/ +/app/assets/builds/* +!/app/assets/builds/.keep +/public/assets diff --git a/spec/rails_applications/7.1.3/.gitattributes b/spec/rails_applications/7.1.3/.gitattributes new file mode 100644 index 0000000..8dc4323 --- /dev/null +++ b/spec/rails_applications/7.1.3/.gitattributes @@ -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 diff --git a/spec/rails_applications/7.1.3/.gitignore b/spec/rails_applications/7.1.3/.gitignore new file mode 100644 index 0000000..5fb66c9 --- /dev/null +++ b/spec/rails_applications/7.1.3/.gitignore @@ -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 diff --git a/spec/rails_applications/7.1.3/.ruby-version b/spec/rails_applications/7.1.3/.ruby-version new file mode 100644 index 0000000..15a2799 --- /dev/null +++ b/spec/rails_applications/7.1.3/.ruby-version @@ -0,0 +1 @@ +3.3.0 diff --git a/spec/rails_applications/7.1.3/Dockerfile b/spec/rails_applications/7.1.3/Dockerfile new file mode 100644 index 0000000..d18898b --- /dev/null +++ b/spec/rails_applications/7.1.3/Dockerfile @@ -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"] diff --git a/spec/rails_applications/7.1.3/Gemfile b/spec/rails_applications/7.1.3/Gemfile new file mode 100644 index 0000000..2972258 --- /dev/null +++ b/spec/rails_applications/7.1.3/Gemfile @@ -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 diff --git a/spec/rails_applications/7.1.3/README.md b/spec/rails_applications/7.1.3/README.md new file mode 100644 index 0000000..7db80e4 --- /dev/null +++ b/spec/rails_applications/7.1.3/README.md @@ -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 + +* ... diff --git a/spec/rails_applications/7.1.3/Rakefile b/spec/rails_applications/7.1.3/Rakefile new file mode 100644 index 0000000..9a5ea73 --- /dev/null +++ b/spec/rails_applications/7.1.3/Rakefile @@ -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 diff --git a/spec/rails_applications/7.1.3/app/assets/config/manifest.js b/spec/rails_applications/7.1.3/app/assets/config/manifest.js new file mode 100644 index 0000000..ddd546a --- /dev/null +++ b/spec/rails_applications/7.1.3/app/assets/config/manifest.js @@ -0,0 +1,4 @@ +//= link_tree ../images +//= link_directory ../stylesheets .css +//= link_tree ../../javascript .js +//= link_tree ../../../vendor/javascript .js diff --git a/spec/rails_applications/7.1.3/app/assets/images/.keep b/spec/rails_applications/7.1.3/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/rails_applications/7.1.3/app/assets/stylesheets/application.css b/spec/rails_applications/7.1.3/app/assets/stylesheets/application.css new file mode 100644 index 0000000..288b9ab --- /dev/null +++ b/spec/rails_applications/7.1.3/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/spec/rails_applications/7.1.3/app/channels/application_cable/channel.rb b/spec/rails_applications/7.1.3/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/spec/rails_applications/7.1.3/app/channels/application_cable/connection.rb b/spec/rails_applications/7.1.3/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..0ff5442 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/spec/rails_applications/7.1.3/app/controllers/application_controller.rb b/spec/rails_applications/7.1.3/app/controllers/application_controller.rb new file mode 100644 index 0000000..09705d1 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/spec/rails_applications/7.1.3/app/controllers/concerns/.keep b/spec/rails_applications/7.1.3/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/rails_applications/7.1.3/app/controllers/home_controller.rb b/spec/rails_applications/7.1.3/app/controllers/home_controller.rb new file mode 100644 index 0000000..fc0b474 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/controllers/home_controller.rb @@ -0,0 +1,2 @@ +class HomeController < ApplicationController +end diff --git a/spec/rails_applications/7.1.3/app/helpers/application_helper.rb b/spec/rails_applications/7.1.3/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/spec/rails_applications/7.1.3/app/helpers/home_helper.rb b/spec/rails_applications/7.1.3/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/spec/rails_applications/7.1.3/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/spec/rails_applications/7.1.3/app/javascript/application.js b/spec/rails_applications/7.1.3/app/javascript/application.js new file mode 100644 index 0000000..0d7b494 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/javascript/application.js @@ -0,0 +1,3 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +import "@hotwired/turbo-rails" +import "controllers" diff --git a/spec/rails_applications/7.1.3/app/javascript/controllers/application.js b/spec/rails_applications/7.1.3/app/javascript/controllers/application.js new file mode 100644 index 0000000..1213e85 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/javascript/controllers/application.js @@ -0,0 +1,9 @@ +import { Application } from "@hotwired/stimulus" + +const application = Application.start() + +// Configure Stimulus development experience +application.debug = false +window.Stimulus = application + +export { application } diff --git a/spec/rails_applications/7.1.3/app/javascript/controllers/hello_controller.js b/spec/rails_applications/7.1.3/app/javascript/controllers/hello_controller.js new file mode 100644 index 0000000..5975c07 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/javascript/controllers/hello_controller.js @@ -0,0 +1,7 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + this.element.textContent = "Hello World!" + } +} diff --git a/spec/rails_applications/7.1.3/app/javascript/controllers/index.js b/spec/rails_applications/7.1.3/app/javascript/controllers/index.js new file mode 100644 index 0000000..54ad4ca --- /dev/null +++ b/spec/rails_applications/7.1.3/app/javascript/controllers/index.js @@ -0,0 +1,11 @@ +// Import and register all your controllers from the importmap under controllers/* + +import { application } from "controllers/application" + +// Eager load all controllers defined in the import map under controllers/**/*_controller +import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" +eagerLoadControllersFrom("controllers", application) + +// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) +// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" +// lazyLoadControllersFrom("controllers", application) diff --git a/spec/rails_applications/7.1.3/app/jobs/application_job.rb b/spec/rails_applications/7.1.3/app/jobs/application_job.rb new file mode 100644 index 0000000..d394c3d --- /dev/null +++ b/spec/rails_applications/7.1.3/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/spec/rails_applications/7.1.3/app/mailers/application_mailer.rb b/spec/rails_applications/7.1.3/app/mailers/application_mailer.rb new file mode 100644 index 0000000..3c34c81 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout "mailer" +end diff --git a/spec/rails_applications/7.1.3/app/models/application_record.rb b/spec/rails_applications/7.1.3/app/models/application_record.rb new file mode 100644 index 0000000..b63caeb --- /dev/null +++ b/spec/rails_applications/7.1.3/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/spec/rails_applications/7.1.3/app/models/concerns/.keep b/spec/rails_applications/7.1.3/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/rails_applications/7.1.3/app/views/home/index.html.erb b/spec/rails_applications/7.1.3/app/views/home/index.html.erb new file mode 100644 index 0000000..cdaea16 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/views/home/index.html.erb @@ -0,0 +1,3 @@ +
+
Find me in app/views/home/index.html.erb
+
<%= Raygun.configuration.js_api_key %>
diff --git a/spec/rails_applications/7.1.3/app/views/home/index.json.erb b/spec/rails_applications/7.1.3/app/views/home/index.json.erb new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/spec/rails_applications/7.1.3/app/views/home/index.json.erb @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/spec/rails_applications/7.1.3/app/views/layouts/application.html.erb b/spec/rails_applications/7.1.3/app/views/layouts/application.html.erb new file mode 100644 index 0000000..b291da2 --- /dev/null +++ b/spec/rails_applications/7.1.3/app/views/layouts/application.html.erb @@ -0,0 +1,16 @@ + + +
+
+ + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + <%= javascript_importmap_tags %> + + +
+