embedded_associations 4.1.0 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/embedded_associations.rb +14 -2
- data/lib/embedded_associations/version.rb +1 -1
- data/spec/embedded_associations_spec.rb +23 -0
- data/spec/support/app/app/controllers/posts_controller.rb +1 -1
- data/spec/support/app/app/models/admin.rb +2 -0
- data/spec/support/app/app/serializers/admin_serializer.rb +3 -0
- data/spec/support/app/db/migrate/20141022213956_create_admins.rb +5 -0
- data/spec/support/app/db/schema.rb +21 -20
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6d41192bb48a2704dbc2356512872935acac014
|
4
|
+
data.tar.gz: eee1b040f3c264e88ab493fca6f18a8c63231857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cc1b91d346d294d8368ba4a2e78724c47294072613896f0e5e4f60c571bcaf6520641bbd188c6d3ae80930ee9909d6e5e9136727d7bdccfbcb1fac37092eba1
|
7
|
+
data.tar.gz: 595ab5ab518d466eb4227d28c0d47781e588ee2b377fdd89c61d558dfa7c8f5d41095745902407d92c4cabbebe75e093aea4fb1565ff1d429d4cef6e8e038a85
|
@@ -123,7 +123,13 @@ module EmbeddedAssociations
|
|
123
123
|
r.assign_attributes(attrs)
|
124
124
|
run_before_update_callbacks(r)
|
125
125
|
else
|
126
|
-
|
126
|
+
inheritance_column = parent.class.reflect_on_association(name).klass.inheritance_column
|
127
|
+
# need to pass in inheritance column in build to get correct class
|
128
|
+
r = if inheritance_column
|
129
|
+
current_assoc.build(attrs.slice(inheritance_column))
|
130
|
+
else
|
131
|
+
current_assoc.build()
|
132
|
+
end
|
127
133
|
attrs = controller.send(:filter_attributes, r.class.name, attrs, :create)
|
128
134
|
handle_resource(child_definition, r, attrs) if child_definition
|
129
135
|
r.assign_attributes(attrs)
|
@@ -147,7 +153,13 @@ module EmbeddedAssociations
|
|
147
153
|
r.mark_for_destruction
|
148
154
|
end
|
149
155
|
elsif attrs && attrs != ''
|
150
|
-
|
156
|
+
inheritance_column = parent.class.reflect_on_association(name).klass.inheritance_column
|
157
|
+
# need to pass in inheritance column in build to get correct class
|
158
|
+
r = if inheritance_column
|
159
|
+
parent.send("build_#{name}", attrs.slice(inheritance_column))
|
160
|
+
else
|
161
|
+
parent.send("build_#{name}")
|
162
|
+
end
|
151
163
|
attrs = controller.send(:filter_attributes, r.class.name, attrs, :create)
|
152
164
|
handle_resource(child_definition, r, attrs) if child_definition
|
153
165
|
r.assign_attributes(attrs)
|
@@ -169,6 +169,29 @@ describe PostsController, type: :controller do
|
|
169
169
|
end
|
170
170
|
|
171
171
|
end
|
172
|
+
|
173
|
+
context "creating with sti belongs_to" do
|
174
|
+
|
175
|
+
it "should create hierarchy" do
|
176
|
+
json = post :create, post: {
|
177
|
+
title: 'ma post',
|
178
|
+
user: {type: 'Admin', name: 'G$', account: {}}
|
179
|
+
}
|
180
|
+
|
181
|
+
parsed_body = JSON.parse(response.body)
|
182
|
+
expect(parsed_body['post']['user']['type']).to eq('Admin')
|
183
|
+
|
184
|
+
expect(Post.count).to eq(1)
|
185
|
+
expect(User.count).to eq(1)
|
186
|
+
expect(Account.count).to eq(1)
|
187
|
+
|
188
|
+
resource = Post.first
|
189
|
+
|
190
|
+
expect(resource.user).to_not be_nil
|
191
|
+
expect(resource.user.account).to_not be_nil
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
172
195
|
|
173
196
|
context "updating" do
|
174
197
|
|
@@ -45,7 +45,7 @@ class PostsController < ApplicationController
|
|
45
45
|
params.require(:post).permit(
|
46
46
|
:title,
|
47
47
|
comments: [:content, user: [:name, :email, account: [:note] ]],
|
48
|
-
user: [:name, :email, account: [:note] ],
|
48
|
+
user: [:type, :name, :email, account: [:note] ],
|
49
49
|
tags: [:name],
|
50
50
|
category: [:name]
|
51
51
|
)
|
@@ -9,51 +9,52 @@
|
|
9
9
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
10
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
11
|
#
|
12
|
-
# It's strongly recommended
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:
|
14
|
+
ActiveRecord::Schema.define(version: 20141022213956) do
|
15
15
|
|
16
|
-
create_table "accounts", :
|
16
|
+
create_table "accounts", force: true do |t|
|
17
17
|
t.integer "user_id"
|
18
18
|
t.string "note"
|
19
|
-
t.datetime "created_at"
|
20
|
-
t.datetime "updated_at"
|
19
|
+
t.datetime "created_at"
|
20
|
+
t.datetime "updated_at"
|
21
21
|
end
|
22
22
|
|
23
|
-
create_table "categories", :
|
23
|
+
create_table "categories", force: true do |t|
|
24
24
|
t.string "name"
|
25
|
-
t.datetime "created_at"
|
26
|
-
t.datetime "updated_at"
|
25
|
+
t.datetime "created_at"
|
26
|
+
t.datetime "updated_at"
|
27
27
|
end
|
28
28
|
|
29
|
-
create_table "comments", :
|
29
|
+
create_table "comments", force: true do |t|
|
30
30
|
t.integer "post_id"
|
31
31
|
t.integer "user_id"
|
32
32
|
t.string "content"
|
33
|
-
t.datetime "created_at"
|
34
|
-
t.datetime "updated_at"
|
33
|
+
t.datetime "created_at"
|
34
|
+
t.datetime "updated_at"
|
35
35
|
end
|
36
36
|
|
37
|
-
create_table "posts", :
|
37
|
+
create_table "posts", force: true do |t|
|
38
38
|
t.string "title"
|
39
39
|
t.integer "user_id"
|
40
40
|
t.integer "category_id"
|
41
|
-
t.datetime "created_at"
|
42
|
-
t.datetime "updated_at"
|
41
|
+
t.datetime "created_at"
|
42
|
+
t.datetime "updated_at"
|
43
43
|
end
|
44
44
|
|
45
|
-
create_table "tags", :
|
45
|
+
create_table "tags", force: true do |t|
|
46
46
|
t.integer "post_id"
|
47
47
|
t.string "name"
|
48
|
-
t.datetime "created_at"
|
49
|
-
t.datetime "updated_at"
|
48
|
+
t.datetime "created_at"
|
49
|
+
t.datetime "updated_at"
|
50
50
|
end
|
51
51
|
|
52
|
-
create_table "users", :
|
52
|
+
create_table "users", force: true do |t|
|
53
53
|
t.string "name"
|
54
54
|
t.string "email"
|
55
|
-
t.datetime "created_at"
|
56
|
-
t.datetime "updated_at"
|
55
|
+
t.datetime "created_at"
|
56
|
+
t.datetime "updated_at"
|
57
|
+
t.string "type"
|
57
58
|
end
|
58
59
|
|
59
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embedded_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gordon L. Hempton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -48,12 +48,14 @@ files:
|
|
48
48
|
- spec/support/app/app/controllers/application_controller.rb
|
49
49
|
- spec/support/app/app/controllers/posts_controller.rb
|
50
50
|
- spec/support/app/app/models/account.rb
|
51
|
+
- spec/support/app/app/models/admin.rb
|
51
52
|
- spec/support/app/app/models/category.rb
|
52
53
|
- spec/support/app/app/models/comment.rb
|
53
54
|
- spec/support/app/app/models/post.rb
|
54
55
|
- spec/support/app/app/models/tag.rb
|
55
56
|
- spec/support/app/app/models/user.rb
|
56
57
|
- spec/support/app/app/serializers/account_serializer.rb
|
58
|
+
- spec/support/app/app/serializers/admin_serializer.rb
|
57
59
|
- spec/support/app/app/serializers/category_serializer.rb
|
58
60
|
- spec/support/app/app/serializers/comment_serializer.rb
|
59
61
|
- spec/support/app/app/serializers/post_serializer.rb
|
@@ -81,6 +83,7 @@ files:
|
|
81
83
|
- spec/support/app/db/migrate/20130225173717_create_accounts.rb
|
82
84
|
- spec/support/app/db/migrate/20130226001629_create_tags.rb
|
83
85
|
- spec/support/app/db/migrate/20130226001639_create_categories.rb
|
86
|
+
- spec/support/app/db/migrate/20141022213956_create_admins.rb
|
84
87
|
- spec/support/app/db/schema.rb
|
85
88
|
- spec/support/app/db/seeds.rb
|
86
89
|
- spec/support/app/lib/assets/.gitkeep
|
@@ -119,12 +122,14 @@ test_files:
|
|
119
122
|
- spec/support/app/app/controllers/application_controller.rb
|
120
123
|
- spec/support/app/app/controllers/posts_controller.rb
|
121
124
|
- spec/support/app/app/models/account.rb
|
125
|
+
- spec/support/app/app/models/admin.rb
|
122
126
|
- spec/support/app/app/models/category.rb
|
123
127
|
- spec/support/app/app/models/comment.rb
|
124
128
|
- spec/support/app/app/models/post.rb
|
125
129
|
- spec/support/app/app/models/tag.rb
|
126
130
|
- spec/support/app/app/models/user.rb
|
127
131
|
- spec/support/app/app/serializers/account_serializer.rb
|
132
|
+
- spec/support/app/app/serializers/admin_serializer.rb
|
128
133
|
- spec/support/app/app/serializers/category_serializer.rb
|
129
134
|
- spec/support/app/app/serializers/comment_serializer.rb
|
130
135
|
- spec/support/app/app/serializers/post_serializer.rb
|
@@ -152,6 +157,7 @@ test_files:
|
|
152
157
|
- spec/support/app/db/migrate/20130225173717_create_accounts.rb
|
153
158
|
- spec/support/app/db/migrate/20130226001629_create_tags.rb
|
154
159
|
- spec/support/app/db/migrate/20130226001639_create_categories.rb
|
160
|
+
- spec/support/app/db/migrate/20141022213956_create_admins.rb
|
155
161
|
- spec/support/app/db/schema.rb
|
156
162
|
- spec/support/app/db/seeds.rb
|
157
163
|
- spec/support/app/lib/assets/.gitkeep
|