diff options
| author | Alban Peignier | 2018-01-10 20:34:09 +0100 |
|---|---|---|
| committer | GitHub | 2018-01-10 20:34:09 +0100 |
| commit | 17a3d2437a4eb60ec4046137fb37d7b433dc48aa (patch) | |
| tree | 4e9f0df17da92ad00903bd851d81cdba6ac39282 /spec | |
| parent | d597c065194e84f3c350c042276480361520b3b9 (diff) | |
| parent | 7a5e523886177de2cda3268effc9001e62246766 (diff) | |
| download | chouette-core-17a3d2437a4eb60ec4046137fb37d7b433dc48aa.tar.bz2 | |
Merge pull request #222 from af83/5505-custom_fields_with_jsonb
Custom fields with jsonb. Refs #5505
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/factories/custom_fields.rb | 9 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_spec.rb | 5 | ||||
| -rw-r--r-- | spec/models/custom_field_spec.rb | 27 |
3 files changed, 38 insertions, 3 deletions
diff --git a/spec/factories/custom_fields.rb b/spec/factories/custom_fields.rb new file mode 100644 index 000000000..2f5fae555 --- /dev/null +++ b/spec/factories/custom_fields.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :custom_field do + code "code" + resource_type "VehicleJourney" + sequence(:name){|n| "custom field ##{n}"} + field_type "list" + options( { "capacity" => "0" } ) + end +end diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index eb2a31794..3ec2387e5 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -399,8 +399,7 @@ describe Chouette::VehicleJourney, :type => :model do end describe ".where_departure_time_between" do - it "selects vehicle journeys whose departure times are between the - specified range" do + it "selects vehicle journeys whose departure times are between the specified range" do journey_early = create( :vehicle_journey, stop_departure_time: '02:00:00' @@ -415,7 +414,7 @@ describe Chouette::VehicleJourney, :type => :model do journey_pattern: journey_pattern, stop_departure_time: '03:00:00' ) - journey_late = create( + create( :vehicle_journey, route: route, journey_pattern: journey_pattern, diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb new file mode 100644 index 000000000..80873683c --- /dev/null +++ b/spec/models/custom_field_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +RSpec.describe CustomField, type: :model do + let( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} } + + context "validates" do + it { should validate_uniqueness_of(:name).scoped_to(:resource_type) } + end + + context "field access" do + let( :custom_field ){ build_stubbed :custom_field } + + it "option's values can be accessed by a key" do + expect( custom_field.options['capacity'] ).to eq("0") + end + end + + + context "custom fields for a resource" do + let!( :fields ){ (1..2).map{ create :custom_field } } + it { expect(vj.custom_fields).to eq(fields) } + end + + context "custom field_values for a resource" do + it { expect(vj.custom_field_value("energy")).to eq(99) } + end +end |
