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
35 changes: 35 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Git
.git
.gitignore
.github

# Claude/AI configuration
.claude
.serena
CLAUDE.md

# Documentation
*.md
!README.md

# Test artifacts
coverage/
test_db
*.sqlite3
.last_run.json
.resultset.json

# Ruby/bundler
.bundle
vendor/bundle

# OS files
.DS_Store
Thumbs.db

# Editor files
.vscode
.idea
*.swp
*.swo
*~
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Gemfile.lock
InstalledFiles
_yardoc
coverage
coverage/
doc/
lib/bundler/man
pkg
Expand All @@ -17,10 +17,11 @@ spec/reports
test/tmp
test/version_tmp
tmp
coverage
test/log
log/*.log
test_db
test_db-journal
test/test_db-shm
test/test_db-wal
.idea
*.iml
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dockerfile for testing jsonapi-resources with multiple Rails versions

FROM ruby:3.2

# Install dependencies
RUN apt-get update -qq && \
apt-get install -y build-essential libpq-dev nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy Gemfile and gemspec
COPY Gemfile jsonapi-resources.gemspec ./
COPY lib/jsonapi/resources/version.rb ./lib/jsonapi/resources/

# Install bundler
RUN gem install bundler

# Note: bundle install will happen at runtime with specific RAILS_VERSION
# This allows testing multiple Rails versions without rebuilding the image
22 changes: 22 additions & 0 deletions Dockerfile.ruby2.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dockerfile for testing jsonapi-resources with Rails 5.1-7.0 (Ruby 2.7)

FROM ruby:2.7

# Install dependencies
RUN apt-get update -qq && \
apt-get install -y build-essential libpq-dev nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy Gemfile and gemspec
COPY Gemfile jsonapi-resources.gemspec ./
COPY lib/jsonapi/resources/version.rb ./lib/jsonapi/resources/

# Install bundler (Ruby 2.7 requires bundler < 2.5)
RUN gem install bundler -v 2.4.22

# Note: bundle install will happen at runtime with specific RAILS_VERSION
# This allows testing multiple Rails versions without rebuilding the image
24 changes: 24 additions & 0 deletions Dockerfile.ruby3.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dockerfile for testing jsonapi-resources with Rails 6.1-8.1 (Ruby 3.1.5)

FROM ruby:3.1.5

# Install dependencies
RUN apt-get update -qq && \
apt-get install -y build-essential libpq-dev nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy Gemfile and gemspec
COPY Gemfile jsonapi-resources.gemspec ./
COPY lib/jsonapi/resources/version.rb ./lib/jsonapi/resources/

# Install specific bundler version for compatibility
RUN gem install bundler -v 2.4.14 --no-document && \
gem install bundler -v 2.4.14 --install-dir /usr/local/bundle --no-document && \
bundle --version

# Note: bundle install will happen at runtime with specific RAILS_VERSION
# This allows testing multiple Rails versions without rebuilding the image
24 changes: 24 additions & 0 deletions Dockerfile.ruby3.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dockerfile for testing jsonapi-resources with Rails 8.0-8.1 (Ruby 3.4)

FROM ruby:3.4

# Install dependencies
RUN apt-get update -qq && \
apt-get install -y build-essential libpq-dev nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy Gemfile and gemspec
COPY Gemfile jsonapi-resources.gemspec ./
COPY lib/jsonapi/resources/version.rb ./lib/jsonapi/resources/

# Install specific bundler version for compatibility
RUN gem install bundler -v 2.4.14 --no-document && \
gem install bundler -v 2.4.14 --install-dir /usr/local/bundle --no-document && \
bundle --version

# Note: bundle install will happen at runtime with specific RAILS_VERSION
# This allows testing multiple Rails versions without rebuilding the image
121 changes: 121 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
services:
# Base service definition for Ruby 3.1.5 (Rails 6.1-8.1)
test-base: &test-base
build:
context: .
dockerfile: Dockerfile.ruby3.1
volumes:
- .:/app
- bundle-cache-ruby31:/usr/local/bundle
working_dir: /app
stdin_open: true
tty: true

# Base service definition for Ruby 2.7 (Rails 5.1-6.0)
test-base-ruby27: &test-base-ruby27
build:
context: .
dockerfile: Dockerfile.ruby2.7
volumes:
- .:/app
- bundle-cache-ruby27:/usr/local/bundle
working_dir: /app
stdin_open: true
tty: true

# Base service definition for Ruby 3.4 (Rails 8.0-8.1)
test-base-ruby34: &test-base-ruby34
build:
context: .
dockerfile: Dockerfile.ruby3.4
volumes:
- .:/app
- bundle-cache-ruby34:/usr/local/bundle
working_dir: /app
stdin_open: true
tty: true

# Rails 5.1.7
rails-5.1:
<<: *test-base-ruby27
container_name: jsonapi-rails-5.1
environment:
- RAILS_VERSION=5.1.7
command: bash -c "rm -f Gemfile.lock && bundle install && bundle exec rake test"

# Rails 5.2.8.1
rails-5.2:
<<: *test-base-ruby27
container_name: jsonapi-rails-5.2
environment:
- RAILS_VERSION=5.2.8.1
command: bash -c "rm -f Gemfile.lock && bundle install && bundle exec rake test"

# Rails 6.0.6
rails-6.0:
<<: *test-base-ruby27
container_name: jsonapi-rails-6.0
environment:
- RAILS_VERSION=6.0.6
command: bash -c "rm -f Gemfile.lock && bundle install && bundle exec rake test"

# Rails 6.1.7.10
rails-6.1:
<<: *test-base
container_name: jsonapi-rails-6.1
environment:
- RAILS_VERSION=6.1.7.10
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"

# Rails 7.0.10
rails-7.0:
<<: *test-base
container_name: jsonapi-rails-7.0
environment:
- RAILS_VERSION=7.0.10
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"

# Rails 7.1.6
rails-7.1:
<<: *test-base
container_name: jsonapi-rails-7.1
environment:
- RAILS_VERSION=7.1.6
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"

# Rails 7.2.3
rails-7.2:
<<: *test-base
container_name: jsonapi-rails-7.2
environment:
- RAILS_VERSION=7.2.3
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"

# Rails 8.0.4 (Ruby 3.4 required)
rails-8.0:
<<: *test-base-ruby34
container_name: jsonapi-rails-8.0
environment:
- RAILS_VERSION=8.0.4
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"

# Rails 8.1.2 (Ruby 3.4 required)
rails-8.1:
<<: *test-base-ruby34
container_name: jsonapi-rails-8.1
environment:
- RAILS_VERSION=8.1.2
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"

# Interactive shell for debugging (defaults to Rails 8.1)
shell:
<<: *test-base
container_name: jsonapi-shell
environment:
- RAILS_VERSION=${RAILS_VERSION:-8.1.2}
command: /bin/bash

volumes:
bundle-cache-ruby31:
bundle-cache-ruby27:
bundle-cache-ruby34:
19 changes: 19 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ class TestApp < Rails::Application
require 'jsonapi-resources'
require 'pry'

# Fix Psych::DisallowedClass error for Rails 6.0 with Ruby 2.7+
# In test environment, allow all classes from YAML (safe for test fixtures)
if defined?(Psych::VERSION) && Psych::VERSION.to_f >= 3.1 && Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR == 0
require 'psych'

# Patch Psych.load to use unsafe_load in test environment
# This is safe because we're only loading trusted test fixtures
module Psych
class << self
alias_method :safe_load_original, :load

def load(yaml, *args, **kwargs)
# Use unsafe_load to allow Date, Time, DateTime from YAML
unsafe_load(yaml)
end
end
end
end

require File.expand_path('../helpers/value_matchers', __FILE__)
require File.expand_path('../helpers/assertions', __FILE__)
require File.expand_path('../helpers/functional_helpers', __FILE__)
Expand Down