diff options
| author | Zog | 2018-04-06 10:09:10 +0200 |
|---|---|---|
| committer | Zog | 2018-04-06 10:09:10 +0200 |
| commit | c1d65c8ae621d88b21cb84686325a584e8bc15da (patch) | |
| tree | cebfd0742061d7a4d38bd800833f29550ff29fc5 | |
| parent | 25473075be6b31632295c95696891368b5bc26f4 (diff) | |
| download | chouette-core-6461-fix-customfields-support.tar.bz2 | |
Refs #6461; Don't initilialize CustomFields when they are not loaded by the model6461-fix-customfields-support
| -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, |
