object_attorney 1.2.1 → 2.1.1

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.
Files changed (44) hide show
  1. checksums.yaml +8 -8
  2. data/db/migrate/20131205114000_create_users.rb +13 -0
  3. data/db/migrate/20131205114900_create_posts.rb +1 -1
  4. data/db/migrate/20131205114901_create_comments.rb +13 -0
  5. data/db/migrate/20131205114902_create_addresses.rb +13 -0
  6. data/lib/object_attorney/association_reflection.rb +52 -15
  7. data/lib/object_attorney/helpers.rb +4 -0
  8. data/lib/object_attorney/nested_objects.rb +88 -21
  9. data/lib/object_attorney/orm.rb +20 -10
  10. data/lib/object_attorney/orm_handlers/smooth_operator.rb +20 -15
  11. data/lib/object_attorney/reflection.rb +35 -0
  12. data/lib/object_attorney/version.rb +1 -1
  13. data/lib/object_attorney.rb +18 -10
  14. data/spec/object_attorney/bulk_post_form_spec.rb +52 -0
  15. data/spec/object_attorney/bulk_posts_allow_only_existing_form_spec.rb +37 -0
  16. data/spec/object_attorney/bulk_posts_allow_only_new_form_spec.rb +39 -0
  17. data/spec/object_attorney/bulk_posts_with_form_objects_form_spec.rb +91 -0
  18. data/spec/object_attorney/post_form_spec.rb +107 -41
  19. data/spec/object_attorney/post_with_comment_form_spec.rb +123 -0
  20. data/spec/object_attorney/post_with_comments_and_address_form_spec.rb +45 -0
  21. data/spec/object_attorney/user_form_spec.rb +61 -0
  22. data/spec/spec_helper.rb +15 -6
  23. data/spec/support/form_objects/bulk_posts_allow_only_existing_form.rb +19 -0
  24. data/spec/support/form_objects/bulk_posts_allow_only_new_form.rb +19 -0
  25. data/spec/support/form_objects/bulk_posts_form.rb +27 -0
  26. data/spec/support/form_objects/bulk_posts_with_form_objects_form.rb +27 -0
  27. data/spec/support/form_objects/comment_form.rb +11 -0
  28. data/spec/support/form_objects/post_form.rb +54 -0
  29. data/spec/support/form_objects/post_with_comment_form.rb +21 -0
  30. data/spec/support/form_objects/post_with_comments_and_address_form.rb +13 -0
  31. data/spec/support/form_objects/user_form.rb +11 -0
  32. data/spec/support/models/address.rb +5 -0
  33. data/spec/support/models/comment.rb +5 -0
  34. data/spec/support/models/post.rb +7 -1
  35. data/spec/support/models/user.rb +7 -0
  36. metadata +44 -19
  37. data/spec/object_attorney/bulk_posts_form_child_spec.rb +0 -191
  38. data/spec/object_attorney/bulk_posts_form_spec.rb +0 -178
  39. data/spec/object_attorney/post_form_child_spec.rb +0 -60
  40. data/spec/support/models/bulk_posts_form.rb +0 -21
  41. data/spec/support/models/bulk_posts_form_child.rb +0 -19
  42. data/spec/support/models/item.rb +0 -3
  43. data/spec/support/models/post_form.rb +0 -13
  44. data/spec/support/models/post_form_child.rb +0 -7
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
3
+ shared_examples "a BulkPostsAllowOnlyNewForm" do
4
+
5
+ it "1. Tabless model 'BulkPostsAllowOnlyNewForm' only accepts new 'Post' requests and ignores editing requests." do
6
+ params = {
7
+ bulk_post: {
8
+ posts_attributes: {
9
+ "0" => { title: "new post" },
10
+ "1" => { id: 1, title: 'altered post' },
11
+ "2" => { id: 2, title: '', _destroy: true }
12
+ }
13
+ }
14
+ }
15
+
16
+ Post.create(title: "My title1")
17
+ Post.create(title: "My title2")
18
+ Post.all.count.should == 2
19
+ Post.find_by_id(1).title.should == 'My title1'
20
+ Post.find_by_id(2).title.should == 'My title2'
21
+
22
+ buld_posts_form = described_class.new(params[:bulk_post])
23
+ buld_posts_form.save
24
+
25
+ Post.all.count.should == 3
26
+ Post.find_by_id(1).title.should == 'My title1'
27
+ Post.find_by_id(2).title.should == 'My title2'
28
+ Post.find_by_id(3).title.should == 'new post'
29
+ end
30
+
31
+ end
32
+
33
+ describe BulkPostsAllowOnlyNewForm::Base do
34
+ it_behaves_like 'a BulkPostsAllowOnlyNewForm'
35
+ end
36
+
37
+ describe BulkPostsAllowOnlyNewForm::Explicit do
38
+ it_behaves_like 'a BulkPostsAllowOnlyNewForm'
39
+ end
@@ -0,0 +1,91 @@
1
+ require "spec_helper"
2
+
3
+ shared_examples "a BulkPostsWithFormObjectsForm" do
4
+
5
+ it "1. If any of the 'Post's is invalid, no changes should take effect." do
6
+ params = {
7
+ bulk_post: {
8
+ posts_attributes: {
9
+ "0" => { title: "new post" },
10
+ "1" => { id: 1, title: '' },
11
+ "2" => { id: 2, title: 'to be destroyed', _destroy: true }
12
+ }
13
+ }
14
+ }
15
+
16
+ Post.create(title: "My title1")
17
+ Post.create(title: "My title2")
18
+ Post.all.count.should == 2
19
+ Post.find_by_id(1).title.should == 'My title1'
20
+ Post.find_by_id(2).title.should == 'My title2'
21
+
22
+ bulk_posts_form = described_class.new(params[:bulk_post])
23
+ bulk_posts_form.save
24
+
25
+ bulk_posts_form.posts.first.should have(1).errors_on(:title)
26
+ Post.all.count.should == 2
27
+ Post.find_by_id(1).title.should == 'My title1'
28
+ Post.find_by_id(2).title.should == 'My title2'
29
+ end
30
+
31
+ it "2. A soon to be deleted 'Post' that is invalid, should not stop all other changes." do
32
+ params = {
33
+ bulk_post: {
34
+ posts_attributes: {
35
+ "0" => { title: "new post" },
36
+ "1" => { id: 1, title: 'altered post' },
37
+ "2" => { id: 2, title: '', _destroy: true }
38
+ }
39
+ }
40
+ }
41
+
42
+ Post.create(title: "My title1")
43
+ Post.create(title: "My title2")
44
+ Post.all.count.should == 2
45
+ Post.find_by_id(1).title.should == 'My title1'
46
+ Post.find_by_id(2).title.should == 'My title2'
47
+
48
+ bulk_posts_form = described_class.new(params[:bulk_post])
49
+ bulk_posts_form.save
50
+
51
+ bulk_posts_form.posts.second.id.should == 2
52
+ bulk_posts_form.posts.second.persisted?.should == false
53
+ bulk_posts_form.posts.second.should have(:no).errors_on(:title)
54
+ Post.all.count.should == 2
55
+ Post.find_by_id(1).title.should == 'altered post'
56
+ Post.find_by_id(3).title.should == 'new post'
57
+ end
58
+
59
+ it "3. 'BulkPostsWithFormObjectsForm' should be importing all of the represented objects errors." do
60
+ params = {
61
+ bulk_post: {
62
+ posts_attributes: {
63
+ "0" => { title: "" },
64
+ "1" => { id: 1, title: '' },
65
+ "2" => { id: 2, title: '', _destroy: true }
66
+ }
67
+ }
68
+ }
69
+
70
+ Post.create(title: "My title1")
71
+ Post.create(title: "My title2")
72
+ Post.all.count.should == 2
73
+
74
+ bulk_posts_form = described_class.new(params[:bulk_post])
75
+ bulk_posts_form.save
76
+
77
+ bulk_posts_form.should have(2).errors_on(:posts)
78
+ bulk_posts_form.posts.first.should have(1).errors_on(:title)
79
+ bulk_posts_form.posts.second.should have(:no).errors_on(:title)
80
+ bulk_posts_form.posts.third.should have(1).errors_on(:title)
81
+ end
82
+
83
+ end
84
+
85
+ describe BulkPostsWithFormObjectsForm::Base do
86
+ it_behaves_like 'a BulkPostsWithFormObjectsForm'
87
+ end
88
+
89
+ describe BulkPostsWithFormObjectsForm::Explicit do
90
+ it_behaves_like 'a BulkPostsWithFormObjectsForm'
91
+ end
@@ -1,60 +1,126 @@
1
1
  require "spec_helper"
