mongoid-slug 6.0.1 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -3
  3. data/lib/mongoid/slug/criteria.rb +10 -6
  4. data/lib/mongoid/slug/index_builder.rb +2 -0
  5. data/lib/mongoid/slug/railtie.rb +2 -0
  6. data/lib/mongoid/slug/slug_id_strategy.rb +2 -0
  7. data/lib/mongoid/slug/unique_slug.rb +8 -9
  8. data/lib/mongoid/slug/version.rb +4 -2
  9. data/lib/mongoid/slug.rb +15 -10
  10. data/lib/mongoid_slug.rb +2 -0
  11. data/lib/tasks/mongoid_slug.rake +3 -1
  12. metadata +9 -168
  13. data/spec/models/alias.rb +0 -6
  14. data/spec/models/article.rb +0 -9
  15. data/spec/models/artist.rb +0 -8
  16. data/spec/models/artwork.rb +0 -10
  17. data/spec/models/author.rb +0 -15
  18. data/spec/models/author_polymorphic.rb +0 -15
  19. data/spec/models/book.rb +0 -12
  20. data/spec/models/book_polymorphic.rb +0 -12
  21. data/spec/models/caption.rb +0 -17
  22. data/spec/models/entity.rb +0 -11
  23. data/spec/models/friend.rb +0 -7
  24. data/spec/models/incorrect_slug_persistence.rb +0 -9
  25. data/spec/models/integer_id.rb +0 -9
  26. data/spec/models/magazine.rb +0 -7
  27. data/spec/models/page.rb +0 -9
  28. data/spec/models/page_localize.rb +0 -9
  29. data/spec/models/page_slug_localized.rb +0 -9
  30. data/spec/models/page_slug_localized_custom.rb +0 -10
  31. data/spec/models/page_slug_localized_history.rb +0 -9
  32. data/spec/models/partner.rb +0 -7
  33. data/spec/models/person.rb +0 -12
  34. data/spec/models/relationship.rb +0 -8
  35. data/spec/models/string_id.rb +0 -9
  36. data/spec/models/subject.rb +0 -7
  37. data/spec/models/without_slug.rb +0 -5
  38. data/spec/mongoid/criteria_spec.rb +0 -207
  39. data/spec/mongoid/index_builder_spec.rb +0 -105
  40. data/spec/mongoid/slug_spec.rb +0 -1175
  41. data/spec/shared/indexes.rb +0 -41
  42. data/spec/spec_helper.rb +0 -61
  43. data/spec/tasks/mongoid_slug_rake_spec.rb +0 -73
@@ -1,41 +0,0 @@
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 DELETED
@@ -1,61 +0,0 @@
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 +0,0 @@
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