Sha256: 9b8403624f3b01400e959f600740549a869bf05dbbb34a6d4868fd6d3e6c9f38
Contents?: true
Size: 1.79 KB
Versions: 2
Compression:
Stored size: 1.79 KB
Contents
require 'spec_helper' describe Topographer::Importer::Mapper::ValidationFieldMapping do let(:validation_mapping) do Topographer::Importer::Mapper::ValidationFieldMapping.new('test mapping', ['field1', 'field2', 'field3']) do |input| sum = input.values.flatten.inject(0) {|sum, x| sum+x} raise 'Sum must be 15' if sum != 15 end end let(:valid_input) do {'field1' => 4, 'field2' => 5, 'field3' => 6} end let(:invalid_input) do {'field1' => 3, 'field2' => 4, 'field3' => 5} end let(:result) { Topographer::Importer::Mapper::Result.new('test') } describe '#initialize' do it 'should not create a validation mapping without a behavior block' do expect { Topographer::Importer::Mapper::ValidationFieldMapping.new('test mapping', ['field1', 'field2', 'field3']) }. to raise_error(Topographer::InvalidMappingError) end end describe '#process_input' do it 'should not return an error if the validation block passes' do validation_mapping.process_input(valid_input, result) expect(result.errors?).to be_falsey expect(result.data.blank?).to be_truthy end it 'should return an error if the validation block raises an error' do validation_mapping.process_input(invalid_input, result) expect(result.errors?).to be_truthy expect(result.errors.values).to include('Sum must be 15') end it 'should not rescue Exceptions that do not inherit from standard error' do mapper = Topographer::Importer::Mapper::ValidationFieldMapping.new('test mapping', ['field1', 'field2', 'field3']) do |input| sum = input.values.flatten.inject(0) {|sum, x| sum+x} raise Exception, 'Sum must be 15' if sum != 15 end expect{ mapper.process_input(invalid_input, result) }.to raise_error(Exception) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
topographer-0.0.9 | spec/topographer/importer/mapper/validation_field_mapping_spec.rb |
topographer-0.0.8 | spec/topographer/importer/mapper/validation_field_mapping_spec.rb |