Skip to content

Commit

Permalink
fix: don't serialize unpresent fields
Browse files Browse the repository at this point in the history
  • Loading branch information
did committed Dec 18, 2024
1 parent 023a424 commit 2fb0bfb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/locomotive/steam/models/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions spec/unit/models/mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fb0bfb

Please sign in to comment.