Browse Source

Change national and ethnic field types and map to correct enums

pull/79/head
Kat 4 years ago
parent
commit
496a7c6d5a
  1. 27
      app/constants/ethnic.rb
  2. 24
      app/constants/national.rb
  3. 2
      app/controllers/case_logs_controller.rb
  4. 5
      app/models/case_log.rb
  5. 4
      app/views/layouts/application.html.erb
  6. 36
      config/forms/2021_2022.json
  7. 1
      db/migrate/20211101192151_rename_fields.rb
  8. 15
      db/migrate/20211103090530_change_field_types.rb
  9. 6
      db/schema.rb
  10. 2
      spec/features/case_log_spec.rb

27
app/constants/ethnic.rb

@ -0,0 +1,27 @@
module Ethnic
@@ethnic = {
"White: English/Scottish/Welsh/Northern Irish/British" => 1,
"White: Irish" => 2,
"White: Gypsy/Irish Traveller" => 18,
"White: Other" => 3,
"Mixed: White & Black Caribbean" => 4,
"Mixed: White & Black African" => 5,
"Mixed: White & Asian" => 6,
"Mixed: Other" => 7,
"Asian or Asian British: Indian" => 8,
"Asian or Asian British: Pakistani" => 9,
"Asian or Asian British: Bangladeshi" => 10,
"Asian or Asian British: Chinese" => 15,
"Asian or Asian British: Other" => 11,
"Black: Caribbean" => 12,
"Black: African" => 13,
"Black: Other" => 14,
"Other Ethnic Group: Arab" => 16,
"Other Ethnic Group: Other" => 19,
"Prefer not to say" => 17,
}
def self.ethnic
@@ethnic
end
end

24
app/constants/national.rb

@ -0,0 +1,24 @@
module National
@@national = {
"UK national resident in UK" => 1,
"A current or former reserve in the UK Armed Forces (exc. National Service)" => 100,
"UK national returning from residence overseas" => 2,
"Czech Republic" => 3,
"Estonia" => 4,
"Hungary" => 5,
"Latvia" => 6,
"Lithuania" => 7,
"Poland" => 8,
"Slovakia" => 9,
"Bulgaria" => 14,
"Romania" => 15,
"Ireland" => 17,
"Other EU Economic Area (EEA country)" => 11,
"Any other country" => 12,
"Prefer not to say" => 13,
}
def self.national
@@national
end
end

2
app/controllers/case_logs_controller.rb

@ -121,7 +121,7 @@ private
end
def authenticate
http_basic_authenticate_or_request_with name: ENV["API_USER"], password: ENV["API_KEY"]
http_basic_authenticate_or_request_with ethnic: ENV["API_USER"], password: ENV["API_KEY"]
end
def api_case_log_params

5
app/models/case_log.rb

@ -37,6 +37,8 @@ end
class CaseLog < ApplicationRecord
include Discard::Model
include SoftValidations
include Ethnic
include National
default_scope -> { kept }
scope :not_completed, -> { where.not(status: "completed") }
@ -47,6 +49,9 @@ class CaseLog < ApplicationRecord
enum status: { "not_started" => 0, "in_progress" => 1, "completed" => 2 }
enum ethnic: Ethnic.ethnic
enum national: National.national, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
def self.editable_fields

4
app/views/layouts/application.html.erb

@ -4,9 +4,9 @@
<title>DLUHC CORE Data Collection</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= tag :meta, name: 'viewport', content: 'width=device-width, initial-scale=1' %>
<%= tag :meta, ethnic: 'viewport', content: 'width=device-width, initial-scale=1' %>
<%= tag :meta, property: 'og:image', content: asset_pack_path('media/images/govuk-opengraph-image.png') %>
<%= tag :meta, name: 'theme-color', content: '#0b0c0c' %>
<%= tag :meta, ethnic: 'theme-color', content: '#0b0c0c' %>
<%= favicon_link_tag asset_pack_path('media/images/favicon.ico') %>
<%= favicon_link_tag asset_pack_path('media/images/govuk-mask-icon.svg'), rel: 'mask-icon', type: 'image/svg', color: "#0b0c0c" %>
<%= favicon_link_tag asset_pack_path('media/images/govuk-apple-touch-icon.png'), rel: 'apple-touch-icon', type: 'image/png' %>

