Browse Source

refactor deactivation_date_type to use default and other as options instead of 1 and 2

pull/981/head
Kat 4 years ago
parent
commit
74737ad118
  1. 5
      app/controllers/locations_controller.rb
  2. 4
      app/views/locations/toggle_active.html.erb
  3. 12
      spec/requests/locations_controller_spec.rb

5
app/controllers/locations_controller.rb

@ -164,11 +164,10 @@ private
def deactivation_date def deactivation_date
return if params[:location].blank? return if params[:location].blank?
return @location.errors.add(:deactivation_date_type, message: I18n.t("validations.location.deactivation_date.not_selected")) if params[:location][:deactivation_date].blank? && params[:location][:deactivation_date_type].blank?
collection_start_date = FormHandler.instance.current_collection_start_date collection_start_date = FormHandler.instance.current_collection_start_date
return collection_start_date if params[:location][:deactivation_date_type] == "default"
return collection_start_date if params[:location][:deactivation_date_type].to_i == 1 return @location.errors.add(:deactivation_date_type, message: I18n.t("validations.location.deactivation_date.not_selected")) if params[:location][:deactivation_date].blank? && params[:location][:deactivation_date_type].blank?
return params[:location][:deactivation_date] if params[:location][:deactivation_date_type].blank? return params[:location][:deactivation_date] if params[:location][:deactivation_date_type].blank?
day = params[:location]["deactivation_date(3i)"] day = params[:location]["deactivation_date(3i)"]

4
app/views/locations/toggle_active.html.erb

@ -19,11 +19,11 @@
hint: { text: I18n.t("hints.location.deactivation", date: collection_start_date.to_formatted_s(:govuk_date)) } do %> hint: { text: I18n.t("hints.location.deactivation", date: collection_start_date.to_formatted_s(:govuk_date)) } do %>
<%= govuk_warning_text text: I18n.t("warnings.location.deactivation.existing_logs") %> <%= govuk_warning_text text: I18n.t("warnings.location.deactivation.existing_logs") %>
<%= f.govuk_radio_button :deactivation_date_type, <%= f.govuk_radio_button :deactivation_date_type,
1, "default",
label: { text: "From the start of the current collection period (#{collection_start_date.to_formatted_s(:govuk_date)})" } %> label: { text: "From the start of the current collection period (#{collection_start_date.to_formatted_s(:govuk_date)})" } %>
<%= f.govuk_radio_button :deactivation_date_type, <%= f.govuk_radio_button :deactivation_date_type,
2, "other",
label: { text: "For tenancies starting after a certain date" }, label: { text: "For tenancies starting after a certain date" },
**basic_conditional_html_attributes({ "deactivation_date" => %w[other] }, "location") do %> **basic_conditional_html_attributes({ "deactivation_date" => %w[other] }, "location") do %>
<%= f.govuk_date_field :deactivation_date, <%= f.govuk_date_field :deactivation_date,

12
spec/requests/locations_controller_spec.rb

@ -1249,7 +1249,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "with default date" do context "with default date" do
let(:params) { { location: { deactivation_date_type: 1 } } } let(:params) { { location: { deactivation_date_type: "default" } } }
it "renders the confirmation page" do it "renders the confirmation page" do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
@ -1288,7 +1288,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when invalid date is entered" do context "when invalid date is entered" do
let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "10", "deactivation_date(2i)": "44", "deactivation_date(1i)": "2022" } } } let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "44", "deactivation_date(1i)": "2022" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -1297,7 +1297,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when the date is entered is before the beginning of current collection window" do context "when the date is entered is before the beginning of current collection window" do
let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } } let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -1306,7 +1306,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when the day is not entered" do context "when the day is not entered" do
let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "", "deactivation_date(2i)": "2", "deactivation_date(1i)": "2022" } } } let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "", "deactivation_date(2i)": "2", "deactivation_date(1i)": "2022" } } }
it "displays page with an error message" do it "displays page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -1315,7 +1315,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when the month is not entered" do context "when the month is not entered" do
let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "2", "deactivation_date(2i)": "", "deactivation_date(1i)": "2022" } } } let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "", "deactivation_date(1i)": "2022" } } }
it "displays page with an error message" do it "displays page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -1324,7 +1324,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when the year is not entered" do context "when the year is not entered" do
let(:params) { { location: { deactivation_date_type: 2, "deactivation_date(3i)": "2", "deactivation_date(2i)": "2", "deactivation_date(1i)": "" } } } let(:params) { { location: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "2", "deactivation_date(1i)": "" } } }
it "displays page with an error message" do it "displays page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)

Loading…
Cancel
Save