Class: TestParameters

Inherits:
Faraday::TestCase show all
Defined in:
test/parameters_test.rb

Defined Under Namespace

Classes: FakeSafeBuffer

Instance Method Summary collapse

Methods inherited from Faraday::TestCase

#capture_warnings, jruby?, rbx?, ssl_mode?, #test_default

Methods included from Faraday::LiveServerConfig

#live_server, #live_server=, #live_server?

Instance Method Details

#test_decode_array_flatObject


45
46
47
48
49
# File 'test/parameters_test.rb', line 45

def test_decode_array_flat
  query = "a=one&a=two&a=three"
  expected = {"a" => ["one", "two", "three"]}
  assert_equal expected, Faraday::FlatParamsEncoder.decode(query)
end

#test_decode_array_nestedObject


39
40
41
42
43
# File 'test/parameters_test.rb', line 39

def test_decode_array_nested
  query = "a[1]=one&a[2]=two&a[3]=three"
  expected = {"a" => ["one", "two", "three"]}
  assert_equal expected, Faraday::NestedParamsEncoder.decode(query)
end

#test_encode_nil_flatObject


61
62
63
# File 'test/parameters_test.rb', line 61

def test_encode_nil_flat
  assert_equal "a", Faraday::FlatParamsEncoder.encode("a" => nil)
end

#test_encode_nil_nestedObject


57
58
59
# File 'test/parameters_test.rb', line 57

def test_encode_nil_nested
  assert_equal "a=", Faraday::NestedParamsEncoder.encode("a" => nil)
end

#test_escaping_safe_buffer_flatObject


20
21
22
23
# File 'test/parameters_test.rb', line 20

def test_escaping_safe_buffer_flat
  monies = FakeSafeBuffer.new("$32,000.00")
  assert_equal "a=%2432%2C000.00", Faraday::FlatParamsEncoder.encode("a" => monies)
end

#test_escaping_safe_buffer_nestedObject


15
16
17
18
# File 'test/parameters_test.rb', line 15

def test_escaping_safe_buffer_nested
  monies = FakeSafeBuffer.new("$32,000.00")
  assert_equal "a=%2432%2C000.00", Faraday::NestedParamsEncoder.encode("a" => monies)
end

#test_nested_decode_hashObject


51
52
53
54
55
# File 'test/parameters_test.rb', line 51

def test_nested_decode_hash
  query = "a[b1]=one&a[b2]=two&a[b][c]=foo"
  expected = {"a" => {"b1" => "one", "b2" => "two", "b" => {"c" => "foo"}}}
  assert_equal expected, Faraday::NestedParamsEncoder.decode(query)
end

#test_raises_typeerror_flatObject


32
33
34
35
36
37
# File 'test/parameters_test.rb', line 32

def test_raises_typeerror_flat
  error = assert_raises TypeError do
    Faraday::FlatParamsEncoder.encode("")
  end
  assert_equal "Can't convert String into Hash.", error.message
end

#test_raises_typeerror_nestedObject


25
26
27
28
29
30
# File 'test/parameters_test.rb', line 25

def test_raises_typeerror_nested
  error = assert_raises TypeError do
    Faraday::NestedParamsEncoder.encode("")
  end
  assert_equal "Can't convert String into Hash.", error.message
end