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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd5628f83716f42ffc44d2c84383340e2115dc03
4
- data.tar.gz: 8ed9a3ae49d8f57f79451c6ad53726fa2fd98bc8
3
+ metadata.gz: 07e0da6c7cb996144c1ea1f24b15885fa04bd381
4
+ data.tar.gz: eaf1ea59ed5d8dc8dd72261ab90d717498d86987
5
5
  SHA512:
6
- metadata.gz: d98d50479fb45a7a88c0757957facb34c285ac04f4757d6dfccc2a0b0d589a18606347f105ac26f805aa522cd967ed47100cc4494ac8a2e5db5a8d4545b1916f
7
- data.tar.gz: f278f8f0f40b51113ba87c5e192a340ceb213e2332f96b04adb765ec6d9b71886f36b40949459b3a72cfbb19e00d55d883cde9b9e0430ab5f41566ab16ce31c6
6
+ metadata.gz: a4f2f851cd05dd4a849f117c8f7108aa5568762dda1014879b36c97d8c5d0a09e1185cb9809ef8c6ed8782a870cf1426133b2630d2c29c5c728a0024d3e3438f
7
+ data.tar.gz: c1c5ad4f886aee692776c8972ce3ea28d1c53ce216df73c1b9e9c29d805859f6e7f3e869f3595c905d0ff4a8a7a04eece1cdbc64a2dd8db310fd336bc1a9dd21
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'mongoid', '>=5.0.0.beta'
3
+ gem 'mongoid', '>=6.0.0'
4
4
 
5
5
  gemspec
6
6
 
@@ -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
- next if val.blank?
72
- url = val.parameterize
73
- next if self.class.find_url(url)
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
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  # Mongoid::Urls::VERSION
3
3
  module Urls
4
- VERSION = '0.3.0'.freeze
4
+ VERSION = '0.5.0'.freeze
5
5
  end
6
6
  end
@@ -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, :title)
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)
@@ -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.3.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-07-27 00:00:00.000000000 Z
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.6.6
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.