aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-09-19 16:59:45 +0200
committerTeddy Wing2017-09-19 17:00:30 +0200
commite1547b52a372942b34cda3b3fee4ab76e9f1b65e (patch)
tree166d3bb167ad1b213a2fae98ec5daf22f3ea90ae
parent30fc0d3f1a9a158a0d45bbaf2f78e176f74ac943 (diff)
downloadchouette-core-e1547b52a372942b34cda3b3fee4ab76e9f1b65e.tar.bz2
ModelAttribute: Add `#code` method
A method that returns a string representation of the attribute, in the form `:class#:name". This will be used to store a reference to the attribute in the database. For example, a validation will reference a `ModelAttribute` in a database column using this `#code` string. Refs #4401
-rw-r--r--lib/model_attribute.rb4
-rw-r--r--spec/lib/model_attribute_spec.rb8
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/model_attribute.rb b/lib/model_attribute.rb
index 081d0cd0f..22c366b37 100644
--- a/lib/model_attribute.rb
+++ b/lib/model_attribute.rb
@@ -55,4 +55,8 @@ class ModelAttribute
# Chouette::RoutingConstraintZone
define :routing_constraint_zone, :name, :string
+
+ def code
+ "#{@klass}##{@name}"
+ end
end
diff --git a/spec/lib/model_attribute_spec.rb b/spec/lib/model_attribute_spec.rb
index da767cfed..ad1dd863f 100644
--- a/spec/lib/model_attribute_spec.rb
+++ b/spec/lib/model_attribute_spec.rb
@@ -13,4 +13,12 @@ RSpec.describe ModelAttribute do
expect(model_attr.data_type).to eq(:string)
end
end
+
+ describe "#code" do
+ it "returns a string representation of the attribute" do
+ model_attr = ModelAttribute.new(:route, :name, :string)
+
+ expect(model_attr.code).to eq('route#name')
+ end
+ end
end