{"action":"created","comment":{"url":"https://api.github.com/repos/mysociety/alaveteli/pulls/comments/37849357","id":37849357,"diff_hunk":"@@ -0,0 +1,123 @@\n+# -*- encoding : utf-8 -*-\n+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')\n+\n+describe AlaveteliGeoIP do\n+\n+\tdescribe '.country_code_from_ip' do\n+\n+    it 'delegates to an instance of the class' do\n+      instance = double\n+      allow(AlaveteliGeoIP).to receive(:instance).and_return(instance)\n+      allow(instance).to receive(:country_code_from_ip).with('127.0.0.1')\n+      AlaveteliGeoIP.country_code_from_ip '127.0.0.1'\n+    end\n+\n+\tend\n+\n+  describe '.instance' do\n+\n+    it 'creates a new instance' do\n+      expect(AlaveteliGeoIP.instance).to be_instance_of(AlaveteliGeoIP)\n+    end\n+\n+    it 'caches the instance' do\n+      expect(AlaveteliGeoIP.instance).to equal(AlaveteliGeoIP.instance)\n+    end\n+\n+  end\n+\n+  describe '.new' do\n+\n+    it 'configures the instance with the configured country code' do\n+      expect(AlaveteliGeoIP.new.current_code).\n+        to eq(AlaveteliConfiguration::iso_country_code)\n+    end\n+\n+    describe 'if there is a geoip database configured and present' do\n+\n+      it 'configures the instance with an instance of geoip' do\n+        allow(File).to receive(:file?).\n+          with(AlaveteliConfiguration::geoip_database).and_return(true)\n+        expect(GeoIP).to receive(:new).with(AlaveteliConfiguration::geoip_database)\n+        AlaveteliGeoIP.new.geoip\n+      end\n+\n+    end\n+\n+    describe 'if there is only a Gaze URL configured' do\n+\n+      it 'configures the instance with the Gaze URL' do\n+        allow(AlaveteliConfiguration).to receive(:geoip_database).and_return(nil)\n+        expect(AlaveteliGeoIP.new.gaze_url).\n+         to equal(AlaveteliConfiguration::gaze_url)\n+\n+      end\n+\n+    end\n+\n+  end\n+\n+  describe 'country_code_from_ip' do\n+\n+    describe 'when the Gaze service is configured and is in different states' do\n+\n+      before (:each) do\n+        FakeWeb.clean_registry\n+        allow(AlaveteliConfiguration).to receive(:geoip_database).and_return ''\n+      end\n+\n+      after (:each) do\n+        FakeWeb.clean_registry\n+      end\n+\n+      it \"returns the country code if the service returns one\" do\n+        allow(AlaveteliConfiguration).to receive(:gaze_url).and_return('http://denmark.com')\n+        FakeWeb.register_uri(:get, %r|denmark.com|, :body => \"DK\")\n+        expect(AlaveteliGeoIP.new.country_code_from_ip('127.0.0.1')).to eq('DK')\n+      end\n+\n+      it \"returns the current code if the service domain doesn't exist\" do\n+        allow(AlaveteliConfiguration).to receive(:gaze_url).and_return('http://12123sdf14qsd.com')\n+        instance = AlaveteliGeoIP.new\n+        expect(instance.country_code_from_ip('127.0.0.1'))\n+          .to eq(instance.current_code)\n+      end\n+\n+      it \"returns the current code if the service doesn't exist\" do\n+        allow(AlaveteliConfiguration).to receive(:gaze_url).and_return('http://www.google.com')\n+        instance = AlaveteliGeoIP.new\n+        expect(instance.country_code_from_ip('127.0.0.1'))\n+          .to eq(instance.current_code)\n+","path":"spec/lib/alaveteli_geoip_spec.rb","position":91,"original_position":91,"commit_id":"436c1f42615f3cedb8de44d2098202a4c68960e2","original_commit_id":"436c1f42615f3cedb8de44d2098202a4c68960e2","user":{"login":"garethrees","id":282788,"avatar_url":"https://avatars.githubusercontent.com/u/282788?v=3","gravatar_id":"","url":"https://api.github.com/users/garethrees","html_url":"https://github.com/garethrees","followers_url":"https://api.github.com/users/garethrees/followers","following_url":"https://api.github.com/users/garethrees/following{/other_user}","gists_url":"https://api.github.com/users/garethrees/gists{/gist_id}","starred_url":"https://api.github.com/users/garethrees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garethrees/subscriptions","organizations_url":"https://api.github.com/users/garethrees/orgs","repos_url":"https://api.github.com/users/garethrees/repos","events_url":"https://api.github.com/users/garethrees/events{/privacy}","received_events_url":"https://api.github.com/users/garethrees/received_events","type":"User","site_admin":false},"body":"Blank line","created_at":"2015-08-25T09:49:16Z","updated_at":"2015-08-25T09:49:16Z","html_url":"https://github.com/mysociety/alaveteli/pull/2734#discussion_r37849357","pull_request_url":"https://api.github.com/repos/mysociety/alaveteli/pulls/2734","_links":{"self":{"href":"https://api.github.com/repos/mysociety/alaveteli/pulls/comments/37849357"},"html":{"href":"https://github.com/mysociety/alaveteli/pull/2734#discussion_r37849357"},"pull_request":{"href":"https://api.github.com/repos/mysociety/alaveteli/pulls/2734"}}},"pull_request":{"url":"https://api.github.com/repos/mysociety/alaveteli/pulls/2734","id":42474115,"html_url":"https://github.com/mysociety/alaveteli/pull/2734","diff_url":"https://github.com/mysociety/alaveteli/pull/2734.diff","patch_url":"https://github.com/mysociety/alaveteli/pull/2734.patch","issue_url":"https://api.github.com/repos/mysociety/alaveteli/issues/2734","number":2734,"state":"open","locked":false,"title":"Use local geoip if possible","user":{"login":"crowbot","id":2912,"avatar_url":"https://avatars.githubusercontent.com/u/2912?v=3","gravatar_id":"","url":"https://api.github.com/users/crowbot","html_url":"https://github.com/crowbot","followers_url":"https://api.github.com/users/crowbot/followers","following_url":"https://api.github.com/users/crowbot/following{/other_user}","gists_url":"https://api.github.com/users/crowbot/gists{/gist_id}","starred_url":"https://api.github.com/users/crowbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crowbot/subscriptions","organizations_url":"https://api.github.com/users/crowbot/orgs","repos_url":"https://api.github.com/users/crowbot/repos","events_url":"https://api.github.com/users/crowbot/events{/privacy}","received_events_url":"https://api.github.com/users/crowbot/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-14T16:37:59Z","updated_at":"2015-08-25T09:49:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5a8c7cff4584feafc0c489845e3dc24d246b57d9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mysociety/alaveteli/pulls/2734/commits","review_comments_url":"https://api.github.com/repos/mysociety/alaveteli/pulls/2734/comments","review_comment_url":"https://api.github.com/repos/mysociety/alaveteli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mysociety/alaveteli/issues/2734/comments","statuses_url":"https://api.github.com/repos/mysociety/alaveteli/statuses/436c1f42615f3cedb8de44d2098202a4c68960e2","head":{"label":"mysociety:lc-use-local-geoip-if-possible","ref":"lc-use-local-geoip-if-possible","sha":"436c1f42615f3cedb8de44d2098202a4c68960e2","user":{"login":"mysociety","id":141338,"avatar_url":"https://avatars.githubusercontent.com/u/141338?v=3","gravatar_id":"","url":"https://api.github.com/users/mysociety","html_url":"https://github.com/mysociety","followers_url":"https://api.github.com/users/mysociety/followers","following_url":"https://api.github.com/users/mysociety/following{/other_user}","gists_url":"https://api.github.com/users/mysociety/gists{/gist_id}","starred_url":"https://api.github.com/users/mysociety/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysociety/subscriptions","organizations_url":"https://api.github.com/users/mysociety/orgs","repos_url":"https://api.github.com/users/mysociety/repos","events_url":"https://api.github.com/users/mysociety/events{/privacy}","received_events_url":"https://api.github.com/users/mysociety/received_events","type":"Organization","site_admin":false},"repo":{"id":1125389,"name":"alaveteli","full_name":"mysociety/alaveteli","owner":{"login":"mysociety","id":141338,"avatar_url":"https://avatars.githubusercontent.com/u/141338?v=3","gravatar_id":"","url":"https://api.github.com/users/mysociety","html_url":"https://github.com/mysociety","followers_url":"https://api.github.com/users/mysociety/followers","following_url":"https://api.github.com/users/mysociety/following{/other_user}","gists_url":"https://api.github.com/users/mysociety/gists{/gist_id}","starred_url":"https://api.github.com/users/mysociety/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysociety/subscriptions","organizations_url":"https://api.github.com/users/mysociety/orgs","repos_url":"https://api.github.com/users/mysociety/repos","events_url":"https://api.github.com/users/mysociety/events{/privacy}","received_events_url":"https://api.github.com/users/mysociety/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mysociety/alaveteli","description":"Provide a Freedom of Information request system for your jurisdiction","fork":false,"url":"https://api.github.com/repos/mysociety/alaveteli","forks_url":"https://api.github.com/repos/mysociety/alaveteli/forks","keys_url":"https://api.github.com/repos/mysociety/alaveteli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mysociety/alaveteli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mysociety/alaveteli/teams","hooks_url":"https://api.github.com/repos/mysociety/alaveteli/hooks","issue_events_url":"https://api.github.com/repos/mysociety/alaveteli/issues/events{/number}","events_url":"https://api.github.com/repos/mysociety/alaveteli/events","assignees_url":"https://api.github.com/repos/mysociety/alaveteli/assignees{/user}","branches_url":"https://api.github.com/repos/mysociety/alaveteli/branches{/branch}","tags_url":"https://api.github.com/repos/mysociety/alaveteli/tags","blobs_url":"https://api.github.com/repos/mysociety/alaveteli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mysociety/alaveteli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mysociety/alaveteli/git/refs{/sha}","trees_url":"https://api.github.com/repos/mysociety/alaveteli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mysociety/alaveteli/statuses/{sha}","languages_url":"https://api.github.com/repos/mysociety/alaveteli/languages","stargazers_url":"https://api.github.com/repos/mysociety/alaveteli/stargazers","contributors_url":"https://api.github.com/repos/mysociety/alaveteli/contributors","subscribers_url":"https://api.github.com/repos/mysociety/alaveteli/subscribers","subscription_url":"https://api.github.com/repos/mysociety/alaveteli/subscription","commits_url":"https://api.github.com/repos/mysociety/alaveteli/commits{/sha}","git_commits_url":"https://api.github.com/repos/mysociety/alaveteli/git/commits{/sha}","comments_url":"https://api.github.com/repos/mysociety/alaveteli/comments{/number}","issue_comment_url":"https://api.github.com/repos/mysociety/alaveteli/issues/comments{/number}","contents_url":"https://api.github.com/repos/mysociety/alaveteli/contents/{+path}","compare_url":"https://api.github.com/repos/mysociety/alaveteli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mysociety/alaveteli/merges","archive_url":"https://api.github.com/repos/mysociety/alaveteli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mysociety/alaveteli/downloads","issues_url":"https://api.github.com/repos/mysociety/alaveteli/issues{/number}","pulls_url":"https://api.github.com/repos/mysociety/alaveteli/pulls{/number}","milestones_url":"https://api.github.com/repos/mysociety/alaveteli/milestones{/number}","notifications_url":"https://api.github.com/repos/mysociety/alaveteli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mysociety/alaveteli/labels{/name}","releases_url":"https://api.github.com/repos/mysociety/alaveteli/releases{/id}","created_at":"2010-11-30T13:11:39Z","updated_at":"2015-08-25T09:41:23Z","pushed_at":"2015-08-25T08:42:32Z","git_url":"git://github.com/mysociety/alaveteli.git","ssh_url":"git@github.com:mysociety/alaveteli.git","clone_url":"https://github.com/mysociety/alaveteli.git","svn_url":"https://github.com/mysociety/alaveteli","homepage":"http://alaveteli.org","size":102288,"stargazers_count":154,"watchers_count":154,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":97,"mirror_url":null,"open_issues_count":707,"forks":97,"open_issues":707,"watchers":154,"default_branch":"develop"}},"base":{"label":"mysociety:develop","ref":"develop","sha":"bc704cf9be71c95bb966277e65f4109f6c2b013f","user":{"login":"mysociety","id":141338,"avatar_url":"https://avatars.githubusercontent.com/u/141338?v=3","gravatar_id":"","url":"https://api.github.com/users/mysociety","html_url":"https://github.com/mysociety","followers_url":"https://api.github.com/users/mysociety/followers","following_url":"https://api.github.com/users/mysociety/following{/other_user}","gists_url":"https://api.github.com/users/mysociety/gists{/gist_id}","starred_url":"https://api.github.com/users/mysociety/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysociety/subscriptions","organizations_url":"https://api.github.com/users/mysociety/orgs","repos_url":"https://api.github.com/users/mysociety/repos","events_url":"https://api.github.com/users/mysociety/events{/privacy}","received_events_url":"https://api.github.com/users/mysociety/received_events","type":"Organization","site_admin":false},"repo":{"id":1125389,"name":"alaveteli","full_name":"mysociety/alaveteli","owner":{"login":"mysociety","id":141338,"avatar_url":"https://avatars.githubusercontent.com/u/141338?v=3","gravatar_id":"","url":"https://api.github.com/users/mysociety","html_url":"https://github.com/mysociety","followers_url":"https://api.github.com/users/mysociety/followers","following_url":"https://api.github.com/users/mysociety/following{/other_user}","gists_url":"https://api.github.com/users/mysociety/gists{/gist_id}","starred_url":"https://api.github.com/users/mysociety/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysociety/subscriptions","organizations_url":"https://api.github.com/users/mysociety/orgs","repos_url":"https://api.github.com/users/mysociety/repos","events_url":"https://api.github.com/users/mysociety/events{/privacy}","received_events_url":"https://api.github.com/users/mysociety/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mysociety/alaveteli","description":"Provide a Freedom of Information request system for your jurisdiction","fork":false,"url":"https://api.github.com/repos/mysociety/alaveteli","forks_url":"https://api.github.com/repos/mysociety/alaveteli/forks","keys_url":"https://api.github.com/repos/mysociety/alaveteli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mysociety/alaveteli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mysociety/alaveteli/teams","hooks_url":"https://api.github.com/repos/mysociety/alaveteli/hooks","issue_events_url":"https://api.github.com/repos/mysociety/alaveteli/issues/events{/number}","events_url":"https://api.github.com/repos/mysociety/alaveteli/events","assignees_url":"https://api.github.com/repos/mysociety/alaveteli/assignees{/user}","branches_url":"https://api.github.com/repos/mysociety/alaveteli/branches{/branch}","tags_url":"https://api.github.com/repos/mysociety/alaveteli/tags","blobs_url":"https://api.github.com/repos/mysociety/alaveteli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mysociety/alaveteli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mysociety/alaveteli/git/refs{/sha}","trees_url":"https://api.github.com/repos/mysociety/alaveteli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mysociety/alaveteli/statuses/{sha}","languages_url":"https://api.github.com/repos/mysociety/alaveteli/languages","stargazers_url":"https://api.github.com/repos/mysociety/alaveteli/stargazers","contributors_url":"https://api.github.com/repos/mysociety/alaveteli/contributors","subscribers_url":"https://api.github.com/repos/mysociety/alaveteli/subscribers","subscription_url":"https://api.github.com/repos/mysociety/alaveteli/subscription","commits_url":"https://api.github.com/repos/mysociety/alaveteli/commits{/sha}","git_commits_url":"https://api.github.com/repos/mysociety/alaveteli/git/commits{/sha}","comments_url":"https://api.github.com/repos/mysociety/alaveteli/comments{/number}","issue_comment_url":"https://api.github.com/repos/mysociety/alaveteli/issues/comments{/number}","contents_url":"https://api.github.com/repos/mysociety/alaveteli/contents/{+path}","compare_url":"https://api.github.com/repos/mysociety/alaveteli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mysociety/alaveteli/merges","archive_url":"https://api.github.com/repos/mysociety/alaveteli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mysociety/alaveteli/downloads","issues_url":"https://api.github.com/repos/mysociety/alaveteli/issues{/number}","pulls_url":"https://api.github.com/repos/mysociety/alaveteli/pulls{/number}","milestones_url":"https://api.github.com/repos/mysociety/alaveteli/milestones{/number}","notifications_url":"https://api.github.com/repos/mysociety/alaveteli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mysociety/alaveteli/labels{/name}","releases_url":"https://api.github.com/repos/mysociety/alaveteli/releases{/id}","created_at":"2010-11-30T13:11:39Z","updated_at":"2015-08-25T09:41:23Z","pushed_at":"2015-08-25T08:42:32Z","git_url":"git://github.com/mysociety/alaveteli.git","ssh_url":"git@github.com:mysociety/alaveteli.git","clone_url":"https://github.com/mysociety/alaveteli.git","svn_url":"https://github.com/mysociety/alaveteli","homepage":"http://alaveteli.org","size":102288,"stargazers_count":154,"watchers_count":154,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":97,"mirror_url":null,"open_issues_count":707,"forks":97,"open_issues":707,"watchers":154,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/mysociety/alaveteli/pulls/2734"},"html":{"href":"https://github.com/mysociety/alaveteli/pull/2734"},"issue":{"href":"https://api.github.com/repos/mysociety/alaveteli/issues/2734"},"comments":{"href":"https://api.github.com/repos/mysociety/alaveteli/issues/2734/comments"},"review_comments":{"href":"https://api.github.com/repos/mysociety/alaveteli/pulls/2734/comments"},"review_comment":{"href":"https://api.github.com/repos/mysociety/alaveteli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mysociety/alaveteli/pulls/2734/commits"},"statuses":{"href":"https://api.github.com/repos/mysociety/alaveteli/statuses/436c1f42615f3cedb8de44d2098202a4c68960e2"}}}}