From ee8b1d1ccbd945a7936faee39c13f80d9782d4b5 Mon Sep 17 00:00:00 2001 From: Steve Kenworthy Date: Fri, 21 Aug 2015 11:54:58 +0800 Subject: [PATCH] Fixed case where uri.host == nil because url was file:/// --- app/models/notice.rb | 2 +- spec/models/notice_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/notice.rb b/app/models/notice.rb index 8104861..c5945f6 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -74,7 +74,7 @@ class Notice def host uri = url && URI.parse(url) - uri.blank? ? "N/A" : uri.host + uri && uri.host || "N/A" rescue URI::InvalidURIError "N/A" end diff --git a/spec/models/notice_spec.rb b/spec/models/notice_spec.rb index 2353024..10d6354 100644 --- a/spec/models/notice_spec.rb +++ b/spec/models/notice_spec.rb @@ -89,6 +89,11 @@ describe Notice, type: 'model' do end it "returns 'N/A' when url is not valid" do + notice = Fabricate.build(:notice, :request => {'url' => "file:///path/to/some/resource/12"}) + expect(notice.host).to eq 'N/A' + end + + it "returns 'N/A' when url is not valid" do notice = Fabricate.build(:notice, :request => {'url' => "some string"}) expect(notice.host).to eq 'N/A' end -- libgit2 0.21.2