lib/wcc/contentful/test/factory.rb in wcc-contentful-1.2.0 vs lib/wcc/contentful/test/factory.rb in wcc-contentful-1.2.1
- old
+ new
@@ -6,13 +6,11 @@
##
# Builds a in-memory instance of the Contentful model for the given content_type.
# All attributes that are known to be required fields on the content type
# will return a default value based on the field type.
def contentful_create(const, context = nil, **attrs)
- unless const.respond_to?(:content_type_definition)
- const = WCC::Contentful::Model.resolve_constant(const.to_s)
- end
+ const = WCC::Contentful::Model.resolve_constant(const.to_s) unless const.respond_to?(:content_type_definition)
attrs = attrs.transform_keys { |a| a.to_s.camelize(:lower) }
id = attrs.delete('id')
sys = attrs.delete('sys')
raw = attrs.delete('raw') || default_raw(const, id)
@@ -57,11 +55,11 @@
{
space: {
sys: {
type: 'Link',
linkType: 'Space',
- id: ENV['CONTENTFUL_SPACE_ID']
+ id: ENV.fetch('CONTENTFUL_SPACE_ID', nil)
}
},
id: id || SecureRandom.urlsafe_base64,
type: 'Entry',
createdAt: Time.now.to_s(:iso8601),
@@ -84,11 +82,11 @@
locale: 'en-US'
}
end
def contentful_fields(model)
- WCC::Contentful::Test::Attributes.defaults(model).each_with_object({}) do |(k, v), h|
- h[k] = { 'en-US' => v }
+ WCC::Contentful::Test::Attributes.defaults(model).transform_values do |v|
+ { 'en-US' => v }
end
end
def to_raw(val, field_type)
if val.is_a? Array