File: route_helpers_test.rb

package info (click to toggle)
rails 2%3A6.1.7.10%2Bdfsg-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 39,756 kB
  • sloc: ruby: 290,662; javascript: 19,241; yacc: 46; sql: 43; makefile: 32; sh: 18
file content (49 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

require "abstract_unit"

class RouteHelperIntegrationTest < ActionDispatch::IntegrationTest
  def self.routes
    @routes ||= ActionDispatch::Routing::RouteSet.new
  end

  class FakeACBase < ActionController::Base
    # Normally done by app initialization to ActionController::Base
    app = RouteHelperIntegrationTest
    extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
  end

  class ApplicationController < FakeACBase
  end

  class FooController < ApplicationController
  end

  # We define many routes in these modules after they have been included into
  # the controllers. For boot performance, it's important that we don't
  # duplicate these modules and make method cache invalidation expensive.
  # https://github.com/rails/rails/pull/37927
  test "only includes one module with route helpers" do
    app = self.class

    url_helpers_module = app.routes.named_routes.url_helpers_module
    path_helpers_module = app.routes.named_routes.path_helpers_module

    assert_operator FooController, :<, url_helpers_module
    assert_operator ApplicationController, :<, url_helpers_module
    assert_not_operator FakeACBase, :<, url_helpers_module

    assert_operator FooController, :<, path_helpers_module
    assert_operator ApplicationController, :<, path_helpers_module
    assert_not_operator FakeACBase, :<, path_helpers_module

    included_modules = FooController.ancestors.grep_v(Class)
    included_modules -= [url_helpers_module, path_helpers_module]

    modules_with_routes = included_modules.select do |mod|
      mod < url_helpers_module || mod < path_helpers_module
    end

    assert_equal 1, modules_with_routes.size
  end
end