From: Andy Allan Date: Wed, 9 Nov 2016 16:00:47 +0000 (+0000) Subject: Extract the hostip.info stubbing into a common method. X-Git-Tag: live~3716^2~1 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/7cc1cc618d1512314a5942188db58f03113fe56e?hp=4d73706ff349e043ca62612e977ae600e8cae4ad Extract the hostip.info stubbing into a common method. There doesn't appear to be any before(:suite) equivalent for Minitest so this is the least-surprising way to do this. --- diff --git a/test/controllers/site_controller_test.rb b/test/controllers/site_controller_test.rb index 71ccc4e51..afa50a356 100644 --- a/test/controllers/site_controller_test.rb +++ b/test/controllers/site_controller_test.rb @@ -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 ## diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index eb57e2689..1b9ada83b 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -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 ## diff --git a/test/integration/oauth_test.rb b/test/integration/oauth_test.rb index 62eab0dee..e3ca53520 100644 --- a/test/integration/oauth_test.rb +++ b/test/integration/oauth_test.rb @@ -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 diff --git a/test/integration/page_locale_test.rb b/test/integration/page_locale_test.rb index 60255f66c..ee1f89afa 100644 --- a/test/integration/page_locale_test.rb +++ b/test/integration/page_locale_test.rb @@ -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 diff --git a/test/integration/user_roles_test.rb b/test/integration/user_roles_test.rb index e228489dd..2613c402c 100644 --- a/test/integration/user_roles_test.rb +++ b/test/integration/user_roles_test.rb @@ -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 diff --git a/test/integration/user_terms_seen_test.rb b/test/integration/user_terms_seen_test.rb index 596cccc43..d4d7450fb 100644 --- a/test/integration/user_terms_seen_test.rb +++ b/test/integration/user_terms_seen_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index c45331f20..420512e74 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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