diff options
| author | Zog | 2018-01-12 09:53:38 +0100 | 
|---|---|---|
| committer | Zog | 2018-02-26 10:00:34 +0100 | 
| commit | 9af498376d51dbd505cf6d276a02e7bfb24e9aa5 (patch) | |
| tree | a1ba49f6d708ef6a00e4dc91e21f3e973a949c85 /spec | |
| parent | 206bf218e1b84dbe53683ec2e3f983cd30f7ded1 (diff) | |
| download | chouette-core-9af498376d51dbd505cf6d276a02e7bfb24e9aa5.tar.bz2 | |
Propose some improvements on CustomFields
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/factories/custom_fields.rb | 2 | ||||
| -rw-r--r-- | spec/models/custom_field_spec.rb | 25 | 
2 files changed, 24 insertions, 3 deletions
| diff --git a/spec/factories/custom_fields.rb b/spec/factories/custom_fields.rb index 2f5fae555..7c43a6147 100644 --- a/spec/factories/custom_fields.rb +++ b/spec/factories/custom_fields.rb @@ -4,6 +4,6 @@ FactoryGirl.define do      resource_type "VehicleJourney"      sequence(:name){|n| "custom field ##{n}"}      field_type "list" -    options( { "capacity" => "0" } ) +    options( { capacity: "0" } )    end  end diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb index 51128b0a2..d1c6d803a 100644 --- a/spec/models/custom_field_spec.rb +++ b/spec/models/custom_field_spec.rb @@ -16,7 +16,6 @@ RSpec.describe CustomField, type: :model do      end    end -    context "custom fields for a resource" do      let!( :fields ){ [create(:custom_field), create(:custom_field, code: :energy)] }      let!( :instance_fields ){ @@ -26,10 +25,32 @@ RSpec.describe CustomField, type: :model do        }      }      it { expect(Chouette::VehicleJourney.custom_fields).to eq(fields) } -    it { expect(vj.custom_fields).to eq(instance_fields) } +    it { +      instance_fields.each do |code, cf| +        cf.each do |k, v| +          expect(vj.custom_fields[code].send(k)).to eq(v) +        end +      end +    }    end    context "custom field_values for a resource" do      it { expect(vj.custom_field_value("energy")).to eq(99) }    end + +  context "with an 'integer' field_type" do +    let!(:field){ [create(:custom_field, code: :energy, options: {field_type: 'integer'})] } +    let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: "99"} } +    it "should cast the value" do +      expect(vj.custom_fields[:energy].value).to eq 99 +    end +  end + +  context "with a 'string' field_type" do +    let!(:field){ [create(:custom_field, code: :energy, options: {field_type: 'string'})] } +    let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} } +    it "should cast the value" do +      expect(vj.custom_fields[:energy].value).to eq '99' +    end +  end  end | 
