object_attorney 2.9.2 → 2.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.rspec +1 -0
- data/lib/object_attorney/nested_objects.rb +12 -4
- data/lib/object_attorney/version.rb +1 -1
- data/spec/object_attorney/post_with_comment_form_spec.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWNjMWJhMWQwZjk1MTUyYTM2OWM3ZmI1NTRlYmZlYmRlMDMzYzAwNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjIwMjYxYzU1MmI5YjJkNTA4MTkxM2NjNzQzYTdmODI1Y2JhODM5Mg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2VmY2M4NTg2OGM4NzEyYzM0ODQ2OGQ1NTFlOWYxMmY3N2Y5OTRjNmQyNmU4
|
10
|
+
MWYxZjViZjZlNWY2MTI0MWY3MjY3MGRiOTlhZGNiOTk1YmNiMzJmNTc4YTM2
|
11
|
+
NGJjMDk3MjczZmQwYzkxMzgzY2UyZGE4NTg5MzdjMDQ4N2NlY2M=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2NjOGY3MDcyOWU2M2Q3MTdlMzdhMmM2YmFhMzI1MGEwOGZiODc3YTdjODZi
|
14
|
+
ZWZkNTJkYmYxNWY5NGE3ODgzODAzMzQ0MWYzYWM4YmFkZGY0NzgxZDQ2N2Mw
|
15
|
+
YWJmMDUxYmM3YWQ4NzQ0YzcyNmIyMzJjOWFjYjkwNmQxMTc5YmY=
|
data/.rspec
CHANGED
@@ -208,17 +208,25 @@ module ObjectAttorney
|
|
208
208
|
|
209
209
|
existing = represented_object.nil? ? (nested_relection.klass.try(:all) || []) : (represented_object.send(nested_object_name) || (nested_relection.has_many? ? [] : nil))
|
210
210
|
|
211
|
-
if represented_object.present?
|
212
|
-
if
|
213
|
-
existing = existing
|
211
|
+
if represented_object.present?
|
212
|
+
if self.class.represented_object_class.respond_to?(:reflect_on_association)
|
213
|
+
existing = _existing_in_form_objects(existing, nested_relection) if nested_relection.klass != self.class.represented_object_class.reflect_on_association(nested_object_name).try(:klass)
|
214
214
|
else
|
215
|
-
existing =
|
215
|
+
existing = _existing_in_form_objects(existing, nested_relection)
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
219
219
|
existing
|
220
220
|
end
|
221
221
|
|
222
|
+
def _existing_in_form_objects(existing, nested_relection)
|
223
|
+
if existing.respond_to?(:map)
|
224
|
+
existing.map { |existing_nested_object| nested_relection.klass.new({}, existing_nested_object) }
|
225
|
+
else
|
226
|
+
nested_relection.klass.new({}, existing)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
222
230
|
module ClassMethods
|
223
231
|
|
224
232
|
def has_many(nested_object_name, options = {})
|
@@ -112,6 +112,19 @@ 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
|
+
|
115
128
|
end
|
116
129
|
|
117
130
|
describe PostWithCommentForm::Base do
|
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.3
|
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-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|