test/functional/renders_controller_test.rb in versioncake-0.2.0 vs test/functional/renders_controller_test.rb in versioncake-0.3.0

- old
+ new

@@ -13,18 +13,28 @@ get :index, "api_version" => "1" assert_equal @controller.requested_version, 1 end test "exposes latest version when requesting the latest" do - get :index, "api_version" => "4" + get :index, "api_version" => "3" assert @controller.is_latest_version end test "reports not the latest version" do get :index, "api_version" => "1" assert !@controller.is_latest_version end + + test "exposes the derived version when the version is not set" do + get :index + assert_equal 3, @controller.derived_version + end + + test "requested version is blank when the version is not set" do + get :index + assert_blank @controller.requested_version + end end class ParameterStragegyTest < ActionController::TestCase tests RendersController @@ -139,7 +149,28 @@ test "renders the higher priority accept parameter version" do @controller.request.stubs(:headers).returns({"HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=2"}) get :index, "api_version" => "1" assert_equal @response.body, "index.v2.html.erb" + end +end + +class UnsupportedVersionTest < ActionController::TestCase + tests RendersController + + setup do + ActionView::Template::Versions.extraction_strategy = :query_parameter + end + + test "responds with 404 when the version is larger than the supported version" do + assert_raise ActionController::RoutingError do + get :index, "api_version" => "4" + end + end + + test "responds with 404 when the version is lower than the latest version, but not an available version" do + ActionView::Template::Versions.supported_version_numbers = [2,3] + assert_raise ActionController::RoutingError do + get :index, "api_version" => "1" + end end end \ No newline at end of file