class ActionDispatch::Routing::MapperTest

Public Instance Methods

test_blows_up_without_via() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 51
def test_blows_up_without_via
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  assert_raises(ArgumentError) do
    mapper.match "/", to: "posts#index", as: :main
  end
end
test_initialize() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 38
def test_initialize
  Mapper.new FakeSet.new
end
test_map_more_slashes() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 126
def test_map_more_slashes
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset

  # FIXME: is this a desired behavior?
  mapper.get "/one/two/", to: "posts#index", as: :main
  assert_equal "/one/two(.:format)", fakeset.asts.first.to_s
end
test_map_slash() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 119
def test_map_slash
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.get "/", to: "posts#index", as: :main
  assert_equal "/", fakeset.asts.first.to_s
end
test_map_wildcard() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 135
def test_map_wildcard
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.get "/*path", to: "pages#show"
  assert_equal "/*path(.:format)", fakeset.asts.first.to_s
  assert_equal(/.+?/, fakeset.requirements.first[:path])
end
test_map_wildcard_with_format_false() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 160
def test_map_wildcard_with_format_false
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.get "/*path", to: "pages#show", format: false
  assert_equal "/*path", fakeset.asts.first.to_s
  assert_nil fakeset.requirements.first[:path]
end
test_map_wildcard_with_format_true() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 168
def test_map_wildcard_with_format_true
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.get "/*path", to: "pages#show", format: true
  assert_equal "/*path.:format", fakeset.asts.first.to_s
end
test_map_wildcard_with_multiple_wildcard() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 151
def test_map_wildcard_with_multiple_wildcard
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.get "/*foo/*bar", to: "pages#show"
  assert_equal "/*foo/*bar(.:format)", fakeset.asts.first.to_s
  assert_equal(/.+?/, fakeset.requirements.first[:foo])
  assert_equal(/.+?/, fakeset.requirements.first[:bar])
end
test_map_wildcard_with_other_element() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 143
def test_map_wildcard_with_other_element
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.get "/*path/foo/:bar", to: "pages#show"
  assert_equal "/*path/foo/:bar(.:format)", fakeset.asts.first.to_s
  assert_equal(/.+?/, fakeset.requirements.first[:path])
end
test_mapping_requirements() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 90
def test_mapping_requirements
  options = {}
  scope = Mapper::Scope.new({})
  ast = Journey::Parser.parse "/store/:name(*rest)"
  m = Mapper::Mapping.build(scope, FakeSet.new, ast, "foo", "bar", nil, [:get], nil, {}, true, options)
  assert_equal(/.+?/, m.requirements[:rest])
end
test_raising_error_when_path_is_not_passed() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 175
def test_raising_error_when_path_is_not_passed
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  app = lambda { |env| [200, {}, [""]] }
  assert_raises ArgumentError do
    mapper.mount app
  end
end
test_raising_error_when_rack_app_is_not_passed() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 184
def test_raising_error_when_rack_app_is_not_passed
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  assert_raises ArgumentError do
    mapper.mount 10, as: "exciting"
  end

  assert_raises ArgumentError do
    mapper.mount as: "exciting"
  end
end
test_random_keys() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 79
def test_random_keys
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.scope(omg: :awesome) do
    mapper.get "/", to: "posts#index", as: :main
  end
  assert_equal({ omg: :awesome, controller: "posts", action: "index" },
               fakeset.defaults.first)
  assert_equal("GET", fakeset.routes.first.verb)
end
test_scope_does_not_destructively_mutate_default_options() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 196
def test_scope_does_not_destructively_mutate_default_options
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset

  frozen = { foo: :bar }.freeze

  assert_nothing_raised do
    mapper.scope(defaults: frozen) do
      # pass
    end
  end
end
test_scope_raises_on_anchor() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 42
def test_scope_raises_on_anchor
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  assert_raises(ArgumentError) do
    mapper.scope(anchor: false) do
    end
  end
end
test_scoped_formatted() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 68
def test_scoped_formatted
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.scope(format: true) do
    mapper.get "/foo", to: "posts#index", as: :main
  end
  assert_equal({ controller: "posts", action: "index" },
               fakeset.defaults.first)
  assert_equal "/foo.:format", fakeset.asts.first.to_s
end
test_to_scope() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 107
def test_to_scope
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.scope(to: "posts#index") do
    mapper.get :all
    mapper.post :most
  end

  assert_equal "posts#index", fakeset.routes.to_a[0].defaults[:to]
  assert_equal "posts#index", fakeset.routes.to_a[1].defaults[:to]
end
test_unscoped_formatted() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 59
def test_unscoped_formatted
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.get "/foo", to: "posts#index", as: :main, format: true
  assert_equal({ controller: "posts", action: "index" },
               fakeset.defaults.first)
  assert_equal "/foo.:format", fakeset.asts.first.to_s
end
test_via_scope() click to toggle source
# File actionpack/test/dispatch/mapper_test.rb, line 98
def test_via_scope
  fakeset = FakeSet.new
  mapper = Mapper.new fakeset
  mapper.scope(via: :put) do
    mapper.match "/", to: "posts#index", as: :main
  end
  assert_equal("PUT", fakeset.routes.first.verb)
end