From c7ddc492f3dbdb429d5e3d76aceb4655e14d7d50 Mon Sep 17 00:00:00 2001 From: Molly T-M Date: Wed, 10 Jun 2020 14:52:31 -0700 Subject: [PATCH] Store locale on DIY Intake and use in generated link Co-authored-by: Ben Golder --- .../diy/personal_info_controller.rb | 1 + .../questions/already_filed_controller.rb | 2 +- app/forms/diy_personal_info_form.rb | 2 +- app/models/diy_intake.rb | 3 ++- ...0200610212912_add_locale_to_diy_intakes.rb | 5 +++++ db/schema.rb | 3 ++- .../diy/personal_info_controller_spec.rb | 22 +++++++++++++++++++ spec/factories/diy_intakes.rb | 1 + spec/models/diy_intake_spec.rb | 1 + .../zendesk_diy_intake_service_spec.rb | 2 +- 10 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20200610212912_add_locale_to_diy_intakes.rb diff --git a/app/controllers/diy/personal_info_controller.rb b/app/controllers/diy/personal_info_controller.rb index c4ba2b63fa..448debda78 100644 --- a/app/controllers/diy/personal_info_controller.rb +++ b/app/controllers/diy/personal_info_controller.rb @@ -22,6 +22,7 @@ def form_params super.merge( source: current_diy_intake.source || source, referrer: current_diy_intake.referrer || referrer, + locale: I18n.locale, ) end end diff --git a/app/controllers/questions/already_filed_controller.rb b/app/controllers/questions/already_filed_controller.rb index 9df1699e08..80c74c1285 100644 --- a/app/controllers/questions/already_filed_controller.rb +++ b/app/controllers/questions/already_filed_controller.rb @@ -17,7 +17,7 @@ def form_params super.merge( source: current_intake.source || source, referrer: current_intake.referrer || referrer, - locale: current_intake.locale || I18n.locale, + locale: I18n.locale, ) end diff --git a/app/forms/diy_personal_info_form.rb b/app/forms/diy_personal_info_form.rb index 2167a917ae..5c619725d2 100644 --- a/app/forms/diy_personal_info_form.rb +++ b/app/forms/diy_personal_info_form.rb @@ -1,5 +1,5 @@ class DiyPersonalInfoForm < DiyForm - set_attributes_for :diy_intake, :state_of_residence, :preferred_name, :source, :referrer + set_attributes_for :diy_intake, :state_of_residence, :preferred_name, :source, :referrer, :locale validates :state_of_residence, inclusion: { in: States.keys, message: I18n.t("forms.validators.state_of_residence_inclusion") } validates :preferred_name, presence: { message: I18n.t("forms.validators.preferred_name_presence") } diff --git a/app/models/diy_intake.rb b/app/models/diy_intake.rb index 414c92716e..8ce0127e55 100644 --- a/app/models/diy_intake.rb +++ b/app/models/diy_intake.rb @@ -4,6 +4,7 @@ # # id :bigint not null, primary key # email_address :string +# locale :string # preferred_name :string # referrer :string # source :string @@ -42,7 +43,7 @@ def issue_token end def start_filing_url - Rails.application.routes.url_helpers.diy_start_filing_url(:token => token) + Rails.application.routes.url_helpers.diy_start_filing_url(token: token, locale: locale) end def duplicate_diy_intakes diff --git a/db/migrate/20200610212912_add_locale_to_diy_intakes.rb b/db/migrate/20200610212912_add_locale_to_diy_intakes.rb new file mode 100644 index 0000000000..f610d4a8fe --- /dev/null +++ b/db/migrate/20200610212912_add_locale_to_diy_intakes.rb @@ -0,0 +1,5 @@ +class AddLocaleToDiyIntakes < ActiveRecord::Migration[6.0] + def change + add_column :diy_intakes, :locale, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 9fe646e14a..94f7c73f1c 100644 --- a/db/schema.rb +++ b/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: 2020_06_10_203523) do +ActiveRecord::Schema.define(version: 2020_06_10_212912) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -72,6 +72,7 @@ create_table "diy_intakes", force: :cascade do |t| t.datetime "created_at", precision: 6, null: false t.string "email_address" + t.string "locale" t.string "preferred_name" t.string "referrer" t.bigint "requester_id" diff --git a/spec/controllers/diy/personal_info_controller_spec.rb b/spec/controllers/diy/personal_info_controller_spec.rb index 44821c3f76..c74d48cfb7 100644 --- a/spec/controllers/diy/personal_info_controller_spec.rb +++ b/spec/controllers/diy/personal_info_controller_spec.rb @@ -28,8 +28,30 @@ expect(diy_intake.state_of_residence).to eq "CO" expect(diy_intake.preferred_name).to eq "Shep" expect(diy_intake.source).to eq "source_from_session" + expect(diy_intake.locale).to eq "en" expect(diy_intake.referrer).to eq "referrer_from_session" end end + + context "with different locale" do + let(:params) do + { + diy_personal_info_form: { + state_of_residence: "CO", + preferred_name: "Shep" + }, + locale: "es" + } + end + + it "saves the locale on the intake" do + expect { + post :update, params: params + }.to change(DiyIntake, :count).by(1) + + diy_intake = DiyIntake.last + expect(diy_intake.locale).to eq "es" + end + end end end diff --git a/spec/factories/diy_intakes.rb b/spec/factories/diy_intakes.rb index 26fd28483d..a0363ac36b 100644 --- a/spec/factories/diy_intakes.rb +++ b/spec/factories/diy_intakes.rb @@ -4,6 +4,7 @@ # # id :bigint not null, primary key # email_address :string +# locale :string # preferred_name :string # referrer :string # source :string diff --git a/spec/models/diy_intake_spec.rb b/spec/models/diy_intake_spec.rb index 83cfffbb21..59b2eda82e 100644 --- a/spec/models/diy_intake_spec.rb +++ b/spec/models/diy_intake_spec.rb @@ -4,6 +4,7 @@ # # id :bigint not null, primary key # email_address :string +# locale :string # preferred_name :string # referrer :string # source :string diff --git a/spec/services/zendesk_diy_intake_service_spec.rb b/spec/services/zendesk_diy_intake_service_spec.rb index f3dbec5372..65e0fb9838 100644 --- a/spec/services/zendesk_diy_intake_service_spec.rb +++ b/spec/services/zendesk_diy_intake_service_spec.rb @@ -13,6 +13,7 @@ email_address: email_address, preferred_name: preferred_name, state_of_residence: state_of_residence, + locale: :en ) end let(:service) { described_class.new(diy_intake) } @@ -55,7 +56,6 @@ before do diy_intake.requester_id = requester_id - I18n.locale = :en end it "calls create_ticket with the right arguments and saves the ticket_id" do