From 352304da06b8aea1da55cc2848c4db3c8f1f99a4 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Tue, 2 Aug 2022 11:37:52 +0100 Subject: [PATCH] Prevent initializing nil attributes to `[]` --- lib/tess/api/material.rb | 1 + tess_api_client.gemspec | 2 +- test/material_test.rb | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tess/api/material.rb b/lib/tess/api/material.rb index 8576fd7..efdddea 100755 --- a/lib/tess/api/material.rb +++ b/lib/tess/api/material.rb @@ -27,6 +27,7 @@ def initialize(params = {}) # TODO: Check if this is really necessary: [:scientific_topic_names, :operation_names, :collection_ids, :keywords, :contributors, :authors, :target_audience, :node_ids, :external_resources_attributes].each do |attr| + next unless params.key?(attr) params[attr] = [params[attr]].flatten.compact end diff --git a/tess_api_client.gemspec b/tess_api_client.gemspec index 5332244..0daac60 100644 --- a/tess_api_client.gemspec +++ b/tess_api_client.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'tess_api_client' - s.version = '0.4.1' + s.version = '0.4.2' s.date = '2022-07-28' s.summary = 'Libraries for uploading files to https://github.com/ElixirTeSS/TeSS' s.description = 'Uses the a Custom RoR API on https://tess.elixir-europe.org to upload data in the format being used by the TeSS project.' diff --git a/test/material_test.rb b/test/material_test.rb index 2a3d220..3e57f8c 100644 --- a/test/material_test.rb +++ b/test/material_test.rb @@ -386,4 +386,9 @@ class MaterialTest < Test::Unit::TestCase assert_include mat.errors.keys, 'url' end end + + test 'do not convert missing attributes to empty arrays' do + material = Tess::API::Material.new + assert_nil material.keywords + end end