diff options
| author | Zog | 2018-04-03 21:53:42 +0200 |
|---|---|---|
| committer | Johan Van Ryseghem | 2018-04-04 11:10:39 +0200 |
| commit | e709a1ddaf5686b3463d7697cd21cee3d15957f2 (patch) | |
| tree | c0f2f57124dae9b0e77dc49162d5dac1f832d3a3 | |
| parent | a59aa62be66340bb1ac22bad7cb980dbf1a5ffa1 (diff) | |
| download | chouette-core-e709a1ddaf5686b3463d7697cd21cee3d15957f2.tar.bz2 | |
Fix specs
| -rw-r--r-- | app/models/concerns/custom_fields_support.rb | 4 | ||||
| -rw-r--r-- | app/models/custom_field.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20180313082623_add_custom_field_values_to_stop_areas.rb | 2 | ||||
| -rw-r--r-- | db/schema.rb | 4 | ||||
| -rw-r--r-- | spec/models/custom_field_spec.rb | 2 | ||||
| -rw-r--r-- | spec/views/stop_areas/edit.html.erb_spec.rb | 1 | ||||
| -rw-r--r-- | spec/views/stop_areas/new.html.erb_spec.rb | 1 |
7 files changed, 9 insertions, 7 deletions
diff --git a/app/models/concerns/custom_fields_support.rb b/app/models/concerns/custom_fields_support.rb index 53be92b90..6b6558ca3 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 = {} custom_fields.each do |code, field| - out[code] = field.preprocess_value_for_assignment(vals[code]) + out[code] = field.preprocess_value_for_assignment(vals.symbolize_keys[code.to_sym]) end self.write_attribute :custom_field_values, out end @@ -30,7 +30,7 @@ module CustomFieldsSupport end def custom_field_value key - (custom_field_values || {})[key.to_s] + (custom_field_values&.stringify_keys || {})[key.to_s] end private diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 6236f482e..9fcfa9cd9 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -166,7 +166,7 @@ class CustomField < ActiveRecord::Base end def display_value - options["list_values"][value.to_s] + options["list_values"][value.to_i] end class Input < Base::Input diff --git a/db/migrate/20180313082623_add_custom_field_values_to_stop_areas.rb b/db/migrate/20180313082623_add_custom_field_values_to_stop_areas.rb index 1b901d139..e49be7e40 100644 --- a/db/migrate/20180313082623_add_custom_field_values_to_stop_areas.rb +++ b/db/migrate/20180313082623_add_custom_field_values_to_stop_areas.rb @@ -1,5 +1,5 @@ class AddCustomFieldValuesToStopAreas < ActiveRecord::Migration def change - add_column :stop_areas, :custom_field_values, :json + add_column :stop_areas, :custom_field_values, :jsonb end end diff --git a/db/schema.rb b/db/schema.rb index 77e35f449..9cf5f8319 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -841,10 +841,8 @@ ActiveRecord::Schema.define(version: 20180319043333) do t.integer "waiting_time" t.string "kind" t.jsonb "localized_names" - t.datetime "confirmed_at" - t.json "custom_field_values" - + t.jsonb "custom_field_values" end add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb index 3a432e7b3..1dfe6d33c 100644 --- a/spec/models/custom_field_spec.rb +++ b/spec/models/custom_field_spec.rb @@ -1,6 +1,7 @@ require 'rails_helper' RSpec.describe CustomField, type: :model do + let( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} } context "validates" do @@ -46,6 +47,7 @@ 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 diff --git a/spec/views/stop_areas/edit.html.erb_spec.rb b/spec/views/stop_areas/edit.html.erb_spec.rb index bfbb0bb55..1bdb42817 100644 --- a/spec/views/stop_areas/edit.html.erb_spec.rb +++ b/spec/views/stop_areas/edit.html.erb_spec.rb @@ -8,6 +8,7 @@ describe "/stop_areas/edit", :type => :view do before do allow(view).to receive(:has_feature?) + allow(view).to receive(:resource){ stop_area } end describe "form" do diff --git a/spec/views/stop_areas/new.html.erb_spec.rb b/spec/views/stop_areas/new.html.erb_spec.rb index 23f7387fa..eced129e4 100644 --- a/spec/views/stop_areas/new.html.erb_spec.rb +++ b/spec/views/stop_areas/new.html.erb_spec.rb @@ -7,6 +7,7 @@ describe "/stop_areas/new", :type => :view do before do allow(view).to receive(:has_feature?) + allow(view).to receive(:resource){ stop_area } end describe "form" do |
