require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ISORecords do context 'for simple data' do let(:iso_records) { ISORecords.new(File.expand_path(File.dirname(__FILE__) + '/../iso_data/simple_data')) } context 'on initialization' do it 'loads data' do iso_records.data.should == [{:code => 'A', :says => 'hello'}, {:code => 'B', :says => 'goodbye'}] end end context 'returns values when' do it 'filtered by a field' do iso_records.values_for(:says).should == ['HELLO', 'GOODBYE'] end it 'filtered by multiple fields' do iso_records.values_for([:code, :says]).should == ['A', 'HELLO', 'B', 'GOODBYE'] end end end context 'for complex data' do let(:iso_records) { ISORecords.new(File.expand_path(File.dirname(__FILE__) + '/../iso_data/complex_data')) } context 'on initialization' do it 'loads data' do iso_records.data.should == [{:code => 'A', :entity => ['Alpha', 'Beta'], :says => 'hello'}, {:code => 'B', :says => 'goodbye'}] end end context 'returns values when' do it 'filtered by a field' do iso_records.values_for(:entity).should == ['ALPHA', 'BETA'] end it 'filtered by a string field' do iso_records.values_for("entity").should == ['ALPHA', 'BETA'] end it 'filtered by multiple fields' do iso_records.values_for([:entity, :says]).should == ['ALPHA', 'BETA', 'HELLO', 'GOODBYE'] end end end end