]> git.openstreetmap.org Git - rails.git/blobdiff - test/test_helper.rb
Fix stubbing of hostip requests
[rails.git] / test / test_helper.rb
index 70f69a3ae94a590140eebd1a97fa15f46437775c..688cbc113afc4810d3f64e79af494ff7753088ad 100644 (file)
@@ -2,7 +2,7 @@ require "coveralls"
 Coveralls.wear!("rails")
 
 ENV["RAILS_ENV"] = "test"
-require File.expand_path("../../config/environment", __FILE__)
+require_relative "../config/environment"
 require "rails/test_help"
 require "webmock/minitest"
 
@@ -82,7 +82,7 @@ module ActiveSupport
     ##
     # set request headers for HTTP basic authentication
     def basic_authorization(user, pass)
-      @request.env["HTTP_AUTHORIZATION"] = format("Basic %s", Base64.encode64("#{user}:#{pass}"))
+      @request.env["HTTP_AUTHORIZATION"] = format("Basic %{auth}", :auth => Base64.encode64("#{user}:#{pass}"))
     end
 
     ##
@@ -130,15 +130,15 @@ module ActiveSupport
     end
 
     def stub_gravatar_request(email, status = 200, body = nil)
-      hash = Digest::MD5.hexdigest(email.downcase)
+      hash = ::Digest::MD5.hexdigest(email.downcase)
       url = "https://www.gravatar.com/avatar/#{hash}?d=404"
       stub_request(:get, url).and_return(:status => status, :body => body)
     end
 
     def stub_hostip_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")
+      stub_request(:get, "https://api.hostip.info/country.php?ip=0.0.0.0")
+      stub_request(:get, "https://api.hostip.info/country.php?ip=127.0.0.1")
     end
 
     def email_text_parts(message)
@@ -150,5 +150,13 @@ module ActiveSupport
         end
       end
     end
+
+    def sign_in_as(user)
+      stub_hostip_requests
+      visit login_path
+      fill_in "username", :with => user.email
+      fill_in "password", :with => "test"
+      click_on "Login", :match => :first
+    end
   end
 end