js-routes 2.2.8 → 2.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -9
- data/Readme.md +60 -45
- data/lib/js_routes/configuration.rb +80 -34
- data/lib/js_routes/engine.rb +2 -0
- data/lib/js_routes/generators/base.rb +19 -0
- data/lib/js_routes/generators/middleware.rb +6 -8
- data/lib/js_routes/generators/webpacker.rb +1 -3
- data/lib/js_routes/instance.rb +50 -15
- data/lib/js_routes/middleware.rb +16 -3
- data/lib/js_routes/route.rb +60 -17
- data/lib/js_routes/types.rb +38 -0
- data/lib/js_routes/version.rb +2 -1
- data/lib/js_routes.rb +25 -7
- metadata +28 -45
- data/.document +0 -5
- data/.eslintrc.js +0 -15
- data/.github/workflows/ci.yml +0 -36
- data/.gitignore +0 -65
- data/.nvmrc +0 -1
- data/.rspec +0 -1
- data/Appraisals +0 -17
- data/Gemfile +0 -4
- data/Rakefile +0 -37
- data/VERSION_2_UPGRADE.md +0 -66
- data/gemfiles/rails50_sprockets_3.gemfile +0 -8
- data/gemfiles/rails51_sprockets_3.gemfile +0 -8
- data/gemfiles/rails52_sprockets_3.gemfile +0 -8
- data/gemfiles/rails70_sprockets_4.gemfile +0 -8
- data/js-routes.gemspec +0 -39
- data/package.json +0 -38
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/config/routes.rb +0 -55
- data/spec/js_routes/default_serializer_spec.rb +0 -31
- data/spec/js_routes/module_types/amd_spec.rb +0 -35
- data/spec/js_routes/module_types/cjs_spec.rb +0 -15
- data/spec/js_routes/module_types/dts/routes.spec.d.ts +0 -115
- data/spec/js_routes/module_types/dts/test.spec.ts +0 -56
- data/spec/js_routes/module_types/dts_spec.rb +0 -111
- data/spec/js_routes/module_types/esm_spec.rb +0 -45
- data/spec/js_routes/module_types/nil_spec.rb +0 -87
- data/spec/js_routes/module_types/umd_spec.rb +0 -85
- data/spec/js_routes/options_spec.rb +0 -508
- data/spec/js_routes/rails_routes_compatibility_spec.rb +0 -473
- data/spec/js_routes/route_specification_spec.rb +0 -37
- data/spec/js_routes/zzz_sprockets_spec.rb +0 -152
- data/spec/spec_helper.rb +0 -135
- data/spec/support/routes.rb +0 -81
- data/spec/tsconfig.json +0 -4
- data/tsconfig.json +0 -28
- data/yarn.lock +0 -2457
@@ -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,111 +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
|
-
OPTIONS = {module_type: 'DTS', include: [/^inboxes$/, /^inbox_message_attachment$/]}
|
10
|
-
let(:extra_options) do
|
11
|
-
{}
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:generated_js) do
|
15
|
-
JsRoutes.generate(**OPTIONS, **extra_options)
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when file is generated" do
|
19
|
-
let(:dir_name) do
|
20
|
-
File.expand_path(__dir__ + "/dts")
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:file_name) do
|
24
|
-
dir_name + "/routes.spec.d.ts"
|
25
|
-
end
|
26
|
-
|
27
|
-
before do
|
28
|
-
FileUtils.mkdir_p(dir_name)
|
29
|
-
File.write(file_name, generated_js)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "has no compile errors", :slow do
|
33
|
-
command = "yarn tsc --strict --noEmit -p spec/tsconfig.json"
|
34
|
-
stdout, stderr, status = Open3.capture3(command)
|
35
|
-
expect(stderr).to eq("")
|
36
|
-
expect(stdout).to include("Done in ")
|
37
|
-
expect(status).to eq(0)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when camel case is enabled" do
|
42
|
-
let(:extra_options) { {camel_case: true} }
|
43
|
-
|
44
|
-
it "camelizes route name and arguments" do
|
45
|
-
|
46
|
-
expect(generated_js).to include(<<-DOC.rstrip)
|
47
|
-
/**
|
48
|
-
* Generates rails route to
|
49
|
-
* /inboxes/:inbox_id/messages/:message_id/attachments/:id(.:format)
|
50
|
-
* @param {any} inboxId
|
51
|
-
* @param {any} messageId
|
52
|
-
* @param {any} id
|
53
|
-
* @param {object | undefined} options
|
54
|
-
* @returns {string} route path
|
55
|
-
*/
|
56
|
-
export const inboxMessageAttachmentPath: ((
|
57
|
-
inboxId: RequiredRouteParameter,
|
58
|
-
messageId: RequiredRouteParameter,
|
59
|
-
id: RequiredRouteParameter,
|
60
|
-
options?: {format?: OptionalRouteParameter} & RouteOptions
|
61
|
-
) => string) & RouteHelperExtras;
|
62
|
-
DOC
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it "exports route helpers" do
|
67
|
-
expect(generated_js).to include(<<-DOC.rstrip)
|
68
|
-
/**
|
69
|
-
* Generates rails route to
|
70
|
-
* /inboxes(.:format)
|
71
|
-
* @param {object | undefined} options
|
72
|
-
* @returns {string} route path
|
73
|
-
*/
|
74
|
-
export const inboxes_path: ((
|
75
|
-
options?: {format?: OptionalRouteParameter} & RouteOptions
|
76
|
-
) => string) & RouteHelperExtras;
|
77
|
-
DOC
|
78
|
-
expect(generated_js).to include(<<-DOC.rstrip)
|
79
|
-
/**
|
80
|
-
* Generates rails route to
|
81
|
-
* /inboxes/:inbox_id/messages/:message_id/attachments/:id(.:format)
|
82
|
-
* @param {any} inbox_id
|
83
|
-
* @param {any} message_id
|
84
|
-
* @param {any} id
|
85
|
-
* @param {object | undefined} options
|
86
|
-
* @returns {string} route path
|
87
|
-
*/
|
88
|
-
export const inbox_message_attachment_path: ((
|
89
|
-
inbox_id: RequiredRouteParameter,
|
90
|
-
message_id: RequiredRouteParameter,
|
91
|
-
id: RequiredRouteParameter,
|
92
|
-
options?: {format?: OptionalRouteParameter} & RouteOptions
|
93
|
-
) => string) & RouteHelperExtras
|
94
|
-
DOC
|
95
|
-
end
|
96
|
-
|
97
|
-
it "exports utility methods" do
|
98
|
-
expect(generated_js).to include("export const serialize: RouterExposedMethods['serialize'];")
|
99
|
-
end
|
100
|
-
|
101
|
-
it "prevents all types from automatic export" do
|
102
|
-
expect(generated_js).to include("export {};")
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "compiled javascript asset" do
|
106
|
-
subject { ERB.new(File.read("app/assets/javascripts/js-routes.js.erb")).result(binding) }
|
107
|
-
it "should have js routes code" do
|
108
|
-
is_expected.to include("export const inbox_message_path = /*#__PURE__*/ __jsr.r(")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
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
|
-
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/string/strip"
|
2
|
-
require "fileutils"
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe JsRoutes, "compatibility with UMD" do
|
6
|
-
describe "generated js" do
|
7
|
-
subject do
|
8
|
-
JsRoutes.generate(
|
9
|
-
module_type: 'UMD',
|
10
|
-
include: /book|inboxes|inbox_message/,
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should include a comment in the header" do
|
15
|
-
app_class = "App"
|
16
|
-
|
17
|
-
is_expected.to include("File generated by js-routes #{JsRoutes::VERSION}")
|
18
|
-
is_expected.to include("Based on Rails #{ActionPack.version} routes of #{app_class}")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should call route function for each route" do
|
22
|
-
is_expected.to include("inboxes_path: __jsr.r(")
|
23
|
-
end
|
24
|
-
it "should have correct function without arguments signature" do
|
25
|
-
is_expected.to include('inboxes_path: __jsr.r({"format":{}}')
|
26
|
-
end
|
27
|
-
it "should have correct function with arguments signature" do
|
28
|
-
is_expected.to include('inbox_message_path: __jsr.r({"inbox_id":{"r":true},"id":{"r":true},"format":{}}')
|
29
|
-
end
|
30
|
-
it "should have correct function signature with unordered hash" do
|
31
|
-
is_expected.to include('inbox_message_attachment_path: __jsr.r({"inbox_id":{"r":true},"message_id":{"r":true},"id":{"r":true},"format":{}}')
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should have correct function comment with options argument" do
|
35
|
-
is_expected.to include(<<-DOC.rstrip)
|
36
|
-
/**
|
37
|
-
* Generates rails route to
|
38
|
-
* /inboxes(.:format)
|
39
|
-
* @param {object | undefined} options
|
40
|
-
* @returns {string} route path
|
41
|
-
*/
|
42
|
-
inboxes_path: __jsr.r
|
43
|
-
DOC
|
44
|
-
end
|
45
|
-
it "should have correct function comment with arguments" do
|
46
|
-
is_expected.to include(<<-DOC.rstrip)
|
47
|
-
/**
|
48
|
-
* Generates rails route to
|
49
|
-
* /inboxes/:inbox_id/messages/:message_id/attachments/new(.:format)
|
50
|
-
* @param {any} inbox_id
|
51
|
-
* @param {any} message_id
|
52
|
-
* @param {object | undefined} options
|
53
|
-
* @returns {string} route path
|
54
|
-
*/
|
55
|
-
new_inbox_message_attachment_path: __jsr.r
|
56
|
-
DOC
|
57
|
-
end
|
58
|
-
|
59
|
-
it "routes should be sorted in alphabetical order" do
|
60
|
-
expect(subject.index("book_path")).to be <= subject.index("inboxes_path")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe ".generate!" do
|
65
|
-
|
66
|
-
let(:name) { Rails.root.join('app', 'assets', 'javascripts', 'routes.js') }
|
67
|
-
|
68
|
-
before(:each) do
|
69
|
-
FileUtils.rm_f(name)
|
70
|
-
JsRoutes.generate!(file: name)
|
71
|
-
end
|
72
|
-
|
73
|
-
after(:each) do
|
74
|
-
FileUtils.rm_f(name)
|
75
|
-
end
|
76
|
-
|
77
|
-
after(:all) do
|
78
|
-
FileUtils.rm_f("#{File.dirname(__FILE__)}/../routes.js") # let(:name) is not available here
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should not generate file before initialization" do
|
82
|
-
expect(File.exist?(name)).to be_falsey
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|