mongoid_slug 3.1.0 → 3.1.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.
- checksums.yaml +4 -4
- data/lib/mongoid/slug.rb +8 -0
- data/lib/mongoid/slug/version.rb +1 -1
- data/spec/mongoid/slug_spec.rb +19 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ce4dfe55677a1b8cb8d39718cf595933dd7eae7
|
4
|
+
data.tar.gz: 799033738af175e6233c03268c73bafe0d17a259
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50ff4db23d6243bb38678fc957d369ff8277607503a1c301d4841a8c835c93925100187549451d550cf4fea6b27b698e700de48962d12b9c5d0d3497fbb0c218
|
7
|
+
data.tar.gz: 56d4bb715d1977746ebcf7c7ca94f58040e3d083028dcaeff7b15fc9963ef256fd20fafbdcf2d9ccff51596a21da53b96efee562be13666b68d9777bad87f814
|
data/lib/mongoid/slug.rb
CHANGED
@@ -131,13 +131,21 @@ module Mongoid
|
|
131
131
|
# @return [true]
|
132
132
|
def build_slug
|
133
133
|
_new_slug = find_unique_slug
|
134
|
+
|
135
|
+
#skip slug generation and use Mongoid id
|
136
|
+
#to find document instead
|
137
|
+
return true if _new_slug.size == 0
|
138
|
+
|
134
139
|
self._slugs.delete(_new_slug) if self._slugs
|
140
|
+
|
135
141
|
if !!self.history && self._slugs.is_a?(Array)
|
136
142
|
self._slugs << _new_slug
|
137
143
|
else
|
138
144
|
self._slugs = [_new_slug]
|
139
145
|
end
|
146
|
+
|
140
147
|
true
|
148
|
+
|
141
149
|
end
|
142
150
|
|
143
151
|
# Finds a unique slug, were specified string used to generate a slug.
|
data/lib/mongoid/slug/version.rb
CHANGED
data/spec/mongoid/slug_spec.rb
CHANGED
@@ -17,14 +17,19 @@ module Mongoid
|
|
17
17
|
#I believe this will now fail
|
18
18
|
x.name = 'te'
|
19
19
|
x.valid?
|
20
|
-
x.slug.should_not == 'te'
|
20
|
+
x.slug.should_not == 'te'
|
21
21
|
|
22
|
-
#I believe this will persist the 'te'
|
22
|
+
#I believe this will persist the 'te'
|
23
23
|
x.name = 'testb'
|
24
24
|
x.save!
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
|
+
it "doesn't persist blank strings" do
|
29
|
+
book = Book.create!(:title => "")
|
30
|
+
book.reload.slugs.should be_empty
|
31
|
+
end
|
32
|
+
|
28
33
|
end
|
29
34
|
|
30
35
|
context "when option skip_id_check is used with UUID _id " do
|
@@ -646,8 +651,8 @@ module Mongoid
|
|
646
651
|
let!(:integer_id2) { IntegerId.new(:name => integer_id.id.to_s).tap { |d| d.id = 456; d.save } }
|
647
652
|
let!(:string_id) { StringId.new(:name => "I have string ids").tap { |d| d.id = 'abc'; d.save } }
|
648
653
|
let!(:string_id2) { StringId.new(:name => string_id.id.to_s).tap { |d| d.id = 'def'; d.save } }
|
649
|
-
let!(:subject) { Subject.create(:
|
650
|
-
let!(:subject2) { Subject.create(:
|
654
|
+
let!(:subject) { Subject.create(:name => "A Subject", :book => book) }
|
655
|
+
let!(:subject2) { Subject.create(:name => "A Subject", :book => book2) }
|
651
656
|
let!(:without_slug) { WithoutSlug.new().tap { |d| d.id = 456; d.save } }
|
652
657
|
|
653
658
|
context "when the model does not use mongoid slugs" do
|
@@ -770,8 +775,8 @@ module Mongoid
|
|
770
775
|
let!(:integer_id2) { IntegerId.new(:name => integer_id.id.to_s).tap { |d| d.id = 456; d.save } }
|
771
776
|
let!(:string_id) { StringId.new(:name => "I have string ids").tap { |d| d.id = 'abc'; d.save } }
|
772
777
|
let!(:string_id2) { StringId.new(:name => string_id.id.to_s).tap { |d| d.id = 'def'; d.save } }
|
773
|
-
let!(:subject) { Subject.create(:
|
774
|
-
let!(:subject2) { Subject.create(:
|
778
|
+
let!(:subject) { Subject.create(:name => "A Subject", :book => book) }
|
779
|
+
let!(:subject2) { Subject.create(:name => "A Subject", :book => book2) }
|
775
780
|
|
776
781
|
context "(single)" do
|
777
782
|
context "and a document is found" do
|
@@ -835,18 +840,25 @@ module Mongoid
|
|
835
840
|
book.to_param
|
836
841
|
book.should_not be_persisted
|
837
842
|
end
|
843
|
+
|
838
844
|
end
|
839
845
|
|
840
846
|
context "when called on an existing record with no slug" do
|
847
|
+
let!(:book_no_title) { Book.create() }
|
848
|
+
|
841
849
|
before do
|
842
850
|
Book.collection.insert(:title => "Proust and Signs")
|
843
851
|
end
|
844
852
|
|
845
|
-
it "should return the id" do
|
853
|
+
it "should return the id if there is no slug" do
|
846
854
|
book = Book.first
|
847
855
|
book.to_param.should == book.id.to_s
|
848
856
|
book.reload.slugs.should be_empty
|
849
857
|
end
|
858
|
+
|
859
|
+
it "should not persist the record" do
|
860
|
+
book_no_title.to_param.should == book_no_title._id.to_s
|
861
|
+
end
|
850
862
|
end
|
851
863
|
end
|
852
864
|
|
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: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Saebjoernsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|