blob: bf1a81a820a91288c51deff79358749b9f4a3f0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
require 'spec_helper'
describe 'reflex:sync' do
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
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
|