2
2
 
3
- describe PostForm do
4
-
5
- it "PostForm becomes invalid when Post does and incorporates its errors" do
6
- post = Post.new
7
- post.should have(1).error_on(:title)
8
- post.title = "My title"
9
- post.should have(:no).errors_on(:title)
10
-
11
- post_form = PostForm.new({ state: 'draft' })
12
- post_form.should have(1).error_on(:title)
13
- post_form.title = "My title"
14
- post_form.should have(:no).errors_on(:title)
15
- end
3
+ shared_examples "a PostForm" do
16
4
 
17
- it "PostForm may require the validations of fields that Post doesn't have" do
18
- params = { post: { title: "My title" } }
5
+ it "1. Creating a 'Post' with nested 'Comment's, through 'FormObjects::Post'" do
6
+ params = {
7
+ post: {
8
+ title: 'First post',
9
+ body: 'post body',
10
+ comments_attributes: {
11
+ "0" => { body: "body1" },
12
+ "1" => { body: "" }
13
+ }
14
+ }
15
+ }
19
16
 
20
- post = Post.new(params[:post])
21
- post.should have(:no).errors_on(:state)
17
+ post_form = described_class.new(params[:post])
22
18
 
23
- post_form = PostForm.new(params[:post])
24
- post_form.should have(1).error_on(:state)
25
- post_form.state = "draft"
26
- post_form.should have(:no).errors_on(:state)
19
+ post_form.save.should == true
20
+
21
+ Post.all.count.should == 1
22
+ post = Post.first
23
+ post.title.should == 'First post'
24
+ post.body.should == 'post body'
25
+
26
+ post.comments.count.should == 2
27
+
28
+ comment = post.comments.first
29
+ comment.post_id.should == post.id
30
+ comment.body.should == 'body1'
27
31
  end
28
32
 
29
- it "Post creation through PostForm" do
30
- params = { post: { state: 'public', title: "My title", body: "My body" } }
31
- post_form = PostForm.new(params[:post])
33
+ it "2. Editing a 'Post' and a nested 'Comment'." do
34
+ params = {
35
+ id: 1,
36
+ post: {
37
+ title: "altered post",
38
+ comments_attributes: {
39
+ "0" => { id: 1, body: "altered comment" }
40
+ }
41
+ }
42
+ }
32
43
 
33
- expect(post_form.save).to(eq(true)) && expect(post_form.post.persisted?).to(eq(true))
34
- end
44
+ Post.create(title: "My title1")
45
+ Post.first.title.should == 'My title1'
46
+ Comment.create(post_id: 1, body: "body1")
47
+ Comment.first.body.should == 'body1'
35
48
 
36
- it "Post can't be created if PostForm isn't valid" do
37
- params = { post: { title: "My title", body: "My body" } }
38
- post_form = PostForm.new(params[:post])
39
-
40
- expect(post_form.save).to(eq(false)) && expect(post_form.post.persisted?).to(eq(false))
49
+ post_form = described_class.new(params[:post], Post.find(params[:id]))
50
+ post_form.save
51
+
52
+ post = Post.first
53
+ post.title.should == 'altered post'
54
+
55
+ comment = post.comments.first
56
+ comment.post_id.should == post.id
57
+ comment.body.should == 'altered comment'
41
58
  end
42
59
 
43
- it "Post can't be created if Post isn't valid" do
44
- params = { post: { state: 'public', body: "My body" } }
45
- post_form = PostForm.new(params[:post])
60
+ it "3. Editing a 'Post' and deleting a nested 'Comment'." do
61
+ params = {
62
+ id: 1,
63
+ post: {
64
+ title: "altered post",
65
+ comments_attributes: {
66
+ "0" => { id: 1, _destroy: true }
67
+ }
68
+ }
69
+ }
70
+
71
+ Post.create(title: "My title1")
72
+ Post.first.title.should == 'My title1'
73
+ Comment.create(post_id: 1, body: "body1")
74
+ Comment.all.count.should == 1
46
75
 
47
- expect(post_form.save).to(eq(false)) && expect(post_form.post.persisted?).to(eq(false))
76
+ post_form = described_class.new(params[:post], Post.find(params[:id]))
77
+ post_form.save
78
+
79
+ Post.first.title.should == 'altered post'
80
+ Comment.all.count.should == 0
48
81
  end
49
82
 
