diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..d05a424c --- /dev/null +++ b/.dockerignore @@ -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 +*~ diff --git a/.gitignore b/.gitignore index 71e71f15..a0da8c34 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ Gemfile.lock InstalledFiles _yardoc -coverage +coverage/ doc/ lib/bundler/man pkg @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..47b7399e --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/Dockerfile.ruby2.7 b/Dockerfile.ruby2.7 new file mode 100644 index 00000000..f53b24f2 --- /dev/null +++ b/Dockerfile.ruby2.7 @@ -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 diff --git a/Dockerfile.ruby3.1 b/Dockerfile.ruby3.1 new file mode 100644 index 00000000..ecb7193a --- /dev/null +++ b/Dockerfile.ruby3.1 @@ -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 diff --git a/Dockerfile.ruby3.4 b/Dockerfile.ruby3.4 new file mode 100644 index 00000000..607bc76b --- /dev/null +++ b/Dockerfile.ruby3.4 @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..59e28158 --- /dev/null +++ b/docker-compose.yml @@ -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: diff --git a/test/test_helper.rb b/test/test_helper.rb index 81514079..e146eef3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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__)