mongoid-slug 5.3.0 → 6.0.1

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.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +20 -20
  3. data/README.md +361 -360
  4. data/lib/mongoid/slug.rb +328 -366
  5. data/lib/mongoid/slug/criteria.rb +107 -107
  6. data/lib/mongoid/slug/{index.rb → index_builder.rb} +67 -51
  7. data/lib/mongoid/slug/railtie.rb +9 -9
  8. data/lib/mongoid/slug/slug_id_strategy.rb +3 -3
  9. data/lib/mongoid/slug/unique_slug.rb +173 -154
  10. data/lib/mongoid/slug/version.rb +5 -5
  11. data/lib/mongoid_slug.rb +2 -2
  12. data/lib/tasks/mongoid_slug.rake +15 -19
  13. data/spec/models/alias.rb +6 -6
  14. data/spec/models/article.rb +9 -9
  15. data/spec/models/artist.rb +8 -8
  16. data/spec/models/artwork.rb +10 -10
  17. data/spec/models/author.rb +15 -15
  18. data/spec/models/author_polymorphic.rb +15 -15
  19. data/spec/models/book.rb +12 -12
  20. data/spec/models/book_polymorphic.rb +12 -12
  21. data/spec/models/caption.rb +17 -17
  22. data/spec/models/entity.rb +11 -12
  23. data/spec/models/friend.rb +7 -7
  24. data/spec/models/incorrect_slug_persistence.rb +9 -9
  25. data/spec/models/integer_id.rb +9 -9
  26. data/spec/models/magazine.rb +7 -7
  27. data/spec/models/page.rb +9 -9
  28. data/spec/models/page_localize.rb +9 -9
  29. data/spec/models/page_slug_localized.rb +9 -9
  30. data/spec/models/page_slug_localized_custom.rb +10 -10
  31. data/spec/models/page_slug_localized_history.rb +9 -9
  32. data/spec/models/partner.rb +7 -7
  33. data/spec/models/person.rb +12 -12
  34. data/spec/models/relationship.rb +8 -8
  35. data/spec/models/string_id.rb +9 -9
  36. data/spec/models/subject.rb +7 -7
  37. data/spec/models/without_slug.rb +5 -5
  38. data/spec/mongoid/criteria_spec.rb +207 -208
  39. data/spec/mongoid/index_builder_spec.rb +105 -0
  40. data/spec/mongoid/slug_spec.rb +1175 -1170
  41. data/spec/shared/indexes.rb +41 -41
  42. data/spec/spec_helper.rb +61 -67
  43. data/spec/tasks/mongoid_slug_rake_spec.rb +73 -73
  44. metadata +14 -24
  45. data/lib/mongoid/slug/paranoia.rb +0 -20
  46. data/spec/models/document_paranoid.rb +0 -9
  47. data/spec/models/paranoid_document.rb +0 -8
  48. data/spec/models/paranoid_permanent.rb +0 -10
  49. data/spec/mongoid/index_spec.rb +0 -34
  50. data/spec/mongoid/paranoia_spec.rb +0 -230
