From b63887c41962576d81bd773206757772f8ffc173 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Mon, 30 Nov 2020 11:53:31 -0500 Subject: [PATCH] Handle Replace::FieldValueWithStaticMapping fallback_val string --- Gemfile.lock | 16 ++++++++-------- lib/kiba/extend/transforms/replace.rb | 2 ++ lib/kiba/extend/version.rb | 2 +- spec/kiba/extend/transforms/replace_spec.rb | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5848aa26b..e5d6fee5d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - kiba-extend (1.5.0) + kiba-extend (1.6.0) activesupport kiba (>= 3.0.0) kiba-common (>= 0.9.0) @@ -10,23 +10,23 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (6.0.3.2) + activesupport (6.0.3.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) zeitwerk (~> 2.2, >= 2.2.2) coderay (1.1.2) - concurrent-ruby (1.1.6) + concurrent-ruby (1.1.7) diff-lcs (1.3) facets (3.1.0) i18n (1.8.5) concurrent-ruby (~> 1.0) - kiba (3.0.0) - kiba-common (1.0.0) + kiba (3.5.0) + kiba-common (1.1.0) kiba (>= 1.0.0, < 4) method_source (0.9.2) - minitest (5.14.1) + minitest (5.14.2) pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) @@ -45,10 +45,10 @@ GEM rspec-support (~> 3.9.0) rspec-support (3.9.3) thread_safe (0.3.6) - tzinfo (1.2.7) + tzinfo (1.2.8) thread_safe (~> 0.1) xxhash (0.4.0) - zeitwerk (2.4.0) + zeitwerk (2.4.1) PLATFORMS ruby diff --git a/lib/kiba/extend/transforms/replace.rb b/lib/kiba/extend/transforms/replace.rb index 8d0534447..2c2f60cb2 100644 --- a/lib/kiba/extend/transforms/replace.rb +++ b/lib/kiba/extend/transforms/replace.rb @@ -50,6 +50,8 @@ def process(row) newvals << oval when :nil newvals << nil + else + newvals << @fallback end end end diff --git a/lib/kiba/extend/version.rb b/lib/kiba/extend/version.rb index 79d743ca6..1c68ddafe 100644 --- a/lib/kiba/extend/version.rb +++ b/lib/kiba/extend/version.rb @@ -1,5 +1,5 @@ module Kiba module Extend - VERSION = "1.6.0" + VERSION = "1.6.1" end end diff --git a/spec/kiba/extend/transforms/replace_spec.rb b/spec/kiba/extend/transforms/replace_spec.rb index 2d8fef244..4f27396bc 100644 --- a/spec/kiba/extend/transforms/replace_spec.rb +++ b/spec/kiba/extend/transforms/replace_spec.rb @@ -93,6 +93,22 @@ expect(result).to eq(expected) end end + + context 'and :fallback_val = a string' do + it 'sends the string through to new column' do + expected = [ + {:id=>'1', :name=>'Unnamed keet', :gender=>'unknown'}, + {:id=>'2', :name=>'Kernel', :gender=>'female'} + ] + result = execute_job(filename: test_csv, + xform: Replace::FieldValueWithStaticMapping, + xformopt: {source: :sex, + target: :gender, + mapping: mapping, + fallback_val: 'unknown'}) + expect(result).to eq(expected) + end + end end end end