|
| 1 | +# typed: false |
| 2 | +# frozen_string_literal: true |
| 3 | + |
| 4 | +require "download_strategy" |
| 5 | + |
| 6 | +RSpec.describe AbstractFileDownloadStrategy do |
| 7 | + subject(:strategy) { Class.new(described_class).new(url, "foo", "1.2.3") } |
| 8 | + |
| 9 | + let(:url) { "https://example.com/foo.tar.gz" } |
| 10 | + |
| 11 | + describe "#parse_basename" do |
| 12 | + it "returns the final path segment for simple URLs" do |
| 13 | + expect(strategy.send(:parse_basename, "https://example.com/foo.tar.gz")).to eq("foo.tar.gz") |
| 14 | + end |
| 15 | + |
| 16 | + it "prefers a path segment with an extension over later extensionless segments" do |
| 17 | + expect(strategy.send(:parse_basename, "https://example.com/foo-1.0.tar.gz/download")).to eq("foo-1.0.tar.gz") |
| 18 | + end |
| 19 | + |
| 20 | + it "extracts the basename from a response-content-disposition query parameter" do |
| 21 | + url = "https://example.com/download.php?file=ignored&response-content-disposition=attachment;filename=\"real.tar.gz\"" |
| 22 | + expect(strategy.send(:parse_basename, url)).to eq("real.tar.gz") |
| 23 | + end |
| 24 | + |
| 25 | + it "uses the query value when the path has no extension" do |
| 26 | + url = "https://example.com/download.php?file=foo-1.0.tar.gz" |
| 27 | + expect(strategy.send(:parse_basename, url)).to eq("foo-1.0.tar.gz") |
| 28 | + end |
| 29 | + |
| 30 | + it "returns the final segment for file:// URLs even when an ancestor directory contains a dot" do |
| 31 | + expect(strategy.send(:parse_basename, "file:///Users/me/git-repos/github.com/Homebrew/brew/naked_executable")) |
| 32 | + .to eq("naked_executable") |
| 33 | + end |
| 34 | + |
| 35 | + it "returns the final segment for file:// URLs with an extension" do |
| 36 | + expect(strategy.send(:parse_basename, "file:///tmp/foo.tar.gz")).to eq("foo.tar.gz") |
| 37 | + end |
| 38 | + end |
| 39 | +end |
0 commit comments