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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWNjMWJhMWQwZjk1MTUyYTM2OWM3ZmI1NTRlYmZlYmRlMDMzYzAwNg==
4
+ ZjU4ZTc4YWEwNzcxNGM4NDliNjYzNDQzYmZiMDZmZGEwNzRmMTMyNg==
5
5
  data.tar.gz: !binary |-
6
- NjIwMjYxYzU1MmI5YjJkNTA4MTkxM2NjNzQzYTdmODI1Y2JhODM5Mg==
6
+ NGYwOWViZGY5MTI5MTAyM2MyMjdlMDA2NDU4NjdkOTFhNzViZTFiYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2VmY2M4NTg2OGM4NzEyYzM0ODQ2OGQ1NTFlOWYxMmY3N2Y5OTRjNmQyNmU4
10
- MWYxZjViZjZlNWY2MTI0MWY3MjY3MGRiOTlhZGNiOTk1YmNiMzJmNTc4YTM2
11
- NGJjMDk3MjczZmQwYzkxMzgzY2UyZGE4NTg5MzdjMDQ4N2NlY2M=
9
+ OWJhNjY2YTljMDAxODk1Nzk5YjBmMDUzNzg2ZjkzMDk3NDE3YmJiZjE5OGNj
10
+ NzBmZjRmMjA1YzQzZWM5MmE3ZjIxZTY4NTExYzU4YjE1NmEzNzRkNDM1MGUw
11
+ YjYzM2QwZWZjYjEzYzM3NDE2ODA0NjNhNDg2MTkzYjgxNjE1YWU=
12
12
  data.tar.gz: !binary |-
13
- N2NjOGY3MDcyOWU2M2Q3MTdlMzdhMmM2YmFhMzI1MGEwOGZiODc3YTdjODZi
14
- ZWZkNTJkYmYxNWY5NGE3ODgzODAzMzQ0MWYzYWM4YmFkZGY0NzgxZDQ2N2Mw
15
- YWJmMDUxYmM3YWQ4NzQ0YzcyNmIyMzJjOWFjYjkwNmQxMTc5YmY=
13
+ ZjVhM2FkMjMxYjM4OTRmNzk3YzhkZGJiZGU0Njg1M2Q1MGY3YzUwMTY5YjNj
14
+ MDVhNjRkM2I3YTk3NGE4MDY0NGI2ZWU2OWNmMTk4N2U2OTNkODYyYTk3MGI1
15
+ YjkzMTRhYjQwMWRhZDFmNjc3ZGRhYmUzYTc5YjU0ZmFmZWFmYzM=
@@ -18,6 +18,8 @@ module ObjectAttorney
18
18
  end
19
19
 
20
20
  def set_relational_keys(origin, destination)
21
+ return nil if options[:standalone] == true
22
+
21
23
  if has_many? || has_one?
22
24
  set_foreign_key(destination, primary_key_of(origin))
23
25
  elsif belongs_to?
@@ -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?
@@ -1,3 +1,3 @@
1
1
  module ObjectAttorney
2
- VERSION = "2.9.3"
2
+ VERSION = "2.9.4"
3
3
  end
@@ -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|
@@ -0,0 +1,9 @@
1
+ class UserAndCommentsForm
2
+
3
+ include ObjectAttorney
4
+
5
+ represents :user, properties: [:email]
6
+
7
+ has_many :comments, class_name: CommentForm, standalone: true
8
+
9
+ 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.9.3
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-06 00:00:00.000000000 Z
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