50
- it "PostForm won't allow weak params to be updated, unlike Post" do
51
- params = { post: { title: 'My title', body: "My body", admin: true } }
83
+ it "4. Editing a 'Post', creating new nested 'Comment', editing another and deleting yet another." do
84
+ params = {
85
+ id: 1,
86
+ post: {
87
+ title: "altered post",
88
+ comments_attributes: {
89
+ "0" => { body: "new comment" },
90
+ "1" => { id: 1, body: 'to be destroyed', _destroy: true },
91
+ "2" => { id: 2, body: 'altered comment' }
92
+ }
93
+ }
94
+ }
95
+
96
+ Post.create(title: "My title1")
97
+ Post.first.title.should == 'My title1'
98
+ Comment.create(post_id: 1, body: "body1")
99
+ Comment.create(post_id: 1, body: "body2")
100
+ Comment.all.count.should == 2
52
101
 
53
- post_form = PostForm.new(params[:post].merge({ state: 'public' }))
54
- expect(post_form.save).to(eq(true)) && expect(post_form.post.admin).to(eq(false))
102
+ post_form = described_class.new(params[:post], Post.find(params[:id]))
103
+ post_form.save
55
104
 
56
- post = Post.new(params[:post])
57
- expect(post.save).to(eq(true)) && expect(post.admin).to(eq(true))
105
+ post = Post.first
106
+ post.title.should == 'altered post'
107
+ post.comments.count.should == 2
108
+
109
+ comment = post.comments.where(id: 2).first
110
+ comment.post_id.should == post.id
111
+ comment.body.should == 'altered comment'
112
+
113
+ comment = post.comments.where(id: 3).first
114
+ comment.post_id.should == post.id
115
+ comment.body.should == 'new comment'
58
116
  end
59
117
 
60
118
  end
