From 18f320565c79afe4e433342cc15dc5669ff4cd73 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 11 Oct 2019 15:56:56 +0300 Subject: [PATCH] Add support for symbol_array type (#129) --- lib/contentful_model/migrations/content_type.rb | 12 +++++++++--- spec/migrations/content_type_spec.rb | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/contentful_model/migrations/content_type.rb b/lib/contentful_model/migrations/content_type.rb index 8216e91..93c8ed0 100644 --- a/lib/contentful_model/migrations/content_type.rb +++ b/lib/contentful_model/migrations/content_type.rb @@ -104,10 +104,16 @@ def management_link_type(type) end def management_items(type) - if %i[entry_array asset_array].include?(type.to_sym) + if %i[entry_array asset_array symbol_array].include?(type.to_sym) + array_type = type.split('_').first.capitalize + items = Contentful::Management::Field.new - items.type = 'Link' - items.link_type = type.split('_').first.capitalize + if %i[entry_array asset_array].include?(type.to_sym) + items.type = 'Link' + items.link_type = array_type + else + items.type = array_type + end items else diff --git a/spec/migrations/content_type_spec.rb b/spec/migrations/content_type_spec.rb index 8bf250a..014f886 100644 --- a/spec/migrations/content_type_spec.rb +++ b/spec/migrations/content_type_spec.rb @@ -166,6 +166,21 @@ expect(items.link_type).to eq('Asset') end + it 'symbol array field' do + field = subject.field('foo', :symbol_array) + + expect(field.id).to eq('foo') + expect(field.name).to eq('foo') + expect(field.type).to eq('Array') + expect(field.link_type).to eq(nil) + + items = field.items + + expect(items).to be_a(Contentful::Management::Field) + expect(items.type).to eq('Symbol') + expect(items.link_type).to eq(nil) + end + it 'rich_text field' do field = subject.field('foo', :rich_text)