Skip to content

Commit

Permalink
Reduce offence seed data for cucumber tests
Browse files Browse the repository at this point in the history
When the cucumber test suite starts, a large volume of production seed
data is loaded into the database. This includes a full list of offences
for nine fee schemes, however only ten of those offences are used in
tests.

In an attempt to speed up the running of the test suite, this amends
`db/seeds/scheme_11.rb` to load a bespoke test-only version of the
offence data for AGFS fee scheme 11, containing only those ten offences.
This set of data is copied for subsequent AGFS fee schemes so the total
number of records being created is reduced from ~6,500 to 50.

* We could consider doing something similar for other seed data.
* We could consider not seeding the database at all and use factories to
generate required data instead.
  • Loading branch information
mpw5 committed Dec 22, 2023
1 parent 738d49f commit e275ce9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion db/seeds/scheme_11.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
ActiveRecord::Base.connection.set_pk_sequence!('offences', 3000) if Offence.order(:id).last.id < 3000

# create new offences (from csv)
file_path = Rails.root.join('lib', 'assets', 'data', 'scheme_11_offences.csv')
file_name = ENV.fetch('RAILS_ENV', 'development') == 'test' ? 'scheme_11_offences_for_testing.csv' : 'scheme_11_offences.csv'
file_path = Rails.root.join('lib', 'assets', 'data', file_name)
csv_file = File.open(file_path, 'r:ISO-8859-1')
csv = CSV.parse(csv_file, headers: true)

Expand Down
10 changes: 10 additions & 0 deletions lib/assets/data/scheme_11_offences_for_testing.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
category,band,description,contrary_to,year_chapter
3,3.4,Possession of offensive weapon on school premises,"Criminal Justice Act 1988, s.139A",1996 c. 26
3,3.5,Racially or religiously aggravated common assault,"Crime and Disorder Act 1998, s.29(1)(c ) and (3)",1998 c. 37
5,5.3,Solicitation by men,"Sexual Offences Act 1956, s.32",1956 c. 69
8,8.1,Harbouring escaped prisoner,"Criminal Justice Act 1961, s.22(2)",1961 c. 39
8,8.1,Have in possession or control identity documents with improper intent,"Identity Documents Act 2010, s.4",2010 c. 40
11,11.2,Burglary (domestic),"Theft Act 1968, s.9(3)(a)",1968 c. 60
11,11.2,Burglary (non-domestic),"Theft Act 1968, s.9(3)(b)",1968 c. 60
16,16.3,Unlicensed or unauthorised air traffic controllers,Air Navigation Order 2016,2016 No. 765
17,17.1,Absconding from lawful custody,Common Law,

0 comments on commit e275ce9

Please sign in to comment.