119
+
120
+ describe PostForm::Base do
121
+ it_behaves_like 'a PostForm'
122
+ end
123
+
124
+ describe PostForm::Explicit do
125
+ it_behaves_like 'a PostForm'
126
+ end
@@ -0,0 +1,123 @@
1
+ require "spec_helper"
2
+
3
+ shared_examples "a PostWithCommentForm" do
4
+
5
+ it "1. 'Post' can't be created if any of the nested comments on 'FormObjects::PostWithCommentForm' isn't valid" do
6
+ params = {
7
+ post: {
8
+ title: 'First post',
9
+ body: 'post body',
10
+ comments_attributes: {
11
+ "0" => { body: "body1" },
12
+ "1" => { body: "" }
13
+ }
14
+ }
15
+ }
16
+
17
+ post2_form = described_class.new(params[:post])
18
+ post2_form.save
19
+
20
+ Post.all.count.should == 0
21
+ Comment.all.count.should == 0
22
+ post2_form.comments.second.should have(1).errors_on(:body)
23
+ end
24
+
25
+ it "2. Editing a 'Post', creating new nested 'Comment' (with errors), editing another and deleting yet another (none of the changes should take place)." do
26
+ params = {
27
+ id: 1,
28
+ post: {
29
+ title: "altered post",
30
+ comments_attributes: {
31
+ "0" => {},
32
+ "1" => { id: 1, body: 'to be destroyed', _destroy: true },
33
+ "2" => { id: 2, body: 'altered comment' }
34
+ }
35
+ }
36
+ }
37
+
38
+ Post.create(title: "My title1")
39
+ Post.first.title.should == 'My title1'
40
+ Comment.create(post_id: 1, body: "body1")
41
+ Comment.create(post_id: 1, body: "body2")
42
+ Comment.all.count.should == 2
43
+
44
+ post_form = described_class.new(params[:post], Post.find(params[:id]))
45
+ post_form.save
46
+
47
+ Post.first.title.should == 'My title1'
48
+ Comment.all.count.should == 2
49
+ Comment.find_by_id(1).body.should == 'body1'
50
+ Comment.find_by_id(2).body.should == 'body2'
51
+ end
52
+
53
+ it "3. Editing a 'Post' (with errors), creating new nested 'Comment', editing another and deleting yet another (none of the changes should take place)." do
54
+ params = {
55
+ id: 1,
56
+ post: {
57
+ title: "",
58
+ comments_attributes: {
59
+ "0" => { body: "new comment" },
60
+ "1" => { id: 1, body: 'to be destroyed', _destroy: true },
61
+ "2" => { id: 2, body: 'altered comment' }
62
+ }
63
+ }
64
+ }
65
+
66
+ Post.create(title: "My title1")
67
+ Post.first.title.should == 'My title1'
68
+ Comment.create(post_id: 1, body: "body1")
69
+ Comment.create(post_id: 1, body: "body2")
70
+ Comment.all.count.should == 2
71
+
72
+ post_form = described_class.new(params[:post], Post.find(params[:id]))
73
+ post_form.save
74
+
75
+ Post.first.title.should == 'My title1'
76
+ Comment.all.count.should == 2
77
+ Comment.find_by_id(1).body.should == 'body1'
78
+ Comment.find_by_id(2).body.should == 'body2'
79
+ end
80
+
81
+ it "4. Editing a 'Post', creating new nested 'Comment', editing another and deleting (with errors) yet another (all changes should take place!)." do
82
+ params = {
83
+ id: 1,
84
+ post: {
85
+ title: "altered post",
86
+ comments_attributes: {
87
+ "0" => { body: "new comment" },
88
+ "1" => { id: 1, _destroy: true },
89
+ "2" => { id: 2, body: 'altered comment' }
90
+ }
91
+ }
92
+ }
93
+
94
+ Post.create(title: "My title1")
95
+ Post.first.title.should == 'My title1'
96
+ Comment.create(post_id: 1, body: "body1")
97
+ Comment.create(post_id: 1, body: "body2")
98
+ Comment.all.count.should == 2
99
+
100
+ post_form = described_class.new(params[:post], Post.find(params[:id]))
101
+ post_form.save
102
+
103
+ Post.first.title.should == 'altered post'
104
+ Comment.all.count.should == 2
105
+
106
+ comment = Comment.find_by_id(2)
107
+ comment.body.should == 'altered comment'
108
+ comment.post_id.should == 1
109
+
110
+ comment = Comment.find_by_id(3)
111
+ comment.body.should == 'new comment'
112
+ comment.post_id.should == 1
113
+ end
114
+
115
+ end
116
+
117
+ describe PostWithCommentForm::Base do
118
+ it_behaves_like 'a PostWithCommentForm'
119
+ end
120
+
121
+ describe PostWithCommentForm::Explicit do
122
+ it_behaves_like 'a PostWithCommentForm'
123
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe PostWithCommentsAndAddressForm do
4
+
5
+ it "1. Creating a 'Post' with nested 'Comment's and a single 'Address'" do
6
+ params = {
7
+ post: {
8
+ title: 'First post',
9
+ body: 'post body',
10
+ comments_attributes: {
11
+ "0" => { body: "body1" },
12
+ "1" => { body: "" }
13
+ },
14
+ address_attributes: {
15
+ '0' => { street: 'street' }
16
+ }
17
+ }
18
+ }
19
+
20
+ post_form = described_class.new(params[:post])
21
+
22
+ post_form.save.should == true
23
+
24
+ Post.all.count.should == 1
25
+ post = Post.first
26
+ post.title.should == 'First post'
27
+ post.body.should == 'post body'
28
+
29
+ post.comments.count.should == 2
30
+
31
+ comment = post.comments.first
32
+ comment.post_id.should == post.id
33
+ comment.body.should == 'body1'
34
+
35
+ comment = post.comments.second
36
+ comment.post_id.should == post.id
37
+ comment.body.should == ''
38
+
39
+ post.address.present?.should == true
40
+ address = Address.first
41
+ address.post_id.should == post.id
42
+ address.street.should == 'street'
43
+ end
44
+
45
+ end
@@ -0,0 +1,61 @@
1
+ require "spec_helper"
2
+
3
+ describe UserForm do
4
+
5
+ it "1. Creating a 'User' using 'UserForm'." do
6
+ params = { user: { email: 'email@gmail.com', terms_of_service: true } }
7
+
8
+ user_form = UserForm.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
+ it "2. 'UserForm' becomes invalid when 'User' does and incorporates its errors." do
16
+ user = User.new
17
+ user.should have(1).error_on(:email)
18
+ user.email = "email@gmail.com"
19
+ user.should have(:no).errors_on(:email)
20
+
21
+ user_form = UserForm.new
22
+ user_form.should have(1).error_on(:email)
23
+ user_form.email = "email@gmail.com"
24
+ user_form.should have(:no).errors_on(:email)
25
+ end
26
+
27
+ it "3. 'UserForm' may require the validations of fields that 'User' doesn't have." do
28
+ params = { user: { email: "email@gmail.com" } }
29
+
30
+ user = User.new(params[:user])
31
+ user.should have(:no).errors_on(:terms_of_service)
32
+
33
+ user_form = UserForm.new(params[:user])
34
+ user_form.should have(1).error_on(:terms_of_service)
35
+ user_form.terms_of_service = true
36
+ user_form.should have(:no).errors_on(:terms_of_service)
37
+ end
38
+
39
+ it "4. 'User' can't be created if 'UserForm' isn't valid." do
40
+ params = { user: { email: 'email@gmail.com' } }
41
+
42
+ user_form = UserForm.new(params[:user])
43
+ save_result = user_form.save
44
+
45
+ save_result.should == false
46
+ User.all.count.should == 0
47
+ end
48
+
49
+ it "5. 'UserForm' won't allow weak params to be updated, unlike 'User'." do
50
+ params = { user: { email: 'email@gmail.com', admin: true } }
51
+
52
+ user = User.new(params[:user])
53
+ user.save.should == true
54
+ user.admin.should == true
55
+
56
+ user_form = UserForm.new(params[:user].merge({ terms_of_service: true }))
57
+ user_form.save.should == true
58
+ user_form.user.admin.should == false
59
+ end
60
+
61
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,15 +12,24 @@ require 'pry'
12
12
  require 'object_attorney'
