mongoid-slug 5.1.0 → 5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb594c9cba9d0b1747cfe7de88bd16025729bb92
4
- data.tar.gz: c196bf56ba7b22a85277955c87a46054be646d7b
3
+ metadata.gz: f62313ab069384e3dea183cd680aae50318beb85
4
+ data.tar.gz: 8881c0bef60727f9c57d8210b74f04bd48f545d6
5
5
  SHA512:
6
- metadata.gz: 5114980882e64954cfa197753e32c36ff78f32d09aa933e75d5ea705a1f04c6efe3837a8060b2f0747e2d8a4fe382c07e4f50d4ee1ec6623a4fae2962bda8d3b
7
- data.tar.gz: 7d29e77096446b20be262a5e648a845e5621e5b8402aab368103115ae890e7a297c5213dc7f31a61fb395227e0e6c7cae5096f016c0af8c65cf2777237a6aae0
6
+ metadata.gz: 0bbf0cc529c6c8da1955ab3f9d40dfddb5e081c740bee1f012b3c115ad1698ed00bd5c8b81e158ce3626678e99dc9337a565ea3a8c67107583e940d20eed78f7
7
+ data.tar.gz: d9b4553651b7c2f588a8fe188974c1074283846dae8e5962d05471b216d50e7dc0db1ae10bad7ed46c932debf502ea28ebe7e1726fa1360866cbb9da802add49
@@ -136,8 +136,7 @@ module Mongoid
136
136
  end
137
137
 
138
138
  def queryable
139
- scope = Mongoid::Compatibility::Version.mongoid5? ? Threaded.current_scope : scope_stack.last
140
- scope || Criteria.new(self) # Use Mongoid::Slug::Criteria for slugged documents.
139
+ current_scope || Criteria.new(self) # Use Mongoid::Slug::Criteria for slugged documents.
141
140
  end
142
141
 
143
142
  # Indicates whether or not the document includes Mongoid::Paranoia
@@ -150,6 +149,22 @@ module Mongoid
150
149
  def is_paranoid_doc?
151
150
  !!(defined?(::Mongoid::Paranoia) && self < ::Mongoid::Paranoia)
152
151
  end
152
+
153
+ private
154
+
155
+ if Mongoid::Compatibility::Version.mongoid5? && Threaded.method(:current_scope).arity == -1
156
+ def current_scope
157
+ Threaded.current_scope(self)
158
+ end
159
+ elsif Mongoid::Compatibility::Version.mongoid5?
160
+ def current_scope
161
+ Threaded.current_scope
162
+ end
163
+ else
164
+ def current_scope
165
+ scope_stack.last
166
+ end
167
+ end
153
168
  end
154
169
 
155
170
  # Builds a new slug.
@@ -1,5 +1,5 @@
1
1
  module Mongoid #:nodoc:
2
2
  module Slug
3
- VERSION = '5.1.0'
3
+ VERSION = '5.1.1'
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ class Artist
2
+ include Mongoid::Document
3
+ include Mongoid::Slug
4
+
5
+ slug :name
6
+ field :name
7
+ has_and_belongs_to_many :artworks
8
+ end
@@ -0,0 +1,10 @@
1
+ class Artwork
2
+ include Mongoid::Document
3
+ include Mongoid::Slug
4
+
5
+ slug :title
6
+ field :title
7
+ field :published, type: Boolean, default: true
8
+ scope :published, -> { where(published: true) }
9
+ has_and_belongs_to_many :artists
10
+ end
@@ -0,0 +1,9 @@
1
+ class DocumentParanoid
2
+ include Mongoid::Document
3
+ # slug, then paranoia
4
+ include Mongoid::Slug
5
+ include Mongoid::Paranoia
6
+
7
+ field :title
8
+ slug :title
9
+ end
@@ -187,4 +187,22 @@ describe Mongoid::Slug::Criteria do
187
187
  end
188
188
  end
189
189
  end
