Class: TestRequestParams
Instance Method Summary
collapse
#capture_warnings, jruby?, rbx?, ssl_mode?, #test_default
#live_server, #live_server=, #live_server?
Instance Method Details
#assert_query_equal(expected, query) ⇒ Object
415
416
417
|
# File 'test/connection_test.rb', line 415
def assert_query_equal(expected, query)
assert_equal expected, query.split('&').sort
end
|
#create_connection(*args) ⇒ Object
405
406
407
408
409
410
411
412
413
|
# File 'test/connection_test.rb', line 405
def create_connection(*args)
@conn = Faraday::Connection.new(*args) do |conn|
yield(conn) if block_given?
class << conn.builder
undef app
def app() lambda { |env| env } end
end
end
end
|
#get(*args) ⇒ Object
516
517
518
519
520
521
|
# File 'test/connection_test.rb', line 516
def get(*args)
env = @conn.get(*args) do |req|
yield(req) if block_given?
end
env[:url].query
end
|
#test_all_overrides_connection_params ⇒ Object
443
444
445
446
447
448
|
# File 'test/connection_test.rb', line 443
def test_all_overrides_connection_params
create_connection 'http://a.co/?a=a', :params => {:c => 'c'} do |conn|
conn.params = {'b' => 'b'}
end
assert_query_equal %w[b=b], get
end
|
#test_array_params_in_params ⇒ Object
492
493
494
495
496
497
498
|
# File 'test/connection_test.rb', line 492
def test_array_params_in_params
with_default_params_encoder(nil) do
create_connection 'http://a.co/page1', :params => {:color => ['red', 'blue']}
query = get
assert_equal "color%5B%5D=red&color%5B%5D=blue", query
end
end
|
#test_array_params_in_params_with_flat_params ⇒ Object
508
509
510
511
512
513
514
|
# File 'test/connection_test.rb', line 508
def test_array_params_in_params_with_flat_params
with_default_params_encoder(Faraday::FlatParamsEncoder) do
create_connection 'http://a.co/page1', :params => {:color => ['red', 'blue']}
query = get
assert_equal "color=red&color=blue", query
end
end
|
#test_array_params_in_url ⇒ Object
484
485
486
487
488
489
490
|
# File 'test/connection_test.rb', line 484
def test_array_params_in_url
with_default_params_encoder(nil) do
create_connection 'http://a.co/page1?color[]=red&color[]=blue'
query = get
assert_equal "color%5B%5D=red&color%5B%5D=blue", query
end
end
|
#test_array_params_in_url_with_flat_params ⇒ Object
500
501
502
503
504
505
506
|
# File 'test/connection_test.rb', line 500
def test_array_params_in_url_with_flat_params
with_default_params_encoder(Faraday::FlatParamsEncoder) do
create_connection 'http://a.co/page1?color=red&color=blue'
query = get
assert_equal "color=red&color=blue", query
end
end
|
#test_merges_connection_and_request_params ⇒ Object
429
430
431
432
433
|
# File 'test/connection_test.rb', line 429
def test_merges_connection_and_request_params
create_connection 'http://a.co/?token=abc', :params => {'format' => 'json'}
query = get '?page=1', :limit => 5
assert_query_equal %w[format=json limit=5 page=1 token=abc], query
end
|
#test_overrides_all_request_params ⇒ Object
472
473
474
475
476
477
478
479
480
481
482
|
# File 'test/connection_test.rb', line 472
def test_overrides_all_request_params
create_connection :params => {:c => 'c'}
query = get '?p=1&a=a', :p => 2 do |req|
assert_equal 'a', req.params[:a]
assert_equal 'c', req.params['c']
assert_equal 2, req.params['p']
req.params = {:b => 'b'}
assert_equal 'b', req.params['b']
end
assert_query_equal %w[b=b], query
end
|
#test_overrides_connection_params ⇒ Object
435
436
437
438
439
440
441
|
# File 'test/connection_test.rb', line 435
def test_overrides_connection_params
create_connection 'http://a.co/?a=a&b=b&c=c', :params => {:a => 'A'} do |conn|
conn.params[:b] = 'B'
assert_equal 'c', conn.params[:c]
end
assert_query_equal %w[a=A b=B c=c], get
end
|
#test_overrides_request_params ⇒ Object
450
451
452
453
454
|
# File 'test/connection_test.rb', line 450
def test_overrides_request_params
create_connection
query = get '?p=1&a=a', :p => 2
assert_query_equal %w[a=a p=2], query
end
|
#test_overrides_request_params_block ⇒ Object
456
457
458
459
460
461
462
|
# File 'test/connection_test.rb', line 456
def test_overrides_request_params_block
create_connection
query = get '?p=1&a=a', :p => 2 do |req|
req.params[:p] = 3
end
assert_query_equal %w[a=a p=3], query
end
|
#test_overrides_request_params_block_url ⇒ Object
464
465
466
467
468
469
470
|
# File 'test/connection_test.rb', line 464
def test_overrides_request_params_block_url
create_connection
query = get nil, :p => 2 do |req|
req.url '?p=1&a=a', 'p' => 3
end
assert_query_equal %w[a=a p=3], query
end
|
#with_default_params_encoder(encoder) ⇒ Object