Sha256: 05ccbfb65c49fa0b8fdf8ca7af5341be0baf774713d2d6b674b017d181c813ef

Contents?: true

Size: 1.11 KB

Versions: 27

Compression:

Stored size: 1.11 KB

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

    def test_optional_params_with_extension
      skip 'wishlisted'
      assert_equal '/1/profiles/2.json', Path.new('/1/profiles(/:id).json', id: 2).to_s
      assert_equal '/1/profiles.json', Path.new('/1/profiles(/:id).json').to_s
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
spyke-5.0.0 test/path_test.rb
spyke-4.1.1 test/path_test.rb
spyke-4.1.0 test/path_test.rb
spyke-4.0.1 test/path_test.rb
spyke-4.0.0 test/path_test.rb
spyke-3.1.5 test/path_test.rb
spyke-3.1.4 test/path_test.rb
spyke-3.1.3 test/path_test.rb
spyke-3.1.2 test/path_test.rb
spyke-3.1.1 test/path_test.rb
spyke-3.1.0 test/path_test.rb
spyke-3.0.0 test/path_test.rb
spyke-2.0.1 test/path_test.rb
spyke-2.0.0 test/path_test.rb
spyke-1.8.11 test/path_test.rb
spyke-1.8.10 test/path_test.rb
spyke-1.8.9 test/path_test.rb
spyke-1.8.8 test/path_test.rb
spyke-1.8.7 test/path_test.rb
spyke-1.8.6 test/path_test.rb