class ActionDispatch::Journey::Path::TestPattern
Constants
- SEPARATORS
Public Instance Methods
test_ast_sets_regular_expressions()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 133 def test_ast_sets_regular_expressions requirements = { name: /(tender|love)/, value: /./ } path = Pattern.build( "/page/:name/:value", requirements, SEPARATORS, true ) nodes = path.ast.grep(Nodes::Symbol) assert_equal 2, nodes.length nodes.each do |node| assert_equal requirements[node.to_sym], node.regexp end end
test_failed_match()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 211 def test_failed_match path = Pattern.from_string "/:controller(/:action(/:id(.:format)))" uri = "content" assert_not path =~ uri end
test_insensitive_regexp_with_group()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 186 def test_insensitive_regexp_with_group path = Pattern.build( "/page/:name/aaron", { name: /(tender|love)/i }, SEPARATORS, true ) assert_match(path, "/page/TENDER/aaron") assert_match(path, "/page/loVE/aaron") assert_no_match(path, "/page/loVE/AAron") end
test_match_controller()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 218 def test_match_controller path = Pattern.from_string "/:controller(/:action(/:id(.:format)))" uri = "/content" match = path =~ uri assert_equal %w{ controller action id format }, match.names assert_equal "content", match[1] assert_nil match[2] assert_nil match[3] assert_nil match[4] end
test_match_controller_action()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 230 def test_match_controller_action path = Pattern.from_string "/:controller(/:action(/:id(.:format)))" uri = "/content/list" match = path =~ uri assert_equal %w{ controller action id format }, match.names assert_equal "content", match[1] assert_equal "list", match[2] assert_nil match[3] assert_nil match[4] end
test_match_controller_action_id()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 242 def test_match_controller_action_id path = Pattern.from_string "/:controller(/:action(/:id(.:format)))" uri = "/content/list/10" match = path =~ uri assert_equal %w{ controller action id format }, match.names assert_equal "content", match[1] assert_equal "list", match[2] assert_equal "10", match[3] assert_nil match[4] end
test_match_data_with_group()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 149 def test_match_data_with_group path = Pattern.build( "/page/:name", { name: /(tender|love)/ }, SEPARATORS, true ) match = path.match "/page/tender" assert_equal "tender", match[1] assert_equal 2, match.length end
test_match_data_with_multi_group()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 161 def test_match_data_with_multi_group path = Pattern.build( "/page/:name/:id", { name: /t(((ender|love)))()/ }, SEPARATORS, true ) match = path.match "/page/tender/10" assert_equal "tender", match[1] assert_equal "10", match[2] assert_equal 3, match.length assert_equal %w{ tender 10 }, match.captures end
test_match_literal()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 254 def test_match_literal path = Path::Pattern.from_string "/books(/:action(.:format))" uri = "/books" match = path =~ uri assert_equal %w{ action format }, match.names assert_nil match[1] assert_nil match[2] end
test_match_literal_with_action()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 264 def test_match_literal_with_action path = Path::Pattern.from_string "/books(/:action(.:format))" uri = "/books/list" match = path =~ uri assert_equal %w{ action format }, match.names assert_equal "list", match[1] assert_nil match[2] end
test_match_literal_with_action_and_format()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 274 def test_match_literal_with_action_and_format path = Path::Pattern.from_string "/books(/:action(.:format))" uri = "/books/list.rss" match = path =~ uri assert_equal %w{ action format }, match.names assert_equal "list", match[1] assert_equal "rss", match[2] end
test_optional_names()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 99 def test_optional_names [ ["/:foo(/:bar(/:baz))", %w{ bar baz }], ["/:foo(/:bar)", %w{ bar }], ["/:foo(/:bar)/:lol(/:baz)", %w{ bar baz }], ].each do |pattern, list| path = Pattern.from_string pattern assert_equal list.sort, path.optional_names.sort end end
test_star_with_custom_re()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 175 def test_star_with_custom_re z = /\d+/ path = Pattern.build( "/page/*foo", { foo: z }, SEPARATORS, true ) assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp) end
test_to_regexp_defaults()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 205 def test_to_regexp_defaults path = Pattern.from_string "/:controller(/:action(/:id))" expected = %r{\A/([^/.?]+)(?:/([^/.?]+)(?:/([^/.?]+))?)?\Z} assert_equal expected, path.to_regexp end
test_to_regexp_match_non_optional()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 110 def test_to_regexp_match_non_optional path = Pattern.build( "/:name", { name: /\d+/ }, SEPARATORS, true ) assert_match(path, "/123") assert_no_match(path, "/") end
test_to_regexp_with_extended_group()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 83 def test_to_regexp_with_extended_group path = Pattern.build( "/page/:name", { name: / #ROFL (tender|love #MAO )/x }, SEPARATORS, true ) assert_match(path, "/page/tender") assert_match(path, "/page/love") assert_no_match(path, "/page/loving") end
test_to_regexp_with_group()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 121 def test_to_regexp_with_group path = Pattern.build( "/page/:name", { name: /(tender|love)/ }, SEPARATORS, true ) assert_match(path, "/page/tender") assert_match(path, "/page/love") assert_no_match(path, "/page/loving") end
test_to_regexp_with_strexp()
click to toggle source
# File actionpack/test/journey/path/pattern_test.rb, line 198 def test_to_regexp_with_strexp path = Pattern.build("/:controller", {}, SEPARATORS, true) x = %r{\A/([^/.?]+)\Z} assert_equal(x.source, path.source) end