object_attorney 2.9.2 → 2.9.3

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
- OTNmNTI5YThjYjcxYThjNmM2YWFmZjY5NjJlNjlkYTYzNGM1MWUwMw==
4
+ OWNjMWJhMWQwZjk1MTUyYTM2OWM3ZmI1NTRlYmZlYmRlMDMzYzAwNg==
5
5
  data.tar.gz: !binary |-
6
- MjY5YWNhNmI1ODUwZDUxNzExNzRiMWJhNDE0N2VjZDlkNzlkYzQ2OQ==
6
+ NjIwMjYxYzU1MmI5YjJkNTA4MTkxM2NjNzQzYTdmODI1Y2JhODM5Mg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODA1NzdlY2U2NmY0Mzc2YTA1NDk1NGY1ZWQ3ZDhjOTY5Zjg0ZTk1YmZjOTM1
10
- MTU5NDMxODAyMmJjYjVhY2ZhZTZlYWFmY2ViOTVjNzI0NjQ1ZTk2ZWQwNGQ5
11
- MmM1MzJjMjYyMTRmYWU5YjI5YTRkZDFkYzhjZTViNzBjYmU2NGQ=
9
+ N2VmY2M4NTg2OGM4NzEyYzM0ODQ2OGQ1NTFlOWYxMmY3N2Y5OTRjNmQyNmU4
10
+ MWYxZjViZjZlNWY2MTI0MWY3MjY3MGRiOTlhZGNiOTk1YmNiMzJmNTc4YTM2
11
+ NGJjMDk3MjczZmQwYzkxMzgzY2UyZGE4NTg5MzdjMDQ4N2NlY2M=
12
12
  data.tar.gz: !binary |-
13
- NjY2YmM2NzNkZWQ0YjZlMTQyOTVmMDNlMTUyZDVjY2FmMjUxNzBhNzMxYzc0
14
- ZmZjZjMwNGVlMGFkM2Y1Y2U5NGQ2YWQzMGUxMTI5MmFmNDUwNGQ1OTc5M2E1
15
- ZjM4MGMyYTk3MzBkYmQ1ODhlN2YwZjY2ODIwODk3NjgyMTg1OWI=
13
+ N2NjOGY3MDcyOWU2M2Q3MTdlMzdhMmM2YmFhMzI1MGEwOGZiODc3YTdjODZi
14
+ ZWZkNTJkYmYxNWY5NGE3ODgzODAzMzQ0MWYzYWM4YmFkZGY0NzgxZDQ2N2Mw
15
+ YWJmMDUxYmM3YWQ4NzQ0YzcyNmIyMzJjOWFjYjkwNmQxMTc5YmY=
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --tty
2
2
  --color
3
3
  --format documentation
4
+ --format html -o "tmp/rspec_result.html"
@@ -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? && self.class.represented_object_class.respond_to?(:reflect_on_association) && nested_relection.klass != self.class.represented_object_class.reflect_on_association(nested_object_name).try(:klass)
212
- if existing.respond_to?(:map)
213
- existing = existing.map { |existing_nested_object| nested_relection.klass.new({}, existing_nested_object) }
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 = nested_relection.klass.new({}, 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 = {})
@@ -1,3 +1,3 @@
1
1
  module ObjectAttorney
2
- VERSION = "2.9.2"
2
+ VERSION = "2.9.3"
3
3
  end
@@ -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.2
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-02-22 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler