js-routes 2.2.9 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -3
  3. data/Readme.md +16 -15
  4. data/lib/js_routes/configuration.rb +7 -5
  5. data/lib/js_routes/generators/base.rb +6 -1
  6. data/lib/js_routes/generators/middleware.rb +2 -3
  7. data/lib/js_routes/generators/webpacker.rb +2 -1
  8. data/lib/js_routes/instance.rb +21 -6
  9. data/lib/js_routes/middleware.rb +5 -4
  10. data/lib/js_routes/route.rb +7 -3
  11. data/lib/js_routes/types.rb +10 -0
  12. data/lib/js_routes/utils.rb +18 -0
  13. data/lib/js_routes/version.rb +1 -1
  14. data/lib/js_routes.rb +12 -4
  15. data/lib/routes.d.ts +7 -6
  16. data/lib/routes.js +19 -18
  17. data/lib/routes.ts +33 -27
  18. data/lib/tasks/js_routes.rake +4 -2
  19. metadata +12 -145
  20. data/.document +0 -5
  21. data/.eslintrc.js +0 -15
  22. data/.github/workflows/ci.yml +0 -36
  23. data/.gitignore +0 -65
  24. data/.nvmrc +0 -1
  25. data/.rspec +0 -1
  26. data/Appraisals +0 -17
  27. data/Gemfile +0 -9
  28. data/Rakefile +0 -37
  29. data/VERSION_2_UPGRADE.md +0 -66
  30. data/bin/tapioca +0 -27
  31. data/gemfiles/rails50_sprockets_3.gemfile +0 -8
  32. data/gemfiles/rails51_sprockets_3.gemfile +0 -8
  33. data/gemfiles/rails52_sprockets_3.gemfile +0 -8
  34. data/gemfiles/rails70_sprockets_4.gemfile +0 -8
  35. data/js-routes.gemspec +0 -42
  36. data/package.json +0 -38
  37. data/sorbet/config +0 -4
  38. data/sorbet/rbi/annotations/.gitattributes +0 -1
  39. data/sorbet/rbi/annotations/actionpack.rbi +0 -428
  40. data/sorbet/rbi/annotations/actionview.rbi +0 -75
  41. data/sorbet/rbi/annotations/activesupport.rbi +0 -421
  42. data/sorbet/rbi/annotations/railties.rbi +0 -61
  43. data/sorbet/rbi/gems/.gitattributes +0 -1
  44. data/sorbet/rbi/gems/actionpack@7.0.4.1.rbi +0 -303
  45. data/sorbet/rbi/gems/actionview@7.0.4.1.rbi +0 -8
  46. data/sorbet/rbi/gems/activesupport@7.0.4.1.rbi +0 -16424
  47. data/sorbet/rbi/gems/appraisal@2.4.1.rbi +0 -584
  48. data/sorbet/rbi/gems/builder@3.2.4.rbi +0 -8
  49. data/sorbet/rbi/gems/bump@0.10.0.rbi +0 -168
  50. data/sorbet/rbi/gems/byebug@11.1.3.rbi +0 -3606
  51. data/sorbet/rbi/gems/coderay@1.1.3.rbi +0 -3426
  52. data/sorbet/rbi/gems/concurrent-ruby@1.2.0.rbi +0 -11570
  53. data/sorbet/rbi/gems/crass@1.0.6.rbi +0 -8
  54. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +0 -1083
  55. data/sorbet/rbi/gems/erubi@1.12.0.rbi +0 -145
  56. data/sorbet/rbi/gems/i18n@1.12.0.rbi +0 -2296
  57. data/sorbet/rbi/gems/libv8-node@16.10.0.0.rbi +0 -8
  58. data/sorbet/rbi/gems/loofah@2.19.1.rbi +0 -8
  59. data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -272
  60. data/sorbet/rbi/gems/mini_racer@0.6.3.rbi +0 -224
  61. data/sorbet/rbi/gems/minitest@5.17.0.rbi +0 -1457
  62. data/sorbet/rbi/gems/netrc@0.11.0.rbi +0 -158
  63. data/sorbet/rbi/gems/nokogiri@1.14.0.rbi +0 -8
  64. data/sorbet/rbi/gems/parallel@1.24.0.rbi +0 -280
  65. data/sorbet/rbi/gems/prettier_print@1.2.1.rbi +0 -951
  66. data/sorbet/rbi/gems/prism@0.24.0.rbi +0 -29744
  67. data/sorbet/rbi/gems/pry-byebug@3.10.1.rbi +0 -1150
  68. data/sorbet/rbi/gems/pry@0.14.2.rbi +0 -10075
  69. data/sorbet/rbi/gems/racc@1.6.2.rbi +0 -150
  70. data/sorbet/rbi/gems/rack-test@2.0.2.rbi +0 -8
  71. data/sorbet/rbi/gems/rack@2.2.6.2.rbi +0 -5585
  72. data/sorbet/rbi/gems/rails-dom-testing@2.0.3.rbi +0 -8
  73. data/sorbet/rbi/gems/rails-html-sanitizer@1.5.0.rbi +0 -8
  74. data/sorbet/rbi/gems/railties@7.0.4.1.rbi +0 -1959
  75. data/sorbet/rbi/gems/rake@13.0.6.rbi +0 -3072
  76. data/sorbet/rbi/gems/rbi@0.1.9.rbi +0 -3006
  77. data/sorbet/rbi/gems/rspec-core@3.12.0.rbi +0 -10868
  78. data/sorbet/rbi/gems/rspec-expectations@3.12.2.rbi +0 -8100
  79. data/sorbet/rbi/gems/rspec-mocks@3.12.3.rbi +0 -5299
  80. data/sorbet/rbi/gems/rspec-support@3.12.0.rbi +0 -1611
  81. data/sorbet/rbi/gems/rspec@3.12.0.rbi +0 -82
  82. data/sorbet/rbi/gems/spoom@1.2.4.rbi +0 -3777
  83. data/sorbet/rbi/gems/sprockets-rails@3.4.2.rbi +0 -14
  84. data/sorbet/rbi/gems/sprockets@4.2.0.rbi +0 -8
  85. data/sorbet/rbi/gems/syntax_tree@6.2.0.rbi +0 -23136
  86. data/sorbet/rbi/gems/tapioca@0.12.0.rbi +0 -3510
  87. data/sorbet/rbi/gems/thor@1.2.1.rbi +0 -3956
  88. data/sorbet/rbi/gems/tzinfo@2.0.5.rbi +0 -5914
  89. data/sorbet/rbi/gems/yard-sorbet@0.8.1.rbi +0 -428
  90. data/sorbet/rbi/gems/yard@0.9.34.rbi +0 -18332
  91. data/sorbet/rbi/gems/zeitwerk@2.6.8.rbi +0 -8
  92. data/sorbet/rbi/todo.rbi +0 -31
  93. data/sorbet/tapioca/config.yml +0 -13
  94. data/sorbet/tapioca/require.rb +0 -4
  95. data/spec/dummy/app/assets/config/manifest.js +0 -2
  96. data/spec/dummy/app/assets/javascripts/.gitkeep +0 -0
  97. data/spec/dummy/config/routes.rb +0 -55
  98. data/spec/js_routes/default_serializer_spec.rb +0 -31
  99. data/spec/js_routes/module_types/amd_spec.rb +0 -35
  100. data/spec/js_routes/module_types/cjs_spec.rb +0 -15
  101. data/spec/js_routes/module_types/dts/routes.spec.d.ts +0 -115
  102. data/spec/js_routes/module_types/dts/test.spec.ts +0 -56
  103. data/spec/js_routes/module_types/dts_spec.rb +0 -126
  104. data/spec/js_routes/module_types/esm_spec.rb +0 -45
  105. data/spec/js_routes/module_types/nil_spec.rb +0 -87
  106. data/spec/js_routes/module_types/umd_spec.rb +0 -85
  107. data/spec/js_routes/options_spec.rb +0 -508
  108. data/spec/js_routes/rails_routes_compatibility_spec.rb +0 -473
  109. data/spec/js_routes/route_specification_spec.rb +0 -37
  110. data/spec/js_routes/zzz_sprockets_spec.rb +0 -152
  111. data/spec/spec_helper.rb +0 -135
  112. data/spec/support/routes.rb +0 -81
  113. data/spec/tsconfig.json +0 -4
  114. data/tsconfig.json +0 -28
  115. data/yarn.lock +0 -2457
