From 15d847c477f32290209548040c9a3a15597c9b03 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 30 Nov 2022 17:28:53 +0000 Subject: [PATCH] test: update model and helper location tests --- spec/helpers/locations_helper_spec.rb | 24 ++++++++++++------------ spec/models/location_spec.rb | 16 ++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index 4d9340542..ebd8f1435 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -2,9 +2,9 @@ require "rails_helper" RSpec.describe LocationsHelper 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."), - 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: "None", name: "None", description: "The majority of units are not designed to wheelchair-user standards or fitted with any equipment and adaptations.")] + 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: "Fitted with stairlifts, ramps, level access showers or grab rails."), + 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 expect(mobility_type_selection).to eq(expected_selection) end @@ -138,15 +138,15 @@ RSpec.describe LocationsHelper do it "returns correct display attributes" do attributes = [ - { name: "Postcode", value: location.postcode }, - { name: "Local authority", value: location.location_admin_district }, - { name: "Location name", value: location.name, edit: true }, - { name: "Total number of units at this location", value: location.units }, - { name: "Common type of unit", value: location.type_of_unit }, - { name: "Mobility type", value: location.mobility_type }, - { name: "Code", value: location.location_code }, - { name: "Availability", value: "Active from 1 April 2022" }, - { name: "Status", value: :active }, + { attribute: "postcode", name: "Postcode", value: location.postcode }, + { attribute: "name", name: "Location name", value: location.name }, + { attribute: "location_admin_district", name: "Local authority", value: location.location_admin_district }, + { attribute: "units", name: "Number of units", value: location.units }, + { attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit }, + { attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type }, + { attribute: "location_code", name: "Code", value: location.location_code }, + { attribute: "availability", name: "Availability", value: "Active from 1 April 2022" }, + { attribute: "status", name: "Status", value: :active }, ] expect(display_location_attributes(location)).to eq(attributes) diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index dd5d697e9..472ed2b0c 100644 --- a/spec/models/location_spec.rb +++ b/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 location.postcode = "invalid" - expect { location.save! } - .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode #{I18n.t('validations.postcode')}") + location.valid?(:postcode) + expect(location.errors.count).to eq(1) end end describe "#units" do 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 - expect { location.save! } - .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Units #{I18n.t('activerecord.errors.models.location.attributes.units.blank')}") + location.valid?(:units) + expect(location.errors.count).to eq(1) end end describe "#type_of_unit" do 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 - expect { location.save! } - .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Type of unit #{I18n.t('activerecord.errors.models.location.attributes.type_of_unit.blank')}") + location.valid?(:type_of_unit) + expect(location.errors.count).to eq(1) end end