spec/differential/parser/reader_spec.rb in differential-1.0.6 vs spec/differential/parser/reader_spec.rb in differential-1.1.0

- old
+ new

@@ -10,13 +10,13 @@ require './spec/spec_helper' describe ::Differential::Parser::Reader do it 'should initialize correctly' do hash = { - record_id_key: :name, - value_key: :minutes, - group_id_key: :transport + record_id_key: :name, + value_key: :minutes, + group_id_key: :transport } reader = ::Differential::Parser::Reader.new(hash) expect(reader.record_id_key).to eq(hash[:record_id_key]) @@ -24,131 +24,62 @@ expect(reader.group_id_key).to eq(hash[:group_id_key]) end context 'When reading just id and value' do it 'should properly create a record from a hash' do - reader = ::Differential::Parser::Reader.new(record_id_key: :name, - value_key: :minutes) + reader = ::Differential::Parser::Reader.new(record_id_key: :name, + value_key: :minutes) - hashes = [ - { - name: 'Matt', - minutes: 34 - } - ] + hash = { + name: 'Matt', + minutes: 34 + } - records = [] - reader.each(hashes) do |record| - records << record - end + record = reader.read(hash) - record = records.first - hash = hashes.first - expect(record.id).to eq(hash[:name]) expect(record.group_id).to eq('') expect(record.value).to eq(hash[:minutes]) expect(record.data).to eq(hash) end - - it 'should skip null records' do - reader = ::Differential::Parser::Reader.new(record_id_key: :name, - value_key: :minutes) - - hashes = [nil] - - records = [] - reader.each(hashes) do |record| - records << record - end - - expect(records.length).to eq(0) - end end - it 'should read non-array input' do - reader = ::Differential::Parser::Reader.new(record_id_key: :name, - value_key: :minutes) - - hashes = { - name: 'Matt', - minutes: 34 - } - - records = [] - reader.each(hashes) do |record| - records << record - end - - expect(records.length).to eq(1) - end - - it 'should read null input' do - reader = ::Differential::Parser::Reader.new(record_id_key: :name, - value_key: :minutes) - - hashes = nil - - records = [] - reader.each(hashes) do |record| - records << record - end - - expect(records.length).to eq(0) - end - context 'When reading singular keys' do it 'should properly create a record from a hash' do - reader = ::Differential::Parser::Reader.new(record_id_key: :name, - value_key: :minutes, + reader = ::Differential::Parser::Reader.new(record_id_key: :name, + value_key: :minutes, group_id_key: :transport) - hashes = [ - { - name: 'Matt', - minutes: 34, - transport: 'Train' - } - ] + hash = { + name: 'Matt', + minutes: 34, + transport: 'Train' + } - records = [] - reader.each(hashes) do |record| - records << record - end + record = reader.read(hash) - record = records.first - hash = hashes.first - expect(record.id).to eq(hash[:name]) expect(record.group_id).to eq(hash[:transport]) expect(record.value).to eq(hash[:minutes]) expect(record.data).to eq(hash) end end context 'When reading multiple id keys' do it 'should properly create a record from a hash' do - reader = ::Differential::Parser::Reader.new(record_id_key: %i[first last], - value_key: :minutes, - group_id_key: %i[transport direction]) + reader = ::Differential::Parser::Reader.new(record_id_key: %i[first last], + value_key: :minutes, + group_id_key: %i[transport direction]) - hashes = [ - { - first: 'Matt', - last: 'Smith', - minutes: 34, - transport: 'Train', - direction: 'Outbound' - } - ] + hash = { + first: 'Matt', + last: 'Smith', + minutes: 34, + transport: 'Train', + direction: 'Outbound' + } - records = [] - reader.each(hashes) do |record| - records << record - end - - record = records.first - hash = hashes.first + record = reader.read(hash) expect(record.id).to eq("#{hash[:first]}:#{hash[:last]}") expect(record.id.data).to eq([hash[:first], hash[:last]]) expect(record.group_id).to eq("#{hash[:transport]}:#{hash[:direction]}") expect(record.value).to eq(hash[:minutes])