<commit_before>describe FeedInfo do
  let (:example_url) { 'https://developers.google.com/transit/gtfs/examples/sample-feed.zip' }
  let (:example_feed_path) { Rails.root.join('spec/support/example_gtfs_archives/example.zip') }

  context '.new' do
    it 'requires url or path' do
      expect { FeedInfo.new }.to raise_error(ArgumentError)
    end
  end

  context '.open' do
    it 'downloads if path not provided' do
      VCR.use_cassette('feed_fetch_example') do
        expect { FeedInfo.new(url: example_url).open { |f| f } }.not_to raise_error
      end
    end

    # SocketError is below where VCR can test. Disabled for now.
    # it 'fails with bad host' do
    #   url = 'http://test.example.com/gtfs.zip'
    #   expect { FeedInfo.new(url: url).open { |f| f } }.to raise_error(SocketError)
    # end

    it 'raises exception on bad gtfs' do
      url_binary = 'http://httpbin.org/stream-bytes/1024?seed=0'
      VCR.use_cassette('feed_fetch_download_binary') do
        expect { FeedInfo.new(url: url_binary).open { |f| f } }.to raise_error(GTFS::InvalidSourceException)
      end
    end
  end

  context '.parse' do
    it 'parses feed' do
      feed, operators = nil, nil
      fi = FeedInfo.new(url: example_url, path: example_feed_path)
      fi.open do |feed_info|
        feed, operators = feed_info.parse_feed_and_operators
      end
      expect(feed.onestop_id).to eq('f-9qs-example')
      expect(feed.url).to eq(example_url)
      expect(feed.geometry).to be_truthy
      expect(feed.operators_in_feed.size).to eq(1)
      expect(feed.operators_in_feed.first.gtfs_agency_id).to eq('DTA')
      expect(feed.operators_in_feed.first.operator.onestop_id).to eq('o-9qs-demotransitauthority')
    end

    end

    it 'parses operators' do
      feed, operators = nil, nil
      fi = FeedInfo.new(url: example_url, path: example_feed_path)
      fi.open do |feed_info|
        feed, operators = feed_info.parse_feed_and_operators
      end
      expect(operators.size).to eq(1)
      operator = operators.first
      expect(operator.onestop_id).to eq('o-9qs-demotransitauthority')
      expect(operator.website).to eq('http://google.com')
      expect(operator.timezone).to eq('America/Los_Angeles')
      expect(operator.geometry).to be_truthy
    end
  end
end
<commit_msg>Check feed_info feed_id makes it into Feed Onestop ID<commit_after>describe FeedInfo do
  let (:example_url) { 'https://developers.google.com/transit/gtfs/examples/sample-feed.zip' }
  let (:example_feed_path) { Rails.root.join('spec/support/example_gtfs_archives/example.zip') }

  context '.new' do
    it 'requires url or path' do
      expect { FeedInfo.new }.to raise_error(ArgumentError)
    end
  end

  context '.open' do
    it 'downloads if path not provided' do
      VCR.use_cassette('feed_fetch_example') do
        expect { FeedInfo.new(url: example_url).open { |f| f } }.not_to raise_error
      end
    end

    # SocketError is below where VCR can test. Disabled for now.
    # it 'fails with bad host' do
    #   url = 'http://test.example.com/gtfs.zip'
    #   expect { FeedInfo.new(url: url).open { |f| f } }.to raise_error(SocketError)
    # end

    it 'raises exception on bad gtfs' do
      url_binary = 'http://httpbin.org/stream-bytes/1024?seed=0'
      VCR.use_cassette('feed_fetch_download_binary') do
        expect { FeedInfo.new(url: url_binary).open { |f| f } }.to raise_error(GTFS::InvalidSourceException)
      end
    end
  end

  context '.parse' do
    it 'parses feed' do
      feed, operators = nil, nil
      fi = FeedInfo.new(url: example_url, path: example_feed_path)
      fi.open do |feed_info|
        feed, operators = feed_info.parse_feed_and_operators
      end
      expect(feed.onestop_id).to eq('f-9qs-example')
      expect(feed.url).to eq(example_url)
      expect(feed.geometry).to be_truthy
      expect(feed.operators_in_feed.size).to eq(1)
      expect(feed.operators_in_feed.first.gtfs_agency_id).to eq('DTA')
      expect(feed.operators_in_feed.first.operator.onestop_id).to eq('o-9qs-demotransitauthority')
    end

    it 'uses feed_info feed_id' do
      feed, operators = nil, nil
      fi = FeedInfo.new(url: example_url, path: example_feed_path)
      fi.open do |feed_info|
        feed, operators = feed_info.parse_feed_and_operators
      end
      expect(feed.onestop_id).to eq('f-9qs-example')
    end

    it 'parses operators' do
      feed, operators = nil, nil
      fi = FeedInfo.new(url: example_url, path: example_feed_path)
      fi.open do |feed_info|
        feed, operators = feed_info.parse_feed_and_operators
      end
      expect(operators.size).to eq(1)
      operator = operators.first
      expect(operator.onestop_id).to eq('o-9qs-demotransitauthority')
      expect(operator.website).to eq('http://google.com')
      expect(operator.timezone).to eq('America/Los_Angeles')
      expect(operator.geometry).to be_truthy
    end
  end
end

{'fraction_non_alphanumeric': 0.11499390491670053, 'fraction_numerical': 0.004266558309630231, 'mean_word_length': 3.0753311258278146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '498514', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1683, 'n_words': 359}