diff options
| author | cedricnjanga | 2017-11-24 17:06:52 +0100 | 
|---|---|---|
| committer | cedricnjanga | 2017-11-24 17:06:52 +0100 | 
| commit | ade8285b084529c09687e6995101b0aa651e2d4d (patch) | |
| tree | 9ad1e0a9f24053cee93bfba04d58a87c428680e4 | |
| parent | 9a08dc4d028f83e43a5fba83ebf09b68f21e9d49 (diff) | |
| download | chouette-core-ade8285b084529c09687e6995101b0aa651e2d4d.tar.bz2 | |
Remove specs we dont need anymore
| -rw-r--r-- | app/models/chouette/connection_link_type.rb | 58 | ||||
| -rw-r--r-- | app/models/chouette/direction.rb | 77 | ||||
| -rw-r--r-- | app/models/chouette/objectid/netex.rb | 6 | ||||
| -rw-r--r-- | app/models/chouette/objectid/stif_netex.rb | 4 | ||||
| -rw-r--r-- | app/models/chouette/objectid_formatter/netex.rb | 3 | ||||
| -rw-r--r-- | app/models/chouette/objectid_formatter/stif_netex.rb | 3 | ||||
| -rw-r--r-- | spec/models/chouette/object_id_spec.rb | 149 | ||||
| -rw-r--r-- | spec/models/chouette/trident_active_record_spec.rb | 53 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_spec.rb | 5 | ||||
| -rw-r--r-- | spec/models/concerns/objectid_support_spec.rb | 161 | ||||
| -rw-r--r-- | spec/models/referential_spec.rb | 6 | 
11 files changed, 188 insertions, 337 deletions
diff --git a/app/models/chouette/connection_link_type.rb b/app/models/chouette/connection_link_type.rb index ce05c3ec4..516395ed9 100644 --- a/app/models/chouette/connection_link_type.rb +++ b/app/models/chouette/connection_link_type.rb @@ -1,11 +1,26 @@  module Chouette    class ConnectionLinkType < ActiveSupport::StringInquirer -      def initialize(text_code, numerical_code)        super text_code.to_s        @numerical_code = numerical_code      end +    def self.new(text_code, numerical_code = nil) +      if text_code and numerical_code +        super +      elsif self === text_code  +        text_code +      else +        if Fixnum === text_code +          text_code, numerical_code = definitions.rassoc(text_code) +        else +          text_code, numerical_code = definitions.assoc(text_code.to_s) +        end + +        super text_code, numerical_code +      end +    end +      def to_i        @numerical_code      end @@ -18,37 +33,18 @@ module Chouette        camelize      end -    class << self -      attr_reader :definitions -      @definitions = [ -        ["underground", 0], -        ["mixed", 1], -        ["overground", 2] -      ] -      @all = nil - -      def new(text_code, numerical_code = nil) -        if text_code and numerical_code -          super -        elsif self === text_code  -          text_code -        else -          if Fixnum === text_code -            text_code, numerical_code = definitions.rassoc(text_code) -          else -            text_code, numerical_code = definitions.assoc(text_code.to_s) -          end - -          super text_code, numerical_code -        end +    @@definitions = [ +      ["underground", 0], +      ["mixed", 1], +      ["overground", 2] +    ] +    cattr_reader :definitions + +    @@all = nil +    def self.all +      @@all ||= definitions.collect do |text_code, numerical_code| +        new(text_code, numerical_code)        end - -      def all -        @all ||= definitions.collect do |text_code, numerical_code| -          new(text_code, numerical_code) -        end -      end -      end    end  end
\ No newline at end of file diff --git a/app/models/chouette/direction.rb b/app/models/chouette/direction.rb index 13d3b87ce..2d3fea10a 100644 --- a/app/models/chouette/direction.rb +++ b/app/models/chouette/direction.rb @@ -1,11 +1,26 @@  module Chouette    class Direction < ActiveSupport::StringInquirer -      def initialize(text_code, numerical_code)        super text_code.to_s        @numerical_code = numerical_code      end +    def self.new(text_code, numerical_code = nil) +      if text_code and numerical_code +        super +      elsif self === text_code  +        text_code +      else +        if Fixnum === text_code +          text_code, numerical_code = definitions.rassoc(text_code) +        else +          text_code, numerical_code = definitions.assoc(text_code.to_s) +        end + +        super text_code, numerical_code +      end +    end +      def to_i        @numerical_code      end @@ -18,47 +33,27 @@ module Chouette        to_s      end -    class << self -       -      attr_reader :definitions -      @definitions = [ -        ["straight_forward", 0], -        ["backward", 1], -        ["clock_wise", 2], -        ["counter_clock_wise", 3], -        ["north", 4], -        ["north_west", 5], -        ["west", 6], -        ["south_west", 7], -        ["south", 8], -        ["south_east", 9], -        ["east", 10], -        ["north_east", 11] -      ] -      @all = nil - -      def new(text_code, numerical_code = nil) -        if text_code and numerical_code -          super -        elsif self === text_code  -          text_code -        else -          if Fixnum === text_code -            text_code, numerical_code = definitions.rassoc(text_code) -          else -            text_code, numerical_code = definitions.assoc(text_code.to_s) -          end - -          super text_code, numerical_code -        end +    @@definitions = [ +      ["straight_forward", 0], +      ["backward", 1], +      ["clock_wise", 2], +      ["counter_clock_wise", 3], +      ["north", 4], +      ["north_west", 5], +      ["west", 6], +      ["south_west", 7], +      ["south", 8], +      ["south_east", 9], +      ["east", 10], +      ["north_east", 11] +    ] +    cattr_reader :definitions + +    @@all = nil +    def self.all +      @@all ||= definitions.collect do |text_code, numerical_code| +        new(text_code, numerical_code)        end - -      def all -        @all ||= definitions.collect do |text_code, numerical_code| -          new(text_code, numerical_code) -        end -      end -      end    end  end
\ No newline at end of file diff --git a/app/models/chouette/objectid/netex.rb b/app/models/chouette/objectid/netex.rb index 57415ac98..5d27abb1f 100644 --- a/app/models/chouette/objectid/netex.rb +++ b/app/models/chouette/objectid/netex.rb @@ -8,10 +8,10 @@ module Chouette        validate :must_respect_format        def initialize(**attributes) -        @provider_id ||= (attributes[:provider_id] ||= 'chouette') +        @provider_id = attributes[:provider_id] || 'chouette'          @object_type = attributes[:object_type]          @local_id = attributes[:local_id] -        @creation_id = (attributes[:creation_id] ||= 'LOC') +        @creation_id = attributes[:creation_id] || 'LOC'        end        @@format = /^([A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ @@ -22,7 +22,7 @@ module Chouette        end        def must_respect_format -        self.to_s.match(format) +        self.to_s.match(self.class.format)        end        def short_id diff --git a/app/models/chouette/objectid/stif_netex.rb b/app/models/chouette/objectid/stif_netex.rb index 5bff21dbf..19fd42702 100644 --- a/app/models/chouette/objectid/stif_netex.rb +++ b/app/models/chouette/objectid/stif_netex.rb @@ -2,8 +2,10 @@ module Chouette    module Objectid      class StifNetex < Chouette::Objectid::Netex +      @@format = Chouette::Objectid::Netex.format +        def initialize(**attributes) -        @provider_id = (attributes[:provider_id] ||= 'stif') +        @provider_id = attributes[:provider_id] ||= 'stif'          super        end diff --git a/app/models/chouette/objectid_formatter/netex.rb b/app/models/chouette/objectid_formatter/netex.rb index b8a903757..00c539553 100644 --- a/app/models/chouette/objectid_formatter/netex.rb +++ b/app/models/chouette/objectid_formatter/netex.rb @@ -2,7 +2,8 @@ module Chouette    module ObjectidFormatter      class Netex        def before_validation(model) -        model.update(objectid: Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub('Chouette::','')).to_s) +        oid = Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub('Chouette::','')) +        model.update(objectid: oid.to_s) if oid.valid?        end        def after_commit(model) diff --git a/app/models/chouette/objectid_formatter/stif_netex.rb b/app/models/chouette/objectid_formatter/stif_netex.rb index 4678cb337..01ddfc528 100644 --- a/app/models/chouette/objectid_formatter/stif_netex.rb +++ b/app/models/chouette/objectid_formatter/stif_netex.rb @@ -6,7 +6,8 @@ module Chouette        end        def after_commit(model) -        model.update(objectid: Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub('Chouette::',''), local_id: model.local_id).to_s) +        oid = Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub('Chouette::',''), local_id: model.local_id) +        model.update(objectid: oid.to_s) if oid.valid?        end        def get_objectid(definition) diff --git a/spec/models/chouette/object_id_spec.rb b/spec/models/chouette/object_id_spec.rb deleted file mode 100644 index 7ac5fe5ca..000000000 --- a/spec/models/chouette/object_id_spec.rb +++ /dev/null @@ -1,149 +0,0 @@ -# require 'spec_helper' - -# describe Chouette::ObjectId, :type => :model do - -#   def objectid(value = "abc:StopArea:abc123") -#     Chouette::ObjectId.new value -#   end - -#   subject { objectid } - -#   context "when invalid" do - -#     subject { objectid("abc") } - -#     it { is_expected.not_to be_valid } - -#     describe '#parts' do -#       subject { super().parts } -#       it { is_expected.to be_nil } -#     end - -#     describe '#system_id' do -#       subject { super().system_id } -#       it { is_expected.to be_nil } -#     end - -#   end -   -#   context "when with spaces in last part" do - -#     subject { objectid("abc:Line:Aze toto") } - -#     it { is_expected.not_to be_valid } - - -#   end -   -#   context "when with spaces in first part" do - -#     subject { objectid("ae abc:Line:Aze") } - -#     it { is_expected.not_to be_valid } - - -#   end -   -#   context "when with spaces in middle part" do - -#     subject { objectid("aeabc:Li ne:Aze") } - -#     it { is_expected.not_to be_valid } -     - -#   end -   -#   context "when invalid in first part" do - -#     subject { objectid("Abc_+19:Line:Abc") } - -#     it { is_expected.not_to be_valid } -#   end -   -#   context "when invalid in middle part" do - -#     subject { objectid("Abc_19:Li56ne:Abc") } - -#     it { is_expected.not_to be_valid } -#   end - -#   context "when invalid in last part" do - -#     subject { objectid("Abc_19:Line:Ab+c") } - -#     it { is_expected.not_to be_valid } -#   end -#   context "when valid" do - -#     subject { objectid("Abc_19:Line:Abc_12-") } - -#     it { is_expected.to be_valid } -#   end - -#   describe "#parts" do - -#     it "should be the 3 parts of the ObjectId" do -#       expect(objectid("abc:StopArea:abc123").parts).to eq(%w{abc StopArea abc123}) -#     end - -#   end - -#   describe "#system_id" do -     -#     it "should be the first ObjectId parts" do -#       expect(objectid("first:second:third").system_id).to eq("first") -#     end - -#   end - -#   describe "#object_type" do -     -#     it "should be the second ObjectId parts" do -#       expect(objectid("first:second:third").object_type).to eq("second") -#     end - -#   end - -#   describe "#local_id" do -     -#     it "should be the third ObjectId parts" do -#       expect(objectid("first:second:third").local_id).to eq("third") -#     end - -#   end - -#   it "should be valid when parts are found" do -#     allow(subject).to receive_messages :parts => "dummy" -#     expect(subject).to be_valid -#   end - -#   describe ".create" do - -#     let(:given_system_id) { "systemId" } -#     let(:given_object_type) { "objectType" } -#     let(:given_local_id) { "localId" } - -#     subject { Chouette::ObjectId.create(given_system_id, given_object_type, given_local_id) } - -#     it "should return ObjectId attributes" do -#       expect(subject.send(:system_id)).to eq(given_system_id) -#       expect(subject.send(:object_type)).to eq(given_object_type) -#       expect(subject.send(:local_id)).to eq(given_local_id) -#     end - -#   end - -#   describe ".new" do -     -#     it "should return an existing ObjectId" do -#       expect(Chouette::ObjectId.new(objectid)).to eq(objectid) -#     end - -#     it "should create an empty ObjectId with nil" do -#       expect(Chouette::ObjectId.new(nil)).to be_empty -#     end - -#   end - - -# end diff --git a/spec/models/chouette/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb deleted file mode 100644 index 50ca27233..000000000 --- a/spec/models/chouette/trident_active_record_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# require 'spec_helper' - -# describe Chouette::TridentActiveRecord, :type => :model do -#   subject { create(:time_table) } - -#   it { should validate_presence_of :objectid } -#   it { should validate_uniqueness_of :objectid } - -#   describe "#default_values" do -#     let(:object) { build(:time_table, objectid: nil) } - -#     it 'should fill __pending_id__' do -#       object.default_values -#       expect(object.objectid.include?('__pending_id__')).to be_truthy -#     end -#   end - -#   describe "#objectid" do -#     let(:object) { build(:time_table, objectid: nil) } - -#     it 'should build objectid on create' do -#       object.save -#       objectid = object.get_objectid -#       id = "#{objectid.provider_id}:#{objectid.object_type}:#{objectid.local_id}:#{objectid.creation_id}" -#       expect(object.read_attribute(:objectid)).to eq(id) -#     end - -#     it 'should not build new objectid is already set' do -#       id = "first:TimeTable:1-1:LOC" -#       object.objectid = id -#       object.save -#       expect(object.objectid).to eq(id) -#     end - -#     xit 'should call default_values on create' do -#       expect(object).to receive(:default_values) -#       object.save -#     end - -#     xit 'should not call default_values on update' do -#       object = create(:time_table) -#       expect(object).to_not receive(:default_values) -#       object.touch -#     end - -#     it 'should create a new objectid when cleared' do -#       object.save -#       object.objectid = nil -#       object.save -#       expect(object.objectid).to be_truthy -#     end -#   end -# end diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index fce0a5f73..86aa475f0 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -98,9 +98,10 @@ describe Chouette::VehicleJourney, :type => :model do        expect(collection.last['objectid']).not_to be_nil -      Chouette::VehicleJourney.last.run_callbacks(:commit) +      obj = Chouette::VehicleJourney.last +      obj.run_callbacks(:commit) -      expect(Chouette::VehicleJourney.last.published_journey_name).to eq 'dummy' +      expect(obj.published_journey_name).to eq 'dummy'      end      it 'should save vehicle_journey_at_stops of newly created vj' do diff --git a/spec/models/concerns/objectid_support_spec.rb b/spec/models/concerns/objectid_support_spec.rb index 3829b2106..fabeeec11 100644 --- a/spec/models/concerns/objectid_support_spec.rb +++ b/spec/models/concerns/objectid_support_spec.rb @@ -1,85 +1,138 @@  RSpec.describe ObjectidSupport do     context 'when referential has an objectid format of stif_netex' do -    let(:route) { create(:route_with_after_commit, objectid: nil) } +    let(:object) { create(:time_table, objectid: nil) } -    context "#objectid_format" do  +    context "#objectid_format" do        it "should be stif_netex" do -        expect(route.referential.objectid_format).not_to be_nil -        expect(route.referential.objectid_format).to eq('stif_netex') +        expect(object.referential.objectid_format).to eq('stif_netex')        end      end +    it 'should fill __pending_id__' do +      expect(object.objectid.include?('__pending_id__')).to be_truthy +    end +      context "#get_objectid" do -      let(:objectid) { route.get_objectid } + +      before(:each) do +        object.run_callbacks(:commit) +      end +        it "should be valid" do -        expect(objectid).to be_valid +        expect(object.get_objectid).to be_valid        end        it "should have the same local id than the object" do -        expect(objectid.local_id).to eq(route.local_id) +        expect(object.get_objectid.local_id).to eq(object.local_id)        end        it "should be a Chouette::Objectid::StifNetex" do -        expect(objectid).to be_kind_of(Chouette::Objectid::StifNetex) +        expect(object.get_objectid).to be_kind_of(Chouette::Objectid::StifNetex)        end        context "#to_s" do          it "should return a string" do -          expect(objectid.to_s).to be_kind_of(String) +          expect(object.get_objectid.to_s).to be_kind_of(String)          end          it "should be the same as the db attribute" do  -          expect(objectid.to_s).to eq(route.read_attribute(:objectid)) -          expect(objectid.to_s).to eq(route.objectid) +          expect(object.get_objectid.to_s).to eq(object.read_attribute(:objectid)) +          expect(object.get_objectid.to_s).to eq(object.objectid)          end +     +    context "#objectid" do + +      it 'should build objectid on create' do +        object.save +        object.run_callbacks(:commit) +        objectid = object.get_objectid +        id = "#{objectid.provider_id}:#{objectid.object_type}:#{objectid.local_id}:#{objectid.creation_id}" +        expect(object.read_attribute(:objectid)).to eq(id) +      end + +      it 'should not build new objectid is already set' do +        id = "first:TimeTable:1-1:LOC" +        object.attributes = {objectid: id} +        object.save +        expect(object.objectid).to eq(id) +      end + +      it 'should create a new objectid when cleared' do +        object.save +        object.attributes = { objectid: nil} +        object.save +        expect(object.objectid).to be_truthy +      end +    end        end      end    end -  # context 'when referential has an objectid format of netex' do -  #   let(:line) { create(:route_with_after_commit, objectid: nil) } - -  #   before(:all) do  -  #     binding.pry -  #     route.referential.objectid_format = 'netex' -  #   end  - -  #   context "#objectid_format" do  -  #     it "should be netex" do -  #       expect(route.objectid_format).to eq('netex') -  #     end -  #     it "should be the same as the referential" do -  #       expect(route.objectid_format).to eq(route.referential.objectid_format) -  #     end -  #   end - -  #   context "#get_objectid" do -  #     let(:objectid) { route.get_objectid } -  #     it "should be valid" do -  #       expect(objectid).to be_valid -  #     end - -  #     it "should have the same local id than the object" do -  #       expect(objectid.local_id).to eq(route.local_id) -  #     end - -  #     it "should be a Chouette::Objectid::Netex" do -  #       expect(objectid).to be_kind_of(Chouette::Objectid::Netex) -  #     end - -  #     context "#to_s" do -  #       it "should return a string" do -  #         expect(objectid.to_s).to be_kind_of(String) -  #       end - -  #       it "should be the same as the db attribute" do  -  #         expect(objectid.to_s).to eq(route.read_attribute(:objectid)) -  #         expect(objectid.to_s).to eq(route.objectid) -  #       end -  #     end -  #   end -  # end +  context 'when referential has an objectid format of netex' do +    before(:all) do +      Referential.first.update(objectid_format: 'netex') +    end + +    let(:object) { create(:time_table, objectid: nil) } + + +    context "#objectid_format" do  +      it "should be netex" do +        expect(object.referential.objectid_format).to eq('netex') +      end +    end + +    context "#get_objectid" do + +      it "should be valid" do +        expect(object.get_objectid).to be_valid +      end + +      it "should have the same local id than the object" do +        expect(object.get_objectid.local_id).to match(/\w+-\w+-\w+-\w+-\w+/) +      end + +      it "should be a Chouette::Objectid::StifNetex" do +        expect(object.get_objectid).to be_kind_of(Chouette::Objectid::Netex) +      end + +      context "#to_s" do +        it "should return a string" do +          expect(object.get_objectid.to_s).to be_kind_of(String) +        end + +        it "should be the same as the db attribute" do  +          expect(object.get_objectid.to_s).to eq(object.read_attribute(:objectid)) +          expect(object.get_objectid.to_s).to eq(object.objectid) +        end +     +    context "#objectid" do + +      it 'should build objectid on create' do +        object.save +        object.run_callbacks(:commit) +        objectid = object.get_objectid +        id = "#{objectid.provider_id}:#{objectid.object_type}:#{objectid.local_id}:#{objectid.creation_id}" +        expect(object.read_attribute(:objectid)).to eq(id) +      end +      it 'should not build new objectid is already set' do +        id = "first:TimeTable:1-1:LOC" +        object.attributes = {objectid: id} +        object.save +        expect(object.objectid).to eq(id) +      end +      it 'should create a new objectid when cleared' do +        object.save +        object.attributes = { objectid: nil} +        object.save +        expect(object.objectid).to be_truthy +      end +    end +      end +    end +  end +    end
\ No newline at end of file diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index 987eea30a..d0b1d6447 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -12,7 +12,11 @@ describe Referential, :type => :model do    it { should belong_to(:workbench) }    it { should belong_to(:referential_suite) } -  # it { should validate_presence_of(:objectid_format) } +  context "validation" do +    subject { build_stubbed(:referential) } + +    it { should validate_presence_of(:objectid_format) } +  end    context ".referential_ids_in_periode" do      it 'should retrieve referential id in periode range' do  | 
