Sha256: 804d7bb8b9520359f656db9dd271fbef3122317a33e43c2a97772bc9b46f6b3b

Contents?: true

Size: 1.88 KB

Versions: 9

Compression:

Stored size: 1.88 KB

Contents

require './test/test_helper'

class VersionedRequestTest < ActiveSupport::TestCase
  test "a request with a supported version returns the version" do
    VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => 2)
    versioned_request = VersionCake::VersionedRequest.new(stub())
    assert_equal 2, versioned_request.version
  end

  test "a request without a version returns the latest version" do
    VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => nil)
    versioned_request = VersionCake::VersionedRequest.new(stub())
    assert_equal 3, versioned_request.version
  end

  test "a request for a version that is higher than the latest version raises an error" do
    VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => 99)
    assert !VersionCake::VersionedRequest.new(stub()).is_version_supported?
  end

  test "a request for a deprecated version raises an exception" do
    VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => 2)
    VersionCake::Configuration.any_instance.stubs(:supports_version? => false)
    assert !VersionCake::VersionedRequest.new(stub()).is_version_supported?
  end

  test "has a method to determine if requesting the latest version" do
    VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => nil)
    versioned_request = VersionCake::VersionedRequest.new(stub())
    assert versioned_request.is_latest_version?
  end

  test "has a method to retrieve the extracted version" do
    VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => nil)
    versioned_request = VersionCake::VersionedRequest.new(stub())
    assert_nil versioned_request.extracted_version
    assert_equal 3, versioned_request.version
  end

  test "the version can be overriden by a parameter" do
    versioned_request = VersionCake::VersionedRequest.new(stub(), 8)
    assert_equal 8, versioned_request.version
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/versioncake-2.3.1/test/unit/versioned_request_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/versioncake-2.3.1/test/unit/versioned_request_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/versioncake-2.3.1/test/unit/versioned_request_test.rb
versioncake-2.5.0 test/unit/versioned_request_test.rb
versioncake-2.4.0 test/unit/versioned_request_test.rb
versioncake-2.3.1 test/unit/versioned_request_test.rb
versioncake-2.3.0 test/unit/versioned_request_test.rb
versioncake-2.2.0 test/unit/versioned_request_test.rb
versioncake-2.1.0 test/unit/versioned_request_test.rb