13
13
  require 'support/database_setup'
14
14
  require 'support/active_model/validations'
15
+ require 'support/models/address'
16
+ require 'support/models/comment'
15
17
  require 'support/models/post'
16
- require 'support/models/item'
17
- require 'support/models/post_form'
18
- require 'support/models/post_form_child'
19
- require 'support/models/bulk_posts_form'
20
- require 'support/models/bulk_posts_form_child'
18
+ require 'support/models/user'
19
+
20
+ require 'support/form_objects/post_form'
21
+ require 'support/form_objects/comment_form'
22
+ require 'support/form_objects/post_with_comment_form'
23
+ require 'support/form_objects/post_with_comments_and_address_form'
24
+ require 'support/form_objects/bulk_posts_form'
25
+ require 'support/form_objects/bulk_posts_allow_only_existing_form'
26
+ require 'support/form_objects/bulk_posts_allow_only_new_form'
27
+ require 'support/form_objects/bulk_posts_with_form_objects_form'
28
+ require 'support/form_objects/user_form'
21
29
 
22
30
  RSpec.configure do |config|
23
- config.filter_run :current
31
+ #config.treat_symbols_as_metadata_keys_with_true_values = true
32
+ #config.filter_run :current
24
33
 
25
34
  I18n.enforce_available_locales = false
26
35
 
@@ -0,0 +1,19 @@
1
+ module BulkPostsAllowOnlyExistingForm
2
+
3
+ class Base < BulkPostsForm::Base
4
+
5
+ def build_post(attributes = {})
6
+ nil
7
+ end
8
+
9
+ end
10
+
11
+ class Explicit < BulkPostsForm::Base
12
+
13
+ def build_post(attributes = {})
14
+ nil
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ module BulkPostsAllowOnlyNewForm
2
+
3
+ class Base < BulkPostsForm::Base
4
+
5
+ def existing_posts
6
+ []
7
+ end
8
+
9
+ end
10
+
11
+ class Explicit < BulkPostsForm::Base
12
+
13
+ def existing_posts
14
+ []
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,27 @@
1
+ module BulkPostsForm
2
+
3
+ class Base
4
+
5
+ include ObjectAttorney
6
+
7
+ has_many :posts
8
+
9
+ end
10
+
11
+ class Explicit
12
+
13
+ include ObjectAttorney
14
+
15
+ has_many :posts
16
+
17
+ def build_post(attributes = {})
18
+ ::Post.new(attributes)
19
+ end
20
+
21
+ def existing_posts
22
+ ::Post.all
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,27 @@
1
+ module BulkPostsWithFormObjectsForm
2
+
3
+ class Base
4
+
5
+ include ObjectAttorney
6
+
7
+ has_many :posts, class_name: PostForm::Base
8
+
9
+ end
10
+
11
+ class Explicit
12
+
13
+ include ObjectAttorney
14
+
15
+ has_many :posts
16
+
17
+ def build_post(attributes = {})
18
+ PostForm::Base.new(attributes)
19
+ end
20
+
21
+ def existing_posts
22
+ PostForm::Base.all
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,11 @@
1
+ class CommentForm
2
+
3
+ include ObjectAttorney
4
+
5
+ represents :comment
6
+
7
+ delegate_properties :body, to: :comment
8
+
9
+ validates_presence_of :body
10
+
11
+ end