diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b5c3478..d4adcae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,9 +3,22 @@ name: CI RSpec Test on: [push, pull_request] jobs: + rubocop: + runs-on: ubuntu-latest + env: + CI: true + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby 3.4 + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.4 + bundler-cache: true + - name: Run RuboCop + run: bundle exec rubocop --parallel + build: - name: >- - ${{ matrix.ruby }} + name: "${{ matrix.ruby }} mongoid-${{ matrix.mongoid }}" env: CI: true TESTOPTS: -v @@ -14,17 +27,24 @@ jobs: strategy: fail-fast: false matrix: - ruby: [2.7, 3.0, 3.1, 3.2] - mongoid: [7, 8] + ruby: + - ruby-2.7 + - ruby-3.0 + - ruby-3.1 + - ruby-3.2 + - ruby-3.3 + - ruby-3.4 + - ruby-4.0 + mongoid: [8, 9] experimental: [false] include: - - ruby: 3.2 + - ruby: ruby-3.2 mongoid: HEAD experimental: true - - ruby: head + - ruby: ruby-head mongoid: 7 experimental: true - - ruby: head + - ruby: ruby-head mongoid: HEAD experimental: true - ruby: jruby @@ -33,6 +53,9 @@ jobs: - ruby: jruby-head mongoid: 8 experimental: true + - ruby: truffleruby-head + mongoid: 7 + experimental: true steps: - name: repo checkout @@ -55,13 +78,6 @@ jobs: env: MONGOID_VERSION: ${{ matrix.mongoid }} - - name: rubocop - timeout-minutes: 5 - run: bundle exec rubocop - continue-on-error: ${{ matrix.experimental }} - env: - MONGOID_VERSION: ${{ matrix.mongoid }} - - name: test timeout-minutes: 10 run: bundle exec rake spec diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bb83ee..39b5d3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [#274](https://github.com/mongoid/mongoid-slug/pull/274): Added support for scoping slugs by multiple fields - [@mikekosulin](https://github.com/mikekosulin). * [#279](https://github.com/mongoid/mongoid-slug/pull/279): Replace deprecated `__find_args__` with `Array#flatten` - [@samiFakhfakhScalingo](https://github.com/samiFakhfakhScalingo), [@aurelien-reeves-scalingo](https://github.com/aurelien-reeves-scalingo). * Your contribution here. +* [#281](https://github.com/mongoid/mongoid-slug/pull/281): Add ruby 4.0 to the ci - [@aurelien-reeves-scalingo](https://github.com/aurelien-reeves-scalingo). ## 7.0.0 (2023/09/18) diff --git a/Gemfile b/Gemfile index 308aac2..ad97cf7 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ end gem 'danger', require: false gem 'danger-changelog', require: false gem 'danger-pr-comment', require: false +gem 'ostruct' gem 'rake' gem 'rspec' gem 'rspec-its' diff --git a/lib/mongoid/slug/unique_slug.rb b/lib/mongoid/slug/unique_slug.rb index 3132129..bb8c90a 100644 --- a/lib/mongoid/slug/unique_slug.rb +++ b/lib/mongoid/slug/unique_slug.rb @@ -145,6 +145,11 @@ def regex_for_slug end def uniqueness_scope + if embedded? + parent_metadata = reflect_on_all_association(:embedded_in)[0] + return model._parent.send(parent_metadata.inverse_of || metadata.name) + end + # If slug_scope is present, we need to handle whether it's a single scope or multiple scopes. if slug_scope # We'll track individual scope results in an array. @@ -190,13 +195,6 @@ def uniqueness_scope return model.class end - # The rest of your method remains unchanged, handling cases where slug_scope isn't defined. - # This is your existing logic for embedded models or deeper superclass retrieval. - if embedded? - parent_metadata = reflect_on_all_association(:embedded_in)[0] - return model._parent.send(parent_metadata.inverse_of || self.metadata.name) - end - # Unless embedded or slug scope, return the deepest document superclass. appropriate_class = model.class appropriate_class = appropriate_class.superclass while appropriate_class.superclass.include?(Mongoid::Document)