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)"]
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)
else
@location.startdate = nil
end
if @location.save(context: :startdate)
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"
click_button "Save and continue"
fill_in "Day", with: 2
fill_in "Month", with: 2
fill_in "Month", with: 5
fill_in "Year", with: 2022
click_button "Save and continue"
end
@ -89,7 +89,7 @@ module SchemesHelpers
choose "location-mobility-type-none-field"
click_button "Save and continue"
fill_in "Day", with: 2
fill_in "Month", with: 2
fill_in "Month", with: 5
fill_in "Year", with: 2022
click_button "Save and continue"
end

20
spec/requests/locations_controller_spec.rb

@ -1089,14 +1089,14 @@ RSpec.describe LocationsController, type: :request do
end
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
patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params:
end
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
it "redirects correctly" do
@ -1106,14 +1106,14 @@ RSpec.describe LocationsController, type: :request do
end
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
patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params:
end
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
it "redirects correctly" do
@ -1131,7 +1131,7 @@ RSpec.describe LocationsController, type: :request do
it "displays the new page with an error message" do
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
@ -1163,14 +1163,14 @@ RSpec.describe LocationsController, type: :request do
end
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
patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params:
end
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
it "redirects correctly" do
@ -1180,14 +1180,14 @@ RSpec.describe LocationsController, type: :request do
end
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
patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params:
end
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
it "redirects correctly" do
@ -1205,7 +1205,7 @@ RSpec.describe LocationsController, type: :request do
it "displays the new page with an error message" do
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

Loading…
Cancel
Save