spec/differential/parser/reader_spec.rb in differential-1.0.2 vs spec/differential/parser/reader_spec.rb in differential-1.0.3
- old
+ new
@@ -47,9 +47,54 @@
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,