Skip to content
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
13 changes: 8 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ jobs:
runs-on: ubuntu-latest
name: Example Rails app
steps:
- name: Install libvips
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends libvips
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
Expand All @@ -29,7 +33,6 @@ jobs:
- '7.2'
- '8.0'
ruby:
- '2.7'
- '3.0'
- '3.1'
- '3.2'
Expand All @@ -41,14 +44,10 @@ jobs:
ruby: '3.1'
- rails: '8.0'
ruby: '3.0'
- rails: '8.0'
ruby: '2.7'

# Rails 7.2 requires Ruby 3.1.
- rails: '7.2'
ruby: '3.0'
- rails: '7.2'
ruby: '2.7'

# Rails 7.0 doesn't work out of the box with Ruby 3.4.
- rails: '7.0'
Expand All @@ -57,6 +56,10 @@ jobs:
BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile
name: RSpec (Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }})
steps:
- name: Install libvips
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends libvips
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
Expand Down
1 change: 1 addition & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
appraise 'rails_7.0' do
gem 'concurrent-ruby', '< 1.3.5'
gem 'rails', '~> 7.0.0'
gem 'sqlite3', '<2'
end

appraise 'rails_7.1' do
Expand Down
15 changes: 14 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,18 @@ gemspec

gem 'appraisal'
gem 'rake'
gem 'rspec'
gem 'rubocop'

# For the example app tests.
gem 'image_processing'
gem 'sprockets-rails'
gem 'sqlite3'

group :development, :test do
gem 'rspec-rails'
end

group :test do
gem 'capybara'
gem 'factory_bot_rails'
end
2 changes: 2 additions & 0 deletions example-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
/log/*
/tmp/*

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

/public/assets
.byebug_history
Expand Down
5 changes: 3 additions & 2 deletions example-app/Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
source 'https://rubygems.org'

gem 'rails', '~> 8.0.1'
gem 'parklife-rails', path: '../'

gem 'image_processing'
gem 'sprockets-rails'
gem 'sqlite3'
gem 'parklife-rails', path: '../'

group :development do
gem 'webrick'
Expand Down
6 changes: 5 additions & 1 deletion example-app/Parkfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'parklife-rails'
require_relative 'config/environment'

Parklife.application.configure do |config|
Expand All @@ -17,4 +16,9 @@ Parklife.application.routes do

# Services typically allow a custom 404 page.
# get '/404.html'

if ENV['RAILS_ENV'] == 'test'
get test_middleware_path
get test_url_path
end
end
11 changes: 11 additions & 0 deletions example-app/app/controllers/test_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class TestController < ApplicationController
layout false

def middleware
render plain: Rails.application.config.middleware.map(&:name).join("\n")
end

def url
render plain: test_url_url
end
end
2 changes: 2 additions & 0 deletions example-app/app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Post < ApplicationRecord
has_one_attached :hero

def to_param
slug
end
Expand Down
8 changes: 8 additions & 0 deletions example-app/app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<% if @post.hero.attached? %>
<div>
<%= image_tag(
@post.hero.variant(resize_to_limit: [100, 100]).processed.url
) %>
</div>
<% end %>

<h1><%= @post.title %></h1>

<%= simple_format @post.body %>
16 changes: 10 additions & 6 deletions example-app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "active_storage/engine"
require "action_controller/railtie"
# require "action_mailer/railtie"
# require "action_mailbox/engine"
Expand All @@ -18,15 +18,19 @@
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

require 'parklife-rails/activestorage'

module Example
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 8.0
config.load_defaults Rails::VERSION::STRING.to_f

# 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])
if config.respond_to?(:autoload_lib)
# 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])
end

# Configuration for the application, engines, and railties goes here.
#
Expand Down
6 changes: 3 additions & 3 deletions example-app/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# Change to :null_store to avoid any caching.
config.cache_store = :memory_store

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

Expand All @@ -48,7 +51,4 @@

# Annotate rendered view with file names.
config.action_view.annotate_rendered_view_with_filenames = true

# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true
end
3 changes: 3 additions & 0 deletions example-app/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = "http://assets.example.com"

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

# Assume all access to the app is happening through a SSL-terminating reverse proxy.
config.assume_ssl = true

Expand Down
6 changes: 3 additions & 3 deletions example-app/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

Expand All @@ -36,7 +39,4 @@

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true
end
11 changes: 11 additions & 0 deletions example-app/config/initializers/parklife_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
case ENV['PARKLIFE_SET_RAILS_URL']
when 'force_ssl'
Rails.application.config.force_ssl = true
when 'yes'
ActionController::Base.relative_url_root = '/foo'

Rails.application.routes.default_url_options.merge!(
host: 'rails.example.org',
protocol: 'https',
)
end
3 changes: 3 additions & 0 deletions example-app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
root to: 'posts#index'

resources :posts

get 'test/middleware', to: 'test#middleware'
get 'test/url', to: 'test#url'
end
34 changes: 34 additions & 0 deletions example-app/config/storage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
test:
service: Parklife
root: <%= Rails.root.join("tmp/storage") %>

local:
service: Parklife
root: <%= Rails.root.join("storage") %>

# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
# region: us-east-1
# bucket: your_own_bucket-<%= Rails.env %>

# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
# project: your_project
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket-<%= Rails.env %>

# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
# storage_account_name: your_account_name
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
# container: your_container_name-<%= Rails.env %>

# mirror:
# service: Mirror
# primary: local
# mirrors: [ amazon, google, microsoft ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
def change
# Use Active Record's configured type for primary and foreign keys
primary_key_type, foreign_key_type = primary_and_foreign_key_types

create_table :active_storage_blobs, id: primary_key_type do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum

if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end

t.index [ :key ], unique: true
end

create_table :active_storage_attachments, id: primary_key_type do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
t.references :blob, null: false, type: foreign_key_type

if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end

t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end

create_table :active_storage_variant_records, id: primary_key_type do |t|
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
t.string :variation_digest, null: false

t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end

private
def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[ primary_key_type, foreign_key_type ]
end
end
32 changes: 31 additions & 1 deletion example-app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,35 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2019_05_07_172823) do
ActiveRecord::Schema[7.0].define(version: 2025_08_31_102030) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
t.bigint "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end

create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.string "service_name", null: false
t.bigint "byte_size", null: false
t.string "checksum"
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end

create_table "active_storage_variant_records", force: :cascade do |t|
t.bigint "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end

create_table "posts", force: :cascade do |t|
t.string "slug", null: false
t.string "title", null: false
Expand All @@ -20,4 +48,6 @@
t.index ["slug"], name: "index_posts_on_slug", unique: true
end

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
end
9 changes: 8 additions & 1 deletion example-app/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Rails.root.join('data').children.each do |path|
plasma_path = File.expand_path('../../spec/fixtures/files/plasma.jpg', __dir__)

Rails.root.join('data').children.each_with_index do |path, i|
id, slug = path.basename('.*').to_s.split('-', 2)
title, rest = path.read.split("\n", 2)

Expand All @@ -7,4 +9,9 @@
post.slug = slug
post.title = title
post.save!

post.hero.attach(
filename: 'plasma.jpg',
io: File.open(plasma_path),
) if i.odd?
end
Loading