mongoid_paranoia 0.4.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.
@@ -1,164 +1,164 @@
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
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