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 let :record do table = DBF::Table.new "#{DB_PATH}/dbase_8b.dbf" 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"} let(:record) { table.find(0) } it 'should have dynamic accessors for the columns' do record.should respond_to(:character) record.character.should == 'One' record.float.should == 1.23456789012346 record.logical.should == true end it 'should not define accessor methods on the base class' do second_table = DBF::Table.new "#{DB_PATH}/dbase_03.dbf" second_record = second_table.find(0) record.character.should == 'One' expect { second_record.character }.to raise_error(NoMethodError) end end describe 'column data for table' do let(:table) { DBF::Table.new "#{DB_PATH}/cp1251.dbf"} let(:record) { table.find(0) } it 'should automatically encodes to default system encoding' do if table.supports_encoding? record.name.encoding.should == Encoding.default_external record.name.encode("UTF-8").unpack("H4").should == ["d0b0"] # russian a end end end end