File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -494,8 +494,15 @@ def association_for(name)
494
494
end
495
495
end
496
496
497
+ def non_serializing_attributes
498
+ [
499
+ self . class . read_only_attributes ,
500
+ self . class . prefix_params . map ( &:to_s )
501
+ ] . flatten
502
+ end
503
+
497
504
def attributes_for_serialization
498
- attributes . except ( *self . class . read_only_attributes ) . slice ( *changed )
505
+ attributes . except ( *non_serializing_attributes ) . slice ( *changed )
499
506
end
500
507
501
508
def relationships_for_serialization
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ class LimitedField < TestResource
6
6
self . read_only_attributes += [ 'foo' ]
7
7
end
8
8
9
+ class NestedResource < TestResource
10
+ belongs_to :bar
11
+ end
12
+
9
13
class CustomSerializerAttributes < TestResource
10
14
11
15
protected
@@ -317,4 +321,19 @@ def test_underscored_relationship_key_serialization
317
321
assert_equal expected , article . as_json_api [ 'relationships' ]
318
322
end
319
323
end
324
+
325
+ def test_ensure_nested_path_params_not_serialized
326
+ resource = NestedResource . new ( foo : 'bar' , id : 1 , bar_id : 99 )
327
+
328
+ expected = {
329
+ 'id' => 1 ,
330
+ 'type' => "nested_resources" ,
331
+ 'attributes' => {
332
+ 'foo' => 'bar'
333
+ }
334
+ }
335
+
336
+ assert_equal expected , resource . as_json_api
337
+ end
338
+
320
339
end
You can’t perform that action at this time.
0 commit comments