From a60bf813aa118648998093242d6db0e1d8613e76 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 19 Sep 2017 18:13:20 +0200 Subject: ModelAttribute: Add `.methods_by_class` method Allows us to get all `ModelAttribute`s given a certain class name. Needed an `#==` method to be able to test object equality more easily so I added one in. I don't like that the `klass` is a lowercase symbol and the `klass` attribute to `.methods_by_class` is a constantized string. Want to correct that and make them uniform. Only did it this way because that's how it was suggested in the ticket. Refs #4401 --- spec/lib/model_attribute_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'spec/lib/model_attribute_spec.rb') diff --git a/spec/lib/model_attribute_spec.rb b/spec/lib/model_attribute_spec.rb index ad1dd863f..73114ae1e 100644 --- a/spec/lib/model_attribute_spec.rb +++ b/spec/lib/model_attribute_spec.rb @@ -14,6 +14,23 @@ RSpec.describe ModelAttribute do end end + describe ".methods_by_class" do + it "returns all ModelAttributes for a given class" do + ModelAttribute.instance_variable_set(:@__all__, [ + ModelAttribute.new(:route, :name, :string), + ModelAttribute.new(:route, :published_name, :string), + ModelAttribute.new(:route, :direction, :string), + ModelAttribute.new(:journey_pattern, :name, :string) + ]) + + expect(ModelAttribute.methods_by_class('Route')).to match_array([ + ModelAttribute.new(:route, :name, :string), + ModelAttribute.new(:route, :published_name, :string), + ModelAttribute.new(:route, :direction, :string) + ]) + end + end + describe "#code" do it "returns a string representation of the attribute" do model_attr = ModelAttribute.new(:route, :name, :string) @@ -21,4 +38,13 @@ RSpec.describe ModelAttribute do expect(model_attr.code).to eq('route#name') end end + + describe "#==" do + it "returns true when :klass, :name, and :data_type attributes match" do + route_name = ModelAttribute.new(:route, :name, :string) + other_route_name = ModelAttribute.new(:route, :name, :string) + + expect(route_name == other_route_name).to be true + end + end end -- cgit v1.2.3