object_attorney 2.9.3 → 2.9.4
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 +8 -8
- data/lib/object_attorney/association_reflection.rb +2 -0
- data/lib/object_attorney/nested_objects.rb +5 -3
- data/lib/object_attorney/version.rb +1 -1
- data/spec/object_attorney/post_with_comment_form_spec.rb +0 -13
- data/spec/object_attorney/user_and_comments_form_spec.rb +34 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/form_objects/user_and_comments_form.rb +9 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
ZjU4ZTc4YWEwNzcxNGM4NDliNjYzNDQzYmZiMDZmZGEwNzRmMTMyNg==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
NGYwOWViZGY5MTI5MTAyM2MyMjdlMDA2NDU4NjdkOTFhNzViZTFiYQ==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
OWJhNjY2YTljMDAxODk1Nzk5YjBmMDUzNzg2ZjkzMDk3NDE3YmJiZjE5OGNj
|
|
10
|
+
NzBmZjRmMjA1YzQzZWM5MmE3ZjIxZTY4NTExYzU4YjE1NmEzNzRkNDM1MGUw
|
|
11
|
+
YjYzM2QwZWZjYjEzYzM3NDE2ODA0NjNhNDg2MTkzYjgxNjE1YWU=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
ZjVhM2FkMjMxYjM4OTRmNzk3YzhkZGJiZGU0Njg1M2Q1MGY3YzUwMTY5YjNj
|
|
14
|
+
MDVhNjRkM2I3YTk3NGE4MDY0NGI2ZWU2OWNmMTk4N2U2OTNkODYyYTk3MGI1
|
|
15
|
+
YjkzMTRhYjQwMWRhZDFmNjc3ZGRhYmUzYTc5YjU0ZmFmZWFmYzM=
|
|
@@ -161,12 +161,12 @@ module ObjectAttorney
|
|
|
161
161
|
|
|
162
162
|
return nil if reflection.options[:new_records] == false
|
|
163
163
|
|
|
164
|
-
if can_represented_object_build_nested?(reflection, nested_object_name)
|
|
164
|
+
if reflection.options[:standalone] == true || !can_represented_object_build_nested?(reflection, nested_object_name)
|
|
165
|
+
new_nested_object = reflection.klass.new(attributes)
|
|
166
|
+
else
|
|
165
167
|
new_nested_object = build_from_represented_object(reflection, nested_object_name)
|
|
166
168
|
|
|
167
169
|
new_nested_object = assign_attributes_or_build_nested_object(reflection, attributes, new_nested_object)
|
|
168
|
-
else
|
|
169
|
-
new_nested_object = reflection.klass.new(attributes)
|
|
170
170
|
end
|
|
171
171
|
|
|
172
172
|
populate_foreign_key(self, new_nested_object, reflection, :has_many)
|
|
@@ -206,6 +206,8 @@ module ObjectAttorney
|
|
|
206
206
|
|
|
207
207
|
return [] if nested_relection.options[:existing_records] == false
|
|
208
208
|
|
|
209
|
+
return (nested_relection.klass.try(:all) || []) if nested_relection.options[:standalone] == true
|
|
210
|
+
|
|
209
211
|
existing = represented_object.nil? ? (nested_relection.klass.try(:all) || []) : (represented_object.send(nested_object_name) || (nested_relection.has_many? ? [] : nil))
|
|
210
212
|
|
|
211
213
|
if represented_object.present?
|
|
@@ -112,19 +112,6 @@ shared_examples "a PostWithCommentForm" do
|
|
|
112
112
|
comment.post_id.should == 1
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
it "5. Editing a 'Post', creating new nested 'Comment' (with errors), editing another and deleting yet another (none of the changes should take place)." do
|
|
116
|
-
Post.create(title: "My title1")
|
|
117
|
-
Post.first.title.should == 'My title1'
|
|
118
|
-
Comment.create(post_id: 1, body: "body1")
|
|
119
|
-
Comment.create(post_id: 1, body: "body2")
|
|
120
|
-
Comment.all.count.should == 2
|
|
121
|
-
|
|
122
|
-
post_form = described_class.new({}, Post.find(1))
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
post_form.comments.first.class.should == CommentForm
|
|
126
|
-
end
|
|
127
|
-
|
|
128
115
|
end
|
|
129
116
|
|
|
130
117
|
describe PostWithCommentForm::Base do
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe UserAndCommentsForm do
|
|
4
|
+
|
|
5
|
+
it "1. Creating a 'User' and 'Comment's at the same time." do
|
|
6
|
+
params = {
|
|
7
|
+
user: {
|
|
8
|
+
email: 'email@gmail.com',
|
|
9
|
+
comments_attributes: {
|
|
10
|
+
"0" => { body: "body1" },
|
|
11
|
+
"1" => { body: "1" }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
user_form = described_class.new(params[:user])
|
|
17
|
+
|
|
18
|
+
user_form.save.should == true
|
|
19
|
+
user_form.comments.length.should == 2
|
|
20
|
+
|
|
21
|
+
User.all.count.should == 1
|
|
22
|
+
user = User.first
|
|
23
|
+
user.email.should == 'email@gmail.com'
|
|
24
|
+
|
|
25
|
+
Comment.all.count.should == 2
|
|
26
|
+
|
|
27
|
+
comment = Comment.find(1)
|
|
28
|
+
comment.body.should == 'body1'
|
|
29
|
+
|
|
30
|
+
comment = Comment.find(2)
|
|
31
|
+
comment.body.should == '1'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -29,6 +29,7 @@ require 'support/form_objects/bulk_posts_form'
|
|
|
29
29
|
require 'support/form_objects/bulk_posts_allow_only_existing_form'
|
|
30
30
|
require 'support/form_objects/bulk_posts_allow_only_new_form'
|
|
31
31
|
require 'support/form_objects/bulk_posts_with_form_objects_form'
|
|
32
|
+
require 'support/form_objects/user_and_comments_form'
|
|
32
33
|
require 'support/form_objects/user_form'
|
|
33
34
|
|
|
34
35
|
RSpec.configure do |config|
|
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.9.
|
|
4
|
+
version: 2.9.4
|
|
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-03-
|
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -102,6 +102,7 @@ files:
|
|
|
102
102
|
- spec/object_attorney/post_with_only_existing_comments_form_spec.rb
|
|
103
103
|
- spec/object_attorney/post_with_only_new_comments_form_spec.rb
|
|
104
104
|
- spec/object_attorney/serialization_spec.rb
|
|
105
|
+
- spec/object_attorney/user_and_comments_form_spec.rb
|
|
105
106
|
- spec/object_attorney/user_form_spec.rb
|
|
106
107
|
- spec/spec_helper.rb
|
|
107
108
|
- spec/support/active_model/validations.rb
|
|
@@ -118,6 +119,7 @@ files:
|
|
|
118
119
|
- spec/support/form_objects/post_with_comments_and_address_form.rb
|
|
119
120
|
- spec/support/form_objects/post_with_only_existing_comments_form.rb
|
|
120
121
|
- spec/support/form_objects/post_with_only_new_comments_form.rb
|
|
122
|
+
- spec/support/form_objects/user_and_comments_form.rb
|
|
121
123
|
- spec/support/form_objects/user_form.rb
|
|
122
124
|
- spec/support/models/address.rb
|
|
123
125
|
- spec/support/models/comment.rb
|
|
@@ -163,6 +165,7 @@ test_files:
|
|
|
163
165
|
- spec/object_attorney/post_with_only_existing_comments_form_spec.rb
|
|
164
166
|
- spec/object_attorney/post_with_only_new_comments_form_spec.rb
|
|
165
167
|
- spec/object_attorney/serialization_spec.rb
|
|
168
|
+
- spec/object_attorney/user_and_comments_form_spec.rb
|
|
166
169
|
- spec/object_attorney/user_form_spec.rb
|
|
167
170
|
- spec/spec_helper.rb
|
|
168
171
|
- spec/support/active_model/validations.rb
|
|
@@ -179,6 +182,7 @@ test_files:
|
|
|
179
182
|
- spec/support/form_objects/post_with_comments_and_address_form.rb
|
|
180
183
|
- spec/support/form_objects/post_with_only_existing_comments_form.rb
|
|
181
184
|
- spec/support/form_objects/post_with_only_new_comments_form.rb
|
|
185
|
+
- spec/support/form_objects/user_and_comments_form.rb
|
|
182
186
|
- spec/support/form_objects/user_form.rb
|
|
183
187
|
- spec/support/models/address.rb
|
|
184
188
|
- spec/support/models/comment.rb
|