Skip to content

Commit

Permalink
Fix crash when neither Geoip nor Gaze are configured
Browse files Browse the repository at this point in the history
  • Loading branch information
alfius committed Mar 5, 2016
1 parent 2395abf commit 964b475
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/alaveteli_geoip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def country_code_from_ip(ip)
elsif gaze_url
country_code_from_gaze(ip)
end
country_code = current_code if country_code.empty?
country_code = current_code if country_code.blank?
country_code
end

Expand Down
8 changes: 8 additions & 0 deletions spec/lib/alaveteli_geoip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@
.to eq(instance.current_code)
end

it "returns the current code if the service isn't configured" do
allow(AlaveteliConfiguration).to receive(:gaze_url).and_return('')
instance = AlaveteliGeoIP.new
expect(instance.country_code_from_ip('127.0.0.1'))
.to eq(instance.current_code)
end


it "returns the current code and logs the error with url if the
service returns an error" do
FakeWeb.register_uri(:get, %r|500.com|, :body => "Error", :status => ["500", "Error"])
Expand Down

0 comments on commit 964b475

Please sign in to comment.