diff --git a/lib/contentful_lite/client.rb b/lib/contentful_lite/client.rb index 7658daf..83617a6 100644 --- a/lib/contentful_lite/client.rb +++ b/lib/contentful_lite/client.rb @@ -11,6 +11,7 @@ def initialize(response, body) super(body['sys'] && body['sys']['type'] == 'Error' ? "#{body['sys']['id']}: #{body['message']}" : "Invalid Contentful Response: #{body}") end end + class NotFoundError < RequestError; end attr_reader :space_id, :environment, :preview diff --git a/lib/contentful_lite/entries_array.rb b/lib/contentful_lite/entries_array.rb index e5cbdc3..919184b 100644 --- a/lib/contentful_lite/entries_array.rb +++ b/lib/contentful_lite/entries_array.rb @@ -52,7 +52,7 @@ def build_entry(id) klass = ContentfulLite::Entry.get_class(hash['sys']['contentType']['sys']['id']) @entries[id] = klass.new(hash) - @entries[id].localized_fields.values.each do |fields| + @entries[id].localized_fields.each_value do |fields| fields.transform_values! { |field| solve_link(field) } end @entries[id] diff --git a/lib/contentful_lite/entry.rb b/lib/contentful_lite/entry.rb index 5bead34..d66f4aa 100644 --- a/lib/contentful_lite/entry.rb +++ b/lib/contentful_lite/entry.rb @@ -12,7 +12,7 @@ class Entry def initialize(raw) super(raw) @content_type_id = raw['sys']['contentType']['sys']['id'] - @localized_fields.values.each do |fields| + @localized_fields.each_value do |fields| fields.transform_values! { |value| build_link(value) } end end diff --git a/lib/contentful_lite/validations/included_asset_validator.rb b/lib/contentful_lite/validations/included_asset_validator.rb index ab28d16..59bcf14 100644 --- a/lib/contentful_lite/validations/included_asset_validator.rb +++ b/lib/contentful_lite/validations/included_asset_validator.rb @@ -7,6 +7,7 @@ class IncludedAssetValidator < ActiveModel::EachValidator def validate_child(record, attr_name, value, idx = nil) record_error(record, attr_name, "value#{idx} is not a published asset") && return unless value.is_a?(ContentfulLite::Asset) + record_error(record, attr_name, "value#{idx} has an invalid asset type. Expecting #{options[:type]}") if options[:type] && !value&.content_type&.include?(options[:type].to_s) end end diff --git a/lib/contentful_lite/validations/included_child_validator.rb b/lib/contentful_lite/validations/included_child_validator.rb index 112d51c..64edaa3 100644 --- a/lib/contentful_lite/validations/included_child_validator.rb +++ b/lib/contentful_lite/validations/included_child_validator.rb @@ -23,6 +23,7 @@ def record_error(record, attr_name, message) def validate_array(record, attr_name, value) record_error(record, attr_name, "value is not an array") && return unless value.is_a?(Array) + value.each_with_index { |asset, idx| validate_child(record, attr_name, asset, "[#{idx}]") } end diff --git a/spec/validations_spec.rb b/spec/validations_spec.rb index c82aebe..b688e5d 100644 --- a/spec/validations_spec.rb +++ b/spec/validations_spec.rb @@ -6,6 +6,7 @@ def create_validable_model(validation_method, options) include ContentfulLite::Validations::Entry attr_reader :fake_field attr_accessor :locale + send(validation_method, :fake_field, options) def initialize(value)