dbf 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  RSpec.describe DBF::Record do
4
4
  describe '#to_a' do
@@ -67,8 +67,7 @@ RSpec.describe DBF::Record do
67
67
  let(:table) { DBF::Table.new fixture('dbase_8b.dbf') }
68
68
  let(:record) { table.find(0) }
69
69
 
70
- %w(character numerical date logical float memo).each do |column_name|
71
-
70
+ %w[character numerical date logical float memo].each do |column_name|
72
71
  it "defines accessor method for '#{column_name}' column" do
73
72
  expect(record).to respond_to(column_name.to_sym)
74
73
  end
@@ -85,19 +84,19 @@ RSpec.describe DBF::Record do
85
84
  expect(record.name.encoding).to eq Encoding.default_external
86
85
 
87
86
  # russian a
88
- expect(record.name.encode("UTF-8").unpack("H4")).to eq ["d0b0"]
87
+ expect(record.name.encode('UTF-8').unpack('H4')).to eq ['d0b0']
89
88
  end
90
89
  end
91
90
 
92
91
  describe 'overriding specified in dbf encoding' do
93
- let(:table) { DBF::Table.new fixture('cp1251.dbf'), nil, 'cp866'}
92
+ let(:table) { DBF::Table.new fixture('cp1251.dbf'), nil, 'cp866' }
94
93
  let(:record) { table.find(0) }
95
94
 
96
95
  it 'should transcode from manually specified encoding to default system encoding' do
97
96
  expect(record.name.encoding).to eq Encoding.default_external
98
97
 
99
98
  # russian а encoded in cp1251 and read as if it was encoded in cp866
100
- expect(record.name.encode("UTF-8").unpack("H4")).to eq ["d180"]
99
+ expect(record.name.encode('UTF-8').unpack('H4')).to eq ['d180']
101
100
  end
102
101
  end
103
102
  end
@@ -112,7 +111,7 @@ RSpec.describe DBF::Record do
112
111
  end
113
112
 
114
113
  it 'has only original field names as keys' do
115
- original_field_names = %w(CHARACTER DATE FLOAT LOGICAL MEMO NUMERICAL)
114
+ original_field_names = %w[CHARACTER DATE FLOAT LOGICAL MEMO NUMERICAL]
116
115
  expect(record.attributes.keys.sort).to eq original_field_names
117
116
  end
118
117
  end
@@ -6,7 +6,11 @@ RSpec.describe DBF::Table do
6
6
  let(:table) { DBF::Table.new dbf_path }
7
7
 
8
8
  specify 'foxpro versions' do
9
- expect(DBF::Table::FOXPRO_VERSIONS.keys.sort).to eq %w(30 31 f5 fb).sort
9
+ expect(DBF::Table::FOXPRO_VERSIONS.keys.sort).to eq %w[30 31 f5 fb].sort
10
+ end
11
+
12
+ specify 'row is an alias of record' do
13
+ expect(table.record(1)).to eq table.row(1)
10
14
  end
11
15
 
12
16
  describe '#initialize' do
@@ -50,11 +54,18 @@ RSpec.describe DBF::Table do
50
54
 
51
55
  describe '#schema' do
52
56
  describe 'when data is IO' do
53
- let(:control_schema) { File.read(fixture('dbase_83_schema.txt')) }
57
+ let(:control_schema) { File.read(fixture('dbase_83_schema_ar.txt')) }
54
58
 
55
59
  it 'matches the test schema fixture' do
56
60
  expect(table.schema).to eq control_schema
57
61
  end
62
+
63
+ it 'raises ArgumentError if there is no matching schema' do
64
+ expect { table.schema(:invalid) }.to raise_error(
65
+ ArgumentError,
66
+ ':invalid is not a valid schema. Valid schemas are: activerecord, json, sequel.'
67
+ )
68
+ end
58
69
  end
59
70
 
60
71
  describe 'when data is StringIO' do
@@ -62,7 +73,7 @@ RSpec.describe DBF::Table do
62
73
  let(:memo) { StringIO.new File.read(memo_path) }
63
74
  let(:table) { DBF::Table.new data }
64
75
 
65
- let(:control_schema) { File.read(fixture('dbase_83_schema.txt')) }
76
+ let(:control_schema) { File.read(fixture('dbase_83_schema_ar.txt')) }
66
77
 
67
78
  it 'matches the test schema fixture' do
68
79
  table.name = 'dbase_83'
@@ -73,51 +84,13 @@ RSpec.describe DBF::Table do
73
84
 
74
85
  describe '#sequel_schema' do
75
86
  it 'should return a valid Sequel migration by default' do
76
- expect(table.sequel_schema).to eq <<-SCHEMA
77
- Sequel.migration do
78
- change do
79
- create_table(:dbase_83) do
80
- column :id, :integer
81
- column :catcount, :integer
82
- column :agrpcount, :integer
83
- column :pgrpcount, :integer
84
- column :order, :integer
85
- column :code, :varchar, :size => 50
86
- column :name, :varchar, :size => 100
87
- column :thumbnail, :varchar, :size => 254
88
- column :image, :varchar, :size => 254
89
- column :price, :float
90
- column :cost, :float
91
- column :desc, :text
92
- column :weight, :float
93
- column :taxable, :boolean
94
- column :active, :boolean
95
- end
96
- end
97
- end
98
- SCHEMA
87
+ control_schema = File.read(fixture('dbase_83_schema_sq.txt'))
88
+ expect(table.sequel_schema).to eq control_schema
99
89
  end
