diff --git a/lib/locomotive/steam/models/mapper.rb b/lib/locomotive/steam/models/mapper.rb index f05575b7..9ba427ab 100644 --- a/lib/locomotive/steam/models/mapper.rb +++ b/lib/locomotive/steam/models/mapper.rb @@ -78,7 +78,8 @@ def serialize(entity) # localized fields @localized_attributes.each do |name| # hack: force the name for select type fields (content entries only) - entity.send(name).serialize(attributes, name) + value = entity.send(name) + value.serialize(attributes, name) if value.respond_to?(:serialize) end # association name -> id (belongs_to) or ids (many_to_many) diff --git a/spec/unit/models/mapper_spec.rb b/spec/unit/models/mapper_spec.rb index 64c1a850..5f1d2448 100644 --- a/spec/unit/models/mapper_spec.rb +++ b/spec/unit/models/mapper_spec.rb @@ -79,6 +79,11 @@ end + describe 'localized attributes' do + let(:block) { ->(_) { localized_attributes(:title) } } + let(:attributes) { { title: { fr: 'Bonjour' }, body: 'Lorem ipsum', published_at: DateTime.parse('2007/06/29 00:00:00') } } + it { expect(subject).to eq('title' => { 'fr' => 'Bonjour' }, 'body' => 'Lorem ipsum', 'published_at' => DateTime.parse('2007/06/29 00:00:00')) } + end end describe '#to_entity' do