Browse Source

test: fix failing tests

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
83eebb501c
  1. 2
      app/controllers/locations_controller.rb
  2. 4
      spec/features/schemes_helpers.rb
  3. 20
      spec/requests/locations_controller_spec.rb

2
app/controllers/locations_controller.rb

@ -123,6 +123,8 @@ class LocationsController < ApplicationController
year = location_params["startdate(1i)"] year = location_params["startdate(1i)"]
if [day, month, year].none?(&:blank?) && Date.valid_date?(year.to_i, month.to_i, day.to_i) if [day, month, year].none?(&:blank?) && Date.valid_date?(year.to_i, month.to_i, day.to_i)
@location.startdate = Time.zone.local(year.to_i, month.to_i, day.to_i) @location.startdate = Time.zone.local(year.to_i, month.to_i, day.to_i)
else
@location.startdate = nil
end end
if @location.save(context: :startdate) if @location.save(context: :startdate)
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])

4
spec/features/schemes_helpers.rb

@ -69,7 +69,7 @@ module SchemesHelpers
choose "location-mobility-type-none-field" choose "location-mobility-type-none-field"
click_button "Save and continue" click_button "Save and continue"
fill_in "Day", with: 2 fill_in "Day", with: 2
fill_in "Month", with: 2 fill_in "Month", with: 5
fill_in "Year", with: 2022 fill_in "Year", with: 2022
click_button "Save and continue" click_button "Save and continue"
end end
@ -89,7 +89,7 @@ module SchemesHelpers
choose "location-mobility-type-none-field" choose "location-mobility-type-none-field"
click_button "Save and continue" click_button "Save and continue"
fill_in "Day", with: 2 fill_in "Day", with: 2
fill_in "Month", with: 2 fill_in "Month", with: 5
fill_in "Year", with: 2022 fill_in "Year", with: 2022
click_button "Save and continue" click_button "Save and continue"
end end

20
spec/requests/locations_controller_spec.rb

@ -1089,14 +1089,14 @@ RSpec.describe LocationsController, type: :request do
end end
context "when startdate is submitted" do context "when startdate is submitted" do
let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "1", "startdate(3i)": "2" } } } let(:params) { { location: { "startdate(1i)": "2022", "startdate(2i)": "1", "startdate(3i)": "2" } } }
before do before do
patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params:
end end
it "adds startdate to location" do it "adds startdate to location" do
expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) expect(Location.last.startdate).to eq(Time.zone.local(2022, 1, 2))
end end
it "redirects correctly" do it "redirects correctly" do
@ -1106,14 +1106,14 @@ RSpec.describe LocationsController, type: :request do
end end
context "when startdate is submitted with leading zeroes" do context "when startdate is submitted with leading zeroes" do
let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "01", "startdate(3i)": "02" } } } let(:params) { { location: { "startdate(1i)": "2022", "startdate(2i)": "01", "startdate(3i)": "02" } } }
before do before do
patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params:
end end
it "adds startdate correctly " do it "adds startdate correctly " do
expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) expect(Location.last.startdate).to eq(Time.zone.local(2022, 1, 2))
end end
it "redirects correctly" do it "redirects correctly" do
@ -1131,7 +1131,7 @@ RSpec.describe LocationsController, type: :request do
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)
expect(page).to have_content(I18n.t("validations.location.startdate_blank")) expect(page).to have_content(I18n.t("validations.location.startdate_invalid"))
end end
end end
@ -1163,14 +1163,14 @@ RSpec.describe LocationsController, type: :request do
end end
context "when startdate is submitted" do context "when startdate is submitted" do
let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "1", "startdate(3i)": "2" } } } let(:params) { { location: { "startdate(1i)": "2022", "startdate(2i)": "1", "startdate(3i)": "2" } } }
before do before do
patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params:
end end
it "adds startdate to location" do it "adds startdate to location" do
expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) expect(Location.last.startdate).to eq(Time.zone.local(2022, 1, 2))
end end
it "redirects correctly" do it "redirects correctly" do
@ -1180,14 +1180,14 @@ RSpec.describe LocationsController, type: :request do
end end
context "when startdate is submitted with leading zeroes" do context "when startdate is submitted with leading zeroes" do
let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "01", "startdate(3i)": "02" } } } let(:params) { { location: { "startdate(1i)": "2022", "startdate(2i)": "01", "startdate(3i)": "02" } } }
before do before do
patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params:
end end
it "adds startdate correctly " do it "adds startdate correctly " do
expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) expect(Location.last.startdate).to eq(Time.zone.local(2022, 1, 2))
end end
it "redirects correctly" do it "redirects correctly" do
@ -1205,7 +1205,7 @@ RSpec.describe LocationsController, type: :request do
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)
expect(page).to have_content(I18n.t("validations.location.startdate_blank")) expect(page).to have_content(I18n.t("validations.location.startdate_invalid"))
end end
end end

Loading…
Cancel
Save