@@ -1,41 +1,41 @@
1
- shared_context 'with an index' do |key|
2
- if Mongoid::Compatibility::Version.mongoid3?
3
- let(:index) { subject.index_options[key] }
4
- let(:index_keys) { key }
5
- let(:index_options) { index }
6
- else
7
- let(:index) { subject.index_specifications.detect { |spec| spec.key == key } }
8
- let(:index_keys) { index.key }
9
- let(:index_options) { index.options }
10
- end
11
- end
12
-
13
- shared_examples 'has an index' do |key, options|
14
- include_context 'with an index', key
15
-
16
- it "has a #{[key, options].compact.join(', ')} index" do
17
- expect(index).not_to be_nil
18
- end
19
-
20
- it 'has the correct order of keys' do
21
- expect(index_keys.keys).to eq key.keys
22
- end
23
-
24
- it 'has the correct order of key values' do
25
- expect(index_keys.values).to eq key.values
26
- end
27
-
28
- it 'matches option values' do
29
- options.each_pair do |name, value|
30
- expect(index_options[name]).to eq(value)
31
- end
32
- end
33
- end
34
-
35
- shared_examples 'does not have an index' do |key|
36
- include_context 'with an index', key
37
-
38
- it "does not have the #{key} index" do
39
- expect(index).to be nil
40
- end
41
- end
1
+ shared_context 'with an index' do |key|
2
+ if Mongoid::Compatibility::Version.mongoid3?
3
+ let(:index) { subject.index_options[key] }
4
+ let(:index_keys) { key }
5
+ let(:index_options) { index }
6
+ else
7
+ let(:index) { subject.index_specifications.detect { |spec| spec.key == key } }
8
+ let(:index_keys) { index.key }
9
+ let(:index_options) { index.options }
10
+ end
11
+ end
12
+
13
+ shared_examples 'has an index' do |key, options|
14
+ include_context 'with an index', key
15
+
16
+ it "has a #{[key, options].compact.join(', ')} index" do
17
+ expect(index).not_to be_nil
18
+ end
19
+
20
+ it 'has the correct order of keys' do
21
+ expect(index_keys.keys).to eq key.keys
22
+ end
23
+
24
+ it 'has the correct order of key values' do
25
+ expect(index_keys.values).to eq key.values
26
+ end
27
+
28
+ it 'matches option values' do
29
+ options.each_pair do |name, value|
30
+ expect(index_options[name]).to eq(value)
31
+ end
32
+ end
33
+ end
34
+
35
+ shared_examples 'does not have an index' do |key|
36
+ include_context 'with an index', key
37
+
38
+ it "does not have the #{key} index" do
39
+ expect(index).to be nil
40
+ end
41
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,67 +1,61 @@
1
- require 'bundler/setup'
2
-
3
- require 'rspec'
4
- require 'uuid'
5
- require 'awesome_print'
6
- require 'active_support'
7
- require 'active_support/deprecation'
8
- require 'mongoid'
9
- require 'mongoid/paranoia'
10
- require 'rspec/its'
11
- require 'mongoid/compatibility'
12
-
13
- require File.expand_path '../../lib/mongoid/slug', __FILE__
14
-
15
- require 'mongoid-observers' unless Mongoid.const_defined?(:Observer)
16
-
17
- module Mongoid
18
- module Slug
19
- module UuidIdStrategy
20
- def self.call(id)
21
- id =~ /\A([0-9a-fA-F]){8}-(([0-9a-fA-F]){4}-){3}([0-9a-fA-F]){12}\z/
22
- end
23
- end
24
- end
25
- end
26
-
27
- def database_id
28
- ENV['CI'] ? "mongoid_slug_#{Process.pid}" : 'mongoid_slug_test'
29
- end
30
-
31
- Mongoid.configure do |config|
32
- config.connect_to database_id
33
- end
34
-
35
- %w(models shared).each do |dir|
36
- Dir["./spec/#{dir}/*.rb"].each { |f| require f }
37
- end
38
-
39
- I18n.available_locales = [:en, :nl]
40
-
41
- RSpec.configure do |c|
42
- c.raise_errors_for_deprecations!
43
-
44
- c.before :all do
45
- Mongoid.logger.level = Logger::INFO
46
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
47
- Mongo::Logger.logger.level = Logger::INFO
48
- end
49
- end
50
-
51
- c.before(:each) do
52
- Mongoid.purge!
53
- Author.create_indexes
54
- Book.create_indexes
55
- AuthorPolymorphic.create_indexes
56
- BookPolymorphic.create_indexes
57
- Mongoid::IdentityMap.clear if defined?(Mongoid::IdentityMap)
58
- end
59
-
60
- c.after(:all) do
61
- if Mongoid::Compatibility::Version.mongoid3? || Mongoid::Compatibility::Version.mongoid4?
62
- Mongoid.default_session.drop
63
- else
64
- Mongoid::Clients.default.database.drop
65
- end
66
- end
67
- end
1
+ require 'bundler/setup'
2
+
3
+ require 'rspec'
4
+ require 'uuid'
5
+ require 'awesome_print'
6
+ require 'active_support'
7
+ require 'active_support/deprecation'
8
+ require 'mongoid'
9
+ require 'rspec/its'
10
+ require 'mongoid/compatibility'
11
+
12
+ require File.expand_path '../lib/mongoid/slug', __dir__
13
+
14
+ module Mongoid
15
+ module Slug
16
+ module UuidIdStrategy
17
+ def self.call(id)
18
+ id =~ /\A([0-9a-fA-F]){8}-(([0-9a-fA-F]){4}-){3}([0-9a-fA-F]){12}\z/
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def database_id
25
+ ENV['CI'] ? "mongoid_slug_#{Process.pid}" : 'mongoid_slug_test'
26
+ end
27
+
28
+ Mongoid.configure do |config|
29
+ config.connect_to database_id
30
+ end
31
+
32
+ %w[models shared].each do |dir|
33
+ Dir["./spec/#{dir}/*.rb"].each { |f| require f }
34
+ end
35
+
36
+ I18n.available_locales = %i[en nl]
37
+
38
+ RSpec.configure do |c|
39
+ c.raise_errors_for_deprecations!
40
+
41
+ c.before :all do
42
+ Mongoid.logger.level = Logger::INFO
43
+ Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5_or_newer?
44
+ end
45
+
46
+ c.before(:each) do
47
+ Author.create_indexes
48
+ Book.create_indexes
49
+ AuthorPolymorphic.create_indexes
50
+ BookPolymorphic.create_indexes
51
+ Mongoid::IdentityMap.clear if defined?(Mongoid::IdentityMap)
52
+ end
53
+
54
+ c.after(:each) do
55
+ if Mongoid::Compatibility::Version.mongoid3? || Mongoid::Compatibility::Version.mongoid4?
56
+ Mongoid.default_session.drop
57
+ else
58
+ Mongoid::Clients.default.database.drop
59
+ end
60
+ end
61
+ end
@@ -1,73 +1,73 @@
1
- require 'spec_helper'
2
- require 'rake'
3
-
4
- describe 'mongoid_slug:set' do
5
- before :all do
6
- load File.expand_path('../../../lib/tasks/mongoid_slug.rake', __FILE__)
7
- Rake::Task.define_task(:environment)
8
- end
9
-
10
- context 'when models parameter is passed' do
11
- before :all do
12
- UninitalizedSlugFirst = Class.new do
13
- include Mongoid::Document
14
- field :name, type: String
15
- store_in collection: 'uninitalized_slug_first'
16
- end
17
- UninitalizedSlugSecond = Class.new do
18
- include Mongoid::Document
19
- field :name, type: String
20
- store_in collection: 'uninitalized_slug_second'
21
- end
22
- end
23
-
24
- it 'goes though all documents of passed models and sets slug if not already set' do
25
- uninitalized_slug1 = UninitalizedSlugFirst.create(name: 'uninitalized-slug1')
26
- uninitalized_slug2 = UninitalizedSlugSecond.create(name: 'uninitalized-slug2')
27
-
28
- UninitalizedSlugFirst.class_eval do
29
- include Mongoid::Slug
30
- slug :name
31
- end
32
- UninitalizedSlugSecond.class_eval do
33
- include Mongoid::Slug
34
- slug :name
35
- end
36
-
37
- expect(uninitalized_slug1.slugs).to be_nil
38
- expect(uninitalized_slug2.slugs).to be_nil
39
-
40
- Rake::Task['mongoid_slug:set'].reenable
41
- Rake::Task['mongoid_slug:set'].invoke('UninitalizedSlugFirst')
42
-
43
- expect(uninitalized_slug1.reload.slugs).to eq(['uninitalized-slug1'])
44
- expect(uninitalized_slug2.reload.slugs).to be nil
45
- end
46
- end
47
-
48
- context 'when models parameter is not passed' do
49
- before :all do
50
- UninitalizedSlugThird = Class.new do
51
- include Mongoid::Document
52
- field :name, type: String
53
- store_in collection: 'uninitalized_slug_third'
54
- end
55
- end
56
-
57
- it 'goes though all documents and sets slug if not already set' do
58
- uninitalized_slug3 = UninitalizedSlugThird.create(name: 'uninitalized-slug3')
59
-
60
- UninitalizedSlugThird.class_eval do
61
- include Mongoid::Slug
62
- slug :name
63
- end
64
-
65
- expect(uninitalized_slug3.slugs).to be_nil
66
-
67
- Rake::Task['mongoid_slug:set'].reenable
68
- Rake::Task['mongoid_slug:set'].invoke
69
-
70
- expect(uninitalized_slug3.reload.slugs).to eq(['uninitalized-slug3'])
71
- end
72
- end
73
- end
1
+ require 'spec_helper'
2
+ require 'rake'
3
+
4
+ describe 'mongoid_slug:set' do
5
+ before :all do
6
+ load File.expand_path('../../lib/tasks/mongoid_slug.rake', __dir__)
7
+ Rake::Task.define_task(:environment)
8
+ end
9
+
10
+ context 'when models parameter is passed' do
11
+ before :all do
12
+ UninitalizedSlugFirst = Class.new do
13
+ include Mongoid::Document
14
+ field :name, type: String
15
+ store_in collection: 'uninitalized_slug_first'
16
+ end
17
+ UninitalizedSlugSecond = Class.new do
18
+ include Mongoid::Document
19
+ field :name, type: String
20
+ store_in collection: 'uninitalized_slug_second'
21
+ end
22
+ end
23
+
24
+ it 'goes though all documents of passed models and sets slug if not already set' do
25
+ uninitalized_slug1 = UninitalizedSlugFirst.create(name: 'uninitalized-slug1')
26
+ uninitalized_slug2 = UninitalizedSlugSecond.create(name: 'uninitalized-slug2')
27
+
28
+ UninitalizedSlugFirst.class_eval do
29
+ include Mongoid::Slug
30
+ slug :name
31
+ end
32
+ UninitalizedSlugSecond.class_eval do
33
+ include Mongoid::Slug
34
+ slug :name
35
+ end
36
+
37
+ expect(uninitalized_slug1.slugs).to be_nil
38
+ expect(uninitalized_slug2.slugs).to be_nil
39
+
40
+ Rake::Task['mongoid_slug:set'].reenable
41
+ Rake::Task['mongoid_slug:set'].invoke('UninitalizedSlugFirst')
42
+
43
+ expect(uninitalized_slug1.reload.slugs).to eq(['uninitalized-slug1'])
44
+ expect(uninitalized_slug2.reload.slugs).to be nil
45
+ end
46
+ end
47
+
48
+ context 'when models parameter is not passed' do
49
+ before :all do
50
+ UninitalizedSlugThird = Class.new do
51
+ include Mongoid::Document
52
+ field :name, type: String
53
+ store_in collection: 'uninitalized_slug_third'
54
+ end
55
+ end
56
+
57
+ it 'goes though all documents and sets slug if not already set' do
58
+ uninitalized_slug3 = UninitalizedSlugThird.create(name: 'uninitalized-slug3')
59
+
60
+ UninitalizedSlugThird.class_eval do
61
+ include Mongoid::Slug
62
+ slug :name
63
+ end
64
+
65
+ expect(uninitalized_slug3.slugs).to be_nil
66
+
67
+ Rake::Task['mongoid_slug:set'].reenable
68
+ Rake::Task['mongoid_slug:set'].invoke
69
+
70
+ expect(uninitalized_slug3.reload.slugs).to eq(['uninitalized-slug3'])
71
+ end
72
+ end
73
+ end
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: 5.3.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Saebjoernsen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-11 00:00:00.000000000 Z
11
+ date: 2021-08-11 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: guard-rspec
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: rake
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: rspec
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-its
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: awesome_print
112
+ name: rspec-its
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -147,8 +147,7 @@ files:
147
147
  - README.md
