aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib/model_attribute_spec.rb
diff options
context:
space:
mode:
authorTeddy Wing2017-09-19 18:13:20 +0200
committerTeddy Wing2017-09-19 18:13:20 +0200
commita60bf813aa118648998093242d6db0e1d8613e76 (patch)
treea75b5ed5275f12515dc2e9ddf1a519c21b34588d /spec/lib/model_attribute_spec.rb
parentc9a997f337c9b45f62b50629de96fa95f20c1a7f (diff)
downloadchouette-core-a60bf813aa118648998093242d6db0e1d8613e76.tar.bz2
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
Diffstat (limited to 'spec/lib/model_attribute_spec.rb')
-rw-r--r--spec/lib/model_attribute_spec.rb26
1 files changed, 26 insertions, 0 deletions
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