|
32 | 32 |
|
33 | 33 | describe '#write' do |
34 | 34 | it 'inserts a county row' do |
35 | | - table.write({ county: 'Cook', short_county: '031', short_state: 'IL', state: 'Illinois' }) |
| 35 | + table.write({ country: 'US', county: 'Cook', short_county: '031', short_state: 'IL', |
| 36 | + state: 'Illinois' }) |
36 | 37 | rows = db.execute('SELECT name, abbr FROM counties') |
37 | 38 | expect(rows.length).to eq(1) |
38 | 39 | expect(rows[0]).to eq(%w[Cook 031]) |
39 | 40 | end |
40 | 41 |
|
41 | 42 | it 'links the county to its state' do |
42 | | - table.write({ county: 'Cook', short_county: '031', short_state: 'IL', state: 'Illinois' }) |
| 43 | + table.write({ country: 'US', county: 'Cook', short_county: '031', short_state: 'IL', |
| 44 | + state: 'Illinois' }) |
43 | 45 | state_id = db.execute("SELECT id FROM states WHERE abbr = 'IL'")[0][0] |
44 | 46 | county_state_id = db.execute('SELECT state_id FROM counties')[0][0] |
45 | 47 | expect(county_state_id).to eq(state_id) |
46 | 48 | end |
47 | 49 |
|
48 | 50 | it 'returns nil and skips when county is nil' do |
49 | | - result = table.write({ county: nil, short_county: nil, short_state: 'IL', state: 'Illinois' }) |
| 51 | + result = table.write({ country: 'US', county: nil, short_county: nil, short_state: 'IL', |
| 52 | + state: 'Illinois' }) |
50 | 53 | expect(result).to be_nil |
51 | 54 | rows = db.execute('SELECT COUNT(*) FROM counties') |
52 | 55 | expect(rows[0][0]).to eq(0) |
53 | 56 | end |
54 | 57 |
|
55 | 58 | it 'returns nil when state cannot be found' do |
56 | | - result = table.write({ county: 'Unknown', short_county: '999', short_state: 'ZZ', |
| 59 | + result = table.write({ country: 'US', county: 'Unknown', short_county: '999', short_state: 'ZZ', |
57 | 60 | state: 'Nonexistent' }) |
58 | 61 | expect(result).to be_nil |
59 | 62 | rows = db.execute('SELECT COUNT(*) FROM counties') |
60 | 63 | expect(rows[0][0]).to eq(0) |
61 | 64 | end |
62 | 65 |
|
63 | 66 | it 'silently ignores duplicate county entries' do |
64 | | - table.write({ county: 'Cook', short_county: '031', short_state: 'IL', state: 'Illinois' }) |
| 67 | + table.write({ country: 'US', county: 'Cook', short_county: '031', short_state: 'IL', |
| 68 | + state: 'Illinois' }) |
65 | 69 | expect do |
66 | | - table.write({ county: 'Cook', short_county: '031', short_state: 'IL', state: 'Illinois' }) |
| 70 | + table.write({ country: 'US', county: 'Cook', short_county: '031', short_state: 'IL', |
| 71 | + state: 'Illinois' }) |
67 | 72 | end.not_to raise_error |
68 | 73 | rows = db.execute('SELECT COUNT(*) FROM counties') |
69 | 74 | expect(rows[0][0]).to eq(1) |
70 | 75 | end |
71 | 76 |
|
72 | 77 | it 'handles county names with single quotes' do |
73 | | - table.write({ county: "Prince George's", short_county: '033', short_state: 'NY', state: 'New York' }) |
| 78 | + table.write({ country: 'US', county: "Prince George's", short_county: '033', short_state: 'NY', |
| 79 | + state: 'New York' }) |
74 | 80 | rows = db.execute('SELECT name FROM counties') |
75 | 81 | expect(rows[0][0]).to eq("Prince George's") |
76 | 82 | end |
|
0 commit comments