aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorXinhui2016-09-06 14:14:36 +0200
committerXinhui2016-09-06 14:34:55 +0200
commitcce7cea1afb1907f92baef42237e731e16af710c (patch)
tree129f7480387db7aef8744fc93a7744ed3b53498b /spec
parent5bc6a593666127aa09072ad790b0499599235af6 (diff)
downloadchouette-core-cce7cea1afb1907f92baef42237e731e16af710c.tar.bz2
Rspec reflex:sync
Diffstat (limited to 'spec')
-rwxr-xr-x[-rw-r--r--]spec/fixtures/reflex.xml8
-rw-r--r--spec/fixtures/reflex.zipbin236609 -> 2469 bytes
-rwxr-xr-xspec/fixtures/reflex_updated.xml207
-rw-r--r--spec/fixtures/reflex_updated.zipbin0 -> 2469 bytes
-rw-r--r--spec/tasks/reflex_rake_spec.rb65
5 files changed, 261 insertions, 19 deletions
diff --git a/spec/fixtures/reflex.xml b/spec/fixtures/reflex.xml
index c432d6957..1a7f37728 100644..100755
--- a/spec/fixtures/reflex.xml
+++ b/spec/fixtures/reflex.xml
@@ -57,9 +57,6 @@
<Name>Frame NETEX_ARRET_STIF</Name>
<Description>Frame NETEX_ARRET_STIF</Description>
<members modificationSet="all">
-
- <!------------------------------ StopPlace ------------------------------------------->
-
<StopPlace version="777416" created="2014-12-29T03:12:51.0Z" changed="2016-07-26T12:07:19.0Z" id="FR:77153:LDA:69325:STIF">
<Name>First stopPlace</Name>
<placeTypes>
@@ -74,7 +71,6 @@
</AccessibilityAssessment>
<StopPlaceType>onstreetBus</StopPlaceType>
</StopPlace>
-
<StopPlace version="42564" created="2014-12-29T03:12:51.0Z" changed="2014-12-29T03:12:51.0Z" id="FR:77153:ZDL:42564:STIF">
<keyList>
<KeyValue typeOfKey="OBJET_QUALIFIER">
@@ -144,8 +140,6 @@
</AccessibilityAssessment>
<StopPlaceType>onstreetBus</StopPlaceType>
</StopPlace>
-
-
<StopPlace version="779966" created="2014-12-29T03:12:51.0Z" changed="2016-07-28T03:07:56.0Z" id="FR:95277:ZDL:46738:STIF">
<keyList>
<KeyValue typeOfKey="OBJET_QUALIFIER">
@@ -170,7 +164,6 @@
<QuayRef ref="FR:95277:ZDE:38010:STIF" version="777963"/>
</quays>
</StopPlace>
-
<Quay version="783636" created="2014-12-29T03:12:51.0Z" changed="2016-08-05T10:08:59.0Z" id="FR:95277:ZDE:38010:STIF">
<keyList>
<KeyValue typeOfKey="OBJET_QUALIFIER">
@@ -196,7 +189,6 @@
<MobilityImpairedAccess>false</MobilityImpairedAccess>
</AccessibilityAssessment>
</Quay>
-
<Quay version="783636" created="2014-12-29T03:12:51.0Z" changed="2016-08-05T10:08:59.0Z" id="FR:77153:ZDE:38240:STIF">
<keyList>
<KeyValue typeOfKey="OBJET_QUALIFIER">
diff --git a/spec/fixtures/reflex.zip b/spec/fixtures/reflex.zip
index 831278863..7c8858a8f 100644
--- a/spec/fixtures/reflex.zip
+++ b/spec/fixtures/reflex.zip
Binary files differ
diff --git a/spec/fixtures/reflex_updated.xml b/spec/fixtures/reflex_updated.xml
new file mode 100755
index 000000000..e49b84759
--- /dev/null
+++ b/spec/fixtures/reflex_updated.xml
@@ -0,0 +1,207 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<PublicationDelivery xsi:schemaLocation="http://www.netex.org.uk/netex localPathToXSDFileIfNecessary/NeTEx_publication.xsd" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:acsb="http://www.ifopt.org.uk/acsb" xmlns:ifopt="http://www.ifopt.org.uk/ifopt" xmlns:netex="http://www.netex.org.uk/netex" xmlns:siri="http://www.siri.org.uk/siri" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <PublicationTimestamp>2016-08-11T06:00:46.0Z</PublicationTimestamp>
+ <ParticipantRef>SYS001</ParticipantRef>
+ <dataObjects>
+ <CompositeFrame version="1" created="2016-08-11T06:00:46.0Z" id="STIF-REFLEX:CompositeFrame:NETEX_STIF">
+ <frames>
+ <GeneralFrame version="001" id="STIF-REFLEX:TypeOfFrame:NETEX_COMMUN">
+ <Name>Frame NETEX_COMMUN</Name>
+ <Description>Frame NETEX_COMMUN</Description>
+ <members modificationSet="all">
+ <GeneralGroupOfEntities version="657750" created="2015-04-21T10:04:37.0Z" changed="2015-04-21T10:04:37.0Z" id="FR:91479:GDL:415731:STIF">
+ <Name>Aéroport d'Orly</Name>
+ <PurposeOfGroupingRef version="any" ref="NETEX_ARRET_STIF:PurposeOfGrouping:groupOfStopPlace"/>
+ <members>
+ <StopPlaceRef ref="FR:91479:LDA:63284:STIF">version=63284</StopPlaceRef>
+ <StopPlaceRef ref="FR:91479:LDA:63278:STIF">version=63278</StopPlaceRef>
+ </members>
+ </GeneralGroupOfEntities>
+ <GeneralGroupOfEntities version="657753" created="2015-04-21T10:04:57.0Z" changed="2015-04-21T10:04:57.0Z" id="FR:77282:GDL:415732:STIF">
+ <Name>Aéroport Roissy Charles de Gaulle</Name>
+ <PurposeOfGroupingRef version="any" ref="NETEX_ARRET_STIF:PurposeOfGrouping:groupOfStopPlace"/>
+ <members>
+ <StopPlaceRef ref="FR:77282:LDA:69212:STIF">version=69212</StopPlaceRef>
+ <StopPlaceRef ref="FR:93073:LDA:412554:STIF">version=480224</StopPlaceRef>
+ <StopPlaceRef ref="FR:93073:LDA:412553:STIF">version=480203</StopPlaceRef>
+ <StopPlaceRef ref="FR:77291:LDA:73699:STIF">version=654808</StopPlaceRef>
+ <StopPlaceRef ref="FR:null:LDA:412679:STIF">version=483360</StopPlaceRef>
+ <StopPlaceRef ref="FR:95527:LDA:74162:STIF">version=739348</StopPlaceRef>
+ <StopPlaceRef ref="FR:77291:LDA:411293:STIF">version=411628</StopPlaceRef>
+ <StopPlaceRef ref="FR:93073:LDA:73596:STIF">version=73596</StopPlaceRef>
+ <StopPlaceRef ref="FR:93073:LDA:73846:STIF">version=73846</StopPlaceRef>
+ <StopPlaceRef ref="FR:77291:LDA:73845:STIF">version=73845</StopPlaceRef>
+ <StopPlaceRef ref="FR:77291:LDA:73595:STIF">version=73595</StopPlaceRef>
+ </members>
+ </GeneralGroupOfEntities>
+ <GeneralGroupOfEntities version="657747" created="2015-04-21T10:04:27.0Z" changed="2015-04-21T10:04:27.0Z" id="FR:75115:GDL:415730:STIF">
+ <Name>Gare Montparnasse</Name>
+ <PurposeOfGroupingRef version="any" ref="NETEX_ARRET_STIF:PurposeOfGrouping:groupOfStopPlace"/>
+ <members>
+ <StopPlaceRef ref="FR:75115:LDA:71139:STIF">version=657746</StopPlaceRef>
+ </members>
+ </GeneralGroupOfEntities>
+ <ValueSet version="any" id="NETEX_ARRET_STIF:ValueSet:VS01">
+ <values>
+ <PurposeOfGrouping version="any" id="NETEX_ARRET_STIF:PurposeOfGrouping:groupOfStopPlace">
+ <Name>Group of Stop Place</Name>
+ <classes>
+ <ClassRef nameOfClass="StopPlace"/>
+ </classes>
+ </PurposeOfGrouping>
+ </values>
+ </ValueSet>
+ </members>
+ </GeneralFrame>
+ <GeneralFrame version="001" id="STIF-REFLEX:TypeOfFrame:NETEX_ARRET_STIF">
+ <Name>Frame NETEX_ARRET_STIF</Name>
+ <Description>Frame NETEX_ARRET_STIF</Description>
+ <members modificationSet="all">
+ <StopPlace version="777416" created="2014-12-29T03:12:51.0Z" changed="2016-07-26T12:07:19.0Z" id="FR:77153:LDA:69325:STIF">
+ <Name>First stopPlace edited</Name>
+ <placeTypes>
+ <TypeOfPlaceRef ref="LDA"/>
+ </placeTypes>
+ <PostalAddress version="any" id="STIF-REFLEX:PostalAddress:69325">
+ <Town>Dammartin-en-Goële</Town>
+ <PostalRegion>77153</PostalRegion>
+ </PostalAddress>
+ <AccessibilityAssessment version="any" id="STIF-REFLEX:AccessibilityAssessment:69325">
+ <MobilityImpairedAccess>false</MobilityImpairedAccess>
+ </AccessibilityAssessment>
+ <StopPlaceType>onstreetBus</StopPlaceType>
+ </StopPlace>
+ <StopPlace version="42564" created="2014-12-29T03:12:51.0Z" changed="2014-12-29T03:12:51.0Z" id="FR:77153:ZDL:42564:STIF">
+ <keyList>
+ <KeyValue typeOfKey="OBJET_QUALIFIER">
+ <Key>OBJECT_STATUS</Key>
+ <Value>REFERENCE_OBJECT</Value>
+ </KeyValue>
+ </keyList>
+ <Name>First stopPlace children edited</Name>
+ <placeTypes>
+ <TypeOfPlaceRef ref="ZDL"/>
+ </placeTypes>
+ <PostalAddress version="any" id="STIF-REFLEX:PostalAddress:42564">
+ <Town>Dammartin-en-Goële</Town>
+ <PostalRegion>77153</PostalRegion>
+ </PostalAddress>
+ <AccessibilityAssessment version="any" id="STIF-REFLEX:AccessibilityAssessment:42564">
+ <MobilityImpairedAccess>false</MobilityImpairedAccess>
+ </AccessibilityAssessment>
+ <ParentSiteRef ref="FR:77153:LDA:69325:STIF" version="777416"/>
+ <entrances>
+ <StopPlaceEntrance version="174" id="FR:91421:ADL:174:STIF">
+ <Name>Montgeron Crosne - Rue Du Moulin De Senlis</Name>
+ <Centroid>
+ <Location>
+ <gml:pos srsName="EPSG:2154">660491.94 6845481.0</gml:pos>
+ </Location>
+ </Centroid>
+ <PostalAddress version="any" id="STIF-REFLEX:PostalAddress:174">
+ <Town>Montgeron</Town>
+ <PostalRegion>91421</PostalRegion>
+ </PostalAddress>
+ <IsEntry>true</IsEntry>
+ <IsExit>true</IsExit>
+ </StopPlaceEntrance>
+ <StopPlaceEntrance version="173" id="FR:91421:ADL:173:STIF">
+ <Name>Montgeron Crosne - Rue Du Moulin De Senlis</Name>
+ <Centroid>
+ <Location>
+ <gml:pos srsName="EPSG:2154">660324.94 6845590.5</gml:pos>
+ </Location>
+ </Centroid>
+ <PostalAddress version="any" id="STIF-REFLEX:PostalAddress:173">
+ <Town>Montgeron</Town>
+ <PostalRegion>91421</PostalRegion>
+ </PostalAddress>
+ <IsEntry>true</IsEntry>
+ <IsExit>true</IsExit>
+ </StopPlaceEntrance>
+ </entrances>
+ <StopPlaceType>onstreetBus</StopPlaceType>
+ <quays>
+ <QuayRef ref="FR:77153:ZDE:38240:STIF" version="782150"/>
+ </quays>
+ </StopPlace>
+ <StopPlace version="779966" created="2014-12-29T03:12:51.0Z" changed="2016-07-28T03:07:56.0Z" id="FR:95277:ZDL:46738:STIF">
+ <keyList>
+ <KeyValue typeOfKey="OBJET_QUALIFIER">
+ <Key>OBJECT_STATUS</Key>
+ <Value>REFERENCE_OBJECT</Value>
+ </KeyValue>
+ </keyList>
+ <Name>Second StopPlace children</Name>
+ <placeTypes>
+ <TypeOfPlaceRef ref="ZDL"/>
+ </placeTypes>
+ <PostalAddress version="any" id="STIF-REFLEX:PostalAddress:46738">
+ <Town>Gonesse</Town>
+ <PostalRegion>95277</PostalRegion>
+ </PostalAddress>
+ <AccessibilityAssessment version="any" id="STIF-REFLEX:AccessibilityAssessment:46738">
+ <MobilityImpairedAccess>false</MobilityImpairedAccess>
+ </AccessibilityAssessment>
+ <ParentSiteRef ref="FR:95277:LDA:65926:STIF" version="779971"/>
+ <StopPlaceType>onstreetBus</StopPlaceType>
+ <quays>
+ <QuayRef ref="FR:95277:ZDE:38010:STIF" version="777963"/>
+ </quays>
+ </StopPlace>
+ <Quay version="783636" created="2014-12-29T03:12:51.0Z" changed="2016-08-05T10:08:59.0Z" id="FR:95277:ZDE:38010:STIF">
+ <keyList>
+ <KeyValue typeOfKey="OBJET_QUALIFIER">
+ <Key>OBJECT_STATUS</Key>
+ <Value>REFERENCE_OBJECT</Value>
+ </KeyValue>
+ <KeyValue typeOfKey="OBJET_QUALIFIER">
+ <Key>LINE_ID</Key>
+ <Value>002002003</Value>
+ </KeyValue>
+ </keyList>
+ <Name>Quay of Second StopPlace children</Name>
+ <Centroid>
+ <Location>
+ <gml:pos srsName="EPSG:2154">657252.0 6847664.0</gml:pos>
+ </Location>
+ </Centroid>
+ <PostalAddress version="any" id="STIF-REFLEX:PostalAddress:21634">
+ <Town>Ablon-sur-Seine</Town>
+ <PostalRegion>94001</PostalRegion>
+ </PostalAddress>
+ <AccessibilityAssessment version="any" id="STIF-REFLEX:AccessibilityAssessment:21634">
+ <MobilityImpairedAccess>false</MobilityImpairedAccess>
+ </AccessibilityAssessment>
+ </Quay>
+ <Quay version="783636" created="2014-12-29T03:12:51.0Z" changed="2016-08-05T10:08:59.0Z" id="FR:77153:ZDE:38240:STIF">
+ <keyList>
+ <KeyValue typeOfKey="OBJET_QUALIFIER">
+ <Key>OBJECT_STATUS</Key>
+ <Value>REFERENCE_OBJECT</Value>
+ </KeyValue>
+ <KeyValue typeOfKey="OBJET_QUALIFIER">
+ <Key>LINE_ID</Key>
+ <Value>002002003</Value>
+ </KeyValue>
+ </keyList>
+ <Name>Quay of First stopPlace children</Name>
+ <Centroid>
+ <Location>
+ <gml:pos srsName="EPSG:2154">657252.0 6847664.0</gml:pos>
+ </Location>
+ </Centroid>
+ <PostalAddress version="any" id="STIF-REFLEX:PostalAddress:21634">
+ <Town>Ablon-sur-Seine</Town>
+ <PostalRegion>94001</PostalRegion>
+ </PostalAddress>
+ <AccessibilityAssessment version="any" id="STIF-REFLEX:AccessibilityAssessment:21634">
+ <MobilityImpairedAccess>false</MobilityImpairedAccess>
+ </AccessibilityAssessment>
+ </Quay>
+ </members>
+ </GeneralFrame>
+ </frames>
+ </CompositeFrame>
+ </dataObjects>
+</PublicationDelivery>
diff --git a/spec/fixtures/reflex_updated.zip b/spec/fixtures/reflex_updated.zip
new file mode 100644
index 000000000..772327c4d
--- /dev/null
+++ b/spec/fixtures/reflex_updated.zip
Binary files differ
diff --git a/spec/tasks/reflex_rake_spec.rb b/spec/tasks/reflex_rake_spec.rb
index f49eb41ec..bf1a81a82 100644
--- a/spec/tasks/reflex_rake_spec.rb
+++ b/spec/tasks/reflex_rake_spec.rb
@@ -1,18 +1,61 @@
require 'spec_helper'
describe 'reflex:sync' do
- before(:all) do
- ['getOP', 'getOR'].each do |method|
- stub_request(:get, "https://reflex.stif.info/ws/reflex/V1/service=getData/?format=xml&idRefa=0&method=#{method}").
- to_return(body: File.open("#{fixture_path}/reflex.zip"), status: 200)
+ context 'On first sync' do
+ before(:each) do
+ ['getOP', 'getOR'].each do |method|
+ stub_request(:get, "https://reflex.stif.info/ws/reflex/V1/service=getData/?format=xml&idRefa=0&method=#{method}").
+ to_return(body: File.open("#{fixture_path}/reflex.zip"), status: 200)
+ end
+ create(:stop_area_referential, name: 'Reflex')
+ Stif::ReflexSynchronization.synchronize
+ end
+
+ it 'should create stopArea on successfull request' do
+ expect(Chouette::StopArea.count).to eq 6
+ expect(Chouette::AccessPoint.count).to eq 2
+ end
+
+ it 'should convert StopPlaceEntrance to AccessPoint' do
+ access = Chouette::AccessPoint.find_by(name: 'Montgeron Crosne - Rue Du Moulin De Senlis')
+ expect(access.stop_area.name).to eq 'First stopPlace children'
+ end
+
+ it 'should save hierarchy' do
+ stop_area = Chouette::StopArea.find_by(name: 'First stopPlace children')
+ expect(stop_area.parent.name).to eq 'First stopPlace'
end
- end
- it 'should create stopArea on successfull request' do
- # Must have an stop_area_referential
- create(:stop_area_referential, name: 'Reflex')
- Stif::ReflexSynchronization.synchronize
- expect(Chouette::StopArea.count).to eq 4309
- expect(Chouette::AccessPoint.count).to eq 49
+ it 'should map xml data to StopArea attribute' do
+ stop_area = Chouette::StopArea.find_by(name: 'First stopPlace')
+ expect(stop_area.city_name).to eq 'Dammartin-en-Goële'
+ expect(stop_area.zip_code).to eq '77153'
+ expect(stop_area.area_type).to eq 'StopPlace'
+ end
+
+ context 'On next sync' do
+ before(:each) do
+ ['getOP', 'getOR'].each do |method|
+ stub_request(:get, "https://reflex.stif.info/ws/reflex/V1/service=getData/?format=xml&idRefa=0&method=#{method}").
+ to_return(body: File.open("#{fixture_path}/reflex_updated.zip"), status: 200)
+ end
+ Stif::ReflexSynchronization.synchronize
+ end
+
+ it 'should not create duplicate stop_area' do
+ expect(Chouette::StopArea.count).to eq 6
+ expect(Chouette::AccessPoint.count).to eq 2
+ end
+
+ it 'should flag deleted_at for missing element from last sync' do
+ stop_area = Chouette::StopArea.find_by(name: 'Second StopPlace')
+ expect(stop_area.deleted_at).to be_within(1.minute).of(Time.now)
+ end
+
+ it 'should update existing stop_area' do
+ expect(Chouette::StopArea.where(name: 'First stopPlace edited')).to exist
+ expect(Chouette::StopArea.where(name: 'First stopPlace children edited')).to exist
+ end
+ end
end
end