Browse Source

test: fix failing tests

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
901a90bdde
  1. 3
      app/controllers/locations_controller.rb
  2. 2
      app/models/location.rb
  3. 4
      app/views/locations/local_authority.html.erb
  4. 20
      spec/features/schemes_spec.rb
  5. 6
      spec/models/location_spec.rb

3
app/controllers/locations_controller.rb

@ -144,8 +144,7 @@ class LocationsController < ApplicationController
def check_answers; end def check_answers; end
def confirm def confirm
@location.confirmed! flash[:notice] = "#{@location.postcode} #{@location.startdate.blank? || @location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme"
flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme"
redirect_to scheme_locations_path(@scheme) redirect_to scheme_locations_path(@scheme)
end end

2
app/models/location.rb

@ -430,7 +430,7 @@ class Location < ApplicationRecord
end end
def validate_confirmed def validate_confirmed
self.confirmed = [postcode, name, location_admin_district, location_code, units, type_of_unit, mobility_type].all?(&:present?) self.confirmed = [postcode, location_admin_district, location_code, units, type_of_unit, mobility_type].all?(&:present?)
end end
def confirmed! def confirmed!

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

@ -29,10 +29,10 @@
<div class="govuk-button-group"> <div class="govuk-button-group">
<% if params[:referrer] == "check_answers" || params[:referrer] == "check_local_authority" %> <% if params[:referrer] == "check_answers" || params[:referrer] == "check_local_authority" %>
<%= f.govuk_submit "Save changes" %> <%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %> <%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% else %> <% else %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> <%= govuk_link_to "Skip for now", scheme_location_name_path(@scheme, @location), secondary: true %>
<% end %> <% end %>
</div> </div>
</div> </div>

20
spec/features/schemes_spec.rb

@ -304,7 +304,7 @@ RSpec.describe "Schemes scheme Features" do
end end
it "has the correct action button text" do it "has the correct action button text" do
expect(page).to have_button("Add this location") expect(page).to have_button("Save and return to locations")
end end
it "allows you to edit the newly added location" do it "allows you to edit the newly added location" do
@ -313,7 +313,7 @@ RSpec.describe "Schemes scheme Features" do
context "when you click save" do context "when you click save" do
before do before do
click_button "Add this location" click_button "Save and return to locations"
end end
it "displays a updated banner" do it "displays a updated banner" do
@ -329,7 +329,7 @@ RSpec.describe "Schemes scheme Features" do
context "when you click to view the scheme details" do context "when you click to view the scheme details" do
before do before do
click_button "Add this location" click_button "Save and return to locations"
click_link("Scheme") click_link("Scheme")
end end
@ -492,7 +492,7 @@ RSpec.describe "Schemes scheme Features" do
it "lets me check my answers after adding a second location" do it "lets me check my answers after adding a second location" do
fill_in_and_save_location fill_in_and_save_location
click_button "Add this location" click_button "Save and return to locations"
fill_in_and_save_second_location fill_in_and_save_second_location
expect(page).to have_content "Check your answers" expect(page).to have_content "Check your answers"
end end
@ -503,7 +503,7 @@ RSpec.describe "Schemes scheme Features" do
create_and_save_a_scheme create_and_save_a_scheme
click_button "Create scheme" click_button "Create scheme"
fill_in_and_save_location fill_in_and_save_location
click_button "Add this location" click_button "Save and return to locations"
click_link "Locations" click_link "Locations"
end end
@ -520,7 +520,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays information about another location" do it "displays information about another location" do
fill_in_and_save_second_location fill_in_and_save_second_location
click_button "Add this location" click_button "Save and return to locations"
expect(page).to have_content "Locations" expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} total location" expect(page).to have_content "#{scheme.locations.count} total location"
end end
@ -538,7 +538,7 @@ RSpec.describe "Schemes scheme Features" do
create_and_save_a_scheme create_and_save_a_scheme
click_button "Create scheme" click_button "Create scheme"
fill_in_and_save_second_location fill_in_and_save_second_location
click_button "Add this location" click_button "Save and return to locations"
end end
it "displays changed location" do it "displays changed location" do
@ -947,7 +947,7 @@ RSpec.describe "Schemes scheme Features" do
end end
it "has the correct action button text" do it "has the correct action button text" do
expect(page).to have_button("Add this location") expect(page).to have_button("Save and return to locations")
end end
it "allows you to edit the newly added location" do it "allows you to edit the newly added location" do
@ -956,7 +956,7 @@ RSpec.describe "Schemes scheme Features" do
context "when you click save" do context "when you click save" do
before do before do
click_button "Add this location" click_button "Save and return to locations"
end end
it "displays a updated banner" do it "displays a updated banner" do
@ -972,7 +972,7 @@ RSpec.describe "Schemes scheme Features" do
context "when you click to view the scheme details" do context "when you click to view the scheme details" do
before do before do
click_button "Add this location" click_button "Save and return to locations"
click_link("Scheme") click_link("Scheme")
end end

6
spec/models/location_spec.rb

@ -120,7 +120,7 @@ RSpec.describe Location, type: :model do
before do before do
FactoryBot.create(:location, name: "ABC", postcode: "NW1 8RR", startdate: Time.zone.today) FactoryBot.create(:location, name: "ABC", postcode: "NW1 8RR", startdate: Time.zone.today)
FactoryBot.create(:location, name: "XYZ", postcode: "SE1 6HJ", startdate: Time.zone.today + 1.day) FactoryBot.create(:location, name: "XYZ", postcode: "SE1 6HJ", startdate: Time.zone.today + 1.day)
FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: Time.zone.today - 1.day, confirmed: false) FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: Time.zone.today - 1.day, units: nil)
FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: nil) FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: nil)
end end
@ -152,8 +152,8 @@ RSpec.describe Location, type: :model do
end end
context "when filtering by active locations" do context "when filtering by active locations" do
it "returns only locations that started today or earlier and have been confirmed" do it "returns only locations that started today or earlier and are complete (and so confirmed)" do
expect(described_class.active.count).to eq(1) expect(described_class.active.count).to eq(2)
end end
end end
end end

Loading…
Cancel
Save