@@ -1,8 +0,0 @@
1
- # typed: true
2
-
3
- # DO NOT EDIT MANUALLY
4
- # This is an autogenerated file for types exported from the `zeitwerk` gem.
5
- # Please instead update this file by running `bin/tapioca gem zeitwerk`.
6
-
7
- # THIS IS AN EMPTY RBI FILE.
8
- # see https://github.com/Shopify/tapioca#manually-requiring-parts-of-a-gem
data/sorbet/rbi/todo.rbi DELETED
@@ -1,31 +0,0 @@
1
- # DO NOT EDIT MANUALLY
2
- # This is an autogenerated file for unresolved constants.
3
- # Please instead update this file by running `bin/tapioca todo`.
4
-
5
- # typed: false
6
-
7
- module ::Rhino; end
8
- module ActionController::MimeResponds::Collector; end
9
- module ActionDispatch::Flash::FlashHash; end
10
- module ActionDispatch::Http::Headers; end
11
- module ActionDispatch::Request::Session; end
12
- module ActionDispatch::Response; end
13
- module ActionDispatch::Response::Header; end
14
- module ActionDispatch::TestRequest; end
15
- module ActionDispatch::TestResponse; end
16
- module ActionView::Base; end
17
- module ActionView::Helpers::SanitizeHelper::ClassMethods; end
18
- module ActionView::Helpers::TagHelper; end
19
- module ActionView::Helpers::UrlHelper::ClassMethods; end
20
- module ActionView::Layouts::ClassMethods; end
21
- module ActionView::Rendering::ClassMethods; end
22
- module ActionView::Template::Error; end
23
- module ActiveSupport::HashWithIndifferentAccess; end
24
- module MiniRacer::JSError; end
25
- module Rack::Test::CookieJar; end
26
- module Sprockets::Context; end
27
- module Sprockets::VERSION; end
28
- module Webpacker; end
29
- class ActionView::ActionViewError; end
30
- class AbstractController::Base; end
31
- class ActionController::Base; end
@@ -1,13 +0,0 @@
1
- gem:
2
- # Add your `gem` command parameters here:
3
- #
4
- # exclude:
5
- # - gem_name
6
- # doc: true
7
- # workers: 5
8
- dsl:
9
- # Add your `dsl` command parameters here:
10
- #
11
- # exclude:
12
- # - SomeGeneratorName
13
- # workers: 5
@@ -1,4 +0,0 @@
1
- # typed: true
2
- # frozen_string_literal: true
3
-
4
- # Add your extra requires here (`bin/tapioca require` can be used to bootstrap this list)
@@ -1,2 +0,0 @@
1
- //= link_tree ../images
2
- //= link_directory ../stylesheets .css
File without changes
@@ -1,55 +0,0 @@
1
- App.routes.draw do
2
- resource "3df1b2d050ae5a96eac8565c9daef37a"
3
- resource "341f9e69e3db1c344de2fc6551885711"
4
- resource "0e1bcb2dc1ce4d80ec15cae9140fb99a"
5
- resource "15b91c612530bfc69c70d121c8713da4"
6
- resource "49e12936168a64dce4d4ec148104fb5a"
7
- resource "d878104611f88952aba49965c1d2d573"
8
- resource "0e94bfc3c8aaee5ea09579fe73cbdaff"
9
- resource "e1c2dd2ea9c63b380eb0947a0e1f49aa"
10
- resource "587c6e26ad7f9a6aa09f81add77b16f5"
11
- resource "8e00bfffebe0c874d6dad1c7b8c7cd6b"
12
- resource "394482d3515e7e49989a8496afa7d367"
13
- resource "4ab9c701622cba87eae50795564abe1c"
14
- resource "af4b4a2ea501fefbdb8367eb108b2e14"
15
- resource "116d17a93932a9a3e5bd2750665582f9"
16
- resource "315f0a62063288cd56373c8a00870596"
17
- resource "d5357ec6df4589f81ca8689cf0231667"
18
- resource "560a3b8cf807e873843cd889400cd52b"
19
- resource "361de6041f545e67db1aeaa6206c8ac7"
20
- resource "28b0a54de4a0884386f1e324edc13194"
21
- resource "ab77f21a956d956295187806cdf38cd1"
22
- resource "0b8a362fd486247fb7c41898709b9815"
23
- resource "5efa0a96733bc027b3309ffb54d1d1d0"
24
- resource "70a3ee535c59fcf59c58b6d39178833c"
25
- resource "5095fc05868c673ce450524f78cd28d3"
26
- resource "79b994cfbc79432d644a3b83804f4924"
27
- resource "e25125c477cd451fd74a76eaaebc9165"
28
- resource "672fbfb432687e2fee7d0e799cc10ea4"
29
- resource "2eb8350243305659082eb92b2e5b702c"
30
- resource "08c9973b624e10b10dc7235659c81346"
31
- resource "fee0d4b123529a2c652bef0ec0116ef2"
32
- resource "8422445d2aa176b7733473164c461a2e"
33
- resource "c24b8252b235431ca3df21a6ac119062"
34
- resource "c08c66c7fc40e9937ff84a86f6c6d18a"
35
- resource "964851acca72064d861188150e848d55"
36
- resource "d02927a4fd37b37c03dbad5d3c7a4753"
37
- resource "2a69df680ff9bd8d3855d9ce5a4e51f7"
38
- resource "d8daed677f9a9a6926005afbdeebcf73"
39
- resource "83d4db872f5f148e9ead108d483fec78"
40
- resource "09f9fb4250595d26f4149b76fcfa957d"
41
- resource "956cdb4d3cbf36bb9ccb7c7fcc36a602"
42
- resource "02816449a6c929f55f8bad958f25d25a"
43
- resource "2dd7ae38bd72f7e8b26aafb5f002d634"
44
- resource "c7c9aaa3f7131f1e7dbc9325b3426d3e"
45
- resource "7556e7d17c2a26acbad7d5fa86e6e640"
46
- resource "d03081ef427a227a808c708282fdc86b"
47
- resource "8f610d21e6e499c1eea98ca08191c05f"
48
- resource "b6b412ae8a369f6bfc7f312245eacc8c"
49
- resource "e9bcda8b00879c49bd7f05afee59a28e"
50
- resource "6e89f4baddd4044b42be7c2d3b382567"
51
- resource "5959c376d15a609f2e74f4f351d0a565"
52
- resource "3b7e418511c305c78f2d2c292a3a1289"
53
- resource "87acf6bf6e8191ff8900f420b33d5268"
54
- resource "648a9b17078423f29f42aa2ecac1cc7d"
55
- end
@@ -1,31 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe JsRoutes, "#serialize" do
4
-
5
- before(:each) do
6
- evallib(module_type: nil, namespace: 'Routes')
7
- end
8
-
9
- it "should provide this method" do
10
- expectjs("Routes.serialize({a: 1, b: [2,3], c: {d: 4, e: 5}, f: ''})").to eq(
11
- "a=1&b%5B%5D=2&b%5B%5D=3&c%5Bd%5D=4&c%5Be%5D=5&f="
12
- )
13
- end
14
-
15
- it "should provide this method" do
16
- expectjs("Routes.serialize({a: 1, b: [2,3], c: {d: 4, e: 5}, f: ''})").to eq(
17
- "a=1&b%5B%5D=2&b%5B%5D=3&c%5Bd%5D=4&c%5Be%5D=5&f="
18
- )
19
- end
20
-
21
- it "works with JS suckiness" do
22
- expectjs(
23
- [
24
- "const query = Object.create(null);",
25
- "query.a = 1;",
26
- "query.b = 2;",
27
- "Routes.serialize(query);",
28
- ].join("\n")
29
- ).to eq("a=1&b=2")
30
- end
31
- end
@@ -1,35 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe JsRoutes, "compatibility with AMD/require.js" do
4
-
5
- before(:each) do
6
- evaljs("var global = this;", force: true)
7
- evaljs("global.GlobalCheck = {};")
8
- evaljs("global.define = function (requirs, callback) { global.GlobalCheck['js-routes'] = callback.call(this); return global.GlobalCheck['js-routes']; };")
9
- evaljs("global.define.amd = { jQuery: true };")
10
- strRequire =<<EOF
11
- global.require = function (r, callback) {
12
- var allArgs, i;
13
-
14
- allArgs = (function() {
15
- var _i, _len, _results;
16
- _results = [];
17
- for (_i = 0, _len = r.length; _i < _len; _i++) {
18
- i = r[_i];
19
- _results.push(global.GlobalCheck[i]);
20
- }
21
- return _results;
22
- })();
23
-
24
- return callback.apply(null, allArgs);
25
- };
26
- EOF
27
- evaljs(strRequire)
28
- evaljs(JsRoutes.generate(module_type: 'AMD'))
29
- end
30
-
31
- it "should working from require" do
32
- expectjs("require(['js-routes'], function(r){ return r.inboxes_path(); })").to eq(test_routes.inboxes_path())
33
- end
34
-
35
- end
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe JsRoutes, "compatibility with CJS" do
4
- before(:each) do
5
- evaljs("module = { exports: null }")
6
- evaljs(JsRoutes.generate(
7
- module_type: 'CJS',
8
- include: /^inboxes/
9
- ))
10
- end
11
-
12
- it "should define module exports" do
13
- expectjs("module.exports.inboxes_path()").to eq(test_routes.inboxes_path())
14
- end
15
- end
@@ -1,115 +0,0 @@
1
- /**
2
- * File generated by js-routes RubyVariables.GEM_VERSION
3
- * Based on Rails RubyVariables.RAILS_VERSION routes of RubyVariables.APP_CLASS
4
- */
5
- declare type Optional<T> = {
6
- [P in keyof T]?: T[P] | null;
7
- };
8
- declare type BaseRouteParameter = string | boolean | Date | number;
9
- declare type MethodRouteParameter = BaseRouteParameter | (() => BaseRouteParameter);
10
- declare type ModelRouteParameter = {
11
- id: MethodRouteParameter;
12
- } | {
13
- to_param: MethodRouteParameter;
14
- } | {
15
- toParam: MethodRouteParameter;
16
- };
17
- declare type RequiredRouteParameter = BaseRouteParameter | ModelRouteParameter;
18
- declare type OptionalRouteParameter = undefined | null | RequiredRouteParameter;
19
- declare type QueryRouteParameter = OptionalRouteParameter | QueryRouteParameter[] | {
20
- [k: string]: QueryRouteParameter;
21
- };
22
- declare type RouteParameters = Record<string, QueryRouteParameter>;
23
- declare type Serializable = Record<string, unknown>;
24
- declare type Serializer = (value: Serializable) => string;
25
- declare type RouteHelperExtras = {
26
- requiredParams(): string[];
27
- toString(): string;
28
- };
29
- declare type RequiredParameters<T extends number> = T extends 1 ? [RequiredRouteParameter] : T extends 2 ? [RequiredRouteParameter, RequiredRouteParameter] : T extends 3 ? [RequiredRouteParameter, RequiredRouteParameter, RequiredRouteParameter] : T extends 4 ? [
30
- RequiredRouteParameter,
31
- RequiredRouteParameter,
32
- RequiredRouteParameter,
33
- RequiredRouteParameter
34
- ] : RequiredRouteParameter[];
35
- declare type RouteHelperOptions = RouteOptions & Record<string, OptionalRouteParameter>;
36
- declare type RouteHelper<T extends number = number> = ((...args: [...RequiredParameters<T>, RouteHelperOptions]) => string) & RouteHelperExtras;
37
- declare type RouteHelpers = Record<string, RouteHelper>;
38
- declare type Configuration = {
39
- prefix: string;
40
- default_url_options: RouteParameters;
41
- special_options_key: string;
42
- serializer: Serializer;
43
- };
44
- interface RouterExposedMethods {
45
- config(): Configuration;
46
- configure(arg: Partial<Configuration>): Configuration;
47
- serialize: Serializer;
48
- }
49
- declare type KeywordUrlOptions = Optional<{
50
- host: string;
51
- protocol: string;
52
- subdomain: string;
53
- port: string | number;
54
- anchor: string;
55
- trailing_slash: boolean;
56
- params: RouteParameters;
57
- }>;
58
- declare type RouteOptions = KeywordUrlOptions & RouteParameters;
59
- declare type PartsTable = Record<string, {
60
- r?: boolean;
61
- d?: OptionalRouteParameter;
62
- }>;
63
- declare type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
64
- declare const RubyVariables: {
65
- PREFIX: string;
66
- DEPRECATED_GLOBBING_BEHAVIOR: boolean;
67
- DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
68
- SPECIAL_OPTIONS_KEY: string;
69
- DEFAULT_URL_OPTIONS: RouteParameters;
70
- SERIALIZER: Serializer;
71
- ROUTES_OBJECT: RouteHelpers;
72
- MODULE_TYPE: ModuleType;
73
- WRAPPER: <T>(callback: T) => T;
74
- };
75
- declare const define: undefined | (((arg: unknown[], callback: () => unknown) => void) & {
76
- amd?: unknown;
77
- });
78
- declare const module: {
79
- exports: any;
80
- } | undefined;
81
- export const configure: RouterExposedMethods['configure'];
82
-
83
- export const config: RouterExposedMethods['config'];
84
-
85
- export const serialize: RouterExposedMethods['serialize'];
86
-
87
- /**
88
- * Generates rails route to
89
- * /inboxes/:inbox_id/messages/:message_id/attachments/:id(.:format)
90
- * @param {any} inbox_id
91
- * @param {any} message_id
92
- * @param {any} id
93
- * @param {object | undefined} options
94
- * @returns {string} route path
95
- */
96
- export const inbox_message_attachment_path: ((
97
- inbox_id: RequiredRouteParameter,
98
- message_id: RequiredRouteParameter,
99
- id: RequiredRouteParameter,
100
- options?: {format?: OptionalRouteParameter} & RouteOptions
101
- ) => string) & RouteHelperExtras;
102
-
103
- /**
104
- * Generates rails route to
105
- * /inboxes(.:format)
106
- * @param {object | undefined} options
107
- * @returns {string} route path
108
- */
109
- export const inboxes_path: ((
110
- options?: {format?: OptionalRouteParameter} & RouteOptions
111
- ) => string) & RouteHelperExtras;
112
-
113
- // By some reason this line prevents all types in a file
114
- // from being automatically exported
115
- export {};
@@ -1,56 +0,0 @@
1
- import {
2
- inbox_message_attachment_path,
3
- inboxes_path,
4
- serialize,
5
- configure,
6
- config,
7
- } from "./routes.spec";
8
-
9
- // Route Helpers
10
- inboxes_path();
11
- inboxes_path({
12
- locale: "en",
13
- search: {
14
- q: "ukraine",
15
- page: 3,
16
- keywords: ["large", "small", { advanced: true }],
17
- },
18
- });
19
-
20
- inbox_message_attachment_path(1, "2", true);
21
- inbox_message_attachment_path(
22
- { id: 1 },
23
- { to_param: () => "2" },
24
- { toParam: () => true }
25
- );
26
- inbox_message_attachment_path(1, "2", true, { format: "json" });
27
- inboxes_path.toString();
28
- inboxes_path.requiredParams();
29
-
30
- // serialize test
31
- const SerializerArgument = {
32
- locale: "en",
33
- search: {
34
- q: "ukraine",
35
- page: 3,
36
- keywords: ["large", "small", { advanced: true }],
37
- },
38
- };
39
- serialize(SerializerArgument);
40
- config().serializer(SerializerArgument);
41
-
42
- // configure test
43
- configure({
44
- default_url_options: { port: 1, host: null },
45
- prefix: "",
46
- special_options_key: "_options",
47
- serializer: (value) => JSON.stringify(value),
48
- });
49
-
50
- // config tests
51
- const Config = config();
52
- console.log(
53
- Config.prefix,
54
- Config.default_url_options,
55
- Config.special_options_key
56
- );
@@ -1,126 +0,0 @@
1
-
2
- require "active_support/core_ext/string/strip"
3
- require "fileutils"
4
- require "open3"
5
- require "spec_helper"
6
-
7
- describe JsRoutes, "compatibility with DTS" do
8
-
9
- INCLUDE_OPTION = [/^inboxes$/, /^inbox_message_attachment$/]
10
- OPTIONS = {module_type: 'DTS', include: INCLUDE_OPTION}
11
-
12
- let(:extra_options) do
13
- {}
14
- end
15
-
16
- let(:options) do
17
- { module_type: 'DTS', include: INCLUDE_OPTION, **extra_options }
18
- end
19
-
20
- let(:generated_js) do
21
- JsRoutes.generate(**options)
22
- end
23
-
24
- context "when file is generated" do
25
- let(:dir_name) do
26
- File.expand_path(__dir__ + "/dts")
27
- end
28
-
29
- let(:file_name) do
30
- dir_name + "/routes.spec.d.ts"
31
- end
32
-
33
- before do
34
- FileUtils.mkdir_p(dir_name)
35
- File.write(file_name, generated_js)
36
- end
37
-
38
- it "has no compile errors", :slow do
39
- command = "yarn tsc --strict --noEmit -p spec/tsconfig.json"
40
- stdout, stderr, status = Open3.capture3(command)
41
- expect(stderr).to eq("")
42
- expect(stdout).to include("Done in ")
43
- expect(status).to eq(0)
44
- end
45
- end
46
-
47
- context "when camel case is enabled" do
48
- let(:extra_options) { {camel_case: true} }
49
-
50
- it "camelizes route name and arguments" do
51
-
52
- expect(generated_js).to include(<<-DOC.rstrip)
53
- /**
54
- * Generates rails route to
55
- * /inboxes/:inbox_id/messages/:message_id/attachments/:id(.:format)
56
- * @param {any} inboxId
57
- * @param {any} messageId
58
- * @param {any} id
59
- * @param {object | undefined} options
60
- * @returns {string} route path
61
- */
62
- export const inboxMessageAttachmentPath: ((
63
- inboxId: RequiredRouteParameter,
64
- messageId: RequiredRouteParameter,
65
- id: RequiredRouteParameter,
66
- options?: {format?: OptionalRouteParameter} & RouteOptions
67
- ) => string) & RouteHelperExtras;
68
- DOC
69
- end
70
- end
71
-
72
- it "exports route helpers" do
73
- expect(generated_js).to include(<<-DOC.rstrip)
74
- /**
75
- * Generates rails route to
76
- * /inboxes(.:format)
77
- * @param {object | undefined} options
78
- * @returns {string} route path
79
- */
80
- export const inboxes_path: ((
81
- options?: {format?: OptionalRouteParameter} & RouteOptions
82
- ) => string) & RouteHelperExtras;
83
- DOC
84
- expect(generated_js).to include(<<-DOC.rstrip)
85
- /**
86
- * Generates rails route to
87
- * /inboxes/:inbox_id/messages/:message_id/attachments/:id(.:format)
88
- * @param {any} inbox_id
89
- * @param {any} message_id
90
- * @param {any} id
91
- * @param {object | undefined} options
92
- * @returns {string} route path
93
- */
94
- export const inbox_message_attachment_path: ((
95
- inbox_id: RequiredRouteParameter,
96
- message_id: RequiredRouteParameter,
97
- id: RequiredRouteParameter,
98
- options?: {format?: OptionalRouteParameter} & RouteOptions
99
- ) => string) & RouteHelperExtras
100
- DOC
101
- end
102
-
103
- it "exports utility methods" do
104
- expect(generated_js).to include("export const serialize: RouterExposedMethods['serialize'];")
105
- end
106
-
107
- it "prevents all types from automatic export" do
108
- expect(generated_js).to include("export {};")
109
- end
110
-
111
- describe "compiled javascript asset" do
112
- subject { ERB.new(File.read("app/assets/javascripts/js-routes.js.erb")).result(binding) }
113
- it "should have js routes code" do
114
- is_expected.to include("export const inbox_message_path = /*#__PURE__*/ __jsr.r(")
115
- end
116
- end
117
-
118
- describe ".definitions" do
119
- let(:extra_options) { { module_type: 'ESM' } }
120
-
121
- it "uses DTS module automatically" do
122
- generated_js = JsRoutes.definitions(**options)
123
- expect(generated_js).to include('export {};')
124
- end
125
- end
126
- end
@@ -1,45 +0,0 @@
1
- require "active_support/core_ext/string/strip"
2
- require "spec_helper"
3
-
4
- describe JsRoutes, "compatibility with ESM" do
5
-
6
- let(:generated_js) {
7
- JsRoutes.generate(module_type: 'ESM')
8
- }
9
-
10
- before(:each) do
11
- # export keyword is not supported by a simulated js environment
12
- evaljs(generated_js.gsub("export const ", "const "))
13
- end
14
-
15
- it "defines route helpers" do
16
- expectjs("inboxes_path()").to eq(test_routes.inboxes_path())
17
- end
18
-
19
- it "exports route helpers" do
20
- expect(generated_js).to include(<<-DOC.rstrip)
21
- /**
22
- * Generates rails route to
23
- * /inboxes(.:format)
24
- * @param {object | undefined} options
25
- * @returns {string} route path
26
- */
27
- export const inboxes_path = /*#__PURE__*/ __jsr.r(
28
- DOC
29
- end
30
-
31
- it "exports utility methods" do
32
- expect(generated_js).to include("export const serialize = ")
33
- end
34
-
35
- it "defines utility methods" do
36
- expectjs("serialize({a: 1, b: 2})").to eq({a: 1, b: 2}.to_param)
37
- end
38
-
39
- describe "compiled javascript asset" do
40
- subject { ERB.new(File.read("app/assets/javascripts/js-routes.js.erb")).result(binding) }
41
- it "should have js routes code" do
42
- is_expected.to include("export const inbox_message_path = /*#__PURE__*/ __jsr.r(")
43
- end
44
- end
45
- end
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe JsRoutes, "compatibility with NIL (legacy browser)" do
4
- let(:generated_js) do
5
- JsRoutes.generate(
6
- module_type: nil,
7
- include: /book|inboxes|inbox_message/,
8
- **_options
9
- )
10
- end
11
-
12
- let(:_options) { {} }
13
- describe "generated js" do
14
- subject do
15
- generated_js
16
- end
17
-
18
- it "should call route function for each route" do
19
- is_expected.to include("inboxes_path: __jsr.r(")
20
- end
21
- it "should have correct function without arguments signature" do
22
- is_expected.to include('inboxes_path: __jsr.r({"format":{}}')
23
- end
24
- it "should have correct function with arguments signature" do
25
- is_expected.to include('inbox_message_path: __jsr.r({"inbox_id":{"r":true},"id":{"r":true},"format":{}}')
26
- end
27
- it "should have correct function signature with unordered hash" do
28
- is_expected.to include('inbox_message_attachment_path: __jsr.r({"inbox_id":{"r":true},"message_id":{"r":true},"id":{"r":true},"format":{}}')
29
- end
30
- end
31
-
32
- describe "inline generation" do
33
- let(:_options) { {namespace: nil} }
34
- before do
35
- evaljs("const r = #{generated_js}")
36
- end
37
-
38
- it "should be possible" do
39
- expectjs("r.inboxes_path()").to eq(test_routes.inboxes_path())
40
- end
41
- end
42
-
43
- describe "namespace option" do
44
- let(:_options) { {namespace: "PHM"} }
45
- let(:_presetup) { "" }
46
- before do
47
- evaljs("var window = this;")
48
- evaljs("window.PHM = {}")
49
- evaljs(_presetup)
50
- evaljs(generated_js)
51
- end
52
- it "should use this namespace for routing" do
53
- expectjs("window.Routes").to be_nil
54
- expectjs("window.PHM.inboxes_path").not_to be_nil
55
- end
56
-
57
- describe "is nested" do
58
- context "and defined on client" do
59
- let(:_presetup) { "window.PHM = {}" }
60
- let(:_options) { {namespace: "PHM.Routes"} }
61
-
62
- it "should use this namespace for routing" do
63
- expectjs("PHM.Routes.inboxes_path").not_to be_nil
64
- end
65
- end
66
-
67
- context "but undefined on client" do
68
- let(:_options) { {namespace: "PHM.Routes"} }
69
-
70
- it "should initialize namespace" do
71
- expectjs("window.PHM.Routes.inboxes_path").not_to be_nil
72
- end
73
- end
74
-
75
- context "and some parts are defined" do
76
- let(:_presetup) { "window.PHM = { Utils: {} };" }
77
- let(:_options) { {namespace: "PHM.Routes"} }
78
-
79
- it "should not overwrite existing parts" do
80
- expectjs("window.PHM.Utils").not_to be_nil
81
- expectjs("window.PHM.Routes.inboxes_path").not_to be_nil
82
- end
83
- end
84
- end
85
- end
86
- end
87
-