mongoid-slug 6.0.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +20 -20
  3. data/README.md +361 -336
  4. data/lib/mongoid/slug.rb +328 -328
  5. data/lib/mongoid/slug/criteria.rb +107 -107
  6. data/lib/mongoid/slug/{index.rb → index_builder.rb} +67 -45
  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 -173
  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 -11
  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 -207
  39. data/spec/mongoid/index_builder_spec.rb +105 -0
  40. data/spec/mongoid/slug_spec.rb +1175 -1169
  41. data/spec/shared/indexes.rb +41 -41
  42. data/spec/spec_helper.rb +61 -61
  43. data/spec/tasks/mongoid_slug_rake_spec.rb +73 -73
  44. metadata +31 -32
  45. data/spec/mongoid/index_spec.rb +0 -33
@@ -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,61 +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 '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
+ 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', __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
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: 6.0.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: 2018-08-17 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
@@ -147,7 +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
150
+ - lib/mongoid/slug/index_builder.rb
151
151
  - lib/mongoid/slug/railtie.rb
152
152
  - lib/mongoid/slug/slug_id_strategy.rb
153
153
  - lib/mongoid/slug/unique_slug.rb
@@ -180,7 +180,7 @@ files:
180
180
  - spec/models/subject.rb
181
181
  - spec/models/without_slug.rb
182
182
  - spec/mongoid/criteria_spec.rb
183
- - spec/mongoid/index_spec.rb
183
+ - spec/mongoid/index_builder_spec.rb
184
184
  - spec/mongoid/slug_spec.rb
185
185
  - spec/shared/indexes.rb
186
186
  - spec/spec_helper.rb
@@ -189,7 +189,7 @@ homepage: https://github.com/mongoid/mongoid-slug
189
189
  licenses:
190
190
  - MIT
191
191
  metadata: {}
192
- post_install_message:
192
+ post_install_message:
193
193
  rdoc_options: []
194
194
  require_paths:
195
195
  - lib
@@ -204,40 +204,39 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
206
  requirements: []
207
- rubyforge_project: mongoid-slug
208
- rubygems_version: 2.7.6
209
- signing_key:
207
+ rubygems_version: 3.2.3
208
+ signing_key:
210
209
  specification_version: 4
211
210
  summary: Mongoid URL slugs
212
211
  test_files:
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
212
+ - spec/models/alias.rb
219
213
  - spec/models/article.rb
220
- - spec/models/integer_id.rb
221
- - spec/models/book.rb
222
- - spec/models/entity.rb
223
- - spec/models/caption.rb
224
- - spec/models/without_slug.rb
225
214
  - spec/models/artist.rb
226
- - spec/models/string_id.rb
227
- - spec/models/page.rb
228
- - spec/models/page_slug_localized.rb
215
+ - spec/models/artwork.rb
229
216
  - spec/models/author.rb
217
+ - spec/models/author_polymorphic.rb
218
+ - spec/models/book.rb
219
+ - spec/models/book_polymorphic.rb
220
+ - spec/models/caption.rb
221
+ - spec/models/entity.rb
230
222
  - spec/models/friend.rb
231
- - spec/models/subject.rb
223
+ - spec/models/incorrect_slug_persistence.rb
224
+ - spec/models/integer_id.rb
232
225
  - spec/models/magazine.rb
226
+ - spec/models/page.rb
227
+ - spec/models/page_localize.rb
228
+ - spec/models/page_slug_localized.rb
229
+ - spec/models/page_slug_localized_custom.rb
230
+ - spec/models/page_slug_localized_history.rb
233
231
  - spec/models/partner.rb
234
- - spec/models/alias.rb
235
232
  - spec/models/person.rb
236
- - spec/models/page_slug_localized_custom.rb
237
233
  - spec/models/relationship.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
234
+ - spec/models/string_id.rb
235
+ - spec/models/subject.rb
236
+ - spec/models/without_slug.rb
237
+ - spec/mongoid/criteria_spec.rb
238
+ - spec/mongoid/index_builder_spec.rb
239
+ - spec/mongoid/slug_spec.rb
240
+ - spec/shared/indexes.rb
241
+ - spec/spec_helper.rb
242
+ - spec/tasks/mongoid_slug_rake_spec.rb