Skip to content

Commit

Permalink
Merge pull request #1197 from transitland/gtfs-auto-detect-root
Browse files Browse the repository at this point in the history
Add auto_detect_root to GTFS open
  • Loading branch information
irees authored Oct 3, 2017
2 parents 8206f14 + ef555d1 commit f2e806e
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/feed_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def open_gtfs
gtfs = GTFS::Source.build(
filename,
strict: false,
auto_detect_root: true,
tmpdir_basepath: Figaro.env.gtfs_tmpdir_basepath.presence
)
file.remove_any_local_cached_copies
Expand Down
1 change: 1 addition & 0 deletions app/services/feed_fetcher_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def self.fetch_gtfs(url: nil, file: nil, ssl_verify: nil)
GTFS::Source.build(
file || url,
strict: false,
auto_detect_root: true,
ssl_verify: ssl_verify,
tmpdir_basepath: Figaro.env.gtfs_tmpdir_basepath.presence
)
Expand Down
1 change: 1 addition & 0 deletions app/services/feed_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def open
@gtfs ||= GTFS::Source.build(
@source || @url,
strict: false,
auto_detect_root: true,
tmpdir_basepath: Figaro.env.gtfs_tmpdir_basepath.presence
)
yield self
Expand Down
1 change: 1 addition & 0 deletions app/workers/feed_info_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def perform(url, cachekey)
progress_download: progress_download,
progress_graph: progress_graph,
strict: false,
auto_detect_root: true,
tmpdir_basepath: Figaro.env.gtfs_tmpdir_basepath.presence
)
feed_info = FeedInfo.new(url: @url, gtfs: gtfs)
Expand Down
26 changes: 26 additions & 0 deletions spec/services/feed_fetcher_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
let (:example_url) { 'http://localhost:8000/example.zip' }
let (:example_nested_flat) { 'http://localhost:8000/example_nested.zip#example_nested/example' }
let (:example_nested_zip) { 'http://localhost:8000/example_nested.zip#example_nested/nested/example.zip' }
let (:example_nested_unambiguous){'http://localhost:8000/example_nested_unambiguous.zip' }
let (:example_nested_ambiguous) { 'http://localhost:8000/example_nested_ambiguous.zip' }


let (:example_sha1_raw) { '2a7503435dcedeec8e61c2e705f6098e560e6bc6' }
let (:example_nested_sha1_raw) { '65d278fdd3f5a9fae775a283ef6ca2cb7b961add' }

Expand Down Expand Up @@ -226,6 +230,28 @@
expect(feed_version.fetched_at).to be_truthy
end

it 'auto_detect_root unambiguous' do
# Note: when root is auto-detected, a raw file is not created.
feed = create(:feed, url: example_nested_unambiguous)
feed_version = nil
VCR.use_cassette('example_nested_unambiguous') do
feed_version = FeedFetcherService.fetch_normalize_validate_create(feed, url: feed.url)
feed_version.save!
end
expect(feed_version.sha1).to eq('ab14bc8689f27acbb9d0e3a0dbf7006da96734bc')
expect(feed_version.sha1_raw).to be_nil
end

it 'auto_detect_root ambiguous' do
feed = create(:feed, url: example_nested_ambiguous)
expect {
VCR.use_cassette('example_nested_ambiguous') do
feed_version = FeedFetcherService.fetch_normalize_validate_create(feed, url: feed.url)
feed_version.save!
end
}.to raise_error(GTFS::AmbiguousZipException)
end

it 'normalizes consistent sha1' do
feed = create(:feed, url: example_nested_flat)
feed_version = nil
Expand Down
Binary file not shown.
Binary file not shown.
231 changes: 231 additions & 0 deletions spec/support/vcr_cassettes/example_nested_ambiguous.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f2e806e

Please sign in to comment.