mongoid-slug 5.3.3 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +1 -25
- data/lib/mongoid/slug.rb +7 -45
- data/lib/mongoid/slug/criteria.rb +1 -1
- data/lib/mongoid/slug/index.rb +0 -6
- data/lib/mongoid/slug/unique_slug.rb +16 -9
- data/lib/mongoid/slug/version.rb +1 -1
- data/spec/models/author.rb +1 -1
- data/spec/models/author_polymorphic.rb +1 -1
- data/spec/models/entity.rb +0 -1
- data/spec/models/person.rb +1 -1
- data/spec/mongoid/criteria_spec.rb +0 -1
- data/spec/mongoid/index_spec.rb +0 -1
- data/spec/mongoid/slug_spec.rb +28 -29
- data/spec/spec_helper.rb +5 -11
- data/spec/tasks/mongoid_slug_rake_spec.rb +1 -1
- metadata +31 -40
- 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/paranoia_spec.rb +0 -230
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cf9ad642da6118dcc879edd3c4b6f43adf2b110e422d691926984ffb743f0dcf
|
4
|
+
data.tar.gz: 800d4c721c01fb89267218aaeff2c5a8d91a906f8587c87aa3680d774011180b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bb6300dd08988c87f922e5cfc308de3ea428a8730a75d9b2c261814cb1a8568ad266b94e8358d710602af131166dbf063ad1e163eca2a2d31108be7d147456d
|
7
|
+
data.tar.gz: 36dd52ca7e37b0e57cd4241ab616a20892688dfb4e79af8e02ada7f7802c30b158bb28b5594337eded30c47de948e20e1e40da69bc84ef2398e463d738c63188
|
data/README.md
CHANGED
@@ -325,30 +325,6 @@ unique = Mongoid::Slug::UniqueSlug.new(Book.new).find_unique(title)
|
|
325
325
|
# return some representation of unique
|
326
326
|
```
|
327
327
|
|
328
|
-
### Mongoid::Paranoia Support
|
329
|
-
|
330
|
-
The [Mongoid::Paranoia](http://github.com/simi/mongoid-paranoia) gem adds "soft-destroy" functionality to Mongoid documents.
|
331
|
-
|
332
|
-
Mongoid::Slug contains special handling for Mongoid::Paranoia:
|
333
|
-
|
334
|
-
* When destroying a paranoid document, the slug will be unset from the database.
|
335
|
-
* When restoring a paranoid document, the slug will be rebuilt. Note that the new slug may not match the old one.
|
336
|
-
* When resaving a destroyed paranoid document, the slug will remain unset in the database.
|
337
|
-
* For indexing purposes, sparse unique indexes are used. The sparse condition will ignore any destroyed paranoid documents, since their slug is not set in database.
|
338
|
-
|
339
|
-
```ruby
|
340
|
-
class Entity
|
341
|
-
include Mongoid::Document
|
342
|
-
include Mongoid::Slug
|
343
|
-
include Mongoid::Paranoia
|
344
|
-
end
|
345
|
-
```
|
346
|
-
|
347
|
-
The following variants of Mongoid Paranoia are officially supported:
|
348
|
-
|
349
|
-
* Mongoid 3 built-in `Mongoid::Paranoia`
|
350
|
-
* Mongoid 4 or 5 gem http://github.com/simi/mongoid_paranoia
|
351
|
-
|
352
328
|
Contributing
|
353
329
|
------------
|
354
330
|
|
@@ -357,4 +333,4 @@ Mongoid-slug is work of [many of contributors](https://github.com/mongoid/mongoi
|
|
357
333
|
Copyright & License
|
358
334
|
-------------------
|
359
335
|
|
360
|
-
Copyright (c) 2010-
|
336
|
+
Copyright (c) 2010-2017 Hakan Ensari & Contributors, see [LICENSE](LICENSE) for details.
|
data/lib/mongoid/slug.rb
CHANGED
@@ -2,7 +2,6 @@ require 'mongoid'
|
|
2
2
|
require 'stringex'
|
3
3
|
require 'mongoid/slug/criteria'
|
4
4
|
require 'mongoid/slug/index'
|
5
|
-
require 'mongoid/slug/paranoia'
|
6
5
|
require 'mongoid/slug/unique_slug'
|
7
6
|
require 'mongoid/slug/slug_id_strategy'
|
8
7
|
require 'mongoid-compatibility'
|
@@ -76,7 +75,7 @@ module Mongoid
|
|
76
75
|
options = fields.extract_options!
|
77
76
|
|
78
77
|
self.slug_scope = options[:scope]
|
79
|
-
self.slug_reserved_words = options[:reserve] || Set.new(%w
|
78
|
+
self.slug_reserved_words = options[:reserve] || Set.new(%w[new edit])
|
80
79
|
self.slugged_attributes = fields.map(&:to_s)
|
81
80
|
self.slug_history = options[:history]
|
82
81
|
self.slug_by_model_type = options[:by_model_type]
|
@@ -86,9 +85,7 @@ module Mongoid
|
|
86
85
|
alias_attribute :slugs, :_slugs
|
87
86
|
|
88
87
|
# Set index
|
89
|
-
unless embedded?
|
90
|
-
index(*Mongoid::Slug::Index.build_index(slug_scope_key, slug_by_model_type))
|
91
|
-
end
|
88
|
+
index(*Mongoid::Slug::Index.build_index(slug_scope_key, slug_by_model_type)) unless embedded?
|
92
89
|
|
93
90
|
self.slug_url_builder = block_given? ? block : default_slug_url_builder
|
94
91
|
|
@@ -99,19 +96,6 @@ module Mongoid
|
|
99
96
|
else
|
100
97
|
set_callback :save, :before, :build_slug, if: :slug_should_be_rebuilt?
|
101
98
|
end
|
102
|
-
|
103
|
-
# If paranoid document:
|
104
|
-
# - include shim to add callbacks for restore method
|
105
|
-
# - unset the slugs on destroy
|
106
|
-
# - recreate the slug on restore
|
107
|
-
# - force reset the slug when saving a destroyed paranoid document, to ensure it stays unset in the database
|
108
|
-
if is_paranoid_doc?
|
109
|
-
send(:include, Mongoid::Slug::Paranoia) unless respond_to?(:before_restore)
|
110
|
-
set_callback :destroy, :after, :unset_slug!
|
111
|
-
set_callback :restore, :before, :set_slug!
|
112
|
-
set_callback :save, :before, :reset_slug!, if: :paranoid_deleted?
|
113
|
-
set_callback :save, :after, :clear_slug!, if: :paranoid_deleted?
|
114
|
-
end
|
115
99
|
end
|
116
100
|
|
117
101
|
def default_slug_url_builder
|
@@ -124,7 +108,7 @@ module Mongoid
|
|
124
108
|
|
125
109
|
# Returns the scope key for indexing, considering associations
|
126
110
|
#
|
127
|
-
# @return [ Array<Document>, Document ]
|
111
|
+
# @return [ Array<Document>, Document ]
|
128
112
|
def slug_scope_key
|
129
113
|
return nil unless slug_scope
|
130
114
|
reflect_on_association(slug_scope).try(:key) || slug_scope
|
@@ -155,26 +139,13 @@ module Mongoid
|
|
155
139
|
current_scope || Criteria.new(self) # Use Mongoid::Slug::Criteria for slugged documents.
|
156
140
|
end
|
157
141
|
|
158
|
-
# Indicates whether or not the document includes Mongoid::Paranoia
|
159
|
-
#
|
160
|
-
# This can be replaced with .paranoid? method once the following PRs are merged:
|
161
|
-
# - https://github.com/simi/mongoid-paranoia/pull/19
|
162
|
-
# - https://github.com/haihappen/mongoid-paranoia/pull/3
|
163
|
-
#
|
164
|
-
# @return [ Array<Document>, Document ] Whether the document is paranoid
|
165
|
-
def is_paranoid_doc?
|
166
|
-
!!(defined?(::Mongoid::Paranoia) && self < ::Mongoid::Paranoia)
|
167
|
-
end
|
168
|
-
|
169
142
|
private
|
170
143
|
|
171
|
-
if Mongoid::Compatibility::Version.
|
172
|
-
Mongoid::Compatibility::Version.mongoid6? &&
|
173
|
-
Threaded.method(:current_scope).arity == -1
|
144
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer? && Threaded.method(:current_scope).arity == -1
|
174
145
|
def current_scope
|
175
146
|
Threaded.current_scope(self)
|
176
147
|
end
|
177
|
-
elsif Mongoid::Compatibility::Version.
|
148
|
+
elsif Mongoid::Compatibility::Version.mongoid5_or_newer?
|
178
149
|
def current_scope
|
179
150
|
Threaded.current_scope
|
180
151
|
end
|
@@ -223,7 +194,6 @@ module Mongoid
|
|
223
194
|
end
|
224
195
|
|
225
196
|
# Builds slug then atomically sets it in the database.
|
226
|
-
# This is used when working with the Mongoid::Paranoia restore callback.
|
227
197
|
#
|
228
198
|
# This method is adapted to use the :set method variants from both
|
229
199
|
# Mongoid 3 (two args) and Mongoid 4 (hash arg)
|
@@ -263,15 +233,7 @@ module Mongoid
|
|
263
233
|
|
264
234
|
# @return [Boolean] Whether the slug requires to be rebuilt
|
265
235
|
def slug_should_be_rebuilt?
|
266
|
-
|
267
|
-
end
|
268
|
-
|
269
|
-
# Indicates whether or not the document has been deleted in paranoid fashion
|
270
|
-
# Always returns false if the document is not paranoid
|
271
|
-
#
|
272
|
-
# @return [Boolean] Whether or not the document has been deleted in paranoid fashion
|
273
|
-
def paranoid_deleted?
|
274
|
-
!!(self.class.is_paranoid_doc? && !deleted_at.nil?)
|
236
|
+
new_record? || _slugs_changed? || slugged_attributes_changed?
|
275
237
|
end
|
276
238
|
|
277
239
|
def slugged_attributes_changed?
|
@@ -343,7 +305,7 @@ module Mongoid
|
|
343
305
|
|
344
306
|
def localized?
|
345
307
|
fields['_slugs'].options[:localize]
|
346
|
-
rescue
|
308
|
+
rescue StandardError
|
347
309
|
false
|
348
310
|
end
|
349
311
|
|
data/lib/mongoid/slug/index.rb
CHANGED
@@ -28,12 +28,6 @@ module Mongoid
|
|
28
28
|
# irrespective of how STI is defined in Mongoid, i.e. ANY child index will be applied to EVERY child.
|
29
29
|
# This can cause collisions using various combinations of scopes.
|
30
30
|
#
|
31
|
-
# 3) Paranoid docs rely on sparse indexes to exclude paranoid-deleted records
|
32
|
-
# from the unique index constraint (i.e. when _slugs is unset.) However, when
|
33
|
-
# using compound keys (`by_model_type` or `scope_key`), paranoid-deleted records
|
34
|
-
# can become inadvertently indexed when _slugs is unset, causing duplicates. This
|
35
|
-
# is already covered by #1 and #2 above.
|
36
|
-
#
|
37
31
|
# In the future, MongoDB may implement partial indexes or improve sparse index behavior.
|
38
32
|
# See: https://jira.mongodb.org/browse/SERVER-785
|
39
33
|
# https://jira.mongodb.org/browse/SERVER-13780
|
@@ -64,7 +64,8 @@ module Mongoid
|
|
64
64
|
|
65
65
|
def_delegators :@model, :slug_scope, :reflect_on_association, :read_attribute,
|
66
66
|
:check_against_id, :slug_reserved_words, :slug_url_builder, :collection_name,
|
67
|
-
:embedded?, :reflect_on_all_associations, :
|
67
|
+
:embedded?, :reflect_on_all_associations, :reflect_on_all_association,
|
68
|
+
:slug_by_model_type, :slug_max_length
|
68
69
|
|
69
70
|
def initialize(model)
|
70
71
|
@model = model
|
@@ -73,7 +74,13 @@ module Mongoid
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def metadata
|
76
|
-
@model.respond_to?(:
|
77
|
+
if @model.respond_to?(:_association)
|
78
|
+
@model.send(:_association)
|
79
|
+
elsif @model.respond_to?(:relation_metadata)
|
80
|
+
@model.relation_metadata
|
81
|
+
else
|
82
|
+
@model.metadata
|
83
|
+
end
|
77
84
|
end
|
78
85
|
|
79
86
|
def find_unique(attempt = nil)
|
@@ -96,9 +103,7 @@ module Mongoid
|
|
96
103
|
where_hash[scope] = model.try(:read_attribute, scope)
|
97
104
|
end
|
98
105
|
|
99
|
-
if slug_by_model_type
|
100
|
-
where_hash[:_type] = model.try(:read_attribute, :_type)
|
101
|
-
end
|
106
|
+
where_hash[:_type] = model.try(:read_attribute, :_type) if slug_by_model_type
|
102
107
|
|
103
108
|
@state = SlugState.new @_slug, uniqueness_scope.unscoped.where(where_hash), escaped_pattern
|
104
109
|
|
@@ -150,15 +155,17 @@ module Mongoid
|
|
150
155
|
end
|
151
156
|
|
152
157
|
if embedded?
|
153
|
-
parent_metadata =
|
158
|
+
parent_metadata = if Mongoid::Compatibility::Version.mongoid7_or_newer?
|
159
|
+
reflect_on_all_association(:embedded_in)[0]
|
160
|
+
else
|
161
|
+
reflect_on_all_associations(:embedded_in)[0]
|
162
|
+
end
|
154
163
|
return model._parent.send(parent_metadata.inverse_of || self.metadata.name)
|
155
164
|
end
|
156
165
|
|
157
166
|
# unless embedded or slug scope, return the deepest document superclass
|
158
167
|
appropriate_class = model.class
|
159
|
-
while appropriate_class.superclass.include?(Mongoid::Document)
|
160
|
-
appropriate_class = appropriate_class.superclass
|
161
|
-
end
|
168
|
+
appropriate_class = appropriate_class.superclass while appropriate_class.superclass.include?(Mongoid::Document)
|
162
169
|
appropriate_class
|
163
170
|
end
|
164
171
|
end
|
data/lib/mongoid/slug/version.rb
CHANGED
data/spec/models/author.rb
CHANGED
@@ -4,7 +4,7 @@ class AuthorPolymorphic
|
|
4
4
|
field :first_name
|
5
5
|
field :last_name
|
6
6
|
slug :first_name, :last_name, scope: :book_polymorphic
|
7
|
-
if Mongoid::Compatibility::Version.
|
7
|
+
if Mongoid::Compatibility::Version.mongoid6_or_newer?
|
8
8
|
belongs_to :book_polymorphic, required: false
|
9
9
|
else
|
10
10
|
belongs_to :book_polymorphic
|
data/spec/models/entity.rb
CHANGED
data/spec/models/person.rb
CHANGED
@@ -4,7 +4,7 @@ class Person
|
|
4
4
|
field :name
|
5
5
|
slug :name, permanent: true, scope: :author
|
6
6
|
embeds_many :relationships
|
7
|
-
if Mongoid::Compatibility::Version.
|
7
|
+
if Mongoid::Compatibility::Version.mongoid6_or_newer?
|
8
8
|
belongs_to :author, inverse_of: :characters, required: false
|
9
9
|
else
|
10
10
|
belongs_to :author, inverse_of: :characters
|
data/spec/mongoid/index_spec.rb
CHANGED
data/spec/mongoid/slug_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
module Mongoid
|
@@ -596,7 +595,7 @@ module Mongoid
|
|
596
595
|
end
|
597
596
|
|
598
597
|
context 'with a value exceeding mongodb max index key' do
|
599
|
-
if Mongoid::Compatibility::Version.
|
598
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
600
599
|
it 'errors with a model without a max length' do
|
601
600
|
expect do
|
602
601
|
Book.create!(title: 't' * 1025)
|
@@ -679,7 +678,7 @@ module Mongoid
|
|
679
678
|
expect(friend2.slugs).to include('foo-2')
|
680
679
|
end
|
681
680
|
|
682
|
-
%w
|
681
|
+
%w[new edit].each do |word|
|
683
682
|
it "should overwrite the default reserved words allowing the word '#{word}'" do
|
684
683
|
friend = Friend.create(name: word)
|
685
684
|
expect(friend.slugs).to include word
|
@@ -687,7 +686,7 @@ module Mongoid
|
|
687
686
|
end
|
688
687
|
end
|
689
688
|
context 'when the model does not have any reserved words set' do
|
690
|
-
%w
|
689
|
+
%w[new edit].each do |word|
|
691
690
|
it "does not use the default reserved word '#{word}'" do
|
692
691
|
book = Book.create(title: word)
|
693
692
|
expect(book.slugs).not_to include word
|
@@ -736,7 +735,7 @@ module Mongoid
|
|
736
735
|
|
737
736
|
context 'when called on an existing record with no slug' do
|
738
737
|
let!(:book_no_slug) do
|
739
|
-
if Mongoid::Compatibility::Version.
|
738
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
740
739
|
Book.collection.insert_one(title: 'Proust and Signs')
|
741
740
|
else
|
742
741
|
Book.collection.insert(title: 'Proust and Signs')
|
@@ -796,7 +795,7 @@ module Mongoid
|
|
796
795
|
it 'ensures uniqueness' do
|
797
796
|
book1 = Book.create(title: 'A Thousand Plateaus', slugs: ['not-what-you-expected'])
|
798
797
|
expect(book1.to_param).to eql 'not-what-you-expected'
|
799
|
-
if Mongoid::Compatibility::Version.
|
798
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
800
799
|
expect do
|
801
800
|
Book.create(title: 'A Thousand Plateaus', slugs: ['not-what-you-expected'])
|
802
801
|
end.to raise_error Mongo::Error::OperationFailure, /duplicate/
|
@@ -825,7 +824,7 @@ module Mongoid
|
|
825
824
|
Book.create(title: 'Sleepyhead')
|
826
825
|
book2 = Book.create(title: 'A Thousand Plateaus')
|
827
826
|
book2.slugs.push 'sleepyhead'
|
828
|
-
if Mongoid::Compatibility::Version.
|
827
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
829
828
|
expect do
|
830
829
|
book2.save
|
831
830
|
end.to raise_error Mongo::Error::OperationFailure, /duplicate/
|
@@ -885,13 +884,13 @@ module Mongoid
|
|
885
884
|
# Turn on i18n fallback
|
886
885
|
require 'i18n/backend/fallbacks'
|
887
886
|
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
888
|
-
::I18n.fallbacks[:nl] = [
|
887
|
+
::I18n.fallbacks[:nl] = %i[nl en]
|
889
888
|
expect(page.slug).to eql 'title-on-english'
|
890
889
|
fallback_slug = page.slug
|
891
890
|
|
892
891
|
fallback_page = begin
|
893
892
|
PageSlugLocalized.find(fallback_slug)
|
894
|
-
rescue
|
893
|
+
rescue StandardError
|
895
894
|
nil
|
896
895
|
end
|
897
896
|
expect(fallback_page).to eq(page)
|
@@ -916,17 +915,17 @@ module Mongoid
|
|
916
915
|
page = PageSlugLocalized.new
|
917
916
|
page.title_translations = { 'en' => 'Title on English', 'nl' => 'Title on Netherlands' }
|
918
917
|
page.save
|
919
|
-
expect(page
|
918
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english'], 'nl' => ['title-on-netherlands'])
|
920
919
|
end
|
921
920
|
|
922
921
|
it 'exact same title multiple langauges' do
|
923
922
|
page = PageSlugLocalized.new
|
924
923
|
page.title_translations = { 'en' => 'Title on English', 'nl' => 'Title on English' }
|
925
924
|
page.save
|
926
|
-
expect(page
|
925
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english'], 'nl' => ['title-on-english'])
|
927
926
|
|
928
927
|
page = PageSlugLocalized.create(title_translations: { 'en' => 'Title on English2', 'nl' => 'Title on English2' })
|
929
|
-
expect(page
|
928
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english2'], 'nl' => ['title-on-english2'])
|
930
929
|
end
|
931
930
|
|
932
931
|
it 'does not produce duplicate slugs' do
|
@@ -944,7 +943,7 @@ module Mongoid
|
|
944
943
|
I18n.locale = old_locale
|
945
944
|
page.title = 'Title on English'
|
946
945
|
expect(page.title_translations).to eq('en' => 'Title on English', 'nl' => 'Title on Netherlands')
|
947
|
-
expect(page
|
946
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english'], 'nl' => ['title-on-netherlands'])
|
948
947
|
end
|
949
948
|
|
950
949
|
it 'does not produce duplicate slugs when one has changed' do
|
@@ -964,8 +963,8 @@ module Mongoid
|
|
964
963
|
page.save
|
965
964
|
expect(page.title_translations).to eq('en' => 'Modified Title on English',
|
966
965
|
'nl' => 'Title on Netherlands')
|
967
|
-
expect(page
|
968
|
-
|
966
|
+
expect(page._slugs_translations).to eq('en' => ['modified-title-on-english'],
|
967
|
+
'nl' => ['title-on-netherlands'])
|
969
968
|
end
|
970
969
|
|
971
970
|
it 'does not produce duplicate slugs when transactions are set directly' do
|
@@ -974,7 +973,7 @@ module Mongoid
|
|
974
973
|
page.save
|
975
974
|
page.title_translations = { 'en' => 'Title on English', 'nl' => 'Title on Netherlands' }
|
976
975
|
page.save
|
977
|
-
expect(page
|
976
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english'], 'nl' => ['title-on-netherlands'])
|
978
977
|
end
|
979
978
|
|
980
979
|
it 'does not produce duplicate slugs when transactions are set directly and one has changed' do
|
@@ -984,15 +983,15 @@ module Mongoid
|
|
984
983
|
page.title_translations = { 'en' => 'Modified Title on English',
|
985
984
|
'nl' => 'Title on Netherlands' }
|
986
985
|
page.save
|
987
|
-
expect(page
|
988
|
-
|
986
|
+
expect(page._slugs_translations).to eq('en' => ['modified-title-on-english'],
|
987
|
+
'nl' => ['title-on-netherlands'])
|
989
988
|
end
|
990
989
|
|
991
990
|
it 'works with a custom slug strategy' do
|
992
991
|
page = PageSlugLocalizedCustom.new
|
993
992
|
page.title = 'a title for the slug'
|
994
993
|
page.save
|
995
|
-
expect(page
|
994
|
+
expect(page._slugs_translations).to eq('en' => ['a-title-for-the-slug'], 'nl' => ['a-title-for-the-slug'])
|
996
995
|
end
|
997
996
|
end
|
998
997
|
|
@@ -1048,13 +1047,13 @@ module Mongoid
|
|
1048
1047
|
# Turn on i18n fallback
|
1049
1048
|
require 'i18n/backend/fallbacks'
|
1050
1049
|
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
1051
|
-
::I18n.fallbacks[:nl] = [
|
1050
|
+
::I18n.fallbacks[:nl] = %i[nl en]
|
1052
1051
|
expect(page.slug).to eql 'title-on-english'
|
1053
1052
|
fallback_slug = page.slug
|
1054
1053
|
|
1055
1054
|
fallback_page = begin
|
1056
1055
|
PageSlugLocalizedHistory.find(fallback_slug)
|
1057
|
-
rescue
|
1056
|
+
rescue StandardError
|
1058
1057
|
nil
|
1059
1058
|
end
|
1060
1059
|
expect(fallback_page).to eq(page)
|
@@ -1067,8 +1066,8 @@ module Mongoid
|
|
1067
1066
|
page.title_translations = { 'en' => 'Modified Title on English',
|
1068
1067
|
'nl' => 'Modified Title on Netherlands' }
|
1069
1068
|
page.save
|
1070
|
-
expect(page
|
1071
|
-
|
1069
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english', 'modified-title-on-english'],
|
1070
|
+
'nl' => ['title-on-netherlands', 'modified-title-on-netherlands'])
|
1072
1071
|
end
|
1073
1072
|
|
1074
1073
|
it 'does not produce duplicate slugs' do
|
@@ -1086,7 +1085,7 @@ module Mongoid
|
|
1086
1085
|
I18n.locale = old_locale
|
1087
1086
|
page.title = 'Title on English'
|
1088
1087
|
expect(page.title_translations).to eq('en' => 'Title on English', 'nl' => 'Title on Netherlands')
|
1089
|
-
expect(page
|
1088
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english'], 'nl' => ['title-on-netherlands'])
|
1090
1089
|
end
|
1091
1090
|
|
1092
1091
|
it 'does not produce duplicate slugs when one has changed' do
|
@@ -1106,8 +1105,8 @@ module Mongoid
|
|
1106
1105
|
page.save
|
1107
1106
|
expect(page.title_translations).to eq('en' => 'Modified Title on English',
|
1108
1107
|
'nl' => 'Title on Netherlands')
|
1109
|
-
expect(page
|
1110
|
-
|
1108
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english', 'modified-title-on-english'],
|
1109
|
+
'nl' => ['title-on-netherlands'])
|
1111
1110
|
end
|
1112
1111
|
|
1113
1112
|
it 'does not produce duplicate slugs when transactions are set directly' do
|
@@ -1116,7 +1115,7 @@ module Mongoid
|
|
1116
1115
|
page.save
|
1117
1116
|
page.title_translations = { 'en' => 'Title on English', 'nl' => 'Title on Netherlands' }
|
1118
1117
|
page.save
|
1119
|
-
expect(page
|
1118
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english'], 'nl' => ['title-on-netherlands'])
|
1120
1119
|
end
|
1121
1120
|
|
1122
1121
|
it 'does not produce duplicate slugs when transactions are set directly and one has changed' do
|
@@ -1125,8 +1124,8 @@ module Mongoid
|
|
1125
1124
|
page.save
|
1126
1125
|
page.title_translations = { 'en' => 'Modified Title on English', 'nl' => 'Title on Netherlands' }
|
1127
1126
|
page.save
|
1128
|
-
expect(page
|
1129
|
-
|
1127
|
+
expect(page._slugs_translations).to eq('en' => ['title-on-english', 'modified-title-on-english'],
|
1128
|
+
'nl' => ['title-on-netherlands'])
|
1130
1129
|
end
|
1131
1130
|
end
|
1132
1131
|
|
data/spec/spec_helper.rb
CHANGED
@@ -6,13 +6,10 @@ require 'awesome_print'
|
|
6
6
|
require 'active_support'
|
7
7
|
require 'active_support/deprecation'
|
8
8
|
require 'mongoid'
|
9
|
-
require 'mongoid/paranoia'
|
10
9
|
require 'rspec/its'
|
11
10
|
require 'mongoid/compatibility'
|
12
11
|
|
13
|
-
require File.expand_path '
|
14
|
-
|
15
|
-
require 'mongoid-observers' unless Mongoid.const_defined?(:Observer)
|
12
|
+
require File.expand_path '../lib/mongoid/slug', __dir__
|
16
13
|
|
17
14
|
module Mongoid
|
18
15
|
module Slug
|
@@ -32,24 +29,21 @@ Mongoid.configure do |config|
|
|
32
29
|
config.connect_to database_id
|
33
30
|
end
|
34
31
|
|
35
|
-
%w
|
32
|
+
%w[models shared].each do |dir|
|
36
33
|
Dir["./spec/#{dir}/*.rb"].each { |f| require f }
|
37
34
|
end
|
38
35
|
|
39
|
-
I18n.available_locales = [
|
36
|
+
I18n.available_locales = %i[en nl]
|
40
37
|
|
41
38
|
RSpec.configure do |c|
|
42
39
|
c.raise_errors_for_deprecations!
|
43
40
|
|
44
41
|
c.before :all do
|
45
42
|
Mongoid.logger.level = Logger::INFO
|
46
|
-
|
47
|
-
Mongo::Logger.logger.level = Logger::INFO
|
48
|
-
end
|
43
|
+
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
49
44
|
end
|
50
45
|
|
51
46
|
c.before(:each) do
|
52
|
-
Mongoid.purge!
|
53
47
|
Author.create_indexes
|
54
48
|
Book.create_indexes
|
55
49
|
AuthorPolymorphic.create_indexes
|
@@ -57,7 +51,7 @@ RSpec.configure do |c|
|
|
57
51
|
Mongoid::IdentityMap.clear if defined?(Mongoid::IdentityMap)
|
58
52
|
end
|
59
53
|
|
60
|
-
c.after(:
|
54
|
+
c.after(:each) do
|
61
55
|
if Mongoid::Compatibility::Version.mongoid3? || Mongoid::Compatibility::Version.mongoid4?
|
62
56
|
Mongoid.default_session.drop
|
63
57
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-slug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Saebjoernsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: awesome_print
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: guard-rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec
|
98
|
+
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rspec-its
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -148,7 +148,6 @@ files:
|
|
148
148
|
- lib/mongoid/slug.rb
|
149
149
|
- lib/mongoid/slug/criteria.rb
|
150
150
|
- lib/mongoid/slug/index.rb
|
151
|
-
- lib/mongoid/slug/paranoia.rb
|
152
151
|
- lib/mongoid/slug/railtie.rb
|
153
152
|
- lib/mongoid/slug/slug_id_strategy.rb
|
154
153
|
- lib/mongoid/slug/unique_slug.rb
|
@@ -164,7 +163,6 @@ files:
|
|
164
163
|
- spec/models/book.rb
|
165
164
|
- spec/models/book_polymorphic.rb
|
166
165
|
- spec/models/caption.rb
|
167
|
-
- spec/models/document_paranoid.rb
|
168
166
|
- spec/models/entity.rb
|
169
167
|
- spec/models/friend.rb
|
170
168
|
- spec/models/incorrect_slug_persistence.rb
|
@@ -175,8 +173,6 @@ files:
|
|
175
173
|
- spec/models/page_slug_localized.rb
|
176
174
|
- spec/models/page_slug_localized_custom.rb
|
177
175
|
- spec/models/page_slug_localized_history.rb
|
178
|
-
- spec/models/paranoid_document.rb
|
179
|
-
- spec/models/paranoid_permanent.rb
|
180
176
|
- spec/models/partner.rb
|
181
177
|
- spec/models/person.rb
|
182
178
|
- spec/models/relationship.rb
|
@@ -185,7 +181,6 @@ files:
|
|
185
181
|
- spec/models/without_slug.rb
|
186
182
|
- spec/mongoid/criteria_spec.rb
|
187
183
|
- spec/mongoid/index_spec.rb
|
188
|
-
- spec/mongoid/paranoia_spec.rb
|
189
184
|
- spec/mongoid/slug_spec.rb
|
190
185
|
- spec/shared/indexes.rb
|
191
186
|
- spec/spec_helper.rb
|
@@ -210,43 +205,39 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
205
|
version: '0'
|
211
206
|
requirements: []
|
212
207
|
rubyforge_project: mongoid-slug
|
213
|
-
rubygems_version: 2.6
|
208
|
+
rubygems_version: 2.7.6
|
214
209
|
signing_key:
|
215
210
|
specification_version: 4
|
216
211
|
summary: Mongoid URL slugs
|
217
212
|
test_files:
|
218
|
-
- spec/
|
213
|
+
- spec/mongoid/criteria_spec.rb
|
214
|
+
- spec/mongoid/slug_spec.rb
|
215
|
+
- spec/mongoid/index_spec.rb
|
216
|
+
- spec/spec_helper.rb
|
217
|
+
- spec/tasks/mongoid_slug_rake_spec.rb
|
218
|
+
- spec/shared/indexes.rb
|
219
219
|
- spec/models/article.rb
|
220
|
-
- spec/models/
|
221
|
-
- spec/models/artwork.rb
|
222
|
-
- spec/models/author.rb
|
223
|
-
- spec/models/author_polymorphic.rb
|
220
|
+
- spec/models/integer_id.rb
|
224
221
|
- spec/models/book.rb
|
225
|
-
- spec/models/book_polymorphic.rb
|
226
|
-
- spec/models/caption.rb
|
227
|
-
- spec/models/document_paranoid.rb
|
228
222
|
- spec/models/entity.rb
|
229
|
-
- spec/models/
|
230
|
-
- spec/models/
|
231
|
-
- spec/models/
|
232
|
-
- spec/models/
|
223
|
+
- spec/models/caption.rb
|
224
|
+
- spec/models/without_slug.rb
|
225
|
+
- spec/models/artist.rb
|
226
|
+
- spec/models/string_id.rb
|
233
227
|
- spec/models/page.rb
|
234
|
-
- spec/models/page_localize.rb
|
235
228
|
- spec/models/page_slug_localized.rb
|
236
|
-
- spec/models/
|
237
|
-
- spec/models/
|
238
|
-
- spec/models/
|
239
|
-
- spec/models/
|
229
|
+
- spec/models/author.rb
|
230
|
+
- spec/models/friend.rb
|
231
|
+
- spec/models/subject.rb
|
232
|
+
- spec/models/magazine.rb
|
240
233
|
- spec/models/partner.rb
|
234
|
+
- spec/models/alias.rb
|
241
235
|
- spec/models/person.rb
|
236
|
+
- spec/models/page_slug_localized_custom.rb
|
242
237
|
- spec/models/relationship.rb
|
243
|
-
- spec/models/
|
244
|
-
- spec/models/
|
245
|
-
- spec/models/
|
246
|
-
- spec/
|
247
|
-
- spec/
|
248
|
-
- spec/
|
249
|
-
- spec/mongoid/slug_spec.rb
|
250
|
-
- spec/shared/indexes.rb
|
251
|
-
- spec/spec_helper.rb
|
252
|
-
- spec/tasks/mongoid_slug_rake_spec.rb
|
238
|
+
- spec/models/book_polymorphic.rb
|
239
|
+
- spec/models/page_slug_localized_history.rb
|
240
|
+
- spec/models/author_polymorphic.rb
|
241
|
+
- spec/models/incorrect_slug_persistence.rb
|
242
|
+
- spec/models/page_localize.rb
|
243
|
+
- spec/models/artwork.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Mongoid
|
2
|
-
module Slug
|
3
|
-
# Lightweight compatibility shim which adds the :restore callback to
|
4
|
-
# older versions of Mongoid::Paranoia
|
5
|
-
module Paranoia
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
define_model_callbacks :restore
|
10
|
-
|
11
|
-
def restore_with_callbacks
|
12
|
-
run_callbacks(:restore) do
|
13
|
-
restore_without_callbacks
|
14
|
-
end
|
15
|
-
end
|
16
|
-
alias_method_chain :restore, :callbacks
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,230 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'Mongoid::Paranoia with Mongoid::Slug' do
|
5
|
-
let(:paranoid_doc) { ParanoidDocument.create!(title: 'slug') }
|
6
|
-
let(:paranoid_doc_2) { ParanoidDocument.create!(title: 'slug') }
|
7
|
-
let(:paranoid_perm) { ParanoidPermanent.create!(title: 'slug') }
|
8
|
-
let(:paranoid_perm_2) { ParanoidPermanent.create!(title: 'slug') }
|
9
|
-
let(:non_paranoid_doc) { Article.create!(title: 'slug') }
|
10
|
-
subject { paranoid_doc }
|
11
|
-
|
12
|
-
describe '.paranoid?' do
|
13
|
-
context 'when Mongoid::Paranoia is included' do
|
14
|
-
subject { paranoid_doc.class }
|
15
|
-
specify { expect(subject.is_paranoid_doc?).to be true }
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when Mongoid::Paranoia not included' do
|
19
|
-
subject { non_paranoid_doc.class }
|
20
|
-
specify { expect(subject.is_paranoid_doc?).to be false }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#paranoid_deleted?' do
|
25
|
-
context 'when Mongoid::Paranoia is included' do
|
26
|
-
context 'when not destroyed' do
|
27
|
-
specify { expect(subject.paranoid_deleted?).to be false }
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'when destroyed' do
|
31
|
-
before { subject.destroy }
|
32
|
-
specify { expect(subject.paranoid_deleted?).to be true }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'when Mongoid::Paranoia not included' do
|
37
|
-
subject { non_paranoid_doc }
|
38
|
-
specify { expect(subject.paranoid_deleted?).to be false }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'restore callbacks' do
|
43
|
-
context 'when Mongoid::Paranoia is included' do
|
44
|
-
subject { paranoid_doc.class }
|
45
|
-
it { is_expected.to respond_to(:before_restore) }
|
46
|
-
it { is_expected.to respond_to(:after_restore) }
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'when Mongoid::Paranoia not included' do
|
50
|
-
it { is_expected.to_not respond_to(:before_restore) }
|
51
|
-
it { is_expected.to_not respond_to(:after_restore) }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe 'index' do
|
56
|
-
context 'simple index' do
|
57
|
-
before { ParanoidDocument.create_indexes }
|
58
|
-
after { ParanoidDocument.remove_indexes }
|
59
|
-
subject { ParanoidDocument }
|
60
|
-
|
61
|
-
it_should_behave_like 'has an index', { _slugs: 1 }, unique: true, sparse: true
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'compound index' do
|
65
|
-
before { ParanoidPermanent.create_indexes }
|
66
|
-
after { ParanoidPermanent.remove_indexes }
|
67
|
-
subject { ParanoidPermanent }
|
68
|
-
|
69
|
-
it_should_behave_like 'has an index', { foo: 1, _slugs: 1 }, unique: nil, sparse: nil
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
shared_examples_for 'paranoid slugs' do
|
74
|
-
context 'querying' do
|
75
|
-
it 'returns paranoid_doc for correct slug' do
|
76
|
-
expect(subject.class.find(subject.slug)).to eq subject
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'delete (callbacks not fired)' do
|
81
|
-
before { subject.delete }
|
82
|
-
|
83
|
-
it 'retains slug value' do
|
84
|
-
expect(subject.slug).to eq 'slug'
|
85
|
-
expect(subject.class.unscoped.find('slug')).to eq subject
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'destroy' do
|
90
|
-
before { subject.destroy }
|
91
|
-
|
92
|
-
it 'unsets slug value when destroyed' do
|
93
|
-
expect(subject._slugs).to eq []
|
94
|
-
expect(subject.slug).to be_nil
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'persists the removed slug' do
|
98
|
-
expect(subject.reload._slugs).to be nil
|
99
|
-
expect(subject.reload.slug).to eq subject._id.to_s
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'persists the removed slug in the database' do
|
103
|
-
expect(subject.class.unscoped.exists(_slugs: false).first).to eq subject
|
104
|
-
expect { subject.class.unscoped.find('slug') }.to raise_error(Mongoid::Errors::DocumentNotFound)
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'when saving the doc again' do
|
108
|
-
before { subject.save }
|
109
|
-
|
110
|
-
it 'should have the default slug value' do
|
111
|
-
expect(subject._slugs).to eq []
|
112
|
-
expect(subject.slug).to be_nil
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'the slug remains unset in the database' do
|
116
|
-
expect(subject.class.unscoped.exists(_slugs: false).first).to eq subject
|
117
|
-
expect { subject.class.unscoped.find('slug') }.to raise_error(Mongoid::Errors::DocumentNotFound)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context 'restore' do
|
123
|
-
before do
|
124
|
-
subject.destroy
|
125
|
-
subject.restore
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'resets slug value when restored' do
|
129
|
-
expect(subject.slug).to eq 'slug'
|
130
|
-
expect(subject.reload.slug).to eq 'slug'
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'multiple documents' do
|
135
|
-
it 'new documents should be able to use the slug of destroyed documents' do
|
136
|
-
expect(subject.slug).to eq 'slug'
|
137
|
-
subject.destroy
|
138
|
-
expect(subject.reload.slug).to eq subject._id.to_s
|
139
|
-
expect(other_doc.slug).to eq 'slug'
|
140
|
-
subject.restore
|
141
|
-
expect(subject.slug).to eq 'slug-1'
|
142
|
-
expect(subject.reload.slug).to eq 'slug-1'
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should allow multiple documents to be destroyed without index conflict' do
|
146
|
-
expect(subject.slug).to eq 'slug'
|
147
|
-
subject.destroy
|
148
|
-
expect(subject.reload.slug).to eq subject._id.to_s
|
149
|
-
expect(other_doc.slug).to eq 'slug'
|
150
|
-
other_doc.destroy
|
151
|
-
expect(other_doc.reload.slug).to eq other_doc._id.to_s
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
[ParanoidDocument, DocumentParanoid].each do |paranoid_klass|
|
157
|
-
context paranoid_klass.to_s do
|
158
|
-
let(:paranoid_doc) { paranoid_klass.create!(title: 'slug') }
|
159
|
-
let(:non_paranoid_doc) { Article.create!(title: 'slug') }
|
160
|
-
|
161
|
-
subject { paranoid_doc }
|
162
|
-
|
163
|
-
describe '.paranoid?' do
|
164
|
-
context 'when Mongoid::Paranoia is included' do
|
165
|
-
subject { paranoid_doc.class }
|
166
|
-
its(:is_paranoid_doc?) { is_expected.to be_truthy }
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'when Mongoid::Paranoia not included' do
|
170
|
-
subject { non_paranoid_doc.class }
|
171
|
-
its(:is_paranoid_doc?) { is_expected.to be_falsey }
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe '#paranoid_deleted?' do
|
176
|
-
context 'when Mongoid::Paranoia is included' do
|
177
|
-
context 'when not destroyed' do
|
178
|
-
its(:paranoid_deleted?) { is_expected.to be_falsey }
|
179
|
-
end
|
180
|
-
|
181
|
-
context 'when destroyed' do
|
182
|
-
before { subject.destroy }
|
183
|
-
its(:paranoid_deleted?) { is_expected.to be_truthy }
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'when Mongoid::Paranoia not included' do
|
188
|
-
subject { non_paranoid_doc }
|
189
|
-
its(:paranoid_deleted?) { is_expected.to be_falsey }
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe 'restore callbacks' do
|
194
|
-
context 'when Mongoid::Paranoia is included' do
|
195
|
-
subject { paranoid_doc.class }
|
196
|
-
it { is_expected.to respond_to(:before_restore) }
|
197
|
-
it { is_expected.to respond_to(:after_restore) }
|
198
|
-
end
|
199
|
-
|
200
|
-
context 'when Mongoid::Paranoia not included' do
|
201
|
-
it { is_expected.not_to respond_to(:before_restore) }
|
202
|
-
it { is_expected.not_to respond_to(:after_restore) }
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe 'index' do
|
207
|
-
before { paranoid_klass.create_indexes }
|
208
|
-
after { paranoid_klass.remove_indexes }
|
209
|
-
subject { paranoid_klass }
|
210
|
-
|
211
|
-
it_should_behave_like 'has an index', { _slugs: 1 }, unique: true, sparse: true
|
212
|
-
end
|
213
|
-
|
214
|
-
context 'non-permanent slug' do
|
215
|
-
let(:paranoid_doc_2) { paranoid_klass.create!(title: 'slug') }
|
216
|
-
subject { paranoid_doc }
|
217
|
-
let(:other_doc) { paranoid_doc_2 }
|
218
|
-
it_behaves_like 'paranoid slugs'
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context 'permanent slug' do
|
224
|
-
let(:paranoid_perm) { ParanoidPermanent.create!(title: 'slug') }
|
225
|
-
let(:paranoid_perm_2) { ParanoidPermanent.create!(title: 'slug') }
|
226
|
-
subject { paranoid_perm }
|
227
|
-
let(:other_doc) { paranoid_perm_2 }
|
228
|
-
it_behaves_like 'paranoid slugs'
|
229
|
-
end
|
230
|
-
end
|