Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ensure test db is safely/freshly created #1444

Open
wants to merge 29 commits into
base: v0-11-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
be970f4
deps: Add MySQL to CI workflow (#1398)
bf4 Jan 25, 2023
896459c
fix: Reliably quote columns/tables (#1400)
bf4 Feb 2, 2023
1da2cb7
Add docker testing setup (#1403)
lgebhardt Mar 3, 2023
f2bcba9
fix: test the adapter-specific query ordering (#1402)
bf4 Mar 10, 2023
01ba9a0
V0.11 refactor resource classes to modules (#1406)
lgebhardt Sep 19, 2023
c70bd4c
Add frozen_string_literal: true
lgebhardt Sep 19, 2023
2f69096
Restore missing requires
lgebhardt Sep 19, 2023
ac46d89
fix: warnings (#1401)
bf4 Sep 19, 2023
8932a6d
Restore `use_related_resource_records_for_joins` for v0_10 (#1412)
lgebhardt Sep 26, 2023
bdce601
Bump jsonapi-resources to 0.11.0.beta2
lgebhardt Sep 26, 2023
81e4ecf
fix: more reliable check of module is included (#1418)
bf4 Oct 27, 2023
26d280a
Fix tests for V0.11 and Rails 7.1 (#1420)
lgebhardt Nov 1, 2023
1bdacf1
Namespace references to Rails using `::Rails` to avoid conflicts with…
lgebhardt Nov 16, 2023
ef0551d
chore: remove sorted_set dependency (#1423)
bf4 Jan 10, 2024
040f980
Make SortedSet for identity arrays optional (#1427)
lgebhardt Jan 11, 2024
cd1a529
Store the resource_klass and id in an array for efficiency (#1428)
lgebhardt Jan 13, 2024
0bbbc0b
Rework ResourceIdentity <=> operator (#1430)
lgebhardt Jan 16, 2024
2668b6b
V0 11 dev performance (#1431)
lgebhardt Jan 16, 2024
9f436b5
fix: allow multiple resource relation retrieval methods (#1425)
bf4 Jan 17, 2024
76ef777
refactor: separate polymorphic functions (#1433)
bf4 Jan 19, 2024
f193a35
feat: teach JR in tests to parse the response (#1437)
bf4 Jan 22, 2024
51c9592
chore: address deprecations (#1436)
bf4 Jan 22, 2024
311b1fe
fix: format model polymorphic type from resource object type (#1435)
bf4 Jan 22, 2024
e4c9707
fix: railtie to use correct load hook (#1438)
bf4 Jan 24, 2024
ae9017b
fix: more flexible polymorphic types lookup (#1434)
bf4 Jan 25, 2024
c529c23
Update the testing matrix (#1442)
lgebhardt Jan 26, 2024
f75acdb
Polymorphic types override per relationship (#1440)
lgebhardt Jan 26, 2024
07888a9
Fix issue with relationship sorts due to missing join_manager (#1443)
lgebhardt Jan 26, 2024
9e35f97
chore: ensure test db is safely/freshly created
bf4 Jan 26, 2024
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
4 changes: 4 additions & 0 deletions .docker/ruby_versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3.0.6
3.1.4
3.2.3
3.3.0
3 changes: 3 additions & 0 deletions .docker/scripts/test_all
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

xargs -L 1 ./test_ruby < ruby_versions.txt
10 changes: 10 additions & 0 deletions .docker/scripts/test_mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

cd /src
bundle update;

RUBY_VERSION=$(ruby -v);

echo "Testing With MySQL and Ruby $RUBY_VERSION";
export DATABASE_URL="mysql2://test:password@mysql:3306/jr_test"
bundle exec rake;
10 changes: 10 additions & 0 deletions .docker/scripts/test_postgresql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

cd /src
bundle update;

RUBY_VERSION=$(ruby -v);

echo "Testing With PostgreSQL and Ruby $RUBY_VERSION";
export DATABASE_URL="postgresql://postgres:password@postgres:5432/jr_test"
bundle exec rake;
7 changes: 7 additions & 0 deletions .docker/scripts/test_ruby
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

rbenv global $1;

../test_postgresql
../test_mysql
../test_sqlite
10 changes: 10 additions & 0 deletions .docker/scripts/test_sqlite
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

cd /src
bundle update;

RUBY_VERSION=$(ruby -v);

echo "Testing With SQLite and Ruby $RUBY_VERSION";
export DATABASE_URL="sqlite3:jr_test"
bundle exec rake;
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- [ ] I've checked to ensure there aren't other open [Pull Requests](https://github.com/cerebris/jsonapi-resources/pulls) for the same update/change.
- [ ] I've submitted a [ticket](https://github.com/cerebris/jsonapi-resources/issues) for my issue if one did not already exist.
- [ ] My submission passes all tests. (Please run the full test suite locally to cut down on noise from travis failures.)
- [ ] My submission passes all tests. (Please run the full test suite locally to cut down on noise from CI failures.)
- [ ] I've used Github [auto-closing keywords](https://help.github.com/articles/closing-issues-via-commit-messages/) in the commit message or the description.
- [ ] I've added/updated tests for this change.

Expand All @@ -23,4 +23,4 @@

### Reviewer Checklist:
- [ ] Maintains compliance with JSON:API
- [ ] Adequate test coverage exists to prevent regressions
- [ ] Adequate test coverage exists to prevent regressions
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Set update schedule for GitHub Actions

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
65 changes: 27 additions & 38 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@ name: CI

on:
push:
branches: [ 'master', 'release-0-8', 'release-0-9', 'release-0-10' ]
branches: [ 'master', 'release-0-8', 'release-0-9', 'release-0-10', 'v0-11-dev' ]
pull_request:
branches: ['**']

jobs:
tests:
runs-on: ubuntu-latest
services:
mysql:
image: mysql
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres:
image: postgres
env:
Expand All @@ -26,43 +38,21 @@ jobs:
fail-fast: false
matrix:
ruby:
- 2.6
- 2.7
- '3.3'
- '3.2'
- '3.1'
- '3.0'
- 3.1
- 3.2
rails:
- 7.0.4
- 6.1.7
- 6.0.6
- 5.2.8.1
- 5.1.7
- '7.1'
- '7.0'
- '6.1'
database_url:
- postgresql://postgres:password@localhost:5432/test
- sqlite3:test_db
exclude:
- ruby: 3.2
rails: 6.0.6
- ruby: 3.2
rails: 5.2.8.1
- ruby: 3.2
rails: 5.1.7
- ruby: 3.1
rails: 6.0.6
- ruby: 3.1
rails: 5.2.8.1
- ruby: 3.1
rails: 5.1.7
- ruby: '3.0'
rails: 6.0.6
- ruby: '3.0'
rails: 5.2.8.1
- ruby: '3.0'
rails: 5.1.7
- ruby: 2.6
rails: 7.0.4
- database_url: postgresql://postgres:password@localhost:5432/test
rails: 5.1.7
- sqlite3:jr_test
- postgresql://postgres:password@localhost:5432/jr_test
- mysql2://root:[email protected]:3306/jr_test
# exclude:
# - ruby: '3.1'
# rails: '6.0'
env:
RAILS_VERSION: ${{ matrix.rails }}
DATABASE_URL: ${{ matrix.database_url }}
Expand All @@ -73,7 +63,6 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: bundle install --jobs 4 --retry 3
bundler-cache: true
- name: Run tests
run: bundle exec rake test
run: bundle exec rake
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ coverage
test/log
test_db
test_db-journal
jr_test
jr_test-journal
.idea
*.iml
*.override.yml
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM buildpack-deps:bullseye

# Install rbenv
RUN git clone https://github.com/sstephenson/rbenv.git /root/.rbenv
RUN git clone https://github.com/sstephenson/ruby-build.git /root/.rbenv/plugins/ruby-build
RUN /root/.rbenv/plugins/ruby-build/install.sh
ENV PATH /root/.rbenv/bin:/root/.rbenv/shims:$PATH
RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh # or /etc/profile
RUN echo 'eval "$(rbenv init -)"' >> .bashrc

# Install supported ruby versions
RUN echo 'gem: --no-document' >> ~/.gemrc

COPY .docker/ruby_versions.txt /
RUN xargs -I % sh -c 'rbenv install %; rbenv global %; gem install bundler' < ruby_versions.txt
RUN rbenv rehash

# COPY just enough to bundle. This allows for most code changes without needing to reinstall all gems
RUN mkdir src
COPY Gemfile jsonapi-resources.gemspec Rakefile ./src/
COPY lib/jsonapi/resources/version.rb ./src/lib/jsonapi/resources/
# This will run bundle install for each ruby version and leave the global version set as the last one.
# So we can control the default ruby version with the order in the ruby_versions.txt file, with last being the default
RUN xargs -I % sh -c 'cd src; rbenv global %; bundle install' < /ruby_versions.txt

# Scripts
COPY .docker/scripts/* /
RUN chmod +x /test_*

# COPY in the rest of the project
COPY lib/ ./src/lib
COPY locales/ ./src/locales
COPY test/ ./src/test
RUN ls -la

CMD ["/test_all"]
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ version = ENV['RAILS_VERSION'] || 'default'

platforms :ruby do
gem 'pg'
gem 'mysql2'

if version.start_with?('4.2', '5.0')
gem 'sqlite3', '~> 1.3.13'
Expand All @@ -26,4 +27,4 @@ when 'default'
gem 'railties', '>= 6.0'
else
gem 'railties', "~> #{version}"
end
end
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2021 Cerebris Corporation
Copyright (c) 2014-2023 Cerebris Corporation

MIT License

Expand Down
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# JSONAPI::Resources [![Gem Version](https://badge.fury.io/rb/jsonapi-resources.svg)](https://badge.fury.io/rb/jsonapi-resources) [![Build Status](https://secure.travis-ci.org/cerebris/jsonapi-resources.svg?branch=master)](http://travis-ci.org/cerebris/jsonapi-resources) [![Code Climate](https://codeclimate.com/github/cerebris/jsonapi-resources/badges/gpa.svg)](https://codeclimate.com/github/cerebris/jsonapi-resources)
# JSONAPI::Resources [![Gem Version](https://badge.fury.io/rb/jsonapi-resources.svg)](https://badge.fury.io/rb/jsonapi-resources) [![Code Climate](https://codeclimate.com/github/cerebris/jsonapi-resources/badges/gpa.svg)](https://codeclimate.com/github/cerebris/jsonapi-resources)

[![Join the chat at https://gitter.im/cerebris/jsonapi-resources](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cerebris/jsonapi-resources?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand Down Expand Up @@ -46,6 +46,43 @@ gem install jsonapi-resources

**For further usage see the [v0.10 alpha Guide](http://jsonapi-resources.com/v0.10/guide/)**

## Development

There is a docker compose setup that can be used for testing your code against the supported versions of ruby and
against PostgreSQL, MYSQL, and SQLite databases.

First build the docker image:
```bash
docker compose build
```
Be sure to rebuild after making code changes. It should be fast after the initial build.

### Running the tests

The default command will run everything (it may take a while):
```bash
docker compose run tests
```

To test just one database against the latest ruby:
```bash
docker compose run tests ./test_mysql
docker compose run tests ./test_postgresql
docker compose run tests ./test_sqlite
```

To test a version of ruby against all databases:
```bash
docker compose run tests ./test_ruby 2.7.7
```

The tests by default run against the latest rails version. To override that you can set the RAILS_VERSION environment
variable:

```bash
docker compose run -e RAILS_VERSION=6.1.1 tests ./test_postgresql
```

## Contributing

1. Submit an issue describing any new features you wish it add or the bug you intend to fix
Expand Down Expand Up @@ -73,4 +110,4 @@ and **paste the content into the issue description or attach as a file**:

## License

Copyright 2014-2021 Cerebris Corporation. MIT License (see LICENSE for details).
Copyright 2014-2023 Cerebris Corporation. MIT License (see LICENSE for details).
38 changes: 32 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,41 @@ Rake::TestTask.new do |t|
t.test_files = FileList['test/**/*_test.rb']
end

task default: [:test]

desc 'Run benchmarks'
namespace :test do

desc 'prepare test database'
task :prepare_database do
database_url = ENV["DATABASE_URL"]
next if database_url.nil? || database_url.empty?
require "active_record/railtie"
connection_class = ActiveRecord::Base
connection_class.establish_connection(database_url)
database_config = connection_class
.connection_db_config
.configuration_hash
database_adapter = database_config.fetch(:adapter)
database_name = database_config.fetch(:database)
database_username = database_config[:username]
case database_adapter
when :postgresql, "postgresql"
sh "psql -c 'DROP DATABASE IF EXISTS #{database_name};' -U #{database_username};"
sh "psql -c 'CREATE DATABASE #{database_name};' -U #{database_username};"
when :mysql2, "mysql2"
sh "mysql -c 'DROP DATABASE IF EXISTS #{database_name};' -U #{database_username};"
sh "mysql -c 'CREATE DATABASE #{database_name};' -U #{database_username};"
else
nil # nothing to do for this database_adapter
end
puts "Preparing to run #{database_adapter} tests"
connection_class.connection.disconnect!
end

desc 'Run benchmarks'
Rake::TestTask.new(:benchmark) do |t|
t.pattern = 'test/benchmark/*_benchmark.rb'
end
end

desc 'Test bug report template'
namespace :test do
desc 'Test bug report template'
namespace :bug_report_template do
task :rails_5 do
puts 'Test bug report templates'
Expand All @@ -33,3 +57,5 @@ namespace :test do
end
end
end

task default: [:"test:prepare_database", :test]
49 changes: 49 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "3.9"

networks:
back:

services:
postgres:
image: postgres:latest
ports:
- "5432"
networks:
back:
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_DB=test
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 2s
retries: 15

mysql:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
ports:
- 3306
networks:
- back
environment:
- MYSQL_DATABASE=test
- MYSQL_USER=test
- MYSQL_PASSWORD=password
- MYSQL_ROOT_PASSWORD=password
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
interval: 2s
retries: 15

tests:
image: jr_tests:latest
build:
context: .
dockerfile: Dockerfile
networks:
- back
depends_on:
postgres:
condition: service_healthy
mysql:
condition: service_healthy
Loading
Loading