Skip to content

Commit

Permalink
Merge branch 'add-id-to-download-csv' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Oct 25, 2023
2 parents b5769c1 + 3376acc commit 5b1f7c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# develop

## Highlighted Features

* Add internal ID number to authority CSV download (Alex Pearson, Graeme
Porteous)

# 0.44.0.0

## Highlighted Features
Expand Down
6 changes: 4 additions & 2 deletions lib/public_body_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
class PublicBodyCSV

def self.default_fields
[:name,
[:id,
:name,
:short_name,
:url_name,
:tag_string,
Expand All @@ -34,7 +35,8 @@ def self.default_fields

# TODO: Generate headers from fields
def self.default_headers
['Name',
['Internal ID',
'Name',
'Short name',
'URL name',
'Tags',
Expand Down
14 changes: 8 additions & 6 deletions spec/lib/public_body_csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
describe '.default_fields' do

it 'has a default set of fields' do
defaults = [:name,
defaults = [:id,
:name,
:short_name,
:url_name,
:tag_string,
Expand All @@ -23,7 +24,8 @@
describe '.default_headers' do

it 'has a default set of headers' do
defaults = ['Name',
defaults = ['Internal ID',
'Name',
'Short name',
'URL name',
'Tags',
Expand All @@ -39,13 +41,13 @@
end

describe '.export' do
it 'should return a valid CSV file with the right number of rows' do
it 'should return a valid CSV file with the right number of rows/columns' do
all_data = CSV.parse(PublicBodyCSV.export)
expect(all_data.length).to eq(7)
# Check that the header has the right number of columns:
expect(all_data[0].length).to eq(11)
expect(all_data[0].length).to eq(12)
# And an actual line of data:
expect(all_data[1].length).to eq(11)
expect(all_data[1].length).to eq(12)
end

it 'only includes visible bodies' do
Expand Down Expand Up @@ -125,7 +127,7 @@
csv = PublicBodyCSV.new
csv << body

expected = ["Exported to CSV,CSV,csv,exported,https://www.localhost,\"\",\"\",An exported authority,2007-10-25 10:51:01 UTC,2007-10-25 10:51:01 UTC,1"]
expected = ["#{body.id},Exported to CSV,CSV,csv,exported,https://www.localhost,\"\",\"\",An exported authority,2007-10-25 10:51:01 UTC,2007-10-25 10:51:01 UTC,1"]
expect(csv.rows).to eq(expected)
end

Expand Down

0 comments on commit 5b1f7c1

Please sign in to comment.