Sha256: dbfec9cdf83694bb7bdba370f43e8892b2b80e870a47a4fd865df34370d3f9e4

Contents?: true

Size: 895 Bytes

Versions: 2

Compression:

Stored size: 895 Bytes

Contents

require 'test_helper'

module Spyke
  class PathTest < MiniTest::Test
    def test_collection_path
      assert_equal '/recipes', Path.new('/recipes/(:id)').to_s
    end

    def test_resource_path
      assert_equal '/recipes/2', Path.new('/recipes/(:id)', id: 2).to_s
    end

    def test_nested_collection_path
      path = Path.new('/users/:user_id/recipes/(:id)', user_id: 1, status: 'published')
      assert_equal [:user_id, :id], path.variables
      assert_equal '/users/1/recipes', path.to_s
    end

    def test_nested_resource_path
      assert_equal '/users/1/recipes/2', Path.new('/users/:user_id/recipes/:id', user_id: 1, id: 2).to_s
    end

    def test_required_params
      assert_raises Spyke::InvalidPathError, 'Missing required params: user_id in /users/:user_id/recipes/(:id)' do
        Path.new('/users/:user_id/recipes/(:id)', id: 2).to_s
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spyke-1.7.1 test/path_test.rb
spyke-1.7.0 test/path_test.rb