diff options
| author | Alban Peignier | 2018-04-25 09:57:15 +0200 | 
|---|---|---|
| committer | Johan Van Ryseghem | 2018-04-25 15:46:33 +0200 | 
| commit | a3d6290d8814817538a1e903aace873f59df7a96 (patch) | |
| tree | bad02087cba9f0d90e1e96e0dadf025aa45e2109 | |
| parent | 91f253454d261767b9a9c9d5a328b3c6d149cee9 (diff) | |
| download | chouette-core-a3d6290d8814817538a1e903aace873f59df7a96.tar.bz2 | |
Make mandatory workgroup for class method custom_fields (not available for Company or StopArea for exemple). Refs #6669
| -rw-r--r-- | app/models/chouette/trident_active_record.rb | 1 | ||||
| -rw-r--r-- | app/models/concerns/custom_fields_support.rb | 9 | ||||
| -rw-r--r-- | spec/models/custom_field_spec.rb | 2 | 
3 files changed, 5 insertions, 7 deletions
| diff --git a/app/models/chouette/trident_active_record.rb b/app/models/chouette/trident_active_record.rb index 7e5140fc4..475589e13 100644 --- a/app/models/chouette/trident_active_record.rb +++ b/app/models/chouette/trident_active_record.rb @@ -11,7 +11,6 @@ module Chouette        referential&.workgroup      end -      def hub_restricted?        referential.data_format == "hub"      end diff --git a/app/models/concerns/custom_fields_support.rb b/app/models/concerns/custom_fields_support.rb index 8bfd0abf8..fd872cc62 100644 --- a/app/models/concerns/custom_fields_support.rb +++ b/app/models/concerns/custom_fields_support.rb @@ -5,15 +5,14 @@ module CustomFieldsSupport      validate :custom_fields_values_are_valid      after_initialize :initialize_custom_fields -    def self.custom_fields _workgroup=nil -      _workgroup ||= self.workgroup -      return [] unless _workgroup +    def self.custom_fields workgroup +      return [] unless workgroup        fields = CustomField.where(resource_type: self.name.split("::").last) -      fields = fields.where(workgroup_id: _workgroup.id) +      fields = fields.where(workgroup_id: workgroup.id)        fields      end -    def self.custom_fields_definitions workgroup=nil +    def self.custom_fields_definitions workgroup        Hash[*custom_fields(workgroup).map{|cf| [cf.code, cf]}.flatten]      end diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb index b0aa0ff1e..2b561e739 100644 --- a/spec/models/custom_field_spec.rb +++ b/spec/models/custom_field_spec.rb @@ -30,7 +30,7 @@ RSpec.describe CustomField, type: :model do          "energy" => fields[1].slice(:code, :name, :field_type, :options).update(value: 99)        }      } -    it { expect(Chouette::VehicleJourney.custom_fields).to eq(fields) } +    it { expect(Chouette::VehicleJourney.custom_fields(workgroup)).to eq(fields) }      it {        instance_fields.each do |code, cf|          cf.each do |k, v| | 
