Extract the hostip.info stubbing into a common method.
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 9 Nov 2016 16:00:47 +0000 (16:00 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 9 Nov 2016 16:00:47 +0000 (16:00 +0000)
There doesn't appear to be any before(:suite) equivalent for Minitest
so this is the least-surprising way to do this.

test/controllers/site_controller_test.rb
test/controllers/user_controller_test.rb
test/integration/oauth_test.rb
test/integration/page_locale_test.rb
test/integration/user_roles_test.rb
test/integration/user_terms_seen_test.rb
test/test_helper.rb

index 71ccc4e..afa50a3 100644 (file)
@@ -9,7 +9,7 @@ class SiteControllerTest < ActionController::TestCase
     Object.const_set("ID_KEY", client_applications(:oauth_web_app).key)
     Object.const_set("POTLATCH2_KEY", client_applications(:oauth_web_app).key)
 
-    stub_request(:get, "http://api.hostip.info/country.php?ip=0.0.0.0")
+    stub_signup_requests
   end
 
   ##
index eb57e26..1b9ada8 100644 (file)
@@ -4,7 +4,7 @@ class UserControllerTest < ActionController::TestCase
   api_fixtures
 
   setup do
-    stub_request(:get, "http://api.hostip.info/country.php?ip=0.0.0.0")
+    stub_signup_requests
   end
 
   ##
index 62eab0d..e3ca535 100644 (file)
@@ -7,7 +7,7 @@ class OAuthTest < ActionDispatch::IntegrationTest
   include OAuth::Helper
 
   setup do
-    stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1")
+    stub_signup_requests
   end
 
   def test_oauth10_web_app
index 60255f6..ee1f89a 100644 (file)
@@ -5,7 +5,7 @@ class PageLocaleTest < ActionDispatch::IntegrationTest
 
   def setup
     I18n.locale = "en"
-    stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1")
+    stub_signup_requests
   end
 
   def teardown
index e228489..2613c40 100644 (file)
@@ -4,7 +4,7 @@ class UserRolesTest < ActionDispatch::IntegrationTest
   fixtures :users, :user_roles
 
   setup do
-    stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1")
+    stub_signup_requests
   end
 
   test "grant" do
index 596cccc..d4d7450 100644 (file)
@@ -4,7 +4,7 @@ class UserTermsSeenTest < ActionDispatch::IntegrationTest
   fixtures :users
 
   setup do
-    stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1")
+    stub_signup_requests
   end
 
   def test_api_blocked
index c45331f..420512e 100644 (file)
@@ -174,5 +174,11 @@ module ActiveSupport
       url = "https://www.gravatar.com/avatar/#{hash}?d=404"
       stub_request(:get, url).and_return(:status => status, :body => body)
     end
+
+    def stub_signup_requests
+      # Controller tests and integration tests use different IPs
+      stub_request(:get, "http://api.hostip.info/country.php?ip=0.0.0.0")
+      stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1")
+    end
   end
 end