Sha256: 09e8f3b28901497407a41025391f7586eeb8579345bc30e73058f80a6521bba9

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

require "spec_helper"

describe DBF::Record do
  
  describe '#to_a' do
    it 'should return an ordered array of attribute values' do
      table = DBF::Table.new "#{DB_PATH}/dbase_8b.dbf"
      
      record = table.record(0)
      record.to_a.should == ["One", 1.0, Date.new(1970, 1, 1), true, 1.23456789012346, "First memo\r\n\037 \037 \037 \037 "]
      
      record = table.record(9)
      record.to_a.should == ["Ten records stored in this database", 10.0, nil, false, 0.1, nil]
    end
  end
  
  describe '#==' do
    before do
      table = DBF::Table.new "#{DB_PATH}/dbase_8b.dbf"
      @record = table.record(9)
    end
    
    it 'should be false if other does not have attributes' do
      (@record == mock('other')).should be_false
    end
    
    it 'should be true if other attributes match' do
      attributes = {:x => 1, :y => 2}
      @record.stub!(:attributes).and_return(attributes)
      other = mock('object', :attributes => attributes)
      (@record == other).should be_true
    end
  end
  
  describe 'column accessors' do
    let(:table) { DBF::Table.new "#{DB_PATH}/dbase_8b.dbf"}
    
    it 'should define accessor methods for each column' do
      record = table.find(0)
      record.should respond_to(:character)
      record.character.should == 'One'
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dbf-1.5.2 spec/dbf/record_spec.rb
dbf-1.5.1 spec/dbf/record_spec.rb
dbf-1.5.0 spec/dbf/record_spec.rb