Skip to content

Commit

Permalink
Support Rails 7.1 (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier-thatch authored Oct 10, 2023
1 parent 6658973 commit 61c492b
Show file tree
Hide file tree
Showing 52 changed files with 917 additions and 4 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ workflows:
- "gemfiles/6.0.gemfile"
- "gemfiles/6.1.gemfile"
- "gemfiles/7.0.gemfile"
- "gemfiles/7.1.gemfile"
exclude:
- ruby_version: "3.1.4"
gemfile: "gemfiles/6.0.gemfile"
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ end
appraise '7.0' do
gem 'rails', '~> 7.0.0'
end

appraise '7.1' do
gem 'rails', '~> 7.1.0'
end
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.7.0
- Add support for Rails 7.1.

## v0.6.0
- Drop support for Ruby < 2.7 and Rails < 6.0.
- Add support for Ruby 3.1.
Expand Down
7 changes: 7 additions & 0 deletions gemfiles/7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 7.1.0"

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/safer_rails_console/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SaferRailsConsole
VERSION = '0.6.0'
VERSION = '0.7.0'
end
2 changes: 1 addition & 1 deletion safer_rails_console.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec_junit_formatter'
spec.add_development_dependency 'salsify_rubocop', '~> 1.27.0'

spec.add_runtime_dependency 'rails', '>= 6.0', '< 7.1'
spec.add_runtime_dependency 'rails', '>= 6.0', '< 7.2'
end
1 change: 1 addition & 0 deletions spec/integration/patches/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
context "sandbox" do
let(:cmd_stdout) do
result = run_console(rails_env: rails_env, input: 'exit')
result.error!
result.stdout
end

Expand Down
28 changes: 28 additions & 0 deletions spec/internal/rails_7_1/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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/*

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

# Ignore assets.
/node_modules/
/app/assets/builds/*
!/app/assets/builds/.keep
/public/assets
9 changes: 9 additions & 0 deletions spec/internal/rails_7_1/.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
24 changes: 24 additions & 0 deletions spec/internal/rails_7_1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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/*

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

/public/assets

# Ignore master key for decrypting credentials and more.
/config/master.key
55 changes: 55 additions & 0 deletions spec/internal/rails_7_1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.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 libpq-dev 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

# Copy application code
COPY . .


# 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 postgresql-client && \
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 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"]
12 changes: 12 additions & 0 deletions spec/internal/rails_7_1/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

# Generated with:
# rails new -JABTCM --skip-keeps --skip-active-storage --skip-system-test --skip-bootsnap --skip-hotwire -d postgresql spec/internal/rails_7_0
# Then modified to match the others

source 'https://rubygems.org'

gem 'pg'
gem 'rails', '~> 7.1.0'

gem 'safer_rails_console', path: '../../../'
24 changes: 24 additions & 0 deletions spec/internal/rails_7_1/README.md
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/internal/rails_7_1/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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Application styles */
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::Base
end
2 changes: 2 additions & 0 deletions spec/internal/rails_7_1/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
7 changes: 7 additions & 0 deletions spec/internal/rails_7_1/app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions spec/internal/rails_7_1/app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
4 changes: 4 additions & 0 deletions spec/internal/rails_7_1/app/models/model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Model < ApplicationRecord
end
15 changes: 15 additions & 0 deletions spec/internal/rails_7_1/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Rails71</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application" %>
</head>

<body>
<%= yield %>
</body>
</html>
8 changes: 8 additions & 0 deletions spec/internal/rails_7_1/bin/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

# If running the rails server then create or migrate existing database
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
./bin/rails db:prepare
fi

exec "${@}"
4 changes: 4 additions & 0 deletions spec/internal/rails_7_1/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path("../config/application", __dir__)
require_relative "../config/boot"
require "rails/commands"
4 changes: 4 additions & 0 deletions spec/internal/rails_7_1/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative "../config/boot"
require "rake"
Rake.application.run
33 changes: 33 additions & 0 deletions spec/internal/rails_7_1/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby
require "fileutils"

# path to your application root.
APP_ROOT = File.expand_path("..", __dir__)

def system!(*args)
system(*args, exception: true)
end

FileUtils.chdir APP_ROOT do
# This script is a way to set up or update your development environment automatically.
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
# Add necessary setup steps to this file.

puts "== Installing dependencies =="
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")

# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
# FileUtils.cp "config/database.yml.sample", "config/database.yml"
# end

puts "\n== Preparing database =="
system! "bin/rails db:prepare"

puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear"

puts "\n== Restarting application server =="
system! "bin/rails restart"
end
6 changes: 6 additions & 0 deletions spec/internal/rails_7_1/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file is used by Rack-based servers to start the application.

require_relative "config/environment"

run Rails.application
Rails.application.load_server
42 changes: 42 additions & 0 deletions spec/internal/rails_7_1/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require_relative "boot"

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
# require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Rails71
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.1

# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_lib(ignore: %w(assets tasks))

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

# Don't generate system test files.
config.generators.system_tests = nil
end
end
5 changes: 5 additions & 0 deletions spec/internal/rails_7_1/config/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "bundler/setup" # Set up gems listed in the Gemfile.

require 'safer_rails_console/patches/boot'
1 change: 1 addition & 0 deletions spec/internal/rails_7_1/config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Z9t6qVWZ8CF3/6mUQvB3h5vzeMAu7fCBFRx+ltgxFKvPZvh6yEtjcp5Z02/IPeC3M96WA/3je5L2Iwk4dKgpfmrulIMpvEL7Ni7N6RSaYxklp/axlogEcaJppvlhSz3mtY144FiLxioOIKaVXestLUnzzw/UNoK3KV6tb8301xDpgXjL9KPpVT8Mku/yc5nwRkKv0Yu1SXIpSxql00nTBtMFuIYnuUsdC/k/DSKjbplYBOiAZO64d/6CQ3c88rWSE8kFwN4nUFwMFRCOraLfkMgUoQAepLsyhflvByHwTGG3vOeq18MdtQ0iopoFRAYVU/sXxED1d7kf/v7IiJOxmi3RxVsd4h0kN3ZURmDtZf0/MumElBTdJfRPMBj6fihWwqtPfn2XKV7Bgr7AGzd+Bo1VXsrSahAxPMIl--MzALHAdrtuGGfm49--BJSRlLaObC8jaP4YbgLM7w==
Loading

0 comments on commit 61c492b

Please sign in to comment.