Sha256: a379eb571d3602df06d37a37a788feca9158c8312f304b3ecef4ce91890ab170

Contents?: true

Size: 1.68 KB

Versions: 17

Compression:

Stored size: 1.68 KB

Contents

#
# This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

require "spec_helper"

describe Ballast::Middlewares::DefaultHost do
  describe "#initialize" do
    it "should save the app and load default hosts" do
      expect(YAML).to receive(:load_file).with("PATH").and_return({"production" => "HOST"})

      subject = Ballast::Middlewares::DefaultHost.new("APP", "PATH")
      expect(subject.instance_variable_get(:@app)).to eq("APP")
      expect(subject.instance_variable_get(:@hosts)).to eq({"production" => "HOST"})
    end
  end

  describe "#call" do
    before(:each) do
      @app = Proc.new { |env| env }
      expect(YAML).to receive(:load_file).with("PATH").and_return({"production" => "HOST"})
      ENV["RACK_ENV"] = "production"
    end

    subject { Ballast::Middlewares::DefaultHost.new(@app, "PATH") }

    it "should correctly replace the IP if the environment is found" do
      expect(subject.call({"SERVER_NAME" => "10.0.0.1", "HTTP_HOST" => "10.0.0.1"})).to eq({"SERVER_NAME" => "HOST", "HTTP_HOST" => "HOST", "ORIG_SERVER_NAME" => "10.0.0.1", "ORIG_HTTP_HOST" => "10.0.0.1"})
    end

    it "should not replace the IP if the environment is not found" do
      ENV["RACK_ENV"] = "staging"
      expect(subject.call({"SERVER_NAME" => "10.0.0.1", "HTTP_HOST" => "10.0.0.1"})).to eq({"SERVER_NAME" => "10.0.0.1", "HTTP_HOST" => "10.0.0.1"})
    end

    it "should not replace a non IP host" do
      expect(subject.call({"SERVER_NAME" => "abc", "HTTP_HOST" => "cde"})).to eq({"SERVER_NAME" => "abc", "HTTP_HOST" => "cde"})

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ballast-1.9.3 spec/ballast/middlewares/default_host_spec.rb
ballast-1.9.2 spec/ballast/middlewares/default_host_spec.rb
ballast-1.9.1 spec/ballast/middlewares/default_host_spec.rb
ballast-1.9.0 spec/ballast/middlewares/default_host_spec.rb
ballast-1.8.0 spec/ballast/middlewares/default_host_spec.rb
ballast-1.7.0 spec/ballast/middlewares/default_host_spec.rb
ballast-1.6.0 spec/ballast/middlewares/default_host_spec.rb
ballast-1.5.3 spec/ballast/middlewares/default_host_spec.rb
ballast-1.5.2 spec/ballast/middlewares/default_host_spec.rb
ballast-1.5.1 spec/ballast/middlewares/default_host_spec.rb
ballast-1.5.0 spec/ballast/middlewares/default_host_spec.rb
ballast-1.4.0 spec/ballast/middlewares/default_host_spec.rb
ballast-1.3.0 spec/ballast/middlewares/default_host_spec.rb
ballast-1.2.0 spec/ballast/middlewares/default_host_spec.rb
ballast-1.1.2 spec/ballast/middlewares/default_host_spec.rb
ballast-1.1.1 spec/ballast/middlewares/default_host_spec.rb
ballast-1.1.0 spec/ballast/middlewares/default_host_spec.rb