From 9239e7a9c1213d3df2a01ca51d50fdf8b452d499 Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Mon, 9 Jul 2018 08:32:48 -0600 Subject: [PATCH 1/2] Add Endpoint#to_s method. --- app/models/endpoint.rb | 2 ++ spec/models/endpoint_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/models/endpoint.rb b/app/models/endpoint.rb index 517c9f70241..a1c76bd8ada 100644 --- a/app/models/endpoint.rb +++ b/app/models/endpoint.rb @@ -12,6 +12,8 @@ class Endpoint < ApplicationRecord after_create :endpoint_created after_destroy :endpoint_destroyed + delegate :to_s, :to => :url, :allow_nil => true + def endpoint_created resource.endpoint_created(role) if resource.respond_to?(:endpoint_created) end diff --git a/spec/models/endpoint_spec.rb b/spec/models/endpoint_spec.rb index 97cba9260a8..fcad1bd437b 100644 --- a/spec/models/endpoint_spec.rb +++ b/spec/models/endpoint_spec.rb @@ -127,4 +127,15 @@ expect(endpoint.ssl_cert_store).to be_a(OpenSSL::X509::Store) end end + + context "to_s" do + it "returns the url if set" do + allow(endpoint).to receive(:url).and_return('https://www.foo.bar') + expect(endpoint.to_s).to eql('https://www.foo.bar') + end + + it "returns a blank string if the url is not set" do + expect(endpoint.to_s).to eql('') + end + end end From f4f4e98b746c1b6146cf0489b6327ba8652dfa40 Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Mon, 12 Nov 2018 13:12:07 -0700 Subject: [PATCH 2/2] Just set endpoint url instead of using allow. --- spec/models/endpoint_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/endpoint_spec.rb b/spec/models/endpoint_spec.rb index fcad1bd437b..90cae1df37c 100644 --- a/spec/models/endpoint_spec.rb +++ b/spec/models/endpoint_spec.rb @@ -130,7 +130,7 @@ context "to_s" do it "returns the url if set" do - allow(endpoint).to receive(:url).and_return('https://www.foo.bar') + endpoint.url = 'https://www.foo.bar' expect(endpoint.to_s).to eql('https://www.foo.bar') end