object_attorney 2.10.3 → 2.10.5
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,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
OGIzZmNlNzdmNDU4ODQzY2RmNzcxNWJjNjkyYTAzYTZiN2E3Y2ZmNg==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
NTk0MDJlYzNjYzE1ZDY4MWU1ZmJiZjBhMTU4NTRlZDcwNTJiMzZiZA==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
YmRlNjFmYjczMDY0ZTNhNDkxNTRhMDhjOTg5OWZlN2U4ZTYxMWEzNjAyMTBm
|
|
10
|
+
ZGRhYTRiMWNjZGQ1ZTkzNjk3NTgyMzU0OGMzM2I5OTFmZTBhYmUxMzZkNzM4
|
|
11
|
+
OTE3OTkyYjgxMTQ4ZjlhY2U4MzIxYTk5ZTkwZDFiNjZkOTFiYWI=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
OGE5MTQ1MTljNjQwZGY2MDEzNzFhMGU2MGU5MjQ2ODM4ZjhmOWVkMTY5MWRl
|
|
14
|
+
NGRiMzRiOTc1NzlkZjFhYjllNjgxNDk1OTA5NTQ0MmVlMjU1NDEwNmUzYjFm
|
|
15
|
+
MzEyNDg0OTU2MjVmYmNjYWYyNTk4OGEzODQ2ZTc1M2I1NDAxNWI=
|
|
@@ -35,6 +35,15 @@ module ObjectAttorney
|
|
|
35
35
|
nested_objects_list
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
def reset_nested_objects(reflection_name = nil)
|
|
39
|
+
self.class.reflect_on_all_associations.each do |reflection|
|
|
40
|
+
next if !reflection_name.nil? && reflection_name != reflection.name
|
|
41
|
+
|
|
42
|
+
self.instance_variable_set("@#{reflection.name}_attributes", {})
|
|
43
|
+
self.instance_variable_set("@#{reflection.name}", nil)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
38
47
|
protected #################### PROTECTED METHODS DOWN BELOW ######################
|
|
39
48
|
|
|
40
49
|
def save_or_destroy_nested_objects(save_method, association_macro)
|
data/lib/object_attorney.rb
CHANGED
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe PostForm::Presenter do
|
|
4
4
|
|
|
5
|
-
it "1. Editing a 'Post', through one property and delegating all missing methods to the represented object"
|
|
5
|
+
it "1. Editing a 'Post', through one property and delegating all missing methods to the represented object" do
|
|
6
6
|
params = {
|
|
7
7
|
post: {
|
|
8
8
|
title: 'altered title',
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe 'Testing the #reset_nested_objects method' do
|
|
4
|
+
|
|
5
|
+
it "1. Creating 'Comments' from 'PostWithCommentForm::Base', adding another, manually and expecting the form_object to not knowing it.", current: true do
|
|
6
|
+
params = {
|
|
7
|
+
post: {
|
|
8
|
+
title: 'new title',
|
|
9
|
+
comments_attributes: {
|
|
10
|
+
"0" => { body: "body1" },
|
|
11
|
+
"1" => { body: "1" }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
post_form = PostWithCommentForm::Base.new(params[:post])
|
|
17
|
+
|
|
18
|
+
post_form.save.should == true
|
|
19
|
+
|
|
20
|
+
Post.all.count.should == 1
|
|
21
|
+
Comment.all.count.should == 2
|
|
22
|
+
|
|
23
|
+
post_form.comments.length.should == 2
|
|
24
|
+
|
|
25
|
+
post = Post.first
|
|
26
|
+
post.comments.create(body: 'new_comment')
|
|
27
|
+
|
|
28
|
+
post_form.post.reload
|
|
29
|
+
post_form.post.comments.length.should == 3
|
|
30
|
+
post_form.comments.length.should == 2
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "1. Creating 'Comments' from 'PostWithCommentForm::Base', adding another, manually and expecting the form_object to know about it.", current: true do
|
|
34
|
+
params = {
|
|
35
|
+
post: {
|
|
36
|
+
title: 'new title',
|
|
37
|
+
comments_attributes: {
|
|
38
|
+
"0" => { body: "body1" },
|
|
39
|
+
"1" => { body: "1" }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
post_form = PostWithCommentForm::Base.new(params[:post])
|
|
45
|
+
|
|
46
|
+
post_form.save.should == true
|
|
47
|
+
|
|
48
|
+
Post.all.count.should == 1
|
|
49
|
+
Comment.all.count.should == 2
|
|
50
|
+
|
|
51
|
+
post_form.comments.length.should == 2
|
|
52
|
+
|
|
53
|
+
post = Post.first
|
|
54
|
+
post.comments.create(body: 'new_comment')
|
|
55
|
+
|
|
56
|
+
post_form.post.reload
|
|
57
|
+
post_form.post.comments.length.should == 3
|
|
58
|
+
|
|
59
|
+
post_form.reset_nested_objects(:comments)
|
|
60
|
+
post_form.comments.length.should == 3
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: object_attorney
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.10.
|
|
4
|
+
version: 2.10.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- João Gonçalves
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -94,6 +94,7 @@ files:
|
|
|
94
94
|
- spec/object_attorney/bulk_posts_allow_only_new_form_spec.rb
|
|
95
95
|
- spec/object_attorney/bulk_posts_with_form_objects_form_spec.rb
|
|
96
96
|
- spec/object_attorney/delegation_spec.rb
|
|
97
|
+
- spec/object_attorney/nested_objects_spec.rb
|
|
97
98
|
- spec/object_attorney/post_form_spec.rb
|
|
98
99
|
- spec/object_attorney/post_validations_form_spec.rb
|
|
99
100
|
- spec/object_attorney/post_with_comment_form_spec.rb
|
|
@@ -157,6 +158,7 @@ test_files:
|
|
|
157
158
|
- spec/object_attorney/bulk_posts_allow_only_new_form_spec.rb
|
|
158
159
|
- spec/object_attorney/bulk_posts_with_form_objects_form_spec.rb
|
|
159
160
|
- spec/object_attorney/delegation_spec.rb
|
|
161
|
+
- spec/object_attorney/nested_objects_spec.rb
|
|
160
162
|
- spec/object_attorney/post_form_spec.rb
|
|
161
163
|
- spec/object_attorney/post_validations_form_spec.rb
|
|
162
164
|
- spec/object_attorney/post_with_comment_form_spec.rb
|