Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for rich_text field #127

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/contentful_model/migrations/content_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ module Migrations
class ContentType
attr_accessor :id, :name

MANAGEMENT_TYPE_MAPPING = {
'string' => 'Symbol',
'rich_text' => 'RichText'
}.freeze

def initialize(name = nil, management_content_type = nil)
@name = name
@management_content_type = management_content_type
Expand Down Expand Up @@ -78,12 +83,12 @@ def fields_from_management_type
def management_type(type)
if %i[text symbol integer number date boolean location object].include?(type.to_sym)
type.capitalize
elsif type == 'string'
'Symbol'
elsif link?(type)
'Link'
elsif array?(type)
'Array'
elsif MANAGEMENT_TYPE_MAPPING.key?(type.to_s)
MANAGEMENT_TYPE_MAPPING[type.to_s]
else
raise_field_type_error(type)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/migrations/content_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@
expect(items.link_type).to eq('Asset')
end

it 'rich_text field' do
field = subject.field('foo', :rich_text)

expect(field.type).to eq('RichText')
end

it 'fails on unknown type' do
expect { subject.field('foo', :bar) }.to raise_error ContentfulModel::Migrations::InvalidFieldTypeError
end
Expand Down