|
| 1 | +require File.dirname(__FILE__) + '/../../test_helper.rb' |
| 2 | +require "drip/client/configuration" |
| 3 | + |
| 4 | +class Drip::Client::ConfigurationTest < Drip::TestCase |
| 5 | + context "#initializer" do |
| 6 | + context "with reasonable parameters" do |
| 7 | + should "accept parameters" do |
| 8 | + config = Drip::Client::Configuration.new(access_token: "123") |
| 9 | + assert_equal "123", config.access_token |
| 10 | + end |
| 11 | + end |
| 12 | + |
| 13 | + context "with one additional parameter" do |
| 14 | + should "raise singular error" do |
| 15 | + err = assert_raises(ArgumentError) { Drip::Client::Configuration.new(blahdeblah: "123") } |
| 16 | + assert_equal "unknown keyword: blahdeblah", err.message |
| 17 | + end |
| 18 | + |
| 19 | + should "match core ruby behavior" do |
| 20 | + def test_method(hello: "test"); end |
| 21 | + err = assert_raises(ArgumentError) { test_method(blahdeblah: "123") } |
| 22 | + assert_equal "unknown keyword: blahdeblah", err.message |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + context "with multiple additional parameters" do |
| 27 | + should "raise plural error" do |
| 28 | + err = assert_raises(ArgumentError) { Drip::Client::Configuration.new(blahdeblah: "123", blahdeblah1: "123") } |
| 29 | + assert_equal "unknown keywords: blahdeblah, blahdeblah1", err.message |
| 30 | + end |
| 31 | + |
| 32 | + should "match core ruby behavior" do |
| 33 | + def test_method(hello: "test"); end |
| 34 | + err = assert_raises(ArgumentError) { test_method(blahdeblah: "123", blahdeblah1: "123") } |
| 35 | + assert_equal "unknown keywords: blahdeblah, blahdeblah1", err.message |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + context "#url_prefix" do |
| 41 | + should "have default url prefix" do |
| 42 | + config = Drip::Client::Configuration.new |
| 43 | + assert_equal "https://api.getdrip.com/", config.url_prefix |
| 44 | + end |
| 45 | + |
| 46 | + should "accept passed parameter" do |
| 47 | + config = Drip::Client::Configuration.new(url_prefix: "https://www.example.com/") |
| 48 | + assert_equal "https://www.example.com/", config.url_prefix |
| 49 | + end |
| 50 | + |
| 51 | + should "allow setter" do |
| 52 | + config = Drip::Client::Configuration.new |
| 53 | + config.url_prefix = "https://www.example.com/" |
| 54 | + assert_equal "https://www.example.com/", config.url_prefix |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + context "#access_token" do |
| 59 | + should "accept passed parameter" do |
| 60 | + config = Drip::Client::Configuration.new(access_token: "blah") |
| 61 | + assert_equal "blah", config.access_token |
| 62 | + end |
| 63 | + |
| 64 | + should "allow setter" do |
| 65 | + config = Drip::Client::Configuration.new |
| 66 | + config.access_token = "blah" |
| 67 | + assert_equal "blah", config.access_token |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | + context "#api_key" do |
| 72 | + should "accept passed parameter" do |
| 73 | + config = Drip::Client::Configuration.new(api_key: "blah") |
| 74 | + assert_equal "blah", config.api_key |
| 75 | + end |
| 76 | + |
| 77 | + should "allow setter" do |
| 78 | + config = Drip::Client::Configuration.new |
| 79 | + config.api_key = "blah" |
| 80 | + assert_equal "blah", config.api_key |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + context "#account_id" do |
| 85 | + should "accept passed parameter" do |
| 86 | + config = Drip::Client::Configuration.new(account_id: "1234567") |
| 87 | + assert_equal "1234567", config.account_id |
| 88 | + end |
| 89 | + |
| 90 | + should "allow setter" do |
| 91 | + config = Drip::Client::Configuration.new |
| 92 | + config.account_id = "1234567" |
| 93 | + assert_equal "1234567", config.account_id |
| 94 | + end |
| 95 | + end |
| 96 | + |
| 97 | + context "#http_open_timeout" do |
| 98 | + should "accept passed parameter" do |
| 99 | + config = Drip::Client::Configuration.new(http_open_timeout: 12) |
| 100 | + assert_equal 12, config.http_open_timeout |
| 101 | + end |
| 102 | + |
| 103 | + should "allow setter" do |
| 104 | + config = Drip::Client::Configuration.new |
| 105 | + config.http_open_timeout = 12 |
| 106 | + assert_equal 12, config.http_open_timeout |
| 107 | + end |
| 108 | + end |
| 109 | + |
| 110 | + context "#http_timeout" do |
| 111 | + should "accept passed parameter" do |
| 112 | + config = Drip::Client::Configuration.new(http_timeout: 42) |
| 113 | + assert_equal 42, config.http_timeout |
| 114 | + end |
| 115 | + |
| 116 | + should "allow setter" do |
| 117 | + config = Drip::Client::Configuration.new |
| 118 | + config.http_timeout = 42 |
| 119 | + assert_equal 42, config.http_timeout |
| 120 | + end |
| 121 | + end |
| 122 | +end |
0 commit comments