Browse Source

test: fix failing tests

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
513b3990ba
  1. 1
      spec/features/schemes_spec.rb
  2. 40
      spec/models/location_spec.rb
  3. 4
      spec/requests/locations_controller_spec.rb

1
spec/features/schemes_spec.rb

@ -514,6 +514,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays information about the first created location" do it "displays information about the first created location" do
expect(page).to have_content "AA1 1AA" expect(page).to have_content "AA1 1AA"
click_link "AA1 1AA"
expect(page).to have_content "Some name" expect(page).to have_content "Some name"
expect(page).to have_content "5" expect(page).to have_content "5"
expect(page).to have_content "Self-contained house" expect(page).to have_content "Self-contained house"

40
spec/models/location_spec.rb

@ -20,7 +20,7 @@ RSpec.describe Location, type: :model do
end end
end end
describe "#validate_postcode" do describe "#postcode" do
let(:location) { FactoryBot.build(:location) } let(:location) { FactoryBot.build(:location) }
it "does not add an error if postcode is valid" do it "does not add an error if postcode is valid" do
@ -37,8 +37,28 @@ RSpec.describe Location, type: :model do
it "does add an error when the postcode is missing" do it "does add an error when the postcode is missing" do
location.postcode = nil location.postcode = nil
expect { location.save! } location.valid?(:postcode)
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode #{I18n.t('validations.postcode')}") expect(location.errors.count).to eq(1)
end
end
describe "#local_authority" do
let(:location) { FactoryBot.build(:location) }
it "does add an error when the local authority is invalid" do
location.location_admin_district = "Select an option"
location.valid?(:location_admin_district)
expect(location.errors.count).to eq(1)
end
end
describe "#name" do
let(:location) { FactoryBot.build(:location) }
it "does add an error when the name is invalid" do
location.name = nil
location.valid?(:name)
expect(location.errors.count).to eq(1)
end end
end end
@ -67,8 +87,18 @@ RSpec.describe Location, type: :model do
it "does add an error when the mobility type is invalid" do it "does add an error when the mobility type is invalid" do
location.mobility_type = nil location.mobility_type = nil
expect { location.save! } location.valid?(:mobility_type)
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Mobility type #{I18n.t('activerecord.errors.models.location.attributes.mobility_type.blank')}") expect(location.errors.count).to eq(1)
end
end
describe "#availability" do
let(:location) { FactoryBot.build(:location) }
it "does add an error when the availability is invalid" do
location.startdate = Time.zone.local(1, 1, 1)
location.valid?(:startdate)
expect(location.errors.count).to eq(1)
end end
end end

4
spec/requests/locations_controller_spec.rb

@ -1244,7 +1244,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) } let!(:location) { FactoryBot.create(:location, scheme:, startdate: Time.zone.local(2000, 1, 1)) }
before do before do
sign_in user sign_in user
@ -1288,7 +1288,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) } let!(:location) { FactoryBot.create(:location, scheme:, startdate: Time.zone.local(2000, 1, 1)) }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)

Loading…
Cancel
Save