From 78d96bbe7fd2ff8d20294b6915905d0873c670b4 Mon Sep 17 00:00:00 2001 From: Katharine Ahern Date: Wed, 18 Oct 2023 15:20:38 +0100 Subject: [PATCH 1/2] ap-4508: Add class to handle linked_application_types --- app/models/linked_application_type.rb | 12 ++++++++++++ spec/models/linked_application_type_spec.rb | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 app/models/linked_application_type.rb create mode 100644 spec/models/linked_application_type_spec.rb diff --git a/app/models/linked_application_type.rb b/app/models/linked_application_type.rb new file mode 100644 index 0000000000..6055a0d245 --- /dev/null +++ b/app/models/linked_application_type.rb @@ -0,0 +1,12 @@ +class LinkedApplicationType + LinkTypeStruct = Struct.new(:code, :description) + + LINK_TYPES = [ + { code: "FAMILY", description: "Family" }, + { code: "LEGAL", description: "Legal" }, + ].freeze + + def self.all + LINK_TYPES.map { |link_type_hash| LinkTypeStruct.new(code: link_type_hash[:code], description: link_type_hash[:description]) } + end +end diff --git a/spec/models/linked_application_type_spec.rb b/spec/models/linked_application_type_spec.rb new file mode 100644 index 0000000000..c0529595ce --- /dev/null +++ b/spec/models/linked_application_type_spec.rb @@ -0,0 +1,10 @@ +require "rails_helper" + +RSpec.describe LinkedApplicationType do + describe ".link_types" do + it "returns link types" do + expect(described_class.all.map(&:description)).to match_array %w[Family Legal] + expect(described_class.all.map(&:code)).to match_array %w[FAMILY LEGAL] + end + end +end From a111cb82828a346486f5fbc54668f8745bfee7c7 Mon Sep 17 00:00:00 2001 From: Katharine Ahern Date: Mon, 30 Oct 2023 08:49:10 +0000 Subject: [PATCH 2/2] ap-4508: simplify model and add tests for type --- app/models/linked_application_type.rb | 6 +++--- spec/models/linked_application_type_spec.rb | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/models/linked_application_type.rb b/app/models/linked_application_type.rb index 6055a0d245..990f267817 100644 --- a/app/models/linked_application_type.rb +++ b/app/models/linked_application_type.rb @@ -2,11 +2,11 @@ class LinkedApplicationType LinkTypeStruct = Struct.new(:code, :description) LINK_TYPES = [ - { code: "FAMILY", description: "Family" }, - { code: "LEGAL", description: "Legal" }, + LinkTypeStruct.new(code: "FAMILY", description: "Family"), + LinkTypeStruct.new(code: "LEGAL", description: "Legal"), ].freeze def self.all - LINK_TYPES.map { |link_type_hash| LinkTypeStruct.new(code: link_type_hash[:code], description: link_type_hash[:description]) } + LINK_TYPES end end diff --git a/spec/models/linked_application_type_spec.rb b/spec/models/linked_application_type_spec.rb index c0529595ce..2986d817e6 100644 --- a/spec/models/linked_application_type_spec.rb +++ b/spec/models/linked_application_type_spec.rb @@ -1,8 +1,15 @@ require "rails_helper" RSpec.describe LinkedApplicationType do - describe ".link_types" do - it "returns link types" do + describe ".all" do + it "returns a collection of Link types" do + described_class.all.each do |link_type| + expect(link_type.respond_to?(:code)).to be true + expect(link_type.respond_to?(:description)).to be true + end + end + + it "returns expected collection attribute values" do expect(described_class.all.map(&:description)).to match_array %w[Family Legal] expect(described_class.all.map(&:code)).to match_array %w[FAMILY LEGAL] end