diff options
| author | Zog | 2018-04-04 09:15:59 +0200 |
|---|---|---|
| committer | Johan Van Ryseghem | 2018-04-04 11:08:20 +0200 |
| commit | a77307ca49c57dc18823f6aece2424ccb3c5a7c2 (patch) | |
| tree | a791261bf42ff23d92aaaa2a2f82d9c979b98e07 | |
| parent | f946eb8d72a5601020c420b33225c31b12277be4 (diff) | |
| download | chouette-core-a77307ca49c57dc18823f6aece2424ccb3c5a7c2.tar.bz2 | |
Fix specs
| -rw-r--r-- | app/models/concerns/custom_fields_support.rb | 2 | ||||
| -rw-r--r-- | app/models/custom_field.rb | 5 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_spec.rb | 1 | ||||
| -rw-r--r-- | spec/models/custom_field_spec.rb | 4 |
4 files changed, 9 insertions, 3 deletions
diff --git a/app/models/concerns/custom_fields_support.rb b/app/models/concerns/custom_fields_support.rb index 4faff694e..7d2c22537 100644 --- a/app/models/concerns/custom_fields_support.rb +++ b/app/models/concerns/custom_fields_support.rb @@ -16,7 +16,7 @@ module CustomFieldsSupport def custom_field_values= vals out = {} vals.each do |k, val| - out[k] = custom_fields[k].preprocess_value_for_assignment(val) + out[k] = custom_fields[k]&.preprocess_value_for_assignment(val) end self.write_attribute :custom_field_values, out end diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 62c43f1b4..98cb38614 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -38,7 +38,7 @@ class CustomField < ActiveRecord::Base @valid = false end attr_accessor :owner - + delegate :code, :name, :field_type, to: :@custom_field def options @@ -73,7 +73,8 @@ class CustomField < ActiveRecord::Base def initialize_custom_field end - def preprocess_value_for_assignment + def preprocess_value_for_assignment val + val end def render_partial diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index c69655bd4..7292f09f9 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -420,6 +420,7 @@ describe Chouette::VehicleJourney, :type => :model do state['published_journey_name'] = 'edited_name' state['published_journey_identifier'] = 'edited_identifier' state['custom_fields'] = {energy: {value: 99}} + create :custom_field, field_type: :integer, code: :energy, name: :energy Chouette::VehicleJourney.state_update(route, collection) expect(state['errors']).to be_nil diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb index d52a29fc8..3a432e7b3 100644 --- a/spec/models/custom_field_spec.rb +++ b/spec/models/custom_field_spec.rb @@ -35,6 +35,10 @@ RSpec.describe CustomField, type: :model do end context "custom field_values for a resource" do + before do + create :custom_field, field_type: :integer, code: :energy, name: :energy + end + it { expect(vj.custom_field_value("energy")).to eq(99) } end |
