object_attorney 2.5.9 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/object_attorney/attribute_assignment.rb +15 -0
- data/lib/object_attorney/nested_objects.rb +3 -15
- data/lib/object_attorney/version.rb +1 -1
- data/spec/object_attorney/post_form_spec.rb +21 -0
- data/spec/object_attorney/user_form_with_ruby_errors_spec.rb +15 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/form_objects/user_form_with_ruby_errors.rb +15 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGFkZjIwNjQ2MzM4NmU5YTYxZGU3ODViMWIwNGM5YzY5NmVhYzVjOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzIzNGI4MzI1ZmRlZGQxMTM2ZWQwNDk0ZWUzN2M0MTkwZGUwMDFiMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmQ5ZjQ5YTFhYjgzYmJiZTIyYjM0MzI1MjNmYjg0NmViYjk5MmJlMDYwMGRi
|
10
|
+
OGFjYmQ2MTNlZjUxMTIyNTJmOTgwODhiNGMyMWQ3ZmNhMDI3NmY2MGE0Y2Y4
|
11
|
+
ZjIzNjg2YzE1MjFhODdmM2VlM2ZlYWEzZWRiY2M5NTExN2U4NmI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzY2M2JhOWFmNzM3NmM1MmU1ZDYzNTljMTliZWQwZTA0YWI2ODAzNDE3ZTQ1
|
14
|
+
ZjM0NDE5NDIwMzc2ZDU0MDM0NTgyNDUyYWRhZjBlMWYzYTk3YzA3NWNiYzhj
|
15
|
+
ZWU1NTc4YzJhY2M2Nzc3YmZlYzkwMmMxYmRjODIzOGE5N2Q0MDM=
|
@@ -29,6 +29,21 @@ module ObjectAttorney
|
|
29
29
|
respond_to?("#{attribute}=")
|
30
30
|
end
|
31
31
|
|
32
|
+
def attributes_without_destroy(attributes)
|
33
|
+
return nil unless attributes.is_a?(Hash)
|
34
|
+
|
35
|
+
_attributes = attributes.dup
|
36
|
+
_attributes.delete("_destroy")
|
37
|
+
_attributes.delete(:_destroy)
|
38
|
+
|
39
|
+
_attributes
|
40
|
+
end
|
41
|
+
|
42
|
+
def attributes_order_destruction?(attributes)
|
43
|
+
_destroy = attributes["_destroy"] || attributes[:_destroy]
|
44
|
+
["true", "1", true].include?(_destroy)
|
45
|
+
end
|
46
|
+
|
32
47
|
end
|
33
48
|
|
34
49
|
end
|
@@ -20,9 +20,7 @@ module ObjectAttorney
|
|
20
20
|
def mark_for_destruction_if_necessary(object, attributes)
|
21
21
|
return nil unless attributes.is_a?(Hash)
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
object.mark_for_destruction if ["true", "1", true].include?(_destroy)
|
23
|
+
object.mark_for_destruction if attributes_order_destruction? attributes
|
26
24
|
end
|
27
25
|
|
28
26
|
def nested_objects(macro = nil)
|
@@ -86,16 +84,6 @@ module ObjectAttorney
|
|
86
84
|
end
|
87
85
|
end
|
88
86
|
|
89
|
-
def attributes_without_destroy(attributes)
|
90
|
-
return nil unless attributes.is_a?(Hash)
|
91
|
-
|
92
|
-
_attributes = attributes.dup
|
93
|
-
_attributes.delete("_destroy")
|
94
|
-
_attributes.delete(:_destroy)
|
95
|
-
|
96
|
-
_attributes
|
97
|
-
end
|
98
|
-
|
99
87
|
def nested_getter(nested_object_name)
|
100
88
|
nested_instance_variable = self.instance_variable_get("@#{nested_object_name}")
|
101
89
|
|
@@ -123,7 +111,7 @@ module ObjectAttorney
|
|
123
111
|
|
124
112
|
nested_object.assign_attributes(attributes_without_destroy(attributes))
|
125
113
|
mark_for_destruction_if_necessary(nested_object, attributes)
|
126
|
-
elsif attributes.keys.present?
|
114
|
+
elsif attributes.keys.present? && !attributes_order_destruction?(attributes)
|
127
115
|
nested_object = send("build_#{Helpers.singularize(nested_object_name)}", attributes_without_destroy(attributes))
|
128
116
|
mark_for_destruction_if_necessary(nested_object, attributes)
|
129
117
|
end
|
@@ -153,7 +141,7 @@ module ObjectAttorney
|
|
153
141
|
|
154
142
|
def build_new_nested_objects(existing_and_new_nested_objects, nested_object_name)
|
155
143
|
(send("#{nested_object_name}_attributes") || {}).values.each do |attributes|
|
156
|
-
next if attributes["id"].present? || attributes[:id].present?
|
144
|
+
next if attributes["id"].present? || attributes[:id].present? || attributes_order_destruction?(attributes)
|
157
145
|
|
158
146
|
new_nested_object = send("build_#{Helpers.singularize(nested_object_name)}", attributes_without_destroy(attributes))
|
159
147
|
next unless new_nested_object
|
@@ -122,6 +122,27 @@ shared_examples "a PostForm" do
|
|
122
122
|
comment.body.should == 'new comment'
|
123
123
|
end
|
124
124
|
|
125
|
+
it "5. Creating new 'Comment's and deleting them at the same time." do
|
126
|
+
params = {
|
127
|
+
id: 1,
|
128
|
+
post: {
|
129
|
+
title: "altered post",
|
130
|
+
comments_attributes: {
|
131
|
+
"0" => { body: '1', _destroy: true },
|
132
|
+
"1" => { body: '2' },
|
133
|
+
"2" => { body: '3', _destroy: true }
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
post_form = described_class.new(params[:post])
|
139
|
+
|
140
|
+
post_form.comments.length.should == 1
|
141
|
+
post_form.save.should == true
|
142
|
+
post_form.comments.length.should == 1
|
143
|
+
Comment.all.count.should == 1
|
144
|
+
end
|
145
|
+
|
125
146
|
end
|
126
147
|
|
127
148
|
describe PostForm::Base do
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe UserFormWithRubyErrors do
|
4
|
+
|
5
|
+
xit "1. 'UserFormWithRubyErrors' when saving should through an error!" do
|
6
|
+
params = { user: { email: 'email@gmail.com', terms_of_service: true } }
|
7
|
+
|
8
|
+
user_form = UserFormWithRubyErrors.new(params[:user])
|
9
|
+
save_result = user_form.save
|
10
|
+
|
11
|
+
save_result.should == true
|
12
|
+
User.all.count.should == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -28,6 +28,7 @@ require 'support/form_objects/bulk_posts_allow_only_existing_form'
|
|
28
28
|
require 'support/form_objects/bulk_posts_allow_only_new_form'
|
29
29
|
require 'support/form_objects/bulk_posts_with_form_objects_form'
|
30
30
|
require 'support/form_objects/user_form'
|
31
|
+
require 'support/form_objects/user_form_with_ruby_errors'
|
31
32
|
|
32
33
|
RSpec.configure do |config|
|
33
34
|
#config.treat_symbols_as_metadata_keys_with_true_values = true
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class UserFormWithRubyErrors
|
2
|
+
|
3
|
+
include ObjectAttorney
|
4
|
+
|
5
|
+
represents :user, properties: [:email]
|
6
|
+
|
7
|
+
attr_accessor :terms_of_service
|
8
|
+
|
9
|
+
validates_acceptance_of :terms_of_service, accept: true, allow_nil: false
|
10
|
+
|
11
|
+
def submit
|
12
|
+
fake_var == true
|
13
|
+
end
|
14
|
+
|
15
|
+
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.
|
4
|
+
version: 2.6.0
|
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-01-
|
11
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- spec/object_attorney/post_with_comment_validations_form_spec.rb
|
99
99
|
- spec/object_attorney/post_with_comments_and_address_form_spec.rb
|
100
100
|
- spec/object_attorney/user_form_spec.rb
|
101
|
+
- spec/object_attorney/user_form_with_ruby_errors_spec.rb
|
101
102
|
- spec/spec_helper.rb
|
102
103
|
- spec/support/active_model/validations.rb
|
103
104
|
- spec/support/database_setup.rb
|
@@ -112,6 +113,7 @@ files:
|
|
112
113
|
- spec/support/form_objects/post_with_comment_validations_form.rb
|
113
114
|
- spec/support/form_objects/post_with_comments_and_address_form.rb
|
114
115
|
- spec/support/form_objects/user_form.rb
|
116
|
+
- spec/support/form_objects/user_form_with_ruby_errors.rb
|
115
117
|
- spec/support/models/address.rb
|
116
118
|
- spec/support/models/comment.rb
|
117
119
|
- spec/support/models/post.rb
|
@@ -153,6 +155,7 @@ test_files:
|
|
153
155
|
- spec/object_attorney/post_with_comment_validations_form_spec.rb
|
154
156
|
- spec/object_attorney/post_with_comments_and_address_form_spec.rb
|
155
157
|
- spec/object_attorney/user_form_spec.rb
|
158
|
+
- spec/object_attorney/user_form_with_ruby_errors_spec.rb
|
156
159
|
- spec/spec_helper.rb
|
157
160
|
- spec/support/active_model/validations.rb
|
158
161
|
- spec/support/database_setup.rb
|
@@ -167,8 +170,8 @@ test_files:
|
|
167
170
|
- spec/support/form_objects/post_with_comment_validations_form.rb
|
168
171
|
- spec/support/form_objects/post_with_comments_and_address_form.rb
|
169
172
|
- spec/support/form_objects/user_form.rb
|
173
|
+
- spec/support/form_objects/user_form_with_ruby_errors.rb
|
170
174
|
- spec/support/models/address.rb
|
171
175
|
- spec/support/models/comment.rb
|
172
176
|
- spec/support/models/post.rb
|
173
177
|
- spec/support/models/user.rb
|
174
|
-
has_rdoc:
|