36
config/forms/2021_2022.json

@ -64,9 +64,9 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "White: English/Scottish/Welsh/Northern Irish/British",
"1": "White: Irish",
"2": "White: Gypsy/Irish Traveller",
"1": "White: English/Scottish/Welsh/Northern Irish/British",
"2": "White: Irish",
"18": "White: Gypsy/Irish Traveller",
"3": "White: Other",
"4": "Mixed: White & Black Caribbean",
"5": "Mixed: White & Black African",
@ -75,14 +75,14 @@
"8": "Asian or Asian British: Indian",
"9": "Asian or Asian British: Pakistani",
"10": "Asian or Asian British: Bangladeshi",
"11": "Asian or Asian British: Chinese",
"12": "Asian or Asian British: Other",
"13": "Black: Caribbean",
"14": "Black: African",
"15": "Black: Other",
"15": "Asian or Asian British: Chinese",
"11": "Asian or Asian British: Other",
"12": "Black: Caribbean",
"13": "Black: African",
"14": "Black: Other",
"16": "Other Ethnic Group: Arab",
"17": "Other Ethnic Group: Other",
"18": "Prefer not to say"
"19": "Other Ethnic Group: Other",
"17": "Prefer not to say"
}
}
}
@ -97,8 +97,8 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "UK national resident in UK",
"1": "A current or former reserve in the UK Armed Forces (exc. National Service)",
"1": "UK national resident in UK",
"100": "A current or former reserve in the UK Armed Forces (exc. National Service)",
"2": "UK national returning from residence overseas",
"3": "Czech Republic",
"4": "Estonia",
@ -107,12 +107,12 @@
"7": "Lithuania",
"8": "Poland",
"9": "Slovakia",
"10": "Bulgaria",
"11": "Romania",
"12": "Ireland",
"13": "Other EU Economic Area (EEA country)",
"14": "Any other country",
"15": "Prefer not to say"
"14": "Bulgaria",
"15": "Romania",
"17": "Ireland",
"11": "Other EU Economic Area (EEA country)",
"12": "Any other country",
"13": "Prefer not to say"
}
}
}

1
db/migrate/20211101192151_rename_fields.rb

@ -102,6 +102,5 @@ class RenameFields < ActiveRecord::Migration[6.1]
rename_column :case_logs, :cbl_letting, :cbl
rename_column :case_logs, :chr_letting, :chr
rename_column :case_logs, :cap_letting, :cap
end
end

15
db/migrate/20211103090530_change_field_types.rb

@ -0,0 +1,15 @@
class ChangeFieldTypes < ActiveRecord::Migration[6.1]
def up
change_table :case_logs, bulk: true do |t|
t.change :ethnic, "integer USING ethnic::integer"
t.change :national, "integer USING national::integer"
end
end
def down
change_table :case_logs, bulk: true do |t|
t.change :ethnic, :string
t.change :national, :string
end
end
end

6
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_11_01_192151) do
ActiveRecord::Schema.define(version: 2021_11_03_090530) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -22,7 +22,7 @@ ActiveRecord::Schema.define(version: 2021_11_01_192151) do
t.string "tenant_code"
t.integer "age1"
t.string "sex1"
t.string "ethnic"
t.integer "ethnic"
t.string "national"
t.string "prevten"
t.string "armed_forces"
@ -135,7 +135,7 @@ ActiveRecord::Schema.define(version: 2021_11_01_192151) do
t.boolean "override_net_income_validation"
t.string "tenancyother"
t.string "net_income_known"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
t.index ["discarded_at"], ethnic: "index_case_logs_on_discarded_at"
end
end

2
spec/features/case_log_spec.rb

@ -223,7 +223,7 @@ RSpec.describe "Test Features" do
describe "Form flow is correct" do
context "given an ordered list of pages" do
it "leads to the next one in the correct order" do
pages = question_answers.map {|_key, val| val[:path]}
pages = question_answers.map { |_key, val| val[:path] }
pages[0..-2].each_with_index do |val, index|
visit("/case_logs/#{id}/#{val}")
click_button("Save and continue")

Loading…
Cancel
Save