mongoid-urls 0.3.0 → 0.5.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 +4 -4
- data/Gemfile +1 -1
- data/lib/mongoid/urls.rb +8 -6
- data/lib/mongoid/urls/version.rb +1 -1
- data/spec/mongoid/urls_spec.rb +12 -4
- data/spec/support/models.rb +10 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07e0da6c7cb996144c1ea1f24b15885fa04bd381
|
4
|
+
data.tar.gz: eaf1ea59ed5d8dc8dd72261ab90d717498d86987
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4f2f851cd05dd4a849f117c8f7108aa5568762dda1014879b36c97d8c5d0a09e1185cb9809ef8c6ed8782a870cf1426133b2630d2c29c5c728a0024d3e3438f
|
7
|
+
data.tar.gz: c1c5ad4f886aee692776c8972ce3ea28d1c53ce216df73c1b9e9c29d805859f6e7f3e869f3595c905d0ff4a8a7a04eece1cdbc64a2dd8db310fd336bc1a9dd21
|
data/Gemfile
CHANGED
data/lib/mongoid/urls.rb
CHANGED
@@ -65,15 +65,17 @@ module Mongoid
|
|
65
65
|
url
|
66
66
|
end
|
67
67
|
|
68
|
+
# Gets a new url.
|
69
|
+
# Go each arg/key one by one, don't join'em.
|
68
70
|
def new_url
|
69
71
|
url_keys.each do |key|
|
70
|
-
val = send(key)
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
next if (val = send(key)).blank?
|
73
|
+
url = val.to_s.parameterize
|
74
|
+
if (dup = self.class.find_url(url))
|
75
|
+
next if dup.id != id
|
76
|
+
end
|
74
77
|
return url
|
75
|
-
end
|
76
|
-
nil
|
78
|
+
end; nil
|
77
79
|
end
|
78
80
|
|
79
81
|
protected
|
data/lib/mongoid/urls/version.rb
CHANGED
data/spec/mongoid/urls_spec.rb
CHANGED
@@ -7,14 +7,15 @@ describe Mongoid::Urls do
|
|
7
7
|
class Document
|
8
8
|
include Mongoid::Document
|
9
9
|
include Mongoid::Urls
|
10
|
-
field :title
|
11
|
-
field :doc
|
10
|
+
field :title, type: String
|
11
|
+
field :doc, type: String
|
12
|
+
field :ary, type: Array
|
12
13
|
end
|
13
14
|
Class.new(Document)
|
14
15
|
end
|
15
16
|
|
16
17
|
let(:document) do
|
17
|
-
document_class.create(title: "I'm a Document!", doc: '123')
|
18
|
+
document_class.create(title: "I'm a Document!", doc: '123', ary: [1, 2])
|
18
19
|
end
|
19
20
|
|
20
21
|
let(:article) do
|
@@ -112,7 +113,7 @@ describe Mongoid::Urls do
|
|
112
113
|
end
|
113
114
|
|
114
115
|
it 'should change `to_param`' do
|
115
|
-
document_class.send(:url,
|
116
|
+
document_class.send(:url, :title)
|
116
117
|
expect(document.to_param).to eq document.urls.first
|
117
118
|
end
|
118
119
|
end
|
@@ -303,6 +304,13 @@ describe Mongoid::Urls do
|
|
303
304
|
expect(com3.url).to eq 'acme-common-name'
|
304
305
|
end
|
305
306
|
|
307
|
+
it 'should keep on same on update' do
|
308
|
+
com = Company.create!(name: 'Common Name', nick: 'ACME')
|
309
|
+
expect(com.url).to eq 'acme'
|
310
|
+
com.update(name: 'Common Namex')
|
311
|
+
expect(com.url).to eq 'acme'
|
312
|
+
end
|
313
|
+
|
306
314
|
it 'should assign attr' do
|
307
315
|
com = Company.new
|
308
316
|
com.assign_attributes(name: 'ACME Corp LLC', nick: nil)
|
data/spec/support/models.rb
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
# A nice model for a blog!
|
2
|
-
class Article
|
3
|
-
include Mongoid::Document
|
4
|
-
include Mongoid::Urls
|
5
|
-
field :title
|
6
|
-
url :title
|
7
|
-
end
|
8
|
-
|
9
1
|
# A model with dynamic key
|
10
2
|
class Company
|
11
3
|
include Mongoid::Document
|
@@ -13,6 +5,7 @@ class Company
|
|
13
5
|
field :name
|
14
6
|
field :nick
|
15
7
|
|
8
|
+
has_many :articles
|
16
9
|
url :nick, :name, :fullname
|
17
10
|
|
18
11
|
def fullname
|
@@ -20,3 +13,12 @@ class Company
|
|
20
13
|
nick || name
|
21
14
|
end
|
22
15
|
end
|
16
|
+
|
17
|
+
# A nice model for a blog!
|
18
|
+
class Article
|
19
|
+
include Mongoid::Document
|
20
|
+
include Mongoid::Urls
|
21
|
+
field :title
|
22
|
+
belongs_to :company, optional: true
|
23
|
+
url :title
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-urls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Piccinini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project: mongoid-urls
|
83
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.5.2
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: A url sanitizer (slugs) for Mongoid documents.
|