mongoid-slug 5.3.0 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +20 -20
- data/README.md +361 -360
- data/lib/mongoid/slug.rb +328 -366
- data/lib/mongoid/slug/criteria.rb +107 -107
- data/lib/mongoid/slug/{index.rb → index_builder.rb} +67 -51
- data/lib/mongoid/slug/railtie.rb +9 -9
- data/lib/mongoid/slug/slug_id_strategy.rb +3 -3
- data/lib/mongoid/slug/unique_slug.rb +173 -154
- data/lib/mongoid/slug/version.rb +5 -5
- data/lib/mongoid_slug.rb +2 -2
- data/lib/tasks/mongoid_slug.rake +15 -19
- data/spec/models/alias.rb +6 -6
- data/spec/models/article.rb +9 -9
- data/spec/models/artist.rb +8 -8
- data/spec/models/artwork.rb +10 -10
- data/spec/models/author.rb +15 -15
- data/spec/models/author_polymorphic.rb +15 -15
- data/spec/models/book.rb +12 -12
- data/spec/models/book_polymorphic.rb +12 -12
- data/spec/models/caption.rb +17 -17
- data/spec/models/entity.rb +11 -12
- data/spec/models/friend.rb +7 -7
- data/spec/models/incorrect_slug_persistence.rb +9 -9
- data/spec/models/integer_id.rb +9 -9
- data/spec/models/magazine.rb +7 -7
- data/spec/models/page.rb +9 -9
- data/spec/models/page_localize.rb +9 -9
- data/spec/models/page_slug_localized.rb +9 -9
- data/spec/models/page_slug_localized_custom.rb +10 -10
- data/spec/models/page_slug_localized_history.rb +9 -9
- data/spec/models/partner.rb +7 -7
- data/spec/models/person.rb +12 -12
- data/spec/models/relationship.rb +8 -8
- data/spec/models/string_id.rb +9 -9
- data/spec/models/subject.rb +7 -7
- data/spec/models/without_slug.rb +5 -5
- data/spec/mongoid/criteria_spec.rb +207 -208
- data/spec/mongoid/index_builder_spec.rb +105 -0
- data/spec/mongoid/slug_spec.rb +1175 -1170
- data/spec/shared/indexes.rb +41 -41
- data/spec/spec_helper.rb +61 -67
- data/spec/tasks/mongoid_slug_rake_spec.rb +73 -73
- metadata +14 -24
- data/lib/mongoid/slug/paranoia.rb +0 -20
- data/spec/models/document_paranoid.rb +0 -9
- data/spec/models/paranoid_document.rb +0 -8
- data/spec/models/paranoid_permanent.rb +0 -10
- data/spec/mongoid/index_spec.rb +0 -34
- data/spec/mongoid/paranoia_spec.rb +0 -230
data/lib/mongoid/slug/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module Mongoid #:nodoc:
|
2
|
-
module Slug
|
3
|
-
VERSION = '
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Mongoid #:nodoc:
|
2
|
+
module Slug
|
3
|
+
VERSION = '6.0.1'.freeze
|
4
|
+
end
|
5
|
+
end
|
data/lib/mongoid_slug.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
# To be removed
|
2
|
-
require 'mongoid/slug'
|
1
|
+
# To be removed
|
2
|
+
require 'mongoid/slug'
|
data/lib/tasks/mongoid_slug.rake
CHANGED
@@ -1,19 +1,15 @@
|
|
1
|
-
namespace :mongoid_slug do
|
2
|
-
desc 'Goes though all documents and sets slug if not already set'
|
3
|
-
task set: :environment do |_, args|
|
4
|
-
::Rails.application.eager_load! if defined?(Rails)
|
5
|
-
klasses =
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
1
|
+
namespace :mongoid_slug do
|
2
|
+
desc 'Goes though all documents and sets slug if not already set'
|
3
|
+
task set: :environment do |_, args|
|
4
|
+
::Rails.application.eager_load! if defined?(Rails)
|
5
|
+
klasses = Mongoid::Config.models.find_all { |c| c.ancestors.include?(Mongoid::Slug) }
|
6
|
+
unless klasses.blank?
|
7
|
+
models = args.extras
|
8
|
+
klasses = (klasses.map(&:to_s) & models.map(&:classify)).map(&:constantize) if models.any?
|
9
|
+
klasses.each do |klass|
|
10
|
+
# set slug for objects having blank slug
|
11
|
+
klass.each { |object| object.set_slug! unless object.slugs? && object.slugs.any? }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/models/alias.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
class Alias
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :name, as: :author_name
|
5
|
-
slug :author_name
|
6
|
-
end
|
1
|
+
class Alias
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :name, as: :author_name
|
5
|
+
slug :author_name
|
6
|
+
end
|
data/spec/models/article.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
class Article
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :brief
|
5
|
-
field :title
|
6
|
-
slug :title, :brief do |doc|
|
7
|
-
[doc.title, doc.brief].reject(&:blank?).first
|
8
|
-
end
|
9
|
-
end
|
1
|
+
class Article
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :brief
|
5
|
+
field :title
|
6
|
+
slug :title, :brief do |doc|
|
7
|
+
[doc.title, doc.brief].reject(&:blank?).first
|
8
|
+
end
|
9
|
+
end
|
data/spec/models/artist.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
class Artist
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
|
5
|
-
slug :name
|
6
|
-
field :name
|
7
|
-
has_and_belongs_to_many :artworks
|
8
|
-
end
|
1
|
+
class Artist
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
|
5
|
+
slug :name
|
6
|
+
field :name
|
7
|
+
has_and_belongs_to_many :artworks
|
8
|
+
end
|
data/spec/models/artwork.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
class Artwork
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
|
5
|
-
slug :title
|
6
|
-
field :title
|
7
|
-
field :published, type: Boolean, default: true
|
8
|
-
scope :published, -> { where(published: true) }
|
9
|
-
has_and_belongs_to_many :artists
|
10
|
-
end
|
1
|
+
class Artwork
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
|
5
|
+
slug :title
|
6
|
+
field :title
|
7
|
+
field :published, type: Boolean, default: true
|
8
|
+
scope :published, -> { where(published: true) }
|
9
|
+
has_and_belongs_to_many :artists
|
10
|
+
end
|
data/spec/models/author.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
class Author
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :first_name
|
5
|
-
field :last_name
|
6
|
-
if Mongoid::Compatibility::Version.
|
7
|
-
belongs_to :book, required: false
|
8
|
-
else
|
9
|
-
belongs_to :book
|
10
|
-
end
|
11
|
-
has_many :characters,
|
12
|
-
class_name: 'Person',
|
13
|
-
foreign_key: :author_id
|
14
|
-
slug :first_name, :last_name, scope: :book, history: false, max_length: 256
|
15
|
-
end
|
1
|
+
class Author
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :first_name
|
5
|
+
field :last_name
|
6
|
+
if Mongoid::Compatibility::Version.mongoid6_or_newer?
|
7
|
+
belongs_to :book, required: false
|
8
|
+
else
|
9
|
+
belongs_to :book
|
10
|
+
end
|
11
|
+
has_many :characters,
|
12
|
+
class_name: 'Person',
|
13
|
+
foreign_key: :author_id
|
14
|
+
slug :first_name, :last_name, scope: :book, history: false, max_length: 256
|
15
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
class AuthorPolymorphic
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :first_name
|
5
|
-
field :last_name
|
6
|
-
slug :first_name, :last_name, scope: :book_polymorphic
|
7
|
-
if Mongoid::Compatibility::Version.
|
8
|
-
belongs_to :book_polymorphic, required: false
|
9
|
-
else
|
10
|
-
belongs_to :book_polymorphic
|
11
|
-
end
|
12
|
-
has_many :characters,
|
13
|
-
class_name: 'Person',
|
14
|
-
foreign_key: :author_id
|
15
|
-
end
|
1
|
+
class AuthorPolymorphic
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :first_name
|
5
|
+
field :last_name
|
6
|
+
slug :first_name, :last_name, scope: :book_polymorphic
|
7
|
+
if Mongoid::Compatibility::Version.mongoid6_or_newer?
|
8
|
+
belongs_to :book_polymorphic, required: false
|
9
|
+
else
|
10
|
+
belongs_to :book_polymorphic
|
11
|
+
end
|
12
|
+
has_many :characters,
|
13
|
+
class_name: 'Person',
|
14
|
+
foreign_key: :author_id
|
15
|
+
end
|
data/spec/models/book.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
class Book
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :title
|
5
|
-
|
6
|
-
slug :title, history: true, max_length: nil
|
7
|
-
embeds_many :subjects
|
8
|
-
has_many :authors
|
9
|
-
end
|
10
|
-
|
11
|
-
class ComicBook < Book
|
12
|
-
end
|
1
|
+
class Book
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :title
|
5
|
+
|
6
|
+
slug :title, history: true, max_length: nil
|
7
|
+
embeds_many :subjects
|
8
|
+
has_many :authors
|
9
|
+
end
|
10
|
+
|
11
|
+
class ComicBook < Book
|
12
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
class BookPolymorphic
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :title
|
5
|
-
|
6
|
-
slug :title, history: true, by_model_type: true
|
7
|
-
embeds_many :subjects
|
8
|
-
has_many :author_polymorphics
|
9
|
-
end
|
10
|
-
|
11
|
-
class ComicBookPolymorphic < BookPolymorphic
|
12
|
-
end
|
1
|
+
class BookPolymorphic
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :title
|
5
|
+
|
6
|
+
slug :title, history: true, by_model_type: true
|
7
|
+
embeds_many :subjects
|
8
|
+
has_many :author_polymorphics
|
9
|
+
end
|
10
|
+
|
11
|
+
class ComicBookPolymorphic < BookPolymorphic
|
12
|
+
end
|
data/spec/models/caption.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
class Caption
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :my_identity, type: String
|
5
|
-
field :title
|
6
|
-
field :medium
|
7
|
-
|
8
|
-
# A fairly complex scenario, where we want to create a slug out of an
|
9
|
-
# my_identity field, which comprises name of artist and some more bibliographic
|
10
|
-
# info in parantheses, and the title of the work.
|
11
|
-
#
|
12
|
-
# We are only interested in the name of the artist so we remove the
|
13
|
-
# paranthesized details.
|
14
|
-
slug :my_identity, :title do |cur_object|
|
15
|
-
cur_object.slug_builder.gsub(/\s*\([^)]+\)/, '').to_url
|
16
|
-
end
|
17
|
-
end
|
1
|
+
class Caption
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :my_identity, type: String
|
5
|
+
field :title
|
6
|
+
field :medium
|
7
|
+
|
8
|
+
# A fairly complex scenario, where we want to create a slug out of an
|
9
|
+
# my_identity field, which comprises name of artist and some more bibliographic
|
10
|
+
# info in parantheses, and the title of the work.
|
11
|
+
#
|
12
|
+
# We are only interested in the name of the artist so we remove the
|
13
|
+
# paranthesized details.
|
14
|
+
slug :my_identity, :title do |cur_object|
|
15
|
+
cur_object.slug_builder.gsub(/\s*\([^)]+\)/, '').to_url
|
16
|
+
end
|
17
|
+
end
|
data/spec/models/entity.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
include Mongoid::
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
field :
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
1
|
+
class Entity
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
|
5
|
+
field :_id, type: String, slug_id_strategy: UuidIdStrategy
|
6
|
+
|
7
|
+
field :name
|
8
|
+
field :user_edited_variation
|
9
|
+
|
10
|
+
slug :user_edited_variation, history: true
|
11
|
+
end
|
data/spec/models/friend.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
class Friend
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :name
|
5
|
-
field :slug_history, type: Array
|
6
|
-
slug :name, reserve: ['foo', 'bar', /^[a-z]{2}$/i], history: true
|
7
|
-
end
|
1
|
+
class Friend
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :name
|
5
|
+
field :slug_history, type: Array
|
6
|
+
slug :name, reserve: ['foo', 'bar', /^[a-z]{2}$/i], history: true
|
7
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class IncorrectSlugPersistence
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
|
5
|
-
field :name
|
6
|
-
slug :name, history: true
|
7
|
-
|
8
|
-
validates_length_of :name, minimum: 4, maximum: 5, allow_blank: true
|
9
|
-
end
|
1
|
+
class IncorrectSlugPersistence
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
|
5
|
+
field :name
|
6
|
+
slug :name, history: true
|
7
|
+
|
8
|
+
validates_length_of :name, minimum: 4, maximum: 5, allow_blank: true
|
9
|
+
end
|
data/spec/models/integer_id.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
class IntegerId
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
|
5
|
-
field :_id, type: Integer
|
6
|
-
field :name, type: String
|
7
|
-
|
8
|
-
slug :name, history: true
|
9
|
-
end
|
1
|
+
class IntegerId
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
|
5
|
+
field :_id, type: Integer
|
6
|
+
field :name, type: String
|
7
|
+
|
8
|
+
slug :name, history: true
|
9
|
+
end
|
data/spec/models/magazine.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
class Magazine
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :title
|
5
|
-
field :publisher_id
|
6
|
-
slug :title, scope: :publisher_id
|
7
|
-
end
|
1
|
+
class Magazine
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :title
|
5
|
+
field :publisher_id
|
6
|
+
slug :title, scope: :publisher_id
|
7
|
+
end
|
data/spec/models/page.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
class Page
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :title
|
5
|
-
field :content
|
6
|
-
field :order, type: Integer
|
7
|
-
slug :title
|
8
|
-
default_scope -> { asc(:order) }
|
9
|
-
end
|
1
|
+
class Page
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :title
|
5
|
+
field :content
|
6
|
+
field :order, type: Integer
|
7
|
+
slug :title
|
8
|
+
default_scope -> { asc(:order) }
|
9
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class PageLocalize
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :title, localize: true
|
5
|
-
field :content
|
6
|
-
field :order, type: Integer
|
7
|
-
slug :title
|
8
|
-
default_scope -> { asc(:order) }
|
9
|
-
end
|
1
|
+
class PageLocalize
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :title, localize: true
|
5
|
+
field :content
|
6
|
+
field :order, type: Integer
|
7
|
+
slug :title
|
8
|
+
default_scope -> { asc(:order) }
|
9
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class PageSlugLocalized
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
field :title, localize: true
|
5
|
-
field :content
|
6
|
-
field :order, type: Integer
|
7
|
-
slug :title, localize: true
|
8
|
-
default_scope -> { asc(:order) }
|
9
|
-
end
|
1
|
+
class PageSlugLocalized
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
field :title, localize: true
|
5
|
+
field :content
|
6
|
+
field :order, type: Integer
|
7
|
+
slug :title, localize: true
|
8
|
+
default_scope -> { asc(:order) }
|
9
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
class PageSlugLocalizedCustom
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Slug
|
4
|
-
|
5
|
-
attr_accessor :title
|
6
|
-
|
7
|
-
slug :title, localize: true do |obj|
|
8
|
-
obj.title.to_url
|
9
|
-
end
|
10
|
-
end
|
1
|
+
class PageSlugLocalizedCustom
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Slug
|
4
|
+
|
5
|
+
attr_accessor :title
|
6
|
+
|
7
|
+
slug :title, localize: true do |obj|
|
8
|
+
obj.title.to_url
|
9
|
+
end
|
10
|
+
end
|