From bb89c498a7681e59ae510d7ca624a33e982a9d0f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:21:24 -0600 Subject: [PATCH] Update rubocop requirement from ~> 0.79 to ~> 1.64 (#20) * Update rubocop requirement from ~> 0.79 to ~> 1.64 Updates the requirements on [rubocop](https://github.com/rubocop/rubocop) to permit the latest version. - [Release notes](https://github.com/rubocop/rubocop/releases) - [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop/compare/v0.79.0...v1.64.1) --- updated-dependencies: - dependency-name: rubocop dependency-type: direct:development ... Signed-off-by: dependabot[bot] * Add require ostruct to fix unitialized constant error * Autocorrect rubocop fixes * Address manual rubocop fixes * Enable new cops and autocorrect --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JDutil --- .rubocop.yml | 3 ++- contentful_lite.gemspec | 3 +-- lib/contentful_lite/assets_array.rb | 2 +- lib/contentful_lite/base_array.rb | 1 + lib/contentful_lite/client.rb | 1 + lib/contentful_lite/entries_array.rb | 4 ++-- lib/contentful_lite/entry.rb | 4 ++-- lib/contentful_lite/validations/included_asset_validator.rb | 1 + lib/contentful_lite/validations/included_child_validator.rb | 3 ++- spec/link_spec.rb | 1 + spec/validations_spec.rb | 1 + 11 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 20785b5..d6574ab 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,8 @@ # Relaxed.Ruby.Style ## Version 2.1 AllCops: - TargetRubyVersion: 2.7.5 + NewCops: enable + TargetRubyVersion: 3.0.0 Gemspec/OrderedDependencies: Enabled: false diff --git a/contentful_lite.gemspec b/contentful_lite.gemspec index c0149ea..299ac65 100644 --- a/contentful_lite.gemspec +++ b/contentful_lite.gemspec @@ -13,7 +13,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0.0' spec.files = Dir["lib/**/*", "LICENSE", "README.md"] - spec.test_files = Dir["spec/**/*"] spec.require_paths = ["lib"] spec.add_dependency "http", '~> 5.0' @@ -23,5 +22,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "webmock", '~> 3.18' spec.add_development_dependency "simplecov", '~> 0.17' spec.add_development_dependency "vcr", '~> 6.0' - spec.add_development_dependency "rubocop", '~> 0.79' + spec.add_development_dependency "rubocop", '~> 1.64' end diff --git a/lib/contentful_lite/assets_array.rb b/lib/contentful_lite/assets_array.rb index aca67b2..bd89936 100644 --- a/lib/contentful_lite/assets_array.rb +++ b/lib/contentful_lite/assets_array.rb @@ -3,7 +3,7 @@ class AssetsArray < BaseArray # @param raw [Hash] raw response from Contentful API # @api private def initialize(raw) - super(raw) + super # Create the array of asset objects @items.collect! { |item| ContentfulLite::Asset.new(item) } diff --git a/lib/contentful_lite/base_array.rb b/lib/contentful_lite/base_array.rb index 3477bd3..9a0c038 100644 --- a/lib/contentful_lite/base_array.rb +++ b/lib/contentful_lite/base_array.rb @@ -10,6 +10,7 @@ class BaseArray < Delegator # @param raw [Hash] raw response from Contentful API # @api private def initialize(raw) + super @total = raw['total'] @skip = raw['skip'] @limit = raw['limit'] 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..da72bb1 100644 --- a/lib/contentful_lite/entries_array.rb +++ b/lib/contentful_lite/entries_array.rb @@ -3,7 +3,7 @@ class EntriesArray < BaseArray # @param raw [Hash] raw response from Contentful API # @api private def initialize(raw) - super(raw) + super # Collect arrays of missing (unresolvable) links @errors = raw.fetch('errors', []).collect! { |error| error.fetch('details', {}) }.each_with_object({}) do |error_detail, hash| @@ -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..9ae2685 100644 --- a/lib/contentful_lite/entry.rb +++ b/lib/contentful_lite/entry.rb @@ -10,9 +10,9 @@ class Entry # @param raw [Hash] raw response from Contentful API # @api private def initialize(raw) - super(raw) + super @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..5b7deab 100644 --- a/lib/contentful_lite/validations/included_child_validator.rb +++ b/lib/contentful_lite/validations/included_child_validator.rb @@ -18,11 +18,12 @@ def validate_each(record, attr_name, value) private def record_error(record, attr_name, message) - record.errors.add(attr_name, :invalid, **{ message: message }.merge(options.except(self.class.options_keys))) + record.errors.add(attr_name, :invalid, message: message, **options.except(self.class.options_keys)) end 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/link_spec.rb b/spec/link_spec.rb index 0e2d37c..b08788c 100644 --- a/spec/link_spec.rb +++ b/spec/link_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'ostruct' RSpec.describe ContentfulLite::Link do let(:entry_hash) { JSON.parse(File.read('fixtures/entries/nyancat.json')) } 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)