diff options
Diffstat (limited to 'spec/tasks')
| -rw-r--r-- | spec/tasks/reflex_rake_spec.rb | 65 |
1 files changed, 54 insertions, 11 deletions
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 |
