Skip to content

Commit ec0b233

Browse files
author
Amy Sutedja
committed
Pluralize state correctly inherits
1 parent da73720 commit ec0b233

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/fast_jsonapi/object_serializer.rb

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def inherited(subclass)
118118
subclass.cachable_relationships_to_serialize = cachable_relationships_to_serialize.dup if cachable_relationships_to_serialize.present?
119119
subclass.uncachable_relationships_to_serialize = uncachable_relationships_to_serialize.dup if uncachable_relationships_to_serialize.present?
120120
subclass.transform_method = transform_method
121+
subclass.pluralized_type = pluralized_type
121122
subclass.cache_length = cache_length
122123
subclass.race_condition_ttl = race_condition_ttl
123124
subclass.data_links = data_links.dup if data_links.present?

spec/lib/object_serializer_inheritance_spec.rb

+17-4
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,23 @@ class EmployeeSerializer < UserSerializer
9595
has_one :account
9696
end
9797

98+
class LegacyUserSerializer < UserSerializer
99+
pluralize_type true
100+
end
101+
102+
class LegacyEmployeeSerializer < LegacyUserSerializer
103+
attributes :location
104+
attributes :compensation
105+
106+
has_one :account
107+
end
108+
98109
it 'sets the correct record type' do
99110
expect(EmployeeSerializer.reflected_record_type).to eq :employee
100111
expect(EmployeeSerializer.record_type).to eq :employee
101112
end
102113

103114
context 'when testing inheritance of attributes' do
104-
105115
it 'includes parent attributes' do
106116
subclass_attributes = EmployeeSerializer.attributes_to_serialize
107117
superclass_attributes = UserSerializer.attributes_to_serialize
@@ -157,12 +167,15 @@ class EmployeeSerializer < UserSerializer
157167
end
158168
end
159169

160-
context 'when test inheritence of other attributes' do
161-
162-
it 'inherits the tranform method' do
170+
context 'when testing inheritence of other attributes' do
171+
it 'inherits the transform method' do
163172
EmployeeSerializer
164173
expect(UserSerializer.transform_method).to eq EmployeeSerializer.transform_method
165174
end
166175

176+
it 'inherits pluralized_type' do
177+
LegacyEmployeeSerializer
178+
expect(LegacyUserSerializer.pluralized_type).to eq LegacyEmployeeSerializer.pluralized_type
179+
end
167180
end
168181
end

0 commit comments

Comments
 (0)