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
71 changes: 53 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,81 @@ on:
- cron: "0 18 * * 6" # Saturdays at 12pm CST
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
test:
name: Ruby ${{ matrix.ruby-version }} / ${{ matrix.active-record.label }}
runs-on: ubuntu-latest
timeout-minutes: 20
env:
CI: true
strategy:
fail-fast: false
matrix:
ruby-version: ['3.2', '3.3', '3.4']
active-record-version-env:
- ACTIVE_RECORD_VERSION="~> 7.0.0"
- ACTIVE_RECORD_VERSION="~> 7.1.0"
- ACTIVE_RECORD_VERSION="~> 7.2.0"
- ACTIVE_RECORD_VERSION="~> 8.0.0"
ruby-version: ["3.3", "3.4", "4.0"]
active-record:
- label: AR 7.2
env: ACTIVE_RECORD_VERSION=~> 7.2.0
- label: AR 8.0
env: ACTIVE_RECORD_VERSION=~> 8.0.0
- label: AR 8.1
env: ACTIVE_RECORD_VERSION=~> 8.1.0
allow-failure: [false]
include:
- ruby-version: '3.4'
active-record-version-env: ACTIVE_RECORD_BRANCH="main"
- ruby-version: "4.0"
active-record:
label: AR main
env: ACTIVE_RECORD_BRANCH=main
allow-failure: true
- ruby-version: '3.4'
active-record-version-env: ACTIVE_RECORD_BRANCH="8-0-stable"
- ruby-version: "4.0"
active-record:
label: AR 8-1-stable
env: ACTIVE_RECORD_BRANCH=8-1-stable
allow-failure: true
- ruby-version: '3.4'
active-record-version-env: ACTIVE_RECORD_BRANCH="7-2-stable"
- ruby-version: "4.0"
active-record:
label: AR 8-0-stable
env: ACTIVE_RECORD_BRANCH=8-0-stable
allow-failure: true
- ruby-version: '3.4'
active-record-version-env: ACTIVE_RECORD_BRANCH="7-1-stable"
- ruby-version: "4.0"
active-record:
label: AR 7-2-stable
env: ACTIVE_RECORD_BRANCH=7-2-stable
allow-failure: true
- ruby-version: '3.4'
active-record-version-env: ACTIVE_RECORD_BRANCH="7-0-stable"
# A canary for the next Ruby, which cannot fail the build.
- ruby-version: ruby-head
active-record:
label: AR 8.1
env: ACTIVE_RECORD_VERSION=~> 8.1.0
allow-failure: true
continue-on-error: ${{ matrix.allow-failure }}
steps:
- uses: actions/checkout@v7
# Set the version here rather than prefixing each command, so the matrix
# value reaches the environment without being interpolated into a script.
- name: Select Active Record version
env:
ACTIVE_RECORD_ENV: ${{ matrix.active-record.env }}
run: echo "$ACTIVE_RECORD_ENV" >> "$GITHUB_ENV"
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
cache-version: ${{ matrix.active-record.env }}
# Gemfile.lock is not checked in, so this resolves the newest gems that
# satisfy the Gemfile on each run rather than a recorded set. `--all` is
# what Bundler 4, shipped with Ruby 4.0, wants for that.
- name: Update bundle
run: ${{ matrix.active-record-version-env }} bundle update
run: bundle update --all
# Not bin/rake: bin/ holds generated binstubs and is not checked in, and
# whether bundling writes them there varies by Bundler version - Bundler 4
# does not, which left Ruby 4.0 with no binstub to run.
- name: Run tests
run: ${{ matrix.active-record-version-env }} bin/rake
run: bundle exec rake
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
column. In 3.0 it will create no table.
- Create minitest models in the order they are declared, so that a model can
refer to another model declared above it.
- Require Ruby 3.2 or later.
- Require Ruby 3.3 or later.
- Require Active Record 7.2 or later.

### 2.2.0

Expand Down
83 changes: 83 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Contributing to with_model

