diff options
| author | Robert | 2017-12-05 11:37:25 +0100 | 
|---|---|---|
| committer | Robert | 2017-12-05 12:19:42 +0100 | 
| commit | 642d2bd3a46a4b459acf18748dbfebf0cb6ca7df (patch) | |
| tree | 773a01b7a4dc86a5dabfab98f6f44bdc9f949a50 /app/models | |
| parent | 089c6935ca0e036de484834381e5beda7545d499 (diff) | |
| download | chouette-core-642d2bd3a46a4b459acf18748dbfebf0cb6ca7df.tar.bz2 | |
Refs: #5179@1.25h; Referential Creation Enforces objectid_format from associated Workbench
  - changed ObjectIdFormatterSupport as requested
  - respeced all defined cases
  - implemented respec
Missing:
  What to do in `define_default_attributes` if ref has no workbench and no `objectid_format`?
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/concerns/objectid_formatter_support.rb | 13 | ||||
| -rw-r--r-- | app/models/referential.rb | 6 | 
2 files changed, 9 insertions, 10 deletions
| diff --git a/app/models/concerns/objectid_formatter_support.rb b/app/models/concerns/objectid_formatter_support.rb index d0b85d8ac..3ef45334c 100644 --- a/app/models/concerns/objectid_formatter_support.rb +++ b/app/models/concerns/objectid_formatter_support.rb @@ -1,19 +1,16 @@  module ObjectidFormatterSupport    extend ActiveSupport::Concern -  class << self -    def legal_formats -      %w(netex stif_netex stif_reflex stif_codifligne) -    end - -    def default_format; 'netex' end +  def self.legal_formats +    %w(netex stif_netex stif_reflex stif_codifligne)    end +    included do      extend Enumerize -    enumerize :objectid_format, in: ObjectidFormatterSupport.legal_formats, default: ObjectidFormatterSupport.default_format +    enumerize :objectid_format, in: ObjectidFormatterSupport.legal_formats      validates_presence_of :objectid_format -     +      def objectid_formatter        objectid_formatter_class.new      end diff --git a/app/models/referential.rb b/app/models/referential.rb index 233a9f24a..e8fb2888e 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -127,10 +127,11 @@ class Referential < ActiveRecord::Base      Chouette::RoutingConstraintZone.all    end -  after_initialize :define_default_attributes +  before_validation :define_default_attributes    def define_default_attributes      self.time_zone ||= Time.zone.name +    self.objectid_format ||= workbench.try(:objectid_format) || ObjectidFormatterSupport.legal_formats.first    end    def switch @@ -140,7 +141,7 @@ class Referential < ActiveRecord::Base    end    def self.new_from(from, functional_scope) -e    Referential.new( +     Referential.new(        name: I18n.t("activerecord.copy", name: from.name),        slug: "#{from.slug}_clone",        prefix: from.prefix, @@ -149,6 +150,7 @@ e    Referential.new(        line_referential: from.line_referential,        stop_area_referential: from.stop_area_referential,        created_from: from, +      objectid_format: from.objectid_format,        metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) }      )    end | 