100
90
 
101
91
  it 'should return a limited Sequel migration when passed true' do
102
- expect(table.sequel_schema(true)).to eq <<-SCHEMA
103
- create_table(:dbase_83) do
104
- column :id, :integer
105
- column :catcount, :integer
106
- column :agrpcount, :integer
107
- column :pgrpcount, :integer
108
- column :order, :integer
109
- column :code, :varchar, :size => 50
110
- column :name, :varchar, :size => 100
111
- column :thumbnail, :varchar, :size => 254
112
- column :image, :varchar, :size => 254
113
- column :price, :float
114
- column :cost, :float
115
- column :desc, :text
116
- column :weight, :float
117
- column :taxable, :boolean
118
- column :active, :boolean
119
- end
120
- SCHEMA
92
+ control_schema = File.read(fixture('dbase_83_schema_sq_lim.txt'))
93
+ expect(table.sequel_schema).to eq control_schema
121
94
  end
122
95
 
123
96
  end
@@ -218,7 +191,7 @@ SCHEMA
218
191
  end
219
192
 
220
193
  it 'returns matching records when used with options' do
221
- expect(table.find(:all, 'WEIGHT' => 0.0)).to eq table.select {|r| r['weight'] == 0.0}
194
+ expect(table.find(:all, 'WEIGHT' => 0.0)).to eq table.select { |r| r['weight'] == 0.0 }
222
195
  end
223
196
 
224
197
  it 'should AND multiple search terms' do
@@ -313,17 +286,28 @@ SCHEMA
313
286
  it 'is an array of Columns' do
314
287
  expect(columns).to be_an(Array)
315
288
  expect(columns).to_not be_empty
316
- expect(columns.all? {|c| c.class == DBF::Column}).to be_truthy
289
+ expect(columns.all? { |c| c.class == DBF::Column }).to be_truthy
317
290
  end
318
291
  end
319
292
 
320
293
  describe '#column_names' do
321
294
  let(:column_names) do
322
- %w(ID CATCOUNT AGRPCOUNT PGRPCOUNT ORDER CODE NAME THUMBNAIL IMAGE PRICE COST DESC WEIGHT TAXABLE ACTIVE)
295
+ %w[ID CATCOUNT AGRPCOUNT PGRPCOUNT ORDER CODE NAME THUMBNAIL IMAGE PRICE COST DESC WEIGHT TAXABLE ACTIVE]
323
296
  end
324
297
 
325
- it 'is an array of all column names' do
326
- expect(table.column_names).to eq column_names
298
+ describe 'when data is an IO' do
299
+ it 'is an array of all column names' do
300
+ expect(table.column_names).to eq column_names
301
+ end
302
+ end
303
+
304
+ describe 'when data is a StringIO' do
305
+ let(:data) { StringIO.new File.read(dbf_path) }
306
+ let(:table) { DBF::Table.new data, nil, Encoding::US_ASCII }
307
+
308
+ it 'is an array of all column names' do
309
+ expect(table.column_names).to eq column_names
310
+ end
327
311
  end
328
312
  end
329
313
 
@@ -0,0 +1,21 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table(:dbase_83) do
4
+ column :id, :integer
5
+ column :catcount, :integer
6
+ column :agrpcount, :integer
7
+ column :pgrpcount, :integer
8
+ column :order, :integer
9
+ column :code, :varchar, :size => 50
10
+ column :name, :varchar, :size => 100
11
+ column :thumbnail, :varchar, :size => 254
12
+ column :image, :varchar, :size => 254
13
+ column :price, :float
14
+ column :cost, :float
15
+ column :desc, :text
16
+ column :weight, :float
17
+ column :taxable, :boolean
18
+ column :active, :boolean
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table(:dbase_83) do
4
+ column :id, :integer
5
+ column :catcount, :integer
6
+ column :agrpcount, :integer
7
+ column :pgrpcount, :integer
8
+ column :order, :integer
9
+ column :code, :varchar, :size => 50
10
+ column :name, :varchar, :size => 100
11
+ column :thumbnail, :varchar, :size => 254
12
+ column :image, :varchar, :size => 254
13
+ column :price, :float
14
+ column :cost, :float
15
+ column :desc, :text
16
+ column :weight, :float
17
+ column :taxable, :boolean
18
+ column :active, :boolean
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-26 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A small fast library for reading dBase, xBase, Clipper and FoxPro database
14
14
  files.
@@ -67,7 +67,9 @@ files:
67
67
  - spec/fixtures/dbase_83_missing_memo_record_0.yml
68
68
  - spec/fixtures/dbase_83_record_0.yml
69
69
  - spec/fixtures/dbase_83_record_9.yml
70
- - spec/fixtures/dbase_83_schema.txt
70
+ - spec/fixtures/dbase_83_schema_ar.txt
71
+ - spec/fixtures/dbase_83_schema_sq.txt
72
+ - spec/fixtures/dbase_83_schema_sq_lim.txt
71
73
  - spec/fixtures/dbase_83_summary.txt
72
74
  - spec/fixtures/dbase_8b.dbf
73
75
  - spec/fixtures/dbase_8b.dbt
@@ -110,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  version: 1.3.0
111
113
  requirements: []
112
114
  rubyforge_project:
113
- rubygems_version: 2.6.11
115
+ rubygems_version: 2.7.3
114
116
  signing_key:
115
117
  specification_version: 4
116
118
  summary: Read xBase files