-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from lyrasis/append-fields
add Append::NilFields transform class
- Loading branch information
Showing
3 changed files
with
39 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Kiba | ||
module Extend | ||
VERSION = "1.10.0" | ||
VERSION = "1.11.0" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Kiba::Extend::Transforms::Append do | ||
let(:test_csv) { 'tmp/test.csv' } | ||
before{ generate_csv(test_csv, rows) } | ||
|
||
describe 'NilFields' do | ||
let(:rows) { [ | ||
['id', 'z'], | ||
[1, 'zz'] | ||
] } | ||
let(:result) { execute_job(filename: test_csv, | ||
xform: Append::NilFields, | ||
xformopt: {fields: %i[a b c z]}) } | ||
it 'adds non-existing fields, populating with nil, while leaving existing fields alone' do | ||
expected = {id: '1', z: 'zz', a: nil, b: nil, c: nil} | ||
expect(result[0]).to eq(expected) | ||
end | ||
end | ||
|
||
describe 'ToFieldValue' do | ||
test_csv = 'tmp/test.csv' | ||
rows = [ | ||
let(:rows) { [ | ||
['id', 'name'], | ||
[1, 'Weddy'], | ||
[2, nil], | ||
[3, ''] | ||
] | ||
|
||
before do | ||
generate_csv(test_csv, rows) | ||
@result = execute_job(filename: test_csv, | ||
xform: Append::ToFieldValue, | ||
xformopt: {field: :name, value: ' (name)'}) | ||
end | ||
] } | ||
let(:result) { execute_job(filename: test_csv, | ||
xform: Append::ToFieldValue, | ||
xformopt: {field: :name, value: ' (name)'}) } | ||
it 'prepends given value to existing field values' do | ||
expected = {id: '1', name: 'Weddy (name)'} | ||
expect(@result[0]).to eq(expected) | ||
expect(result[0]).to eq(expected) | ||
end | ||
it 'leaves nil values alone' do | ||
expected = {id: '2', name: nil} | ||
expect(@result[1]).to eq(expected) | ||
expect(result[1]).to eq(expected) | ||
end | ||
it 'leaves blank values alone' do | ||
expected = {id: '3', name: ''} | ||
expect(@result[2]).to eq(expected) | ||
expect(result[2]).to eq(expected) | ||
end | ||
end | ||
end |