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
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on: [push]
env:
# Sets the superuser username and password for PostgreSQL.
POSTGRES_USER: github
POSTGRES_PASSWORD: oiz5FeebOosh6aet
jobs:
build:
strategy:
matrix:
ruby_version: ["3.4", "3.3"]
runs-on: ubuntu-latest
services:
postgres:
image: postgres:17
env:
# Default database that is created when the image is first started.
POSTGRES_DB: active_record_collation_test
# This is so dumb…
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v5
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- run: bundle exec rubocop
- run: cd test/dummy && rm -f db/schema.rb && RAILS_ENV=test bundle exec rake db:drop db:create db:migrate
- run: bundle exec rake test
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AllCops:
TargetRubyVersion: 3.3
Exclude:
- test/dummy/db/schema.rb
- vendor/**/*
Layout/LineLength:
Max: 100
Metrics/BlockLength:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ See [Postgres collation documentation](https://www.postgresql.org/docs/current/c

## Setup

Add `activerecord-collations` to your dependencies. If you also want the `collate` class method on your model you also include the collation module:
Add `activerecord-collations` to your dependencies. Include the collation concern into your models to get access to the `collate` class method.

```ruby
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
primary_abstract_class

include ActiveRecord::Collation
end
```

The collate method creates an ARel expression for the column with a certain collation.
The `collate` method creates an ARel expression for the column with a certain collation.

```ruby
scope :ordered, -> { order(collate(:title, "natural_#{I18n.locale}") }
Expand All @@ -45,11 +45,11 @@ Arel::Nodes::InfixOperation.new(
)
```

## Testing
## Development

The Dummy application uses the gem so you can load the schema and run migrations there:
Run tests in this repository with `rake`. Migrations are exercised by running them in the dummy application.

```
cd test/dummy
RAILS_ENV=test rake db:migrate
rm -f db/schema.rb && RAILS_ENV=test rake db:drop db:create db:migrate
```
2 changes: 2 additions & 0 deletions test/dummy/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ test:
host: localhost
pool: 16
database: active_record_collation_test
user: <%= ENV.fetch("POSTGRES_USER", nil) %>
password: <%= ENV.fetch("POSTGRES_PASSWORD", nil) %>