Browse Source

test: update model and helper location tests

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
15d847c477
  1. 24
      spec/helpers/locations_helper_spec.rb
  2. 16
      spec/models/location_spec.rb

24
spec/helpers/locations_helper_spec.rb

@ -2,9 +2,9 @@ require "rails_helper"
RSpec.describe LocationsHelper do RSpec.describe LocationsHelper do
describe "mobility type selection" do describe "mobility type selection" do
expected_selection = [OpenStruct.new(id: "Wheelchair-user standard", name: "Wheelchair-user standard", description: "The majority of units are suitable for someone who uses a wheelchair and offer the full use of all rooms and facilities."), expected_selection = [OpenStruct.new(id: "Wheelchair-user standard", name: "Wheelchair-user standard", description: "Suitable for someone who uses a wheelchair and offers the full use of all rooms and facilities."),
OpenStruct.new(id: "Fitted with equipment and adaptations", name: "Fitted with equipment and adaptations", description: "For example, the majority of units have been fitted with stairlifts, ramps, level access showers or grab rails."), OpenStruct.new(id: "Fitted with equipment and adaptations", name: "Fitted with equipment and adaptations", description: "Fitted with stairlifts, ramps, level access showers or grab rails."),
OpenStruct.new(id: "None", name: "None", description: "The majority of units are not designed to wheelchair-user standards or fitted with any equipment and adaptations.")] OpenStruct.new(id: "None", name: "None", description: "Not designed to wheelchair-user standards or fitted with any equipment or adaptations.")]
it "returns correct selection to display" do it "returns correct selection to display" do
expect(mobility_type_selection).to eq(expected_selection) expect(mobility_type_selection).to eq(expected_selection)
end end
@ -138,15 +138,15 @@ RSpec.describe LocationsHelper do
it "returns correct display attributes" do it "returns correct display attributes" do
attributes = [ attributes = [
{ name: "Postcode", value: location.postcode }, { attribute: "postcode", name: "Postcode", value: location.postcode },
{ name: "Local authority", value: location.location_admin_district }, { attribute: "name", name: "Location name", value: location.name },
{ name: "Location name", value: location.name, edit: true }, { attribute: "location_admin_district", name: "Local authority", value: location.location_admin_district },
{ name: "Total number of units at this location", value: location.units }, { attribute: "units", name: "Number of units", value: location.units },
{ name: "Common type of unit", value: location.type_of_unit }, { attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit },
{ name: "Mobility type", value: location.mobility_type }, { attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type },
{ name: "Code", value: location.location_code }, { attribute: "location_code", name: "Code", value: location.location_code },
{ name: "Availability", value: "Active from 1 April 2022" }, { attribute: "availability", name: "Availability", value: "Active from 1 April 2022" },
{ name: "Status", value: :active }, { attribute: "status", name: "Status", value: :active },
] ]
expect(display_location_attributes(location)).to eq(attributes) expect(display_location_attributes(location)).to eq(attributes)

16
spec/models/location_spec.rb

@ -31,28 +31,28 @@ RSpec.describe Location, type: :model do
it "does add an error when the postcode is invalid" do it "does add an error when the postcode is invalid" do
location.postcode = "invalid" location.postcode = "invalid"
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
end end
describe "#units" do describe "#units" do
let(:location) { FactoryBot.build(:location) } let(:location) { FactoryBot.build(:location) }
it "does add an error when the postcode is invalid" do it "does add an error when units is nil" do
location.units = nil location.units = nil
expect { location.save! } location.valid?(:units)
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Units #{I18n.t('activerecord.errors.models.location.attributes.units.blank')}") expect(location.errors.count).to eq(1)
end end
end end
describe "#type_of_unit" do describe "#type_of_unit" do
let(:location) { FactoryBot.build(:location) } let(:location) { FactoryBot.build(:location) }
it "does add an error when the postcode is invalid" do it "does add an error when the type_of_unit is nil" do
location.type_of_unit = nil location.type_of_unit = nil
expect { location.save! } location.valid?(:type_of_unit)
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Type of unit #{I18n.t('activerecord.errors.models.location.attributes.type_of_unit.blank')}") expect(location.errors.count).to eq(1)
end end
end end

Loading…
Cancel
Save