190
+
191
+ describe '.where' do
192
+ let!(:artist1) { Artist.create!(name: 'Leonardo') }
193
+ let!(:artist2) { Artist.create!(name: 'Malevich') }
194
+ let!(:artwork1) { Artwork.create!(title: 'Mona Lisa', artist_ids: [artist1.id], published: true) }
195
+ let!(:artwork2) { Artwork.create!(title: 'Black Square', artist_ids: [artist2.id], published: false) }
196
+ let!(:artwork3) { Artwork.create! }
197
+
198
+ it 'counts artworks' do
199
+ expect(Artwork.in(artist_ids: artist1.id).count).to eq 1
200
+ expect(Artwork.in(artist_ids: artist2.id).count).to eq 1
201
+ end
202
+
203
+ it 'counts published artworks' do
204
+ expect(Artwork.in(artist_ids: artist1.id).published.count).to eq 1
205
+ expect(Artwork.in(artist_ids: artist2.id).published.count).to eq 0
206
+ end
207
+ end
190
208
  end
@@ -2,64 +2,6 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe 'Mongoid::Paranoia with Mongoid::Slug' do
5
- let(:paranoid_doc) { ParanoidDocument.create!(title: 'slug') }
6
- let(:paranoid_doc_2) { ParanoidDocument.create!(title: 'slug') }
7
- let(:paranoid_perm) { ParanoidPermanent.create!(title: 'slug') }
8
- let(:paranoid_perm_2) { ParanoidPermanent.create!(title: 'slug') }
9
- let(:non_paranoid_doc) { Article.create!(title: 'slug') }
10
- subject { paranoid_doc }
11
-
12
- describe '.paranoid?' do
13
- context 'when Mongoid::Paranoia is included' do
14
- subject { paranoid_doc.class }
15
- its(:is_paranoid_doc?) { should be_truthy }
16
- end
17
-
18
- context 'when Mongoid::Paranoia not included' do
19
- subject { non_paranoid_doc.class }
20
- its(:is_paranoid_doc?) { should be_falsey }
21
- end
22
- end
23
-
24
- describe '#paranoid_deleted?' do
25
- context 'when Mongoid::Paranoia is included' do
26
- context 'when not destroyed' do
27
- its(:paranoid_deleted?) { should be_falsey }
28
- end
29
-
30
- context 'when destroyed' do
31
- before { subject.destroy }
32
- its(:paranoid_deleted?) { should be_truthy }
33
- end
34
- end
35
-
36
- context 'when Mongoid::Paranoia not included' do
37
- subject { non_paranoid_doc }
38
- its(:paranoid_deleted?) { should be_falsey }
39
- end
40
- end
41
-
42
- describe 'restore callbacks' do
43
- context 'when Mongoid::Paranoia is included' do
44
- subject { paranoid_doc.class }
45
- it { is_expected.to respond_to(:before_restore) }
46
- it { is_expected.to respond_to(:after_restore) }
47
- end
48
-
49
- context 'when Mongoid::Paranoia not included' do
50
- it { is_expected.not_to respond_to(:before_restore) }
51
- it { is_expected.not_to respond_to(:after_restore) }
52
- end
53
- end
54
-
55
- describe 'index' do
56
- before { ParanoidDocument.create_indexes }
57
- after { ParanoidDocument.remove_indexes }
58
- subject { ParanoidDocument }
59
-
60
- it_should_behave_like 'has an index', { _slugs: 1 }, unique: true, sparse: true
61
- end
62
-
63
5
  shared_examples_for 'paranoid slugs' do
64
6
  context 'querying' do
65
7
  it 'returns paranoid_doc for correct slug' do
@@ -143,13 +85,76 @@ describe 'Mongoid::Paranoia with Mongoid::Slug' do
143
85
  end
144
86
  end
145
87
 
