mongoid-paranoia 1.0.0.beta1 → 1.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/Gemfile +0 -6
- data/README.md +4 -3
- data/lib/mongoid/core_ext/builders/nested_attributes/many.rb +1 -1
- data/lib/mongoid/core_ext/document.rb +17 -0
- data/lib/mongoid/core_ext/relations/embedded/many.rb +2 -2
- data/lib/mongoid/core_ext/validatable/uniqueness.rb +1 -1
- data/lib/mongoid/paranoia.rb +1 -1
- data/lib/mongoid/paranoia/version.rb +1 -1
- data/mongoid-paranoia.gemspec +4 -1
- data/spec/app/models/person.rb +1 -1
- data/spec/mongoid/attributes/nested_spec.rb +9 -9
- data/spec/mongoid/criteria/scopable_spec.rb +4 -4
- data/spec/mongoid/document_spec.rb +21 -0
- data/spec/mongoid/paranoia_spec.rb +45 -45
- data/spec/mongoid/scoping_spec.rb +4 -4
- data/spec/mongoid/validatable/uniqueness_spec.rb +3 -3
- metadata +50 -8
- data/gemfiles/mongoid_master.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3c0fcf38d5f974f58f75a90175139e7bd17aeae
|
4
|
+
data.tar.gz: 83eeee2f0f452ca8debc682758beab91f2a9ea4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6a6270e9e39ce8b4d966847f321e93b98e0c909681c9eb2c7916a9a9a9632de0b6ecb2329ca0b62a0fb195646ce2dd681f20cc72d180f60b2f660ba704c1bb4
|
7
|
+
data.tar.gz: ada8e8bd22f88f22ca32b45871112b59bfb75cece72531ec9413bd5e5f000547cf35c7c1a54ccda27febcd24e46a9f12e3658ad6b9477e8532cce80512533c65
|
data/.travis.yml
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
language: ruby
|
2
|
+
services: mongodb
|
2
3
|
|
3
4
|
rvm:
|
4
5
|
- 1.9.3
|
5
6
|
- 2.0.0
|
6
7
|
- 2.1.0
|
7
|
-
- ruby-head
|
8
8
|
|
9
9
|
gemfile:
|
10
10
|
- Gemfile
|
11
|
-
- gemfiles/mongoid_master.gemfile
|
12
11
|
|
13
12
|
branches:
|
14
13
|
only:
|
@@ -17,4 +16,3 @@ branches:
|
|
17
16
|
matrix:
|
18
17
|
allow_failures:
|
19
18
|
- rvm: ruby-head
|
20
|
-
- gemfile: gemfiles/mongoid_master.gemfile
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# mongoid-paranoia [![Build Status](https://travis-ci.org/haihappen/mongoid-paranoia.png)](https://travis-ci.org/haihappen/mongoid-paranoia)
|
2
2
|
|
3
|
-
**Important:** This gem is an extraction of [Mongoid::Paranoia](http://mongoid.org/en/mongoid/
|
3
|
+
**Important:** This gem is an extraction of [Mongoid::Paranoia](http://mongoid.org/en/mongoid/v3/extras.html#paranoia) from the official [mongoid](http://mongoid.org) gem.
|
4
|
+
Since Mongoid::Paranoia was removed in the `4.0.0` release of Mongoid, this gem re-enables the functionality of paranoid documents.
|
4
5
|
|
5
|
-
**Please submit only bug and security fixes**.
|
6
|
+
**Please submit only bug and security fixes**. Neither I will accept new features nor changes to existing APIs. Please consider forking the project if you want new features to appear! :)
|
6
7
|
|
7
8
|
---
|
8
9
|
|
@@ -49,7 +50,7 @@ Person.deleted # Returns documents that have been "flagged" as deleted.
|
|
49
50
|
|
50
51
|
(The MIT license)
|
51
52
|
|
52
|
-
Copyright (c) 2013 Mario Uher
|
53
|
+
Copyright (c) 2013-2014 Mario Uher
|
53
54
|
|
54
55
|
Permission is hereby granted, free of charge, to any person obtaining
|
55
56
|
a copy of this software and associated documentation files (the
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mongoid
|
3
|
+
module Paranoia
|
4
|
+
module Document
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
# Indicates whether or not the document includes Mongoid::Paranoia.
|
9
|
+
# In Mongoid 3, this method was defined on all Mongoid::Documents.
|
10
|
+
# In Mongoid 4, it is no longer defined, hence we are shimming it here.
|
11
|
+
class_attribute :paranoid
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Mongoid::Document.send(:include, Mongoid::Paranoia::Document)
|
@@ -19,9 +19,9 @@ module Mongoid
|
|
19
19
|
execute_callback :before_remove, document
|
20
20
|
doc = target.delete_one(document)
|
21
21
|
if doc && !_binding?
|
22
|
-
_unscoped.delete_one(doc) unless doc.
|
22
|
+
_unscoped.delete_one(doc) unless doc.paranoid?
|
23
23
|
if _assigning?
|
24
|
-
if doc.
|
24
|
+
if doc.paranoid?
|
25
25
|
doc.destroy(suppress: true)
|
26
26
|
else
|
27
27
|
base.add_atomic_pull(doc)
|
@@ -33,7 +33,7 @@ module Mongoid
|
|
33
33
|
name = document.database_field_name(item)
|
34
34
|
criteria = criteria.where(item => document.attributes[name])
|
35
35
|
end
|
36
|
-
criteria = criteria.where(deleted_at: nil) if document.
|
36
|
+
criteria = criteria.where(deleted_at: nil) if document.paranoid?
|
37
37
|
criteria
|
38
38
|
end
|
39
39
|
end
|
data/lib/mongoid/paranoia.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'mongoid/core_ext/document'
|
1
2
|
require 'mongoid/core_ext/builders/nested_attributes/many'
|
2
3
|
require 'mongoid/core_ext/relations/embedded/many'
|
3
4
|
require 'mongoid/core_ext/validatable/uniqueness'
|
@@ -20,7 +21,6 @@ module Mongoid
|
|
20
21
|
|
21
22
|
included do
|
22
23
|
field :deleted_at, type: Time
|
23
|
-
class_attribute :paranoid
|
24
24
|
self.paranoid = true
|
25
25
|
|
26
26
|
default_scope ->{ where(deleted_at: nil) }
|
data/mongoid-paranoia.gemspec
CHANGED
@@ -14,5 +14,8 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_path = 'lib'
|
15
15
|
|
16
16
|
gem.add_dependency 'activesupport'
|
17
|
-
gem.add_dependency 'mongoid', '4.0.0
|
17
|
+
gem.add_dependency 'mongoid', '~> 4.0.0'
|
18
|
+
gem.add_development_dependency 'mongoid-versioning', '1.0.0.beta2'
|
19
|
+
gem.add_development_dependency 'rake'
|
20
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
18
21
|
end
|
data/spec/app/models/person.rb
CHANGED
@@ -18,7 +18,7 @@ class Person
|
|
18
18
|
field :map_with_default, type: Hash, default: {}
|
19
19
|
field :score, type: Integer
|
20
20
|
field :blood_alcohol_content, type: Float, default: ->{ 0.0 }
|
21
|
-
field :last_drink_taken_at, type: Date
|
21
|
+
field :last_drink_taken_at, type: Date
|
22
22
|
field :ssn
|
23
23
|
field :owner_id, type: Integer
|
24
24
|
field :security_code
|
@@ -79,7 +79,7 @@ describe Mongoid::Attributes::Nested do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it "does not destroy the child" do
|
82
|
-
persisted.reload.paranoid_phones.
|
82
|
+
expect(persisted.reload.paranoid_phones).not_to be_empty
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -123,23 +123,23 @@ describe Mongoid::Attributes::Nested do
|
|
123
123
|
end
|
124
124
|
|
125
125
|
it "removes the first document from the relation" do
|
126
|
-
persisted.paranoid_phones.size.
|
126
|
+
expect(persisted.paranoid_phones.size).to eq(2)
|
127
127
|
end
|
128
128
|
|
129
129
|
it "does not delete the unmarked document" do
|
130
|
-
persisted.paranoid_phones.first.number.
|
130
|
+
expect(persisted.paranoid_phones.first.number).to eq("3")
|
131
131
|
end
|
132
132
|
|
133
133
|
it "adds the new document to the relation" do
|
134
|
-
persisted.paranoid_phones.last.number.
|
134
|
+
expect(persisted.paranoid_phones.last.number).to eq("4")
|
135
135
|
end
|
136
136
|
|
137
137
|
it "has the proper persisted count" do
|
138
|
-
persisted.paranoid_phones.count.
|
138
|
+
expect(persisted.paranoid_phones.count).to eq(1)
|
139
139
|
end
|
140
140
|
|
141
141
|
it "soft deletes the removed document" do
|
142
|
-
phone_one.
|
142
|
+
expect(phone_one).to be_destroyed
|
143
143
|
end
|
144
144
|
|
145
145
|
context "when saving the parent" do
|
@@ -149,15 +149,15 @@ describe Mongoid::Attributes::Nested do
|
|
149
149
|
end
|
150
150
|
|
151
151
|
it "deletes the marked document from the relation" do
|
152
|
-
persisted.reload.paranoid_phones.count.
|
152
|
+
expect(persisted.reload.paranoid_phones.count).to eq(2)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "does not delete the unmarked document" do
|
156
|
-
persisted.reload.paranoid_phones.first.number.
|
156
|
+
expect(persisted.reload.paranoid_phones.first.number).to eq("3")
|
157
157
|
end
|
158
158
|
|
159
159
|
it "persists the new document to the relation" do
|
160
|
-
persisted.reload.paranoid_phones.last.number.
|
160
|
+
expect(persisted.reload.paranoid_phones.last.number).to eq("4")
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
@@ -11,7 +11,7 @@ describe Mongoid::Criteria::Scopable do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "includes the deleted_at criteria in the selector" do
|
14
|
-
criteria.selector.
|
14
|
+
expect(criteria.selector).to eq({
|
15
15
|
"deleted_at" => nil, "fresh" => true
|
16
16
|
})
|
17
17
|
end
|
@@ -24,7 +24,7 @@ describe Mongoid::Criteria::Scopable do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "does not include the deleted_at in the selector" do
|
27
|
-
criteria.selector.
|
27
|
+
expect(criteria.selector).to eq({ "fresh" => true })
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,7 +35,7 @@ describe Mongoid::Criteria::Scopable do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "includes the deleted_at $ne criteria in the selector" do
|
38
|
-
criteria.selector.
|
38
|
+
expect(criteria.selector).to eq({
|
39
39
|
"deleted_at" => { "$ne" => nil }, "fresh" => true
|
40
40
|
})
|
41
41
|
end
|
@@ -48,7 +48,7 @@ describe Mongoid::Criteria::Scopable do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "includes no default scoping information in the selector" do
|
51
|
-
criteria.selector.
|
51
|
+
expect(criteria.selector).to eq({ "fresh" => true })
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Document do
|
4
|
+
|
5
|
+
describe ".paranoid?" do
|
6
|
+
|
7
|
+
context "when Mongoid::Paranoia is included" do
|
8
|
+
subject { ParanoidPost }
|
9
|
+
it "returns true" do
|
10
|
+
expect(subject.paranoid?).to be_truthy
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when Mongoid::Paranoia not included" do
|
15
|
+
subject { Author }
|
16
|
+
it "returns true" do
|
17
|
+
expect(subject.paranoid?).to be_falsey
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -5,7 +5,7 @@ describe Mongoid::Paranoia do
|
|
5
5
|
describe ".scoped" do
|
6
6
|
|
7
7
|
it "returns a scoped criteria" do
|
8
|
-
ParanoidPost.scoped.selector.
|
8
|
+
expect(ParanoidPost.scoped.selector).to eq({ "deleted_at" => nil })
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -26,7 +26,7 @@ describe Mongoid::Paranoia do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns the deleted documents" do
|
29
|
-
deleted.
|
29
|
+
expect(deleted).to eq([ post ])
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -46,11 +46,11 @@ describe Mongoid::Paranoia do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "returns the deleted documents" do
|
49
|
-
person.paranoid_phones.deleted.to_a.
|
49
|
+
expect(person.paranoid_phones.deleted.to_a).to eq([ phone ])
|
50
50
|
end
|
51
51
|
|
52
52
|
it "returns the correct count" do
|
53
|
-
person.paranoid_phones.deleted.count.
|
53
|
+
expect(person.paranoid_phones.deleted.count).to eq(1)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -72,15 +72,15 @@ describe Mongoid::Paranoia do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it "hard deletes the document" do
|
75
|
-
raw.
|
75
|
+
expect(raw).to be_nil
|
76
76
|
end
|
77
77
|
|
78
78
|
it "executes the before destroy callbacks" do
|
79
|
-
post.before_destroy_called.
|
79
|
+
expect(post.before_destroy_called).to be_truthy
|
80
80
|
end
|
81
81
|
|
82
82
|
it "executes the after destroy callbacks" do
|
83
|
-
post.after_destroy_called.
|
83
|
+
expect(post.after_destroy_called).to be_truthy
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -103,15 +103,15 @@ describe Mongoid::Paranoia do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
it "hard deletes the document" do
|
106
|
-
raw["paranoid_phones"].
|
106
|
+
expect(raw["paranoid_phones"]).to be_empty
|
107
107
|
end
|
108
108
|
|
109
109
|
it "executes the before destroy callbacks" do
|
110
|
-
phone.before_destroy_called.
|
110
|
+
expect(phone.before_destroy_called).to be_truthy
|
111
111
|
end
|
112
112
|
|
113
113
|
it "executes the after destroy callbacks" do
|
114
|
-
phone.after_destroy_called.
|
114
|
+
expect(phone.after_destroy_called).to be_truthy
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -154,7 +154,7 @@ describe Mongoid::Paranoia do
|
|
154
154
|
end
|
155
155
|
|
156
156
|
it "soft deletes the document" do
|
157
|
-
raw["deleted_at"].
|
157
|
+
expect(raw["deleted_at"]).to be_within(1).of(Time.now)
|
158
158
|
end
|
159
159
|
|
160
160
|
it "does not return the document in a find" do
|
@@ -164,11 +164,11 @@ describe Mongoid::Paranoia do
|
|
164
164
|
end
|
165
165
|
|
166
166
|
it "executes the before destroy callbacks" do
|
167
|
-
post.before_destroy_called.
|
167
|
+
expect(post.before_destroy_called).to be_truthy
|
168
168
|
end
|
169
169
|
|
170
170
|
it "executes the after destroy callbacks" do
|
171
|
-
post.after_destroy_called.
|
171
|
+
expect(post.after_destroy_called).to be_truthy
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
@@ -191,7 +191,7 @@ describe Mongoid::Paranoia do
|
|
191
191
|
end
|
192
192
|
|
193
193
|
it "soft deletes the document" do
|
194
|
-
raw["paranoid_phones"].first["deleted_at"].
|
194
|
+
expect(raw["paranoid_phones"].first["deleted_at"]).to be_within(1).of(Time.now)
|
195
195
|
end
|
196
196
|
|
197
197
|
it "does not return the document in a find" do
|
@@ -201,15 +201,15 @@ describe Mongoid::Paranoia do
|
|
201
201
|
end
|
202
202
|
|
203
203
|
it "does not include the document in the relation" do
|
204
|
-
person.paranoid_phones.scoped.
|
204
|
+
expect(person.paranoid_phones.scoped).to be_empty
|
205
205
|
end
|
206
206
|
|
207
207
|
it "executes the before destroy callbacks" do
|
208
|
-
phone.before_destroy_called.
|
208
|
+
expect(phone.before_destroy_called).to be_truthy
|
209
209
|
end
|
210
210
|
|
211
211
|
it "executes the after destroy callbacks" do
|
212
|
-
phone.after_destroy_called.
|
212
|
+
expect(phone.after_destroy_called).to be_truthy
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
@@ -252,7 +252,7 @@ describe Mongoid::Paranoia do
|
|
252
252
|
end
|
253
253
|
|
254
254
|
it "does not destroy the document" do
|
255
|
-
post.
|
255
|
+
expect(post).not_to be_destroyed
|
256
256
|
end
|
257
257
|
end
|
258
258
|
end
|
@@ -272,7 +272,7 @@ describe Mongoid::Paranoia do
|
|
272
272
|
end
|
273
273
|
|
274
274
|
it "returns true" do
|
275
|
-
post.
|
275
|
+
expect(post).to be_destroyed
|
276
276
|
end
|
277
277
|
end
|
278
278
|
|
@@ -283,7 +283,7 @@ describe Mongoid::Paranoia do
|
|
283
283
|
end
|
284
284
|
|
285
285
|
it "returns true" do
|
286
|
-
post.
|
286
|
+
expect(post).to be_destroyed
|
287
287
|
end
|
288
288
|
end
|
289
289
|
end
|
@@ -305,7 +305,7 @@ describe Mongoid::Paranoia do
|
|
305
305
|
end
|
306
306
|
|
307
307
|
it "returns true" do
|
308
|
-
phone.
|
308
|
+
expect(phone).to be_destroyed
|
309
309
|
end
|
310
310
|
end
|
311
311
|
|
@@ -316,7 +316,7 @@ describe Mongoid::Paranoia do
|
|
316
316
|
end
|
317
317
|
|
318
318
|
it "returns true" do
|
319
|
-
phone.
|
319
|
+
expect(phone).to be_destroyed
|
320
320
|
end
|
321
321
|
end
|
322
322
|
end
|
@@ -337,7 +337,7 @@ describe Mongoid::Paranoia do
|
|
337
337
|
end
|
338
338
|
|
339
339
|
it "returns true" do
|
340
|
-
post.
|
340
|
+
expect(post).to be_deleted
|
341
341
|
end
|
342
342
|
end
|
343
343
|
|
@@ -348,7 +348,7 @@ describe Mongoid::Paranoia do
|
|
348
348
|
end
|
349
349
|
|
350
350
|
it "returns true" do
|
351
|
-
post.
|
351
|
+
expect(post).to be_deleted
|
352
352
|
end
|
353
353
|
end
|
354
354
|
end
|
@@ -370,7 +370,7 @@ describe Mongoid::Paranoia do
|
|
370
370
|
end
|
371
371
|
|
372
372
|
it "returns true" do
|
373
|
-
phone.
|
373
|
+
expect(phone).to be_deleted
|
374
374
|
end
|
375
375
|
end
|
376
376
|
|
@@ -381,7 +381,7 @@ describe Mongoid::Paranoia do
|
|
381
381
|
end
|
382
382
|
|
383
383
|
it "returns true" do
|
384
|
-
phone.
|
384
|
+
expect(phone).to be_deleted
|
385
385
|
end
|
386
386
|
end
|
387
387
|
end
|
@@ -404,7 +404,7 @@ describe Mongoid::Paranoia do
|
|
404
404
|
end
|
405
405
|
|
406
406
|
it "hard deletes the document" do
|
407
|
-
raw.
|
407
|
+
expect(raw).to be_nil
|
408
408
|
end
|
409
409
|
end
|
410
410
|
|
@@ -427,7 +427,7 @@ describe Mongoid::Paranoia do
|
|
427
427
|
end
|
428
428
|
|
429
429
|
it "hard deletes the document" do
|
430
|
-
raw["paranoid_phones"].
|
430
|
+
expect(raw["paranoid_phones"]).to be_empty
|
431
431
|
end
|
432
432
|
end
|
433
433
|
|
@@ -470,7 +470,7 @@ describe Mongoid::Paranoia do
|
|
470
470
|
end
|
471
471
|
|
472
472
|
it "soft deletes the document" do
|
473
|
-
raw["deleted_at"].
|
473
|
+
expect(raw["deleted_at"]).to be_within(1).of(Time.now)
|
474
474
|
end
|
475
475
|
|
476
476
|
it "does not return the document in a find" do
|
@@ -480,7 +480,7 @@ describe Mongoid::Paranoia do
|
|
480
480
|
end
|
481
481
|
|
482
482
|
it "clears out the persistence options" do
|
483
|
-
ParanoidPost.persistence_options.
|
483
|
+
expect(ParanoidPost.persistence_options).to be_nil
|
484
484
|
end
|
485
485
|
end
|
486
486
|
|
@@ -503,7 +503,7 @@ describe Mongoid::Paranoia do
|
|
503
503
|
end
|
504
504
|
|
505
505
|
it "soft deletes the document" do
|
506
|
-
raw["paranoid_phones"].first["deleted_at"].
|
506
|
+
expect(raw["paranoid_phones"].first["deleted_at"]).to be_within(1).of(Time.now)
|
507
507
|
end
|
508
508
|
|
509
509
|
it "does not return the document in a find" do
|
@@ -513,7 +513,7 @@ describe Mongoid::Paranoia do
|
|
513
513
|
end
|
514
514
|
|
515
515
|
it "does not include the document in the relation" do
|
516
|
-
person.paranoid_phones.scoped.
|
516
|
+
expect(person.paranoid_phones.scoped).to be_empty
|
517
517
|
end
|
518
518
|
end
|
519
519
|
|
@@ -556,7 +556,7 @@ describe Mongoid::Paranoia do
|
|
556
556
|
end
|
557
557
|
|
558
558
|
it "does not destroy the document" do
|
559
|
-
post.
|
559
|
+
expect(post).not_to be_destroyed
|
560
560
|
end
|
561
561
|
end
|
562
562
|
end
|
@@ -576,7 +576,7 @@ describe Mongoid::Paranoia do
|
|
576
576
|
end
|
577
577
|
|
578
578
|
it "sets the deleted flag" do
|
579
|
-
post.
|
579
|
+
expect(post).to be_destroyed
|
580
580
|
end
|
581
581
|
end
|
582
582
|
|
@@ -594,15 +594,15 @@ describe Mongoid::Paranoia do
|
|
594
594
|
end
|
595
595
|
|
596
596
|
it "removes the deleted at time" do
|
597
|
-
post.deleted_at.
|
597
|
+
expect(post.deleted_at).to be_nil
|
598
598
|
end
|
599
599
|
|
600
600
|
it "persists the change" do
|
601
|
-
post.reload.deleted_at.
|
601
|
+
expect(post.reload.deleted_at).to be_nil
|
602
602
|
end
|
603
603
|
|
604
604
|
it "marks document again as persisted" do
|
605
|
-
post.persisted
|
605
|
+
expect(post.persisted?).to be_truthy
|
606
606
|
end
|
607
607
|
end
|
608
608
|
|
@@ -622,11 +622,11 @@ describe Mongoid::Paranoia do
|
|
622
622
|
end
|
623
623
|
|
624
624
|
it "removes the deleted at time" do
|
625
|
-
phone.deleted_at.
|
625
|
+
expect(phone.deleted_at).to be_nil
|
626
626
|
end
|
627
627
|
|
628
628
|
it "persists the change" do
|
629
|
-
person.reload.paranoid_phones.first.deleted_at.
|
629
|
+
expect(person.reload.paranoid_phones.first.deleted_at).to be_nil
|
630
630
|
end
|
631
631
|
end
|
632
632
|
end
|
@@ -638,7 +638,7 @@ describe Mongoid::Paranoia do
|
|
638
638
|
end
|
639
639
|
|
640
640
|
it "returns a scoped criteria" do
|
641
|
-
scoped.selector.
|
641
|
+
expect(scoped.selector).to eq({ "deleted_at" => nil })
|
642
642
|
end
|
643
643
|
end
|
644
644
|
|
@@ -657,7 +657,7 @@ describe Mongoid::Paranoia do
|
|
657
657
|
end
|
658
658
|
|
659
659
|
it "persists the change" do
|
660
|
-
post.reload.deleted_at.
|
660
|
+
expect(post.reload.deleted_at).to be_within(1).of(time)
|
661
661
|
end
|
662
662
|
end
|
663
663
|
|
@@ -668,7 +668,7 @@ describe Mongoid::Paranoia do
|
|
668
668
|
end
|
669
669
|
|
670
670
|
it "returns an unscoped criteria" do
|
671
|
-
unscoped.selector.
|
671
|
+
expect(unscoped.selector).to eq({})
|
672
672
|
end
|
673
673
|
end
|
674
674
|
|
@@ -681,7 +681,7 @@ describe Mongoid::Paranoia do
|
|
681
681
|
context "when the document is new" do
|
682
682
|
|
683
683
|
it "still returns nil" do
|
684
|
-
post.to_param.
|
684
|
+
expect(post.to_param).to be_nil
|
685
685
|
end
|
686
686
|
end
|
687
687
|
|
@@ -692,7 +692,7 @@ describe Mongoid::Paranoia do
|
|
692
692
|
end
|
693
693
|
|
694
694
|
it "returns the id as a string" do
|
695
|
-
post.to_param.
|
695
|
+
expect(post.to_param).to eq(post.id.to_s)
|
696
696
|
end
|
697
697
|
end
|
698
698
|
|
@@ -704,7 +704,7 @@ describe Mongoid::Paranoia do
|
|
704
704
|
end
|
705
705
|
|
706
706
|
it "returns the id as a string" do
|
707
|
-
post.to_param.
|
707
|
+
expect(post.to_param).to eq(post.id.to_s)
|
708
708
|
end
|
709
709
|
end
|
710
710
|
end
|
@@ -11,7 +11,7 @@ describe Mongoid::Criteria::Scopable do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "includes the deleted_at criteria in the selector" do
|
14
|
-
criteria.selector.
|
14
|
+
expect(criteria.selector).to eq({
|
15
15
|
"deleted_at" => nil, "fresh" => true
|
16
16
|
})
|
17
17
|
end
|
@@ -24,7 +24,7 @@ describe Mongoid::Criteria::Scopable do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "does not include the deleted_at in the selector" do
|
27
|
-
criteria.selector.
|
27
|
+
expect(criteria.selector).to eq({ "fresh" => true })
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,7 +35,7 @@ describe Mongoid::Criteria::Scopable do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "includes the deleted_at $ne criteria in the selector" do
|
38
|
-
criteria.selector.
|
38
|
+
expect(criteria.selector).to eq({
|
39
39
|
"deleted_at" => { "$ne" => nil }, "fresh" => true
|
40
40
|
})
|
41
41
|
end
|
@@ -48,7 +48,7 @@ describe Mongoid::Criteria::Scopable do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "includes no default scoping information in the selector" do
|
51
|
-
criteria.selector.
|
51
|
+
expect(criteria.selector).to eq({ "fresh" => true })
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -27,7 +27,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns true" do
|
30
|
-
new_post.
|
30
|
+
expect(new_post).to be_valid
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -42,7 +42,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "returns true" do
|
45
|
-
new_post.
|
45
|
+
expect(new_post).to be_valid
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -53,7 +53,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "returns false" do
|
56
|
-
new_post.
|
56
|
+
expect(new_post).not_to be_valid
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-paranoia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Uher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,16 +28,58 @@ dependencies:
|
|
28
28
|
name: mongoid
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.0.0
|
33
|
+
version: 4.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mongoid-versioning
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
37
44
|
requirements:
|
38
45
|
- - '='
|
39
46
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
47
|
+
version: 1.0.0.beta2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0.beta2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3'
|
41
83
|
description: There may be times when you don't want documents to actually get deleted
|
42
84
|
from the database, but "flagged" as deleted.
|
43
85
|
email: uher.mario@gmail.com
|
@@ -51,8 +93,8 @@ files:
|
|
51
93
|
- Gemfile
|
52
94
|
- README.md
|
53
95
|
- Rakefile
|
54
|
-
- gemfiles/mongoid_master.gemfile
|
55
96
|
- lib/mongoid/core_ext/builders/nested_attributes/many.rb
|
97
|
+
- lib/mongoid/core_ext/document.rb
|
56
98
|
- lib/mongoid/core_ext/relations/embedded/many.rb
|
57
99
|
- lib/mongoid/core_ext/validatable/uniqueness.rb
|
58
100
|
- lib/mongoid/paranoia.rb
|
@@ -244,6 +286,7 @@ files:
|
|
244
286
|
- spec/config/mongoid.yml
|
245
287
|
- spec/mongoid/attributes/nested_spec.rb
|
246
288
|
- spec/mongoid/criteria/scopable_spec.rb
|
289
|
+
- spec/mongoid/document_spec.rb
|
247
290
|
- spec/mongoid/paranoia_spec.rb
|
248
291
|
- spec/mongoid/scoping_spec.rb
|
249
292
|
- spec/mongoid/validatable/uniqueness_spec.rb
|
@@ -267,9 +310,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
310
|
version: 1.3.1
|
268
311
|
requirements: []
|
269
312
|
rubyforge_project:
|
270
|
-
rubygems_version: 2.2.
|
313
|
+
rubygems_version: 2.2.2
|
271
314
|
signing_key:
|
272
315
|
specification_version: 4
|
273
316
|
summary: Extraction of mongoid-paranoia into its own gem.
|
274
317
|
test_files: []
|
275
|
-
has_rdoc:
|