mongoid_paranoia 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,247 +0,0 @@
1
- class NormBase
2
- include Mongoid::Document
3
-
4
- has_one :norm_has_one, dependent: :destroy
5
- has_one :para_has_one, dependent: :destroy
6
-
7
- has_many :norm_has_many, dependent: :destroy
8
- has_many :para_has_many, dependent: :destroy
9
-
10
- has_many :norm_has_many_poly, dependent: :destroy
11
- has_many :para_has_many_poly, dependent: :destroy
12
-
13
- belongs_to :norm_belongs_to_one, dependent: :destroy
14
- belongs_to :para_belongs_to_one, dependent: :destroy
15
-
16
- belongs_to :norm_belongs_to, dependent: :destroy
17
- belongs_to :para_belongs_to, dependent: :destroy
18
-
19
- has_and_belongs_to_many :norm_habtm, dependent: :destroy
20
- has_and_belongs_to_many :para_habtm, dependent: :destroy
21
-
22
- embeds_one :norm_embeds_one
23
- embeds_one :para_embeds_one
24
-
25
- embeds_many :norm_embeds_many
26
- embeds_many :para_embeds_many
27
-
28
- embeds_many :norm_embeds_many_poly
29
- embeds_many :para_embeds_many_poly
30
- end
31
-
32
- class ParaBase
33
- include Mongoid::Document
34
- include Mongoid::Paranoia
35
-
36
- has_one :norm_has_one, dependent: :destroy
37
- has_one :para_has_one, dependent: :destroy
38
-
39
- has_many :norm_has_many, dependent: :destroy
40
- has_many :para_has_many, dependent: :destroy
41
-
42
- has_many :norm_has_many_poly, dependent: :destroy
43
- has_many :para_has_many_poly, dependent: :destroy
44
-
45
- belongs_to :norm_belongs_to_one, dependent: :destroy
46
- belongs_to :para_belongs_to_one, dependent: :destroy
47
-
48
- belongs_to :norm_belongs_to, dependent: :destroy
49
- belongs_to :para_belongs_to, dependent: :destroy
50
-
51
- has_and_belongs_to_many :norm_habtm, dependent: :destroy
52
- has_and_belongs_to_many :para_habtm, dependent: :destroy
53
-
54
- embeds_one :norm_embeds_one
55
- embeds_one :para_embeds_one
56
-
57
- embeds_many :norm_embeds_many
58
- embeds_many :para_embeds_many
59
-
60
- embeds_many :norm_embeds_many_poly
61
- embeds_many :para_embeds_many_poly
62
- end
63
-
64
- class NormHasOne
65
- include Mongoid::Document
66
-
67
- belongs_to :norm_base
68
- belongs_to :para_base
69
-
70
- has_one :norm_belongs_to, dependent: :destroy
71
- has_one :para_belongs_to, dependent: :destroy
72
-
73
- has_one :norm_habtm, dependent: :destroy
74
- has_one :norm_habtm, dependent: :destroy
75
- end
76
-
77
- class NormHasMany
78
- include Mongoid::Document
79
-
80
- belongs_to :norm_base
81
- belongs_to :para_base
82
-
83
- has_many :norm_belongs_to, dependent: :destroy
84
- has_many :para_belongs_to, dependent: :destroy
85
-
86
- has_many :norm_habtm, dependent: :destroy
87
- has_many :norm_habtm, dependent: :destroy
88
- end
89
-
90
- class NormHasManyPoly
91
- include Mongoid::Document
92
-
93
- belongs_to :base, polymorphic: true
94
- end
95
-
96
- class NormBelongsToOne
97
- include Mongoid::Document
98
-
99
- has_one :norm_base
100
- has_one :para_base
101
- end
102
-
103
- class NormBelongsTo
104
- include Mongoid::Document
105
-
106
- has_many :norm_base
107
- has_many :para_base
108
-
109
- belongs_to :norm_has_one, dependent: :destroy
110
- belongs_to :para_has_one, dependent: :destroy
111
-
112
- belongs_to :norm_has_many, dependent: :destroy
113
- belongs_to :para_has_many, dependent: :destroy
114
- end
115
-
116
- class NormHabtm
117
- include Mongoid::Document
118
-
119
- has_and_belongs_to_many :norm_base
120
- has_and_belongs_to_many :para_base
121
-
122
- belongs_to :norm_has_one, dependent: :destroy
123
- belongs_to :para_has_one, dependent: :destroy
124
-
125
- belongs_to :norm_has_many, dependent: :destroy
126
- belongs_to :para_has_many, dependent: :destroy
127
-
128
- has_and_belongs_to_many :recursive, class_name: 'NormHabtm', inverse_of: :recursive, dependent: :destroy
129
- has_and_belongs_to_many :para_habtm, dependent: :destroy
130
- end
131
-
132
- class NormEmbedsOne
133
- include Mongoid::Document
134
-
135
- embedded_in :norm_base
136
- embedded_in :para_base
137
- end
138
-
139
- class NormEmbedsMany
140
- include Mongoid::Document
141
-
142
- embedded_in :norm_base
143
- embedded_in :para_base
144
- end
145
-
146
- class NormEmbedsManyPoly
147
- include Mongoid::Document
148
-
149
- embedded_in :base, polymorphic: true
150
- end
151
-
152
- class ParaHasOne
153
- include Mongoid::Document
154
- include Mongoid::Paranoia
155
-
156
- belongs_to :norm_base
157
- belongs_to :para_base
158
-
159
- has_one :norm_belongs_to, dependent: :destroy
160
- has_one :para_belongs_to, dependent: :destroy
161
-
162
- has_one :norm_habtm, dependent: :destroy
163
- has_one :norm_habtm, dependent: :destroy
164
- end
165
-
166
- class ParaHasMany
167
- include Mongoid::Document
168
- include Mongoid::Paranoia
169
-
170
- belongs_to :norm_base
171
- belongs_to :para_base
172
-
173
- has_many :norm_belongs_to, dependent: :destroy
174
- has_many :para_belongs_to, dependent: :destroy
175
-
176
- has_many :norm_habtm, dependent: :destroy
177
- has_many :norm_habtm, dependent: :destroy
178
- end
179
-
180
- class ParaHasManyPoly
181
- include Mongoid::Document
182
- include Mongoid::Paranoia
183
-
184
- belongs_to :base, polymorphic: true
185
- end
186
-
187
- class ParaBelongsToOne
188
- include Mongoid::Document
189
- include Mongoid::Paranoia
190
-
191
- has_one :norm_base
192
- has_one :para_base
193
- end
194
-
195
- class ParaBelongsTo
196
- include Mongoid::Document
197
- include Mongoid::Paranoia
198
-
199
- has_many :norm_base
200
- has_many :para_base
201
-
202
- belongs_to :norm_has_one, dependent: :destroy
203
- belongs_to :para_has_one, dependent: :destroy
204
-
205
- belongs_to :norm_has_many, dependent: :destroy
206
- belongs_to :para_has_many, dependent: :destroy
207
- end
208
-
209
- class ParaHabtm
210
- include Mongoid::Document
211
- include Mongoid::Paranoia
212
-
213
- has_and_belongs_to_many :norm_base
214
- has_and_belongs_to_many :para_base
215
-
216
- belongs_to :norm_has_one, dependent: :destroy
217
- belongs_to :para_has_one, dependent: :destroy
218
-
219
- belongs_to :norm_has_many, dependent: :destroy
220
- belongs_to :para_has_many, dependent: :destroy
221
-
222
- has_and_belongs_to_many :norm_habtm, dependent: :destroy
223
- has_and_belongs_to_many :recursive, class_name: 'ParaHabtm', inverse_of: :recursive, dependent: :destroy
224
- end
225
-
226
- class ParaEmbedsOne
227
- include Mongoid::Document
228
- include Mongoid::Paranoia
229
-
230
- embedded_in :norm_base
231
- embedded_in :para_base
232
- end
233
-
234
- class ParaEmbedsMany
235
- include Mongoid::Document
236
- include Mongoid::Paranoia
237
-
238
- embedded_in :norm_base
239
- embedded_in :para_base
240
- end
241
-
242
- class ParaEmbedsManyPoly
243
- include Mongoid::Document
244
- include Mongoid::Paranoia
245
-
246
- embedded_in :base, polymorphic: true
247
- end
@@ -1,6 +0,0 @@
1
- class Tag
2
- include Mongoid::Document
3
- field :text, type: String
4
- has_and_belongs_to_many :paranoid_posts
5
- has_and_belongs_to_many :related, class_name: "Tag", inverse_of: :related
6
- end
@@ -1,4 +0,0 @@
1
- class Title
2
- include Mongoid::Document
3
- belongs_to :paranoid_post
4
- end
@@ -1,19 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Mongoid
4
- module Paranoia
5
- describe Configuration do
6
- describe '#paranoid_field' do
7
- it 'initializes with default value set to :deleted_at' do
8
- expect(Configuration.new.paranoid_field).to eq(:deleted_at)
9
- end
10
-
11
- it 'can be updated' do
12
- config = Configuration.new
13
- config.paranoid_field = :myFieldName
14
- expect(config.paranoid_field).to eq(:myFieldName)
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,21 +0,0 @@
1
- require "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
@@ -1,164 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Mongoid::Attributes::Nested do
4
- describe "##{name}_attributes=" do
5
- context "when the parent document is new" do
6
- context "when the relation is an embeds many" do
7
- context "when ids are passed" do
8
-
9
- let(:person) do
10
- Person.create
11
- end
12
-
13
- let(:address_one) do
14
- Address.new(street: "Unter den Linden")
15
- end
16
-
17
- let(:address_two) do
18
- Address.new(street: "Kurfeurstendamm")
19
- end
20
-
21
- let(:phone_one) do
22
- ParanoidPhone.new(number: "1")
23
- end
24
-
25
- let(:phone_two) do
26
- ParanoidPhone.new(number: "2")
27
- end
28
-
29
- before do
30
- person.addresses << [ address_one, address_two ]
31
- end
32
-
33
- context "when destroy attributes are passed" do
34
- context "when the ids match" do
35
- context "when allow_destroy is true" do
36
- context "when the child is paranoid" do
37
-
38
- before(:all) do
39
- Person.send(:undef_method, :paranoid_phones_attributes=)
40
- Person.accepts_nested_attributes_for :paranoid_phones,
41
- allow_destroy: true
42
- end
43
-
44
- after(:all) do
45
- Person.send(:undef_method, :paranoid_phones_attributes=)
46
- Person.accepts_nested_attributes_for :paranoid_phones
47
- end
48
-
49
- [ 1, "1", true, "true" ].each do |truth|
50
-
51
- context "when passed a #{truth} with destroy" do
52
- context "when the parent is persisted" do
53
-
54
- let!(:persisted) do
55
- Person.create do |p|
56
- p.paranoid_phones << [ phone_one, phone_two ]
57
- end
58
- end
59
-
60
- context "when setting, pulling, and pushing in one op" do
61
-
62
- before do
63
- persisted.paranoid_phones_attributes =
64
- {
65
- "bar" => { "id" => phone_one.id, "_destroy" => truth },
66
- "foo" => { "id" => phone_two.id, "number" => "3" },
67
- "baz" => { "number" => "4" }
68
- }
69
- end
70
-
71
- it "removes the first document from the relation" do
72
- expect(persisted.paranoid_phones.size).to eq(2)
73
- end
74
-
75
- it "does not delete the unmarked document" do
76
- expect(persisted.paranoid_phones.first.number).to eq("3")
77
- end
78
-
79
- it "adds the new document to the relation" do
80
- expect(persisted.paranoid_phones.last.number).to eq("4")
81
- end
82
-
83
- it "has the proper persisted count" do
84
- expect(persisted.paranoid_phones.count).to eq(1)
85
- end
86
-
87
- it "soft deletes the removed document" do
88
- expect(phone_one).to be_destroyed
89
- end
90
-
91
- context "when saving the parent" do
92
-
93
- before do
94
- persisted.save
95
- end
96
-
97
- it "deletes the marked document from the relation" do
98
- expect(persisted.reload.paranoid_phones.count).to eq(2)
99
- end
100
-
101
- it "does not delete the unmarked document" do
102
- expect(persisted.reload.paranoid_phones.first.number).to eq("3")
103
- end
104
-
105
- it "persists the new document to the relation" do
106
- expect(persisted.reload.paranoid_phones.last.number).to eq("4")
107
- end
108
- end
109
- end
110
- end
111
- end
112
- end
113
- end
114
-
115
- context "when the child has defaults" do
116
-
117
- before(:all) do
118
- Person.accepts_nested_attributes_for :appointments, allow_destroy: true
119
- end
120
-
121
- after(:all) do
122
- Person.send(:undef_method, :appointments_attributes=)
123
- end
124
- context "when the parent is persisted" do
125
- context "when the child returns false in a before callback" do
126
- context "when the child is paranoid" do
127
-
128
- before(:all) do
129
- Person.accepts_nested_attributes_for :paranoid_phones, allow_destroy: true
130
- end
131
-
132
- after(:all) do
133
- Person.send(:undef_method, :paranoid_phones=)
134
- Person.accepts_nested_attributes_for :paranoid_phones
135
- end
136
-
137
- let!(:persisted) do
138
- Person.create(age: 42)
139
- end
140
-
141
- let!(:phone) do
142
- persisted.paranoid_phones.create
143
- end
144
-
145
- before do
146
- persisted.paranoid_phones_attributes =
147
- { "foo" => { "id" => phone.id, "number" => 42, "_destroy" => true }}
148
- end
149
-
150
- it "does not destroy the child" do
151
- expect(persisted.reload.paranoid_phones).not_to be_empty
152
- end
153
- end
154
- end
155
- end
156
- end
157
- end
158
- end
159
- end
160
- end
161
- end
162
- end
163
- end
164
- end