diff options
| author | Teddy Wing | 2017-09-22 12:42:41 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-09-22 12:42:41 +0200 |
| commit | 9086e4c7d253927e7fad07bcd4eb194eeff393ca (patch) | |
| tree | 102d744113f1a605ac0a5ea0eb3323ca779f9c5d /spec/lib/model_attribute_spec.rb | |
| parent | 404b143af9ed49912e1e0065c832639188aa87de (diff) | |
| download | chouette-core-9086e4c7d253927e7fad07bcd4eb194eeff393ca.tar.bz2 | |
ModelAttribute: Add `.group_by_class` method
This returns all defined `ModelAttribute`s as a hash of class keys
containing lists of the attributes they contain.
Refs #4401
Diffstat (limited to 'spec/lib/model_attribute_spec.rb')
| -rw-r--r-- | spec/lib/model_attribute_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/lib/model_attribute_spec.rb b/spec/lib/model_attribute_spec.rb index 9e10bf40f..0ca90430f 100644 --- a/spec/lib/model_attribute_spec.rb +++ b/spec/lib/model_attribute_spec.rb @@ -30,6 +30,30 @@ RSpec.describe ModelAttribute do end end + describe ".group_by_class" do + it "returns all ModelAttributes grouped by klass" do + ModelAttribute.instance_variable_set(:@__all__, [ + ModelAttribute.new(:route, :name, :string), + ModelAttribute.new(:route, :published_name, :string), + ModelAttribute.new(:journey_pattern, :name, :string), + ModelAttribute.new(:vehicle_journey, :number, :integer) + ]) + + expect(ModelAttribute.group_by_class).to eq({ + route: [ + ModelAttribute.new(:route, :name, :string), + ModelAttribute.new(:route, :published_name, :string), + ], + journey_pattern: [ + ModelAttribute.new(:journey_pattern, :name, :string), + ], + vehicle_journey: [ + ModelAttribute.new(:vehicle_journey, :number, :integer) + ] + }) + end + end + describe ".methods_by_class" do it "returns all ModelAttributes for a given class" do ModelAttribute.instance_variable_set(:@__all__, [ |
