File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 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)
494494 end
495495 end
496496
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+
497504 def attributes_for_serialization
498- attributes . except ( *self . class . read_only_attributes ) . slice ( *changed )
505+ attributes . except ( *non_serializing_attributes ) . slice ( *changed )
499506 end
500507
501508 def relationships_for_serialization
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ class LimitedField < TestResource
66 self . read_only_attributes += [ 'foo' ]
77 end
88
9+ class NestedResource < TestResource
10+ belongs_to :bar
11+ end
12+
913 class CustomSerializerAttributes < TestResource
1014
1115 protected
@@ -317,4 +321,19 @@ def test_underscored_relationship_key_serialization
317321 assert_equal expected , article . as_json_api [ 'relationships' ]
318322 end
319323 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+
320339end
You can’t perform that action at this time.
0 commit comments