Skip to content
Permalink
Browse files

Allow legislation to be specified when bulk uploading

This change means that an additional, optional 3rd column is permitted
in the bulk upload CSV 'legislation'. If the value in this field
exactly matches the `name` of an existing Legislation the uploaded
statement will be associated with that legislation.
  • Loading branch information...
chrislo committed Jun 25, 2018
1 parent 5d3abe0 commit 638d1b02c6c2398bb4487abe7428766c533eaa40
Showing with 23 additions and 4 deletions.
  1. +2 −2 app/controllers/admin/bulk_uploads_controller.rb
  2. +4 −2 app/models/statement.rb
  3. +17 −0 features/bulk_upload.feature
@@ -22,9 +22,9 @@ def alert_csv
end

def bulk_create(statement_params_array)
statement_params_array.each do |statement_params|
statement_params_array.each do |params|
begin
Statement.bulk_create!(statement_params['company_name'], statement_params['statement_url'])
Statement.bulk_create!(params['company_name'], params['statement_url'], params['legislation'])
rescue StandardError => e
logger.error(e)
end
@@ -40,12 +40,14 @@ def self.url_exists?(url)
exists?(url: uri.to_s)
end

def self.bulk_create!(company_name, statement_url)
def self.bulk_create!(company_name, statement_url, legislation_name)
return if Statement.url_exists?(statement_url)

begin
company = Company.find_or_create_by!(name: company_name)
company.statements.create!(url: statement_url)
legislation = Legislation.find_by(name: legislation_name)
statement = company.statements.create!(url: statement_url)
statement.legislations << legislation
rescue ActiveRecord::RecordInvalid => e
e.message += "\nCompany Name: '#{company_name}', Statement URL: '#{statement_url}'"
raise e
@@ -14,6 +14,23 @@ Feature: Bulk upload
| Approved by board | Unspecified |
| Link on front page | No |

Scenario: Administrator bulk uploads statements with legislation
Given the following legislations exist:
| Name | Include in compliance stats? |
| UK Modern Slavery Act | Yes |
| California Transparency in Supply Chains Act | No |
Given Patricia is logged in
When Patricia uploads a CSV with the following statements:
| company_name | statement_url | legislation |
| Cucumber Ltd | https://cucumber.io/anti-slavery-statement | UK Modern Slavery Act |
| BigCorp | https://bigcorp.com/anti-slavery-statement | California Transparency in Supply Chains Act |
Then Patricia should see 1 statement for "Cucumber Ltd" with:
| Statement URL | https://cucumber.io/anti-slavery-statement |
| Signed by director | No |
| Approved by board | Unspecified |
| Link on front page | No |
| Legislations | UK Modern Slavery Act |

Scenario: Administrator bulk uploads statements with some invalid URLs
Given Patricia is logged in
When Patricia uploads a CSV with the following statements:

0 comments on commit 638d1b0

Please sign in to comment.
You can’t perform that action at this time.