Skip to content

Commit

Permalink
Store locale on DIY Intake and use in generated link
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Golder <bgolder@codeforamerica.org>
  • Loading branch information
kayline and bengolder committed Jun 10, 2020
1 parent f767456 commit c7ddc49
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/controllers/diy/personal_info_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/questions/already_filed_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/forms/diy_personal_info_form.rb
Original file line number Diff line number Diff line change
@@ -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") }
Expand Down
3 changes: 2 additions & 1 deletion app/models/diy_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# id :bigint not null, primary key
# email_address :string
# locale :string
# preferred_name :string
# referrer :string
# source :string
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200610212912_add_locale_to_diy_intakes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLocaleToDiyIntakes < ActiveRecord::Migration[6.0]
def change
add_column :diy_intakes, :locale, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions spec/controllers/diy/personal_info_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/factories/diy_intakes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# id :bigint not null, primary key
# email_address :string
# locale :string
# preferred_name :string
# referrer :string
# source :string
Expand Down
1 change: 1 addition & 0 deletions spec/models/diy_intake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# id :bigint not null, primary key
# email_address :string
# locale :string
# preferred_name :string
# referrer :string
# source :string
Expand Down
2 changes: 1 addition & 1 deletion spec/services/zendesk_diy_intake_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c7ddc49

Please sign in to comment.