From 7723e374b40e0345fd70f92c610dc87d5ac6a07a Mon Sep 17 00:00:00 2001 From: rhuberdeau Date: Tue, 11 May 2021 20:14:34 -0400 Subject: [PATCH 1/3] Adds to_json to response objects that inherit from Domain. --- lib/twilio-ruby/framework/domain.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/twilio-ruby/framework/domain.rb b/lib/twilio-ruby/framework/domain.rb index c9a242dd7..17f7290ad 100644 --- a/lib/twilio-ruby/framework/domain.rb +++ b/lib/twilio-ruby/framework/domain.rb @@ -31,6 +31,10 @@ def request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeo timeout ) end + + def as_json(*) + @properties + end end end end From 5b97bf75d074d65d1874156d3daa1c84441ab1f2 Mon Sep 17 00:00:00 2001 From: rhuberdeau Date: Wed, 16 Jun 2021 21:21:50 -0400 Subject: [PATCH 2/3] Adds initial test for as_json. --- spec/framework/domain_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 spec/framework/domain_spec.rb diff --git a/spec/framework/domain_spec.rb b/spec/framework/domain_spec.rb new file mode 100644 index 000000000..8579b07b4 --- /dev/null +++ b/spec/framework/domain_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' +require 'logger' + +describe Twilio::REST::Domain do + class MyDomain < Twilio::REST::Domain + def initialize(client) + # Marshaled Properties + @properties = { + 'account_sid' => "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + 'auth_token' => "ABC1234", + 'url' => "http://www.example.com", + } + end + end + + describe '#as_json' do + before do + @domain = MyDomain.new(@client) + @json = @domain.as_json + end + + it 'converts the objects properties to json' do + expect(@json["account_sid"]).to eq("RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + expect(@json["auth_token"]).to eq("ABC1234") + expect(@json["url"]).to eq("http://www.example.com") + end + end +end From c569ae51e0fc5e23e6b7be6c899808517c6f67fc Mon Sep 17 00:00:00 2001 From: rhuberdeau Date: Tue, 11 Apr 2023 18:48:05 -0400 Subject: [PATCH 3/3] Fixes namespace issue in test. --- spec/framework/domain_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/framework/domain_spec.rb b/spec/framework/domain_spec.rb index 8579b07b4..14bef46f3 100644 --- a/spec/framework/domain_spec.rb +++ b/spec/framework/domain_spec.rb @@ -2,7 +2,7 @@ require 'logger' describe Twilio::REST::Domain do - class MyDomain < Twilio::REST::Domain + class MyOtherDomain < Twilio::REST::Domain def initialize(client) # Marshaled Properties @properties = { @@ -15,7 +15,7 @@ def initialize(client) describe '#as_json' do before do - @domain = MyDomain.new(@client) + @domain = MyOtherDomain.new(@client) @json = @domain.as_json end