From 93804438a7c8ecabb0a1c4bb865e40ebc7c79f95 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Mon, 18 Sep 2023 04:15:04 +0900 Subject: [PATCH 1/6] Cleanup - Remove Mongoid::Danger - Fix Rubocop issues - CI coverage should includeMongoid 8 and Ruby 3.2 --- .github/workflows/test.yml | 9 +- .rubocop.yml | 20 +++- .rubocop_todo.yml | 40 +------ CHANGELOG.md | 203 +++++++++++++++++--------------- Dangerfile | 3 - Gemfile | 17 +-- README.md | 2 +- lib/mongoid/slug.rb | 2 +- lib/mongoid/slug/unique_slug.rb | 8 +- lib/mongoid/slug/version.rb | 2 +- lib/tasks/mongoid_slug.rake | 2 +- mongoid-slug.gemspec | 8 +- 12 files changed, 147 insertions(+), 169 deletions(-) delete mode 100644 Dangerfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a97250e..1b94bcf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,14 +13,11 @@ jobs: continue-on-error: ${{ matrix.experimental }} strategy: matrix: - ruby: [2.5, 2.6, 2.7, 3.0, jruby, truffleruby] - mongoid: [7] + ruby: [2.7, 3.0, 3.1, 3.2, jruby, truffleruby] + mongoid: [7, 8] experimental: [false] include: - - ruby: 2.7 - mongoid: HEAD - experimental: true - - ruby: 3.0 + - ruby: 3.2 mongoid: HEAD experimental: true - ruby: head diff --git a/.rubocop.yml b/.rubocop.yml index 8da7c7d..d9984b6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,28 @@ inherit_from: .rubocop_todo.yml AllCops: - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.7 NewCops: enable SuggestExtensions: false +Metrics/AbcSize: + Enabled: false + +Metrics/BlockLength: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Metrics/ModuleLength: + Enabled: false + +Metrics/PerceivedComplexity: + Enabled: false + Style/Documentation: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dd08ae7..f8f6580 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2021-08-11 17:20:10 UTC using RuboCop version 1.18.4. +# on 2023-09-17 18:58:11 UTC using RuboCop version 1.56.3. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -13,41 +13,3 @@ Lint/ConstantDefinitionInBlock: Exclude: - 'spec/mongoid/slug_spec.rb' - 'spec/tasks/mongoid_slug_rake_spec.rb' - -# Offense count: 4 -# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. -Metrics/AbcSize: - Max: 44 - -# Offense count: 24 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. -# IgnoredMethods: refine -Metrics/BlockLength: - Max: 525 - -# Offense count: 2 -# Configuration parameters: IgnoredMethods. -Metrics/CyclomaticComplexity: - Max: 10 - -# Offense count: 7 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. -Metrics/MethodLength: - Max: 23 - -# Offense count: 2 -# Configuration parameters: CountComments, CountAsOne. -Metrics/ModuleLength: - Max: 937 - -# Offense count: 1 -# Configuration parameters: IgnoredMethods. -Metrics/PerceivedComplexity: - Max: 11 - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowOnConstant. -Style/CaseEquality: - Exclude: - - 'lib/mongoid/slug/unique_slug.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index eba03ab..1edb779 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,261 +1,270 @@ -## 7.0.0 (Next) +## 7.0.1 (Next) * Your contribution here. -* [#268](https://github.com/mongoid/mongoid-slug/pull/268): Ensure localized slugs index expected localized slug fields - [@johnnyshields](https://github.com/johnnyshields). + +## 7.0.0 (2023/09/18) + +* [#270](https://github.com/mongoid/mongoid-slug/pull/270): Drop support for Mongoid prior to version 7.0 - [@johnnyshields](https://github.com/johnnyshields) +* [#272](https://github.com/mongoid/mongoid-slug/pull/272): Drop support for Ruby prior to version 2.7 - [@johnnyshields](https://github.com/johnnyshields) +* [#272](https://github.com/mongoid/mongoid-slug/pull/272): Add CI coverage through Ruby 3.2 and Mongoid 8 - [@johnnyshields](https://github.com/johnnyshields) +* [#272](https://github.com/mongoid/mongoid-slug/pull/272): Remove mongoid-danger gem dependency - [@johnnyshields](https://github.com/johnnyshields) +* [#272](https://github.com/mongoid/mongoid-slug/pull/272): Fix various Rubocop issues - [@johnnyshields](https://github.com/johnnyshields) +* [#271](https://github.com/mongoid/mongoid-slug/pull/271): Add :index option to slug macro to disable auto-index - [@johnnyshields](https://github.com/johnnyshields) ## 6.0.1 (2021/08/12) -* [#266](https://github.com/mongoid/mongoid-slug/pull/266): Ensure localized slugs index expected localized slug fields - [@onomated](https://github.com/onomated), [@johnnyshields](https://github.com/johnnyshields). -* [#265](https://github.com/mongoid/mongoid-slug/pull/265): Add Github Actions and remove Travis CI - [@johnnyshields](https://github.com/kailan). -* [#255](https://github.com/mongoid/mongoid-slug/pull/255): Use mongoid::config#models in rake task, resolves #247 - [@kailan](https://github.com/kailan). +* [#268](https://github.com/mongoid/mongoid-slug/pull/268): Improvements to localized slugs - [@johnnyshields](https://github.com/johnnyshields) +* [#266](https://github.com/mongoid/mongoid-slug/pull/266): Ensure localized slugs index expected localized slug fields - [@onomated](https://github.com/onomated), [@johnnyshields](https://github.com/johnnyshields) +* [#265](https://github.com/mongoid/mongoid-slug/pull/265): Add Github Actions and remove Travis CI - [@johnnyshields](https://github.com/kailan) +* [#255](https://github.com/mongoid/mongoid-slug/pull/255): Use Mongoid::Config#models in rake task, resolves #247 - [@kailan](https://github.com/kailan) ## 6.0.0 (2018/09/17) -* [#252](https://github.com/mongoid/mongoid-slug/pull/252): Compatibility with Mongoid 7.0.0+ - [@kailan](https://github.com/kailan). +* [#252](https://github.com/mongoid/mongoid-slug/pull/252): Compatibility with Mongoid 7.0.0+ - [@kailan](https://github.com/kailan) ## 5.3.3 (2017/04/06) -* [#240](https://github.com/mongoid/mongoid-slug/pull/240): Fix: ensure we find the correct `BSON::Regexp::Raw` class - [@artfuldodger](https://github.com/artfuldodger). +* [#240](https://github.com/mongoid/mongoid-slug/pull/240): Fix: ensure we find the correct `BSON::Regexp::Raw` class - [@artfuldodger](https://github.com/artfuldodger) ## 5.3.2 (2017/04/03) -* [#234](https://github.com/mongoid/mongoid-slug/pull/234): Compatibility with Mongoid 6 - [@moodlemags](https://github.com/moodlemags), [@dblock](https://github.com/dblock). -* [#238](https://github.com/mongoid/mongoid-slug/pull/238): Use `BSON::Regexp::Raw` instead of Ruby's Regexp to avoid a performance hit - [@mzikherman](https://github.com/mzikherman). +* [#234](https://github.com/mongoid/mongoid-slug/pull/234): Compatibility with Mongoid 6 - [@moodlemags](https://github.com/moodlemags), [@dblock](https://github.com/dblock) +* [#238](https://github.com/mongoid/mongoid-slug/pull/238): Use `BSON::Regexp::Raw` instead of Ruby's Regexp to avoid a performance hit - [@mzikherman](https://github.com/mzikherman) ## 5.3.0 (2016/09/11) -* [#228](https://github.com/mongoid/mongoid-slug/pull/228): Moved to the [mongoid](http://mongoid.github.io) organization - [@dblock](https://github.com/dblock), [@digitalplaywright](https://github.com/digitalplaywright). -* [#166](https://github.com/mongoid/mongoid-slug/issues/166): Configure slug builder globally - [@anujaware](https://github.com/anujaware). -* [#209](https://github.com/mongoid/mongoid-slug/issues/209): Prefixed internal `Mongoid::Slug` class attributes with `slug_` to avoid conflicts - [@dblock](https://github.com/dblock). -* [#217](https://github.com/mongoid/mongoid-slug/issues/217): Fixed `mongoid_slug:set` rake task for Mongoid 6 - [@dblock](https://github.com/dblock). -* [#219](https://github.com/mongoid/mongoid-slug/pull/219): Mongoid HEAD and Rails 5.0.0.rc1 support - [@Fudoshiki](https://github.com/Fudoshiki). -* [#224](https://github.com/mongoid/mongoid-slug/pull/224): Use Danger, PR linter - [@dblock](https://github.com/dblock). -* [#222](https://github.com/mongoid/mongoid-slug/pull/225): Fix: `Mongo::Error::OperationFailure: E11000 duplicate key error index` error with blank slugs, default `_slugs` to `nil` instead of `[]` - [@dblock](https://github.com/dblock). -* [#172](https://github.com/mongoid/mongoid-slug/pull/172): Improved handling of unique and sparse index constraints - [@johnnyshields](https://github.com/johnnyshields). -* [#229](https://github.com/mongoid/mongoid-slug/pull/229): Upgraded to RuboCop 0.42.0 - [@dblock](https://github.com/dblock). +* [#228](https://github.com/mongoid/mongoid-slug/pull/228): Moved to the [mongoid](http://mongoid.github.io) organization - [@dblock](https://github.com/dblock), [@digitalplaywright](https://github.com/digitalplaywright) +* [#166](https://github.com/mongoid/mongoid-slug/issues/166): Configure slug builder globally - [@anujaware](https://github.com/anujaware) +* [#209](https://github.com/mongoid/mongoid-slug/issues/209): Prefixed internal `Mongoid::Slug` class attributes with `slug_` to avoid conflicts - [@dblock](https://github.com/dblock) +* [#217](https://github.com/mongoid/mongoid-slug/issues/217): Fixed `mongoid_slug:set` rake task for Mongoid 6 - [@dblock](https://github.com/dblock) +* [#219](https://github.com/mongoid/mongoid-slug/pull/219): Mongoid HEAD and Rails 5.0.0.rc1 support - [@Fudoshiki](https://github.com/Fudoshiki) +* [#224](https://github.com/mongoid/mongoid-slug/pull/224): Use Danger, PR linter - [@dblock](https://github.com/dblock) +* [#222](https://github.com/mongoid/mongoid-slug/pull/225): Fix: `Mongo::Error::OperationFailure: E11000 duplicate key error index` error with blank slugs, default `_slugs` to `nil` instead of `[]` - [@dblock](https://github.com/dblock) +* [#172](https://github.com/mongoid/mongoid-slug/pull/172): Improved handling of unique and sparse index constraints - [@johnnyshields](https://github.com/johnnyshields) +* [#229](https://github.com/mongoid/mongoid-slug/pull/229): Upgraded to RuboCop 0.42.0 - [@dblock](https://github.com/dblock) ## 5.2.0 (2016/01/03) -* [#204](https://github.com/mongoid/mongoid-slug/pull/204): The text portion of the slug is now truncated at `Mongoid::Slug::MONGO_INDEX_KEY_LIMIT_BYTES - 32` bytes by default and can be set via `max_length` - [@dblock](https://github.com/dblock). -* [#177](https://github.com/mongoid/mongoid-slug/issues/177): Added `mongoid_slug:set` rake task to set slug for legacy data - [@anuja-joshi](https://github.com/anuja-joshi). +* [#204](https://github.com/mongoid/mongoid-slug/pull/204): The text portion of the slug is now truncated at `Mongoid::Slug::MONGO_INDEX_KEY_LIMIT_BYTES - 32` bytes by default and can be set via `max_length` - [@dblock](https://github.com/dblock) +* [#177](https://github.com/mongoid/mongoid-slug/issues/177): Added `mongoid_slug:set` rake task to set slug for legacy data - [@anuja-joshi](https://github.com/anuja-joshi) ## 5.1.1 -* [#197](https://github.com/mongoid/mongoid-slug/pull/197): Compatibility with Mongoid 5.0.1, fix [MONGOID-4177](https://jira.mongodb.org/browse/MONGOID-4177) - [@dblock](https://github.com/dblock). +* [#197](https://github.com/mongoid/mongoid-slug/pull/197): Compatibility with Mongoid 5.0.1, fix [MONGOID-4177](https://jira.mongodb.org/browse/MONGOID-4177) - [@dblock](https://github.com/dblock) ## 5.1.0 -* [#194](https://github.com/mongoid/mongoid-slug/issues/194): Fixed compatibility with Mongoid::Observer - [@dblock](https://github.com/dblock). +* [#194](https://github.com/mongoid/mongoid-slug/issues/194): Fixed compatibility with Mongoid::Observer - [@dblock](https://github.com/dblock) ## 5.0.0 -* [#187](https://github.com/mongoid/mongoid-slug/pull/187): Mongoid 5 support - [@dblock](https://github.com/dblock). -* [#188](https://github.com/mongoid/mongoid-slug/pull/188): Removed deprecated name, _mongoid_slug_ - [@dblock](https://github.com/dblock). -* [#189](https://github.com/mongoid/mongoid-slug/pull/189): Implemented RuboCop - [@dblock](https://github.com/dblock). +* [#187](https://github.com/mongoid/mongoid-slug/pull/187): Mongoid 5 support - [@dblock](https://github.com/dblock) +* [#188](https://github.com/mongoid/mongoid-slug/pull/188): Removed deprecated name, _mongoid_slug_ - [@dblock](https://github.com/dblock) +* [#189](https://github.com/mongoid/mongoid-slug/pull/189): Implemented RuboCop - [@dblock](https://github.com/dblock) ## 4.0.0 -* [#179](https://github.com/mongoid/mongoid-slug/pull/179): Renamed gem to mongoid-slug - [@nofxx](https://github.com/nofxx). -* [#168](https://github.com/mongoid/mongoid-slug/pull/168): Finding a unique slug is now threadsafe - [@jaxesn](https://github.com/jaxesn). -* [#165](https://github.com/mongoid/mongoid-slug/pull/165): Fixed compatibility with Mongoid::Paranoia - [@johnnyshields](https://github.com/johnnyshields). +* [#179](https://github.com/mongoid/mongoid-slug/pull/179): Renamed gem to mongoid-slug - [@nofxx](https://github.com/nofxx) +* [#168](https://github.com/mongoid/mongoid-slug/pull/168): Finding a unique slug is now threadsafe - [@jaxesn](https://github.com/jaxesn) +* [#165](https://github.com/mongoid/mongoid-slug/pull/165): Fixed compatibility with Mongoid::Paranoia - [@johnnyshields](https://github.com/johnnyshields) ## 3.2.2 ## Bugfixes -* [#163](https://github.com/mongoid/mongoid-slug/pull/163): Avoid scope error in tests - [@johnnyshields](https://github.com/johnnyshields). -* Require activesupport dependencies to fix error in test on ruby 1.9.3 and Mongoid 4 - [@digitalplaywright](https://github.com/digitalplaywright). +* [#163](https://github.com/mongoid/mongoid-slug/pull/163): Avoid scope error in tests - [@johnnyshields](https://github.com/johnnyshields) +* Require activesupport dependencies to fix error in test on ruby 1.9.3 and Mongoid 4 - [@digitalplaywright](https://github.com/digitalplaywright) ## 3.2.1 ### Improvements -* Bumped Mongoid 4 requirement to beta1 - [@digitalplaywright](https://github.com/digitalplaywright). +* Bumped Mongoid 4 requirement to beta1 - [@digitalplaywright](https://github.com/digitalplaywright) ### Bugfixes -* Fixed Mongoid4 - [@blackxored](https://github.com/blackxored). -* Fixed translation tests - [@digitalplaywright](https://github.com/digitalplaywright). -* Added sparse option to slug index - [@klacointe](https://github.com/klacointe). +* Fixed Mongoid4 - [@blackxored](https://github.com/blackxored) +* Fixed translation tests - [@digitalplaywright](https://github.com/digitalplaywright) +* Added sparse option to slug index - [@klacointe](https://github.com/klacointe) ## 3.2.0 ### Improvements -* Updated stringex dependency to 2.0 or higher - [@digitalplaywright](https://github.com/digitalplaywright). -* Added Mongoid 4 support - [@dblock](https://github.com/dblock). +* Updated stringex dependency to 2.0 or higher - [@digitalplaywright](https://github.com/digitalplaywright) +* Added Mongoid 4 support - [@dblock](https://github.com/dblock) ### Bugfixes -* Fixed for when using localized slug with custom slug building strategy on virtual attrbitues - [@astjohn](https://github.com/astjohn). +* Fixed for when using localized slug with custom slug building strategy on virtual attrbitues - [@astjohn](https://github.com/astjohn) ## 3.1.2 ### Bugfixes -* Fixes for i8n slug generation - [@astjohn](https://github.com/astjohn). -* Don't use unique indexes with polymorphics - [@pdf](https://github.com/pdf). +* Fixes for i8n slug generation - [@astjohn](https://github.com/astjohn) +* Don't use unique indexes with polymorphics - [@pdf](https://github.com/pdf) ### Improvements -* Refactored of test cases - [@lucasrenan](https://github.com/lucasrenan). +* Refactored of test cases - [@lucasrenan](https://github.com/lucasrenan) ## 3.1.1 ### Bugfixes -* [#121](https://github.com/mongoid/mongoid-slug/issues/121), [#122](https://github.com/mongoid/mongoid-slug/issues/122): Do not generate empty slug - [@digitalplaywright](https://github.com/digitalplaywright). +* [#121](https://github.com/mongoid/mongoid-slug/issues/121), [#122](https://github.com/mongoid/mongoid-slug/issues/122): Do not generate empty slug - [@digitalplaywright](https://github.com/digitalplaywright) ## 3.1.0 ### New Features -* Optionally slugs are created and found per model type - [@joe1chen](https://github.com/joe1chen). +* Optionally slugs are created and found per model type - [@joe1chen](https://github.com/joe1chen) ### Bugfixes -* Fixed issue with default scope and slug uniqueness - [@loopj](https://github.com/loopj). +* Fixed issue with default scope and slug uniqueness - [@loopj](https://github.com/loopj) ## 3.0.0 ### Bugfixes -* Avoid using reserved words as slugs - [@deepakkumarnd](https://github.com/deepakkumarnd). -* Fixed localized slug creation when using history and when the locale changes after document is created - [@byscripts](https://github.com/byscripts). -* Improved specs for reserved words - [@astjohn](https://github.com/astjohn). -* Added Mongoid Paranoia specs - [@simi](https://github.com/simi). -* Fixed Mongoid Slug for Ruby 2.0.0 - [@digitalplaywright](https://github.com/digitalplaywright). +* Avoid using reserved words as slugs - [@deepakkumarnd](https://github.com/deepakkumarnd) +* Fixed localized slug creation when using history and when the locale changes after document is created - [@byscripts](https://github.com/byscripts) +* Improved specs for reserved words - [@astjohn](https://github.com/astjohn) +* Added Mongoid Paranoia specs - [@simi](https://github.com/simi) +* Fixed Mongoid Slug for Ruby 2.0.0 - [@digitalplaywright](https://github.com/digitalplaywright) ### New Features -* Made slugs localizable by option - [@xslim](https://github.com/xslim). +* Made slugs localizable by option - [@xslim](https://github.com/xslim) ## 2.0.1 ### Bugfixes -* Fix wrong homepage link in gemspec - [@digitalplaywright](https://github.com/digitalplaywright). +* Fix wrong homepage link in gemspec - [@digitalplaywright](https://github.com/digitalplaywright) ## 2.0.0 ### New Features -* Separated out unique finding logic into own class - [@guyboertje](https://github.com/guyboertje). -* Enabled custom specification of looks_like_slug? method - [@guyboertje](https://github.com/guyboertje). +* Separated out unique finding logic into own class - [@guyboertje](https://github.com/guyboertje) +* Enabled custom specification of looks_like_slug? method - [@guyboertje](https://github.com/guyboertje) ### Major Changes (Backwards Incompatible) -* Calling `to_param` on a document without a slug no longer builds a slug and persists the document - [@gerad](https://github.com/gerad). -* Removed transfer from history - [@guyboertje](https://github.com/guyboertje). +* Calling `to_param` on a document without a slug no longer builds a slug and persists the document - [@gerad](https://github.com/gerad) +* Removed transfer from history - [@guyboertje](https://github.com/guyboertje) ## 1.0.1 ### Bugfixes -* Do not create indexes for embedded documents - [@digitalplaywright](https://github.com/digitalplaywright). +* Do not create indexes for embedded documents - [@digitalplaywright](https://github.com/digitalplaywright) ## 1.0.0 ### Features -* Only look for a new unique slug if the existing slugs contains the current slug - [@digitalplaywright](https://github.com/digitalplaywright). +* Only look for a new unique slug if the existing slugs contains the current slug - [@digitalplaywright](https://github.com/digitalplaywright) ### Minor Changes -* [#76](https://github.com/mongoid/mongoid-slug/pull/76): Cleanup of callback handling - [@empact](https://github.com/empact). +* [#76](https://github.com/mongoid/mongoid-slug/pull/76): Cleanup of callback handling - [@empact](https://github.com/empact) ### Major Changes (Backwards Incompatible) -* Custom slug block now passes in the object - [@digitalplaywright](https://github.com/digitalplaywright). -* Fixed broken #find - [@al](https://github.com/al). -* Only Mongoid 3.0 syntax is supported - [@digitalplaywright](https://github.com/digitalplaywright). -* Store all slugs in a single field of array type - [@digitalplaywright](https://github.com/digitalplaywright). -* Removed the ':as' feature - [@digitalplaywright](https://github.com/digitalplaywright). -* Renamed slug field to _slugs - [@digitalplaywright](https://github.com/digitalplaywright). -* Slugs are indexes by default and removed the :index option - [@digitalplaywright](https://github.com/digitalplaywright). -* Reserved words should default to :new and :edit - [@digitalplaywright](https://github.com/digitalplaywright). -* Removed find_by_slug - [@digitalplaywright](https://github.com/digitalplaywright). -* Added `#find_by_slug!` - [@al](https://github.com/al). +* Custom slug block now passes in the object - [@digitalplaywright](https://github.com/digitalplaywright) +* Fixed broken #find - [@al](https://github.com/al) +* Only Mongoid 3.0 syntax is supported - [@digitalplaywright](https://github.com/digitalplaywright) +* Store all slugs in a single field of array type - [@digitalplaywright](https://github.com/digitalplaywright) +* Removed the ':as' feature - [@digitalplaywright](https://github.com/digitalplaywright) +* Renamed slug field to _slugs - [@digitalplaywright](https://github.com/digitalplaywright) +* Slugs are indexes by default and removed the :index option - [@digitalplaywright](https://github.com/digitalplaywright) +* Reserved words should default to :new and :edit - [@digitalplaywright](https://github.com/digitalplaywright) +* Removed find_by_slug - [@digitalplaywright](https://github.com/digitalplaywright) +* Added `#find_by_slug!` - [@al](https://github.com/al) ### Bugfixes -* Corrected index creation on scoped slugs - [@DouweM](https://github.com/DouweM). +* Corrected index creation on scoped slugs - [@DouweM](https://github.com/DouweM) ## 0.10.0 -* Fixed Slug history should only apply if history is set to true - [@tomaswitek](https://github.com/tomaswitek). -* Fixed Model.slug should alias to to_param - [@tomaswitek](https://github.com/tomaswitek). -* Added .find_unique_slug_for and #find_unique_slug_for methods - [@DouweM](https://github.com/DouweM). -* Ensured uniqueness of slug set manually - [@DouweM](https://github.com/DouweM). -* Added support for reserved slugs - [@siong1987](https://github.com/siong1987), [@DouweM](https://github.com/DouweM). -* Added support for keeping a history of slugs - [@DouweM](https://github.com/DouweM). -* Added by_slug(slug) scope - [@DouweM](https://github.com/DouweM). -* Allowed set slug on aliased field - [@eagleas](https://github.com/eagleas). +* Fixed Slug history should only apply if history is set to true - [@tomaswitek](https://github.com/tomaswitek) +* Fixed Model.slug should alias to to_param - [@tomaswitek](https://github.com/tomaswitek) +* Added .find_unique_slug_for and #find_unique_slug_for methods - [@DouweM](https://github.com/DouweM) +* Ensured uniqueness of slug set manually - [@DouweM](https://github.com/DouweM) +* Added support for reserved slugs - [@siong1987](https://github.com/siong1987), [@DouweM](https://github.com/DouweM) +* Added support for keeping a history of slugs - [@DouweM](https://github.com/DouweM) +* Added by_slug(slug) scope - [@DouweM](https://github.com/DouweM) +* Allowed set slug on aliased field - [@eagleas](https://github.com/eagleas) ## 0.9.0 -* [#43](https://github.com/mongoid/mongoid-slug/pull/43): Allowed overriding of slug at model creation time - [@bdmac](https://github.com/bdmac). +* [#43](https://github.com/mongoid/mongoid-slug/pull/43): Allowed overriding of slug at model creation time - [@bdmac](https://github.com/bdmac) ## 0.8.3 -* Bumped version of Stringex dependency - [@digitalplaywright](https://github.com/digitalplaywright). +* Bumped version of Stringex dependency - [@digitalplaywright](https://github.com/digitalplaywright) ## 0.8.2 -* Generated a slug when an existing document does not have one - [@digitalplaywright](https://github.com/digitalplaywright). +* Generated a slug when an existing document does not have one - [@digitalplaywright](https://github.com/digitalplaywright) ## 0.8.1 -* [#27](https://github.com/mongoid/mongoid-slug/pull/27): No longer necessary to require library in Gemfile - [@etehtsea](https://github.com/etehtsea). +* [#27](https://github.com/mongoid/mongoid-slug/pull/27): No longer necessary to require library in Gemfile - [@etehtsea](https://github.com/etehtsea) ## 0.8.0 -* [#23](https://github.com/mongoid/mongoid-slug/pull/23): Fix edbug concerning slugs with double-digit counters - [@jbredeche](https://github.com/jbredeche). -* Removed #slug!. The method is of limited value - [@digitalplaywright](https://github.com/digitalplaywright). +* [#23](https://github.com/mongoid/mongoid-slug/pull/23): Fix edbug concerning slugs with double-digit counters - [@jbredeche](https://github.com/jbredeche) +* Removed #slug!. The method is of limited value - [@digitalplaywright](https://github.com/digitalplaywright) ## 0.7.2 -* [#21](https://github.com/mongoid/mongoid-slug/pull/21): Added `#find_by_slug!` - [@ajsharp](https://github.com/ajsharp). +* [#21](https://github.com/mongoid/mongoid-slug/pull/21): Added `#find_by_slug!` - [@ajsharp](https://github.com/ajsharp) ## 0.7.1 -* [#16](https://github.com/mongoid/mongoid-slug/pull/16): Library no longers hit database multiple times to find unique slug when duplicates exist - [@tiendung](https://github.com/tiendung). +* [#16](https://github.com/mongoid/mongoid-slug/pull/16): Library no longers hit database multiple times to find unique slug when duplicates exist - [@tiendung](https://github.com/tiendung) ## 0.7.0 -* Slug now can be given an optional block to build a custom slug out of the specified fields - [@digitalplaywright](https://github.com/digitalplaywright). +* Slug now can be given an optional block to build a custom slug out of the specified fields - [@digitalplaywright](https://github.com/digitalplaywright) ## 0.6.4 -* [#10](https://github.com/mongoid/mongoid-slug/pull/10): Added :any option to use first present field when multiple fields are slugged - [@iamnader](https://github.com/iamnader). +* [#10](https://github.com/mongoid/mongoid-slug/pull/10): Added :any option to use first present field when multiple fields are slugged - [@iamnader](https://github.com/iamnader) ## 0.6.3 -* [#13](https://github.com/mongoid/mongoid-slug/pull/13): Mongoid no longer requires that emmbedded_in pass `:inverse_of` option - [@sporkd](https://github.com/sporkd). +* [#13](https://github.com/mongoid/mongoid-slug/pull/13): Mongoid no longer requires that emmbedded_in pass `:inverse_of` option - [@sporkd](https://github.com/sporkd) ## 0.6.2 -* Added #slug! to generate slug for an existing document - [@digitalplaywright](https://github.com/digitalplaywright). +* Added #slug! to generate slug for an existing document - [@digitalplaywright](https://github.com/digitalplaywright) ## 0.6.1 -* Added support for STI models - [@dmathieu](https://github.com/dmathieu). +* Added support for STI models - [@dmathieu](https://github.com/dmathieu) ## 0.6.0 -* Fixed internals to work with Mongoid RC - [@digitalplaywright](https://github.com/digitalplaywright). -* Finder is now dynamic - [@digitalplaywright](https://github.com/digitalplaywright). +* Fixed internals to work with Mongoid RC - [@digitalplaywright](https://github.com/digitalplaywright) +* Finder is now dynamic - [@digitalplaywright](https://github.com/digitalplaywright) ## 0.5.1 -* Added support for scoping by reference association - [@ches](https://github.com/ches). -* Brought indexing back in as an option - [@digitalplaywright](https://github.com/digitalplaywright). +* Added support for scoping by reference association - [@ches](https://github.com/ches) +* Brought indexing back in as an option - [@digitalplaywright](https://github.com/digitalplaywright) ## 0.5.0 -* Added support for non-Latin languages - [@etehtsea](https://github.com/etehtsea). -* Removed :scoped. Embedded objects are now scoped by parent by default - [@digitalplaywright](https://github.com/digitalplaywright). -* Added finder method - [@digitalplaywright](https://github.com/digitalplaywright). +* Added support for non-Latin languages - [@etehtsea](https://github.com/etehtsea) +* Removed :scoped. Embedded objects are now scoped by parent by default - [@digitalplaywright](https://github.com/digitalplaywright) +* Added finder method - [@digitalplaywright](https://github.com/digitalplaywright) ## Earlier tags -* To be found in the dustbin of git log - [@digitalplaywright](https://github.com/digitalplaywright). +* To be found in the dustbin of git log - [@digitalplaywright](https://github.com/digitalplaywright) diff --git a/Dangerfile b/Dangerfile deleted file mode 100644 index de2a4a0..0000000 --- a/Dangerfile +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -danger.import_dangerfile(gem: 'mongoid-danger') diff --git a/Gemfile b/Gemfile index d6f3782..17ccaec 100644 --- a/Gemfile +++ b/Gemfile @@ -4,17 +4,18 @@ source 'https://rubygems.org' gemspec name: 'mongoid-slug' -case version = ENV['MONGOID_VERSION'] || '7' +case (version = ENV['MONGOID_VERSION'] || '8') when 'HEAD' gem 'mongoid', github: 'mongodb/mongoid' -when /^7/ - gem 'mongoid', '~> 7' +when /\A\d+\z/ + gem 'mongoid', "~> #{version}.0" else gem 'mongoid', version end -group :test do - gem 'mongoid-danger', '~> 0.1.0', require: false - gem 'rubocop', '~> 1.18.4' - gem 'rubocop-rspec' -end +gem 'rake' +gem 'rspec' +gem 'rspec-its' +gem 'rubocop' +gem 'rubocop-rspec' +gem 'uuid' diff --git a/README.md b/README.md index 36e8bdf..0cceb57 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ It sits idly on top of [stringex](https://github.com/rsl/stringex), supporting n ### Version Support -Mongoid Slug 7.x requires at least Mongoid 7.0.0 and Ruby 2.5.0. For earlier Mongoid and Ruby version support, please use an earlier version of Mongoid Slug. +Mongoid Slug 7.x requires at least Mongoid 7.0.0 and Ruby 2.7.0. For earlier Mongoid and Ruby version support, please use an earlier version of Mongoid Slug. Mongoid Slug is compatible with all MongoDB versions which Mongoid supports, however, please see "Slug Max Length" section below for MongoDB 4.0 and earlier. diff --git a/lib/mongoid/slug.rb b/lib/mongoid/slug.rb index 1be4199..e547ea1 100644 --- a/lib/mongoid/slug.rb +++ b/lib/mongoid/slug.rb @@ -183,7 +183,7 @@ def apply_slug # skip slug generation and use Mongoid id # to find document instead - return true if new_slug.size.zero? + return true if new_slug.empty? # avoid duplicate slugs _slugs&.delete(new_slug) diff --git a/lib/mongoid/slug/unique_slug.rb b/lib/mongoid/slug/unique_slug.rb index 471b4bd..ab26fe1 100644 --- a/lib/mongoid/slug/unique_slug.rb +++ b/lib/mongoid/slug/unique_slug.rb @@ -23,11 +23,9 @@ def initialize(slug, documents, pattern) history_slugs = doc._slugs next if history_slugs.nil? - existing_slugs.push(*history_slugs.find_all { |cur_slug| cur_slug =~ regexp_pattern }) + existing_slugs.push(*history_slugs.grep(regexp_pattern)) last_entered_slug.push(*history_slugs.last) if history_slugs.last =~ regexp_pattern - existing_history_slugs.push(*history_slugs.first(history_slugs.length - 1).find_all do |cur_slug| - cur_slug =~ regexp_pattern - end) + existing_history_slugs.push(*history_slugs.first(history_slugs.length - 1).grep(regexp_pattern)) end end @@ -116,7 +114,7 @@ def find_unique(attempt = nil) @state.include_slug unless model.class.look_like_slugs?([@_slug]) # make sure that the slug is not equal to a reserved word - @state.include_slug if slug_reserved_words.any? { |word| word === @_slug } + @state.include_slug if slug_reserved_words.any? { |word| word == @_slug } # only look for a new unique slug if the existing slugs contains the current slug # - e.g if the slug 'foo-2' is taken, but 'foo' is available, the user can use 'foo'. diff --git a/lib/mongoid/slug/version.rb b/lib/mongoid/slug/version.rb index 1d4f848..e4eac64 100644 --- a/lib/mongoid/slug/version.rb +++ b/lib/mongoid/slug/version.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Mongoid #:nodoc: +module Mongoid # :nodoc: module Slug VERSION = '7.0.0' end diff --git a/lib/tasks/mongoid_slug.rake b/lib/tasks/mongoid_slug.rake index dea5148..b338230 100644 --- a/lib/tasks/mongoid_slug.rake +++ b/lib/tasks/mongoid_slug.rake @@ -3,7 +3,7 @@ namespace :mongoid_slug do desc 'Goes though all documents and sets slug if not already set' task set: :environment do |_, args| - ::Rails.application.eager_load! if defined?(Rails) + Rails.application.eager_load! if defined?(Rails) klasses = Mongoid::Config.models.find_all { |c| c.ancestors.include?(Mongoid::Slug) } unless klasses.blank? models = args.extras diff --git a/mongoid-slug.gemspec b/mongoid-slug.gemspec index 34fb83e..23d9158 100644 --- a/mongoid-slug.gemspec +++ b/mongoid-slug.gemspec @@ -14,16 +14,12 @@ Gem::Specification.new do |s| s.description = 'Mongoid URL slug or permalink generator' s.license = 'MIT' - s.required_ruby_version = '>= 2.5' + s.required_ruby_version = '>= 2.7' s.add_dependency 'mongoid', '>= 7.0' s.add_dependency 'stringex', '~> 2.0' - s.add_development_dependency 'rake' - s.add_development_dependency 'rspec' - s.add_development_dependency 'rspec-its' - s.add_development_dependency 'uuid' s.files = Dir.glob('lib/**/*') + %w[LICENSE README.md] - s.test_files = Dir.glob('spec/**/*') s.require_paths = ['lib'] + s.metadata['rubygems_mfa_required'] = 'true' end From 15524c16979b6f40d038455e60dc32f8a8b192bf Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Mon, 18 Sep 2023 04:45:03 +0900 Subject: [PATCH 2/6] Fix spec --- .github/workflows/test.yml | 1 + lib/mongoid/slug/unique_slug.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b94bcf..c7ca87d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: ${{ matrix.experimental }} strategy: + fail-fast: false matrix: ruby: [2.7, 3.0, 3.1, 3.2, jruby, truffleruby] mongoid: [7, 8] diff --git a/lib/mongoid/slug/unique_slug.rb b/lib/mongoid/slug/unique_slug.rb index ab26fe1..4596a29 100644 --- a/lib/mongoid/slug/unique_slug.rb +++ b/lib/mongoid/slug/unique_slug.rb @@ -114,7 +114,7 @@ def find_unique(attempt = nil) @state.include_slug unless model.class.look_like_slugs?([@_slug]) # make sure that the slug is not equal to a reserved word - @state.include_slug if slug_reserved_words.any? { |word| word == @_slug } + @state.include_slug if slug_reserved_words.any? { |word| word === @_slug } # rubocop:disable Style/CaseEquality # only look for a new unique slug if the existing slugs contains the current slug # - e.g if the slug 'foo-2' is taken, but 'foo' is available, the user can use 'foo'. From 533f8c68e6dd798c265c51f5fb5ac831d61a0d29 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Mon, 18 Sep 2023 04:48:21 +0900 Subject: [PATCH 3/6] Fix JRuby --- spec/spec_helper.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1640a19..250ac51 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,8 +39,10 @@ def database_id c.raise_errors_for_deprecations! c.before :all do - Mongoid.logger.level = Logger::INFO - Mongo::Logger.logger.level = Logger::INFO + if defined?(Logger::INFO) + Mongoid.logger.level = Logger::INFO + Mongo::Logger.logger.level = Logger::INFO + end end c.before(:each) do From 9433bcec321e596bbfff6221ccf65cd639828f2f Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Mon, 18 Sep 2023 04:51:22 +0900 Subject: [PATCH 4/6] Fix parenthesis --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 250ac51..40bae23 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,7 +38,7 @@ def database_id RSpec.configure do |c| c.raise_errors_for_deprecations! - c.before :all do + c.before(:all) do if defined?(Logger::INFO) Mongoid.logger.level = Logger::INFO Mongo::Logger.logger.level = Logger::INFO From 27c0b99d0d0ef37e5d0886f165e3386ade7c6455 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Mon, 18 Sep 2023 05:03:43 +0900 Subject: [PATCH 5/6] Revert JRuby fix --- spec/spec_helper.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 40bae23..ce43a00 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,10 +39,8 @@ def database_id c.raise_errors_for_deprecations! c.before(:all) do - if defined?(Logger::INFO) - Mongoid.logger.level = Logger::INFO - Mongo::Logger.logger.level = Logger::INFO - end + Mongoid.logger.level = Logger::INFO + Mongo::Logger.logger.level = Logger::INFO end c.before(:each) do From 02b2524c591407e8e401600c33820bffd398f648 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Mon, 18 Sep 2023 05:04:30 +0900 Subject: [PATCH 6/6] Make JRuby specs experimental --- .github/workflows/test.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c7ca87d..d6dc685 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: [2.7, 3.0, 3.1, 3.2, jruby, truffleruby] + ruby: [2.7, 3.0, 3.1, 3.2, truffleruby] mongoid: [7, 8] experimental: [false] include: @@ -27,8 +27,11 @@ jobs: - ruby: head mongoid: HEAD experimental: true + - ruby: jruby + mongoid: 8 + experimental: true - ruby: jruby-head - mongoid: 7 + mongoid: 8 experimental: true - ruby: truffleruby-head mongoid: 7