diff options
| -rw-r--r-- | app/models/concerns/custom_fields_support.rb | 1 | ||||
| -rw-r--r-- | spec/models/custom_field_spec.rb | 5 | 
2 files changed, 5 insertions, 1 deletions
| diff --git a/app/models/concerns/custom_fields_support.rb b/app/models/concerns/custom_fields_support.rb index 017f496a8..ba4ea9912 100644 --- a/app/models/concerns/custom_fields_support.rb +++ b/app/models/concerns/custom_fields_support.rb @@ -33,6 +33,7 @@ module CustomFieldsSupport      end      def initialize_custom_fields +      return unless self.attributes.has_key?("custom_field_values")        self.custom_field_values ||= {}        custom_fields(:all).values.each &:initialize_custom_field        custom_fields(:all).each do |k, v| diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb index 1dfe6d33c..4c1b65a15 100644 --- a/spec/models/custom_field_spec.rb +++ b/spec/models/custom_field_spec.rb @@ -47,11 +47,14 @@ RSpec.describe CustomField, type: :model do      let!(:field){ [create(:custom_field, code: :energy, field_type: 'list', options: {list_values: %w(foo bar baz)})] }      let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: "1"} }      it "should cast the value" do -      p vj.custom_fields        expect(vj.custom_fields[:energy].value).to eq 1        expect(vj.custom_fields[:energy].display_value).to eq "bar"      end +    it "should not break initailizartion if the model does not have the :custom_field_values attribute" do +      expect{Chouette::VehicleJourney.where(id: vj.id).select(:id).last}.to_not raise_error(ActiveModel::MissingAttributeError) +    end +      it "should validate the value" do        {          "1" => true, | 
