Skip to content

Commit

Permalink
Improve handling of query string when uploading from URL
Browse files Browse the repository at this point in the history
Closes refile#243
  • Loading branch information
Jonas Nicklas and Kim Burgestrand committed May 26, 2015
1 parent 56911b0 commit 6e4ee22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/refile/attacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def download(url)
response = RestClient::Request.new(method: :get, url: url, raw_response: true).execute
@metadata = {
size: response.file.size,
filename: ::File.basename(url),
filename: URI.parse(url).path.split("/").last,
content_type: response.headers[:content_type]
}
if valid?
Expand Down
8 changes: 5 additions & 3 deletions spec/refile/features/normal_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@
end

scenario "Upload a file from a remote URL" do
stub_request(:get, "http://www.example.com/some_file").to_return(
url = "http://www.example.com/foo/bar/some_file.png?some-query-string=true"

stub_request(:get, url).to_return(
status: 200,
body: "abc",
headers: {
Expand All @@ -130,13 +132,13 @@

visit "/normal/posts/new"
fill_in "Title", with: "A cool post"
fill_in "Remote document url", with: "http://www.example.com/some_file"
fill_in "Remote document url", with: url
click_button "Create"

expect(page).to have_selector("h1", text: "A cool post")
expect(download_link("Document")).to eq("abc")
expect(page).to have_selector(".content-type", text: "image/png")
expect(page).to have_selector(".size", text: "3")
expect(page).to have_selector(".filename", text: "some_file")
expect(page).to have_selector(".filename", text: "some_file.png", exact: true)
end
end

0 comments on commit 6e4ee22

Please sign in to comment.