diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fa7bb06 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/.rubocop.yml b/.rubocop.yml index 9bac860..ebe5235 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,7 @@ AllCops: TargetRubyVersion: 3.3 Exclude: - test/dummy/db/schema.rb + - vendor/**/* Layout/LineLength: Max: 100 Metrics/BlockLength: diff --git a/README.md b/README.md index 804dca2..6cd2723 100644 --- a/README.md +++ b/README.md @@ -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}") } @@ -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 ``` diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml index 077f773..a572209 100644 --- a/test/dummy/config/database.yml +++ b/test/dummy/config/database.yml @@ -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) %>