If you experience a bug, we welcome you to report it. Please include a minimal
example showing the code you ran, what happened, and what you expected to happen
instead — a failing `with_model` block is ideal, since it can be dropped straight
into the suite. If you can fix the bug and open a pull request, it will get
resolved sooner, but don't hesitate to report an issue you don't know how to fix.

If you have a substantial feature in mind, consider opening an issue to discuss
it first. We may have thought about it already, and can sometimes save you a
detour.

When in doubt, go ahead and open a pull request. If something needs rethinking,
we will do our best to say so clearly. Don't be discouraged if we ask you to
change your code — we appreciate the work, and we also have opinions about style
and object design.

## Supported versions

The [gemspec](./with_model.gemspec) declares the minimum supported Ruby and
Active Record, and the [CI workflow](./.github/workflows/ci.yml) lists every
combination actually tested. It can be hard to try them all locally, so please
avoid anything that only works on the newest of either.

## Running the tests

The suite runs against both supported test harnesses, so `with_model` has to work
under each:

- `spec/` covers behavior under RSpec.
- `test/` covers the minitest life cycle — the setup and teardown hooks, and
their ordering — rather than repeating the specs.

Run everything, including the linter, with:

```sh
bundle exec rake
```

`bin/` holds generated binstubs and is not checked in. Whether bundling writes
them for you depends on your Bundler version, so create them once if you would
rather type `bin/rake`:

```sh
bundle binstubs --all
```

Our automated tests begin by updating every gem to its newest version. That is
deliberate: we would rather find out about an incompatibility from our own build
than from a bug report. `Gemfile.lock` is not checked in, so you can do the same
at any time with `bundle update --all`.

To try a particular Active Record, set `ACTIVE_RECORD_VERSION` to a version
requirement and update the bundle:

```sh
ACTIVE_RECORD_VERSION="~> 8.1.0" bundle update --all
ACTIVE_RECORD_VERSION="~> 8.1.0" bundle exec rake
```

To test against Active Record from git instead — an unreleased branch, or `main`
— set `ACTIVE_RECORD_BRANCH`:

```sh
ACTIVE_RECORD_BRANCH=main bundle update --all
ACTIVE_RECORD_BRANCH=main bundle exec rake
```

Style is enforced by [Standard](https://github.com/standardrb/standard), which
`rake` runs. To correct what it can:

```sh
bundle exec standardrb --fix
```

## Changes and releases

Please add a line to `CHANGELOG.md` under `### Unreleased` describing your change
from the point of view of someone using the gem. Leave `lib/with_model/version.rb`
alone: version bumps and releases are cut separately by a maintainer, so a bump
in a pull request only creates a conflict.

Last, but not least, have fun.
8 changes: 1 addition & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ ar_version = ENV.fetch("ACTIVE_RECORD_VERSION", nil)

if ar_branch
gem "activerecord", git: "https://github.com/rails/rails.git", branch: ar_branch
gem "arel", git: "https://github.com/rails/arel.git" if ar_branch == "master"
elsif ar_version
gem "activerecord", ar_version
end
Expand All @@ -23,10 +22,5 @@ gem "mutex_m"
gem "rake"
gem "rspec"
gem "ruby-lsp"
gem "sqlite3"
gem "standard"

if ar_branch == "7-0-stable" || ar_version == "~> 7.0.0"
gem "sqlite3", "< 2"
else
gem "sqlite3"
end
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ See the [gemspec metadata](https://rubygems.org/gems/with_model) for dependency

In general, `with_model` is not guaranteed to be thread-safe, but is, in certain usages, safe to use concurrently across multiple processes with a single database schema.

## Contributing

Bug reports and pull requests are welcome. See the
[CONTRIBUTING guide](/CONTRIBUTING.md) for how to run the tests against a
particular Ruby or Active Record.

## Versioning

`with_model` uses [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html).
Expand Down
4 changes: 2 additions & 2 deletions with_model.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 3.2"
spec.required_ruby_version = ">= 3.3"

spec.add_dependency "activerecord", ">= 7.0"
spec.add_dependency "activerecord", ">= 7.2"
end