summaryrefslogtreecommitdiff
path: root/test/unit/adapters/celluloid_http_test.rb
blob: 68b9606e6dd2ecc1028aaed5498e3bfe0e83b8a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'test_helper'
require 'nickserver/adapters/celluloid_http'

class Nickserver::Adapters::CelluloidHttpTest < Minitest::Test

  def setup
    super
    Celluloid.boot
  end

  def teardown
    Celluloid.shutdown
    super
  end

  def test_request_without_query
    url = 'http://url.to'
    stub_http_request(:get, url)
      .to_return status: 200, body: 'body'
    status, body = adapter.get url
    assert_equal 200, status
    assert_equal 'body', body
  end

  def test_successful_request_with_query
    url = 'http://url.to'
    stub_http_request(:get, url)
      .with(query: {key: :value})
      .to_return status: 200, body: 'body'
    status, body = adapter.get(url, query: {key: :value})
    assert_equal 200, status
    assert_equal 'body', body
  end

  def test_https_for_hkp
    url = Nickserver::Config.hkp_url
    real_network do
      status, _body = adapter.get url
      assert_equal 404, status
    end
  end

  protected

  def adapter
    @adapter ||= Nickserver::Adapters::CelluloidHttp.new
  end
end