Sha256: 77bc7736644ce87f2b483ac7fdf1bab916855a09cd7b99ea2e4601d855fed928

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

require 'tests/common'

module DeltacloudUnitTest
  class UrlForTest < Test::Unit::TestCase
    include Rack::Test::Methods

    def app
      Sinatra::Application
    end

    def test_it_works_for_root
      verify_url_for("/", "/")
    end

    def test_it_works_for_root_absolute
      verify_url_for("/", "http://localhost/", :full)
    end

    def test_it_works_with_spaces
      verify_url_for("/url with spaces", "/url%20with%20spaces")
    end

    def test_it_works_when_given_absolute
      verify_url_for("http://test.com", "http://test.com")
    end

    def test_it_works_when_not_at_root_context
      verify_url_for("/", "context/", :path_only, {}, {"SCRIPT_NAME" => "context"})
    end

    def verify_url_for(url, expected_url, mode=:path_only, params={}, rack_env={})
      # generate a unique url for each test
      test_url = "/url_for_test/#{expected_url.hash}/#{Time.now.to_i}"
      # Create our sinatra test endpoint
      self.class.create_test_url_content(test_url, url, mode)

      # verify the generated url matches what we expect
      get test_url, params, rack_env
      last_response.body.should == expected_url
    end

    def self.create_test_url_content(test_url, url_content, mode)
      get test_url do
        content_type "text/plain"
          url_for(url_content, mode)
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
steamcannon-deltacloud-core-0.0.7.2 tests/url_for_test.rb
steamcannon-deltacloud-core-0.0.7.2-java tests/url_for_test.rb
steamcannon-deltacloud-core-0.0.7.1 tests/url_for_test.rb
steamcannon-deltacloud-core-0.0.7.1-java tests/url_for_test.rb
deltacloud-core-0.0.7 tests/url_for_test.rb