146
- context 'non-permanent slug' do
147
- subject { paranoid_doc }
148
- let(:other_doc) { paranoid_doc_2 }
149
- it_behaves_like 'paranoid slugs'
88
+ [ParanoidDocument, DocumentParanoid].each do |paranoid_klass|
89
+ context "#{paranoid_klass}" do
90
+ let(:paranoid_doc) { paranoid_klass.create!(title: 'slug') }
91
+ let(:non_paranoid_doc) { Article.create!(title: 'slug') }
92
+
93
+ subject { paranoid_doc }
94
+
95
+ describe '.paranoid?' do
96
+ context 'when Mongoid::Paranoia is included' do
97
+ subject { paranoid_doc.class }
98
+ its(:is_paranoid_doc?) { should be_truthy }
99
+ end
100
+
101
+ context 'when Mongoid::Paranoia not included' do
102
+ subject { non_paranoid_doc.class }
103
+ its(:is_paranoid_doc?) { should be_falsey }
104
+ end
105
+ end
106
+
107
+ describe '#paranoid_deleted?' do
108
+ context 'when Mongoid::Paranoia is included' do
109
+ context 'when not destroyed' do
110
+ its(:paranoid_deleted?) { should be_falsey }
111
+ end
112
+
113
+ context 'when destroyed' do
114
+ before { subject.destroy }
115
+ its(:paranoid_deleted?) { should be_truthy }
116
+ end
117
+ end
118
+
119
+ context 'when Mongoid::Paranoia not included' do
120
+ subject { non_paranoid_doc }
121
+ its(:paranoid_deleted?) { should be_falsey }
122
+ end
123
+ end
124
+
125
+ describe 'restore callbacks' do
126
+ context 'when Mongoid::Paranoia is included' do
127
+ subject { paranoid_doc.class }
128
+ it { is_expected.to respond_to(:before_restore) }
129
+ it { is_expected.to respond_to(:after_restore) }
130
+ end
131
+
132
+ context 'when Mongoid::Paranoia not included' do
133
+ it { is_expected.not_to respond_to(:before_restore) }
134
+ it { is_expected.not_to respond_to(:after_restore) }
135
+ end
136
+ end
137
+
138
+ describe 'index' do
139
+ before { paranoid_klass.create_indexes }
140
+ after { paranoid_klass.remove_indexes }
141
+ subject { paranoid_klass }
142
+
143
+ it_should_behave_like 'has an index', { _slugs: 1 }, unique: true, sparse: true
144
+ end
145
+
146
+ context 'non-permanent slug' do
147
+ let(:paranoid_doc_2) { paranoid_klass.create!(title: 'slug') }
148
+ subject { paranoid_doc }
149
+ let(:other_doc) { paranoid_doc_2 }
150
+ it_behaves_like 'paranoid slugs'
151
+ end
152
+ end
150
153
  end
151
154
 
152
155
  context 'permanent slug' do
156
+ let(:paranoid_perm) { ParanoidPermanent.create!(title: 'slug') }
157
+ let(:paranoid_perm_2) { ParanoidPermanent.create!(title: 'slug') }
153
158
  subject { paranoid_perm }
154
159
  let(:other_doc) { paranoid_perm_2 }
155
160
  it_behaves_like 'paranoid slugs'
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: 5.1.0
4
+ version: 5.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: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -183,11 +183,14 @@ files:
183
183
  - lib/mongoid_slug.rb
184
184
  - spec/models/alias.rb
185
185
  - spec/models/article.rb
186
+ - spec/models/artist.rb
187
+ - spec/models/artwork.rb
186
188
  - spec/models/author.rb
187
189
  - spec/models/author_polymorphic.rb
188
190
  - spec/models/book.rb
189
191
  - spec/models/book_polymorphic.rb
190
192
  - spec/models/caption.rb
193
+ - spec/models/document_paranoid.rb
191
194
  - spec/models/entity.rb
192
195
  - spec/models/friend.rb
193
196
  - spec/models/incorrect_slug_persistence.rb
@@ -239,11 +242,14 @@ summary: Mongoid URL slugs
239
242
  test_files:
240
243
  - spec/models/alias.rb
241
244
  - spec/models/article.rb
245
+ - spec/models/artist.rb
246
+ - spec/models/artwork.rb
242
247
  - spec/models/author.rb
243
248
  - spec/models/author_polymorphic.rb
244
249
  - spec/models/book.rb
245
250
  - spec/models/book_polymorphic.rb
246
251
  - spec/models/caption.rb
252
+ - spec/models/document_paranoid.rb
247
253
  - spec/models/entity.rb
248
254
  - spec/models/friend.rb
249
255
  - spec/models/incorrect_slug_persistence.rb