Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #151 from nevesenin/master

Strip the accept header value.
  • Loading branch information...
commit 602fac5060529d38c8a21db2bf6c8b4a16894d1b 2 parents e85e9ea + d9ca104
Rob Nichols reggieb authored
Showing with 40 additions and 1 deletion.
  1. +1 −1  lib/geminabox/server.rb
  2. +39 −0 test/requests/is_api_request_test.rb
2  lib/geminabox/server.rb
View
@@ -155,7 +155,7 @@ def handle_incoming_gem(gem)
end
def api_request?
- request.accept.first != "text/html"
+ request.accept.first.to_s != "text/html"
end
def error_response(code, message)
39 test/requests/is_api_request_test.rb
View
@@ -0,0 +1,39 @@
+require 'test_helper'
+require 'minitest/unit'
+require 'rack/test'
+
+class IsApiRequestTest < Minitest::Test
+ include Rack::Test::Methods
+
+ def setup
+ clean_data_dir
+
+ silence do
+ Gem::Indexer.new(Geminabox.data).generate_index
+ end
+ end
+
+ def app
+ Geminabox::Server
+ end
+
+ test "test upload via web interface" do
+ filename = GemFactory.gem_file(:example)
+ header "Accept", "text/html"
+ post '/upload', { file: Rack::Test::UploadedFile.new(filename, 'application/octet-stream', true) }
+
+ follow_redirect!
+
+ assert last_response.ok?
+ assert_match(/<h1>Gem in a Box<\/h1>/, last_response.body)
+ end
+
+ test "test upload via api" do
+ filename = GemFactory.gem_file(:example)
+ header "Accept", "text/plain"
+ post '/upload', { file: Rack::Test::UploadedFile.new(filename, 'application/octet-stream', true) }
+
+ assert last_response.ok?
+ assert_match(/Gem .* received and indexed\./, last_response.body)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.