Skip to content

Commit

Permalink
Merge pull request #2979 from bitzesty/staging
Browse files Browse the repository at this point in the history
Production deploy
  • Loading branch information
Lubosky authored Jun 24, 2024
2 parents 3e648ac + a77641f commit d35f6b5
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 20 deletions.
3 changes: 3 additions & 0 deletions app/models/form_answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class FormAnswer < ApplicationRecord

BUSINESS_AWARD_TYPES = %w[trade innovation development mobility]

AWARD_TYPES_WITH_NICKNAME_REQUIRED = %w[innovation mobility]

AWARD_TYPE_FULL_NAMES = {
"trade" => "International Trade",
"innovation" => "Innovation",
Expand Down Expand Up @@ -133,6 +135,7 @@ def secondary
inclusion: {
in: POSSIBLE_AWARDS,
}
validates :nickname, presence: true, if: -> { award_type.in?(AWARD_TYPES_WITH_NICKNAME_REQUIRED) }
validates :urn, uniqueness: { allow_blank: true } # rubocop:disable Rails/UniqueValidationWithoutIndex
validates :sic_code, format: { with: SicCode::REGEX }, allow_blank: true
validate :validate_answers
Expand Down
15 changes: 9 additions & 6 deletions app/views/content_only/_award_nickname.html.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- is_nickname_required = award_type.in?(FormAnswer::AWARD_TYPES_WITH_NICKNAME_REQUIRED)
- is_promotion = award_type == "promotion"

.page-pre-eligibility
h2.govuk-heading-l The Process

Expand All @@ -7,7 +10,7 @@
ul.govuk-list.govuk-list--bullet
li
' This is to ensure that your
- if award_type == "promotion"
- if is_promotion
' nominee
- else
' organisation
Expand All @@ -25,7 +28,7 @@
li
p.govuk-body
' Submit your
- if award_type == "promotion"
- if is_promotion
' nomination
- else
' application
Expand All @@ -36,15 +39,15 @@
' .
li
' You can still edit submitted
- if award_type == "promotion"
- if is_promotion
' nominations
- else
' applications
' up to this date.

- if award_type == "innovation"
= render "content_only/award_nickname_block"
- if is_nickname_required
= render partial: "content_only/award_nickname_block", locals: { award_type: award_type }

p#get-started.get-started.group.govuk-body
- title = award_type == "innovation" ? "Save and start eligibility questionnaire" : "Start eligibility questionnaire"
- title = is_nickname_required ? "Save and start eligibility questionnaire" : "Start eligibility questionnaire"
= submit_tag title, class: "govuk-button", rel: "external"
18 changes: 12 additions & 6 deletions app/views/content_only/_award_nickname_block.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ br

.govuk-form-group
h2.govuk-label-wrapper
= label_tag :nickname, "Please choose a reference for this application (optional):", class: 'govuk-label govuk-label--l', for: 'award-nickname'
= label_tag :nickname, "Please choose a reference for this application:", class: 'govuk-label govuk-label--l', for: 'award-nickname'

p.govuk-hint
| If you have more than one innovation (and want them to be considered for an award), you will have to submit a separate application for each of them.
p.govuk-hint
| You can create a reference, for example, 'Fibre optic device' so that it helps you and your collaborators to distinguish between different innovation applications. It will appear on the Applications page. Once chosen, your reference is permanent.
- if local_assigns[:award_type] == "innovation"
p.govuk-hint
| If you have more than one innovation (and want them to be considered for an award), you will have to submit a separate application for each of them.
p.govuk-hint
| Please create a reference. This will help you and your collaborators distinguish between different applications. Your reference will appear on the Applications page. Once chosen, it is permanent.
- elsif local_assigns[:award_type] == "mobility"
p.govuk-hint
| If you are applying for more than one Promoting Opportunity Award (through social mobility), you will have to submit a separate application for each.
p.govuk-hint
| You can create a reference, for example, 'Fibre optic device' so that it helps you and your collaborators to distinguish between different innovation applications. It will appear on the Applications page. Once chosen, your reference is permanent.

= text_field_tag :nickname, "", autocomplete: "off", type: "text", class: "govuk-input govuk-!-width-two-thirds", id: 'award-nickname'
= text_field_tag :nickname, "", autocomplete: "off", required: true, aria: { required: true }, type: "text", class: "govuk-input govuk-!-width-two-thirds", id: 'award-nickname'
7 changes: 3 additions & 4 deletions app/views/content_only/apply_social_mobility_award.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
h1.govuk-heading-xl Promoting Opportunity Award (through social mobility) Application

.article-related-positioning-container
.article-container
article.group role="article"
= form_tag new_social_mobility_form_path, method: :get do
= render "award_nickname", award_type: "mobility"
article.group role="article"
= form_tag new_social_mobility_form_path, method: :get do
= render "award_nickname", award_type: "mobility"
23 changes: 23 additions & 0 deletions lib/tasks/form_answers.rake
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,27 @@ namespace :form_answers do

Rails.logger.info "\e[32mCompleted!\e[0m"
end

desc "Populate `nickname` field for Innovation and Promoting Opportunity applications"
task populate_nickname: :environment do
scope = FormAnswer.where(nickname: nil).where(award_type: FormAnswer::AWARD_TYPES_WITH_NICKNAME_REQUIRED)
count = scope.count

idx = 0

print "\e[32mPopulating nickname for #{count} records…\e[0m"

scope.find_in_batches(batch_size: 500) do |collection|
idx += collection.size
ids = collection.map(&:id).join(",").to_s

query = %{
UPDATE form_answers
SET nickname = CASE WHEN award_type = 'mobility' THEN 'Promoting Opportunity' ELSE 'Innovation' END
WHERE form_answers.id IN (#{ids})
}.squish

ActiveRecord::Base.connection.execute(query)
end
end
end
1 change: 1 addition & 0 deletions spec/acceptance/steps/application_form_creation_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
step "I create innovation form" do
step "I go to dashboard"
click_link "New application", href: "/apply_innovation_award"
fill_in "nickname", with: "Innovation"
click_button "Save and start eligibility questionnaire"
click_link "Continue to eligibility questions"
click_button "Continue" # eligibility step
Expand Down
20 changes: 17 additions & 3 deletions spec/controllers/form_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@

describe "#new_social_mobility_form" do
it "allows to open mobility form" do
expect(get(:new_social_mobility_form)).to redirect_to(edit_form_url(FormAnswer.where(award_type: "mobility").last))
expect(get(:new_social_mobility_form, params: { nickname: "Promoting Opportunity" })).to redirect_to(edit_form_url(FormAnswer.where(award_type: "mobility").last))
end

it "does not allow to create an application without nickname/reference field filled" do
expect { get(:new_social_mobility_form, params: { nickname: "" }) }.to raise_error(ActiveRecord::RecordInvalid)
end
end

describe "#new_innovation_form" do
it "allows to open innovation form" do
expect(get(:new_innovation_form, params: { nickname: "Innovation" })).to redirect_to(edit_form_url(FormAnswer.where(award_type: "innovation").last))
end

it "does not allow to create an application without nickname/reference field filled" do
expect { get(:new_innovation_form, params: { nickname: "" }) }.to raise_error(ActiveRecord::RecordInvalid)
end
end

Expand All @@ -69,7 +83,7 @@

describe "#new_social_mobility_form" do
it "allows to create an application if mobility deadline has past" do
expect(get(:new_social_mobility_form)).to redirect_to(edit_form_url(FormAnswer.where(award_type: "mobility").last))
expect(get(:new_social_mobility_form, params: { nickname: "Promoting Opportunity" })).to redirect_to(edit_form_url(FormAnswer.where(award_type: "mobility").last))
end

it "does not allow to create an application if mobility start deadline has not past" do
Expand All @@ -91,7 +105,7 @@

describe "#new_innovation_form" do
it "allows to create an application if innovation start deadline has past" do
expect(get(:new_innovation_form)).to redirect_to(edit_form_url(FormAnswer.where(award_type: "innovation").last))
expect(get(:new_innovation_form, params: { nickname: "Innovation" })).to redirect_to(edit_form_url(FormAnswer.where(award_type: "innovation").last))
end

it "does not allow to create an application if innovation start deadline has not past" do
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/form_answer_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

trait :innovation do
award_type { "innovation" }
nickname { "Innovation" }
document do
FormAnswer::DocumentParser.parse_json_document(
JSON.parse(
Expand All @@ -73,6 +74,7 @@

trait :mobility do
award_type { "mobility" }
nickname { "Promoting Opportunity" }
document do
FormAnswer::DocumentParser.parse_json_document(
JSON.parse(
Expand Down
2 changes: 1 addition & 1 deletion spec/features/users/eligibility_form_fulfillment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
it "process the eligibility form" do
visit dashboard_path
new_application("Innovation Award")
# fill_in("nickname", with: "innovation nick")
fill_in("nickname", with: "innovation nick")
click_button("Save and start eligibility questionnaire")
click_link("Continue to eligibility questions")
form_choice(["Yes", "Yes", /Business/, /Product/, "Yes", "No", "Yes", "Yes", "Yes", "Yes"])
Expand Down

0 comments on commit d35f6b5

Please sign in to comment.