lib/wcc/contentful/test/attributes.rb in wcc-contentful-0.4.0.pre.rc vs lib/wcc/contentful/test/attributes.rb in wcc-contentful-1.0.0.pre.rc1

- old
+ new

@@ -3,14 +3,26 @@ module WCC::Contentful::Test::Attributes DEFAULTS = { String: 'test', Int: 0, Float: 0.0, - DateTime: Time.at(0), + DateTime: Time.at(0).to_s, Boolean: false, - Json: -> { OpenStruct.new }, - Coordinates: -> { OpenStruct.new } + Json: ->(_f) { {} }, + Coordinates: ->(_f) { {} }, + Asset: ->(f) { + WCC::Contentful::Link.new( + "fake-#{f.name}-#{SecureRandom.urlsafe_base64[1..6]}", + :Asset + ).raw + }, + Link: ->(f) { + WCC::Contentful::Link.new( + "fake-#{f.name}-#{SecureRandom.urlsafe_base64[1..6]}", + :Link + ).raw + } }.freeze class << self def [](key) DEFAULTS[key] @@ -33,11 +45,11 @@ # This comes from the 'content_type_definition' of a contentful model class. def default_value(field) return [] if field.array return unless field.required - val = DEFAULTS[field] - return val.call if val.respond_to?(:call) + val = DEFAULTS[field.type] + return val.call(field) if val.respond_to?(:call) val end end end