lib/wcc/contentful/test/double.rb in wcc-contentful-1.2.0 vs lib/wcc/contentful/test/double.rb in wcc-contentful-1.2.1

- old
+ new

@@ -6,13 +6,11 @@ ## # Builds a rspec double 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_double(const, **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.symbolize_keys! bad_attrs = attrs.reject { |a| const.instance_methods.include?(a) } raise ArgumentError, "Attribute(s) do not exist on #{const}: #{bad_attrs.keys}" if bad_attrs.any? @@ -43,11 +41,11 @@ sys: { space: { sys: { type: 'Link', linkType: 'Space', - id: ENV['CONTENTFUL_SPACE_ID'] + id: ENV.fetch('CONTENTFUL_SPACE_ID', nil) } }, id: SecureRandom.urlsafe_base64, type: 'Asset', createdAt: Time.now.to_s(:iso8601), @@ -60,10 +58,10 @@ } }, revision: rand(100), locale: 'en-US' }, - fields: attrs.each_with_object({}) { |(k, v), h| h[k] = { 'en-US' => v } } + fields: attrs.transform_values { |v| { 'en-US' => v } } } double(attrs) end