148
148
  - lib/mongoid/slug.rb
149
149
  - lib/mongoid/slug/criteria.rb
150
- - lib/mongoid/slug/index.rb
151
- - lib/mongoid/slug/paranoia.rb
150
+ - lib/mongoid/slug/index_builder.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
@@ -184,8 +180,7 @@ files:
184
180
  - spec/models/subject.rb
185
181
  - spec/models/without_slug.rb
186
182
  - spec/mongoid/criteria_spec.rb
187
- - spec/mongoid/index_spec.rb
188
- - spec/mongoid/paranoia_spec.rb
183
+ - spec/mongoid/index_builder_spec.rb
189
184
  - spec/mongoid/slug_spec.rb
190
185
  - spec/shared/indexes.rb
191
186
  - spec/spec_helper.rb
@@ -194,7 +189,7 @@ homepage: https://github.com/mongoid/mongoid-slug
194
189
  licenses:
195
190
  - MIT
196
191
  metadata: {}
197
- post_install_message:
192
+ post_install_message:
198
193
  rdoc_options: []
199
194
  require_paths:
200
195
  - lib
@@ -209,9 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
204
  - !ruby/object:Gem::Version
210
205
  version: '0'
211
206
  requirements: []
212
- rubyforge_project: mongoid-slug
213
- rubygems_version: 2.5.1
214
- signing_key:
207
+ rubygems_version: 3.2.3
208
+ signing_key:
215
209
  specification_version: 4
216
210
  summary: Mongoid URL slugs
217
211
  test_files:
@@ -224,7 +218,6 @@ test_files:
224
218
  - spec/models/book.rb
225
219
  - spec/models/book_polymorphic.rb
226
220
  - spec/models/caption.rb
227
- - spec/models/document_paranoid.rb
228
221
  - spec/models/entity.rb
229
222
  - spec/models/friend.rb
230
223
  - spec/models/incorrect_slug_persistence.rb
@@ -235,8 +228,6 @@ test_files:
235
228
  - spec/models/page_slug_localized.rb
236
229
  - spec/models/page_slug_localized_custom.rb
237
230
  - spec/models/page_slug_localized_history.rb
238
- - spec/models/paranoid_document.rb
239
- - spec/models/paranoid_permanent.rb
240
231
  - spec/models/partner.rb
241
232
  - spec/models/person.rb
242
233
  - spec/models/relationship.rb
@@ -244,8 +235,7 @@ test_files:
244
235
  - spec/models/subject.rb
245
236
  - spec/models/without_slug.rb
246
237
  - spec/mongoid/criteria_spec.rb
247
- - spec/mongoid/index_spec.rb
248
- - spec/mongoid/paranoia_spec.rb
238
+ - spec/mongoid/index_builder_spec.rb
249
239
  - spec/mongoid/slug_spec.rb
250
240
  - spec/shared/indexes.rb
251
241
  - spec/spec_helper.rb