Commit ee8b1d1ccbd945a7936faee39c13f80d9782d4b5
1 parent
47085886
Exists in
master
and in
1 other branch
Fixed case where uri.host == nil because url was file:///
Showing
2 changed files
with
6 additions
and
1 deletions
Show diff stats
app/models/notice.rb
| @@ -74,7 +74,7 @@ class Notice | @@ -74,7 +74,7 @@ class Notice | ||
| 74 | 74 | ||
| 75 | def host | 75 | def host |
| 76 | uri = url && URI.parse(url) | 76 | uri = url && URI.parse(url) |
| 77 | - uri.blank? ? "N/A" : uri.host | 77 | + uri && uri.host || "N/A" |
| 78 | rescue URI::InvalidURIError | 78 | rescue URI::InvalidURIError |
| 79 | "N/A" | 79 | "N/A" |
| 80 | end | 80 | end |
spec/models/notice_spec.rb
| @@ -89,6 +89,11 @@ describe Notice, type: 'model' do | @@ -89,6 +89,11 @@ describe Notice, type: 'model' do | ||
| 89 | end | 89 | end |
| 90 | 90 | ||
| 91 | it "returns 'N/A' when url is not valid" do | 91 | it "returns 'N/A' when url is not valid" do |
| 92 | + notice = Fabricate.build(:notice, :request => {'url' => "file:///path/to/some/resource/12"}) | ||
| 93 | + expect(notice.host).to eq 'N/A' | ||
| 94 | + end | ||
| 95 | + | ||
| 96 | + it "returns 'N/A' when url is not valid" do | ||
| 92 | notice = Fabricate.build(:notice, :request => {'url' => "some string"}) | 97 | notice = Fabricate.build(:notice, :request => {'url' => "some string"}) |
| 93 | expect(notice.host).to eq 'N/A' | 98 | expect(notice.host).to eq 'N/A' |
| 94 | end | 99 | end |