aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2018-04-26 10:58:34 +0200
committerJohan Van Ryseghem2018-04-26 11:22:34 +0200
commitcc1be3219f3263e23023590ab04bc8cc94405754 (patch)
tree551c1f4fe93899cb22dfcc5ef136f95958625543
parentb5d113b0e6bfc15775eca753a9395f3a961c1e5e (diff)
downloadchouette-core-cc1be3219f3263e23023590ab04bc8cc94405754.tar.bz2
Truncate Referential#slug. Refs #6811
-rw-r--r--app/models/referential.rb3
-rw-r--r--spec/models/referential_spec.rb8
2 files changed, 5 insertions, 6 deletions
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 78b719fab..0522d72c0 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -242,7 +242,6 @@ class Referential < ApplicationModel
def self.new_from(from, organisation)
Referential.new(
name: I18n.t("activerecord.copy", name: from.name),
- slug: "#{from.slug}_clone",
prefix: from.prefix,
time_zone: from.time_zone,
bounds: from.bounds,
@@ -434,7 +433,7 @@ class Referential < ApplicationModel
def assign_slug(time_reference = Time)
self.slug ||= begin
- prefix = name.parameterize.gsub('-','_').gsub(/[^a-zA-Z_]/,'').gsub(/^_/,'')
+ prefix = name.parameterize.gsub('-','_').gsub(/[^a-zA-Z_]/,'').gsub(/^_/,'')[0..12]
prefix = "referential" if prefix.blank?
"#{prefix}_#{time_reference.now.to_i}"
end if name
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb
index ca2caf57f..5dfab5348 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -14,10 +14,10 @@ describe Referential, :type => :model do
time_reference = double(now: 1234567890)
conditions = {
- "2018-Hiver-Jezequel-MM-Lyon-Nice": "hiver_jezequel_mm_lyon_nice_1234567890",
- "2018-Hiver-Jezequel-23293MM-Lyon-Nice": "hiver_jezequel_mm_lyon_nice_1234567890",
- "-Hiver-Jezequel-MM-Lyon-Nice": "hiver_jezequel_mm_lyon_nice_1234567890",
- "Hiver-Jezequel-MM-Lyon-Nice": "hiver_jezequel_mm_lyon_nice_1234567890",
+ "2018-Hiver-Jezequel-MM-Lyon-Nice": "hiver_jezeque_1234567890",
+ "2018-Hiver-Jezequel-23293MM-Lyon-Nice": "hiver_jezeque_1234567890",
+ "-Hiver-Jezequel-MM-Lyon-Nice": "hiver_jezeque_1234567890",
+ "Hiver-Jezequel-MM-Lyon-Nice": "hiver_jezeque_1234567890",
"20179282": "referential_1234567890"
}