js-routes 1.3.3 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/Appraisals +3 -3
- data/CHANGELOG.md +36 -0
- data/Readme.md +13 -1
- data/gemfiles/rails32.gemfile +1 -1
- data/gemfiles/rails40.gemfile +1 -1
- data/gemfiles/rails40_sprockets3.gemfile +1 -1
- data/gemfiles/rails41.gemfile +1 -1
- data/gemfiles/rails41_sprockets3.gemfile +1 -1
- data/gemfiles/rails42.gemfile +1 -2
- data/gemfiles/rails42_sprockets3.gemfile +1 -2
- data/gemfiles/rails50.gemfile +1 -1
- data/gemfiles/rails50_sprockets3.gemfile +1 -1
- data/js-routes.gemspec +1 -2
- data/lib/js_routes.rb +48 -43
- data/lib/js_routes/engine.rb +3 -5
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.js +59 -37
- data/lib/routes.js.coffee +45 -29
- data/spec/js_routes/amd_compatibility_spec.rb +2 -2
- data/spec/js_routes/default_serializer_spec.rb +3 -1
- data/spec/js_routes/generated_javascript_spec.rb +0 -4
- data/spec/js_routes/options_spec.rb +110 -137
- data/spec/js_routes/rails_routes_compatibility_spec.rb +84 -84
- data/spec/js_routes/zzz_last_post_rails_init_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -3
- metadata +5 -5
@@ -7,11 +7,11 @@ describe JsRoutes, "compatibility with Rails" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should generate collection routing" do
|
10
|
-
expect(evaljs("Routes.inboxes_path()")).to eq(
|
10
|
+
expect(evaljs("Routes.inboxes_path()")).to eq(test_routes.inboxes_path())
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should generate member routing" do
|
14
|
-
expect(evaljs("Routes.inbox_path(1)")).to eq(
|
14
|
+
expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1))
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should raise error if required argument is not passed" do
|
@@ -26,63 +26,63 @@ describe JsRoutes, "compatibility with Rails" do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should support 0 as a member parameter" do
|
29
|
-
expect(evaljs("Routes.inbox_path(0)")).to eq(
|
29
|
+
expect(evaljs("Routes.inbox_path(0)")).to eq(test_routes.inbox_path(0))
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should generate nested routing with one parameter" do
|
33
|
-
expect(evaljs("Routes.inbox_messages_path(1)")).to eq(
|
33
|
+
expect(evaljs("Routes.inbox_messages_path(1)")).to eq(test_routes.inbox_messages_path(1))
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should generate nested routing" do
|
37
|
-
expect(evaljs("Routes.inbox_message_path(1,2)")).to eq(
|
37
|
+
expect(evaljs("Routes.inbox_message_path(1,2)")).to eq(test_routes.inbox_message_path(1, 2))
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should generate routing with format" do
|
41
|
-
expect(evaljs("Routes.inbox_path(1, {format: 'json'})")).to eq(
|
41
|
+
expect(evaljs("Routes.inbox_path(1, {format: 'json'})")).to eq(test_routes.inbox_path(1, :format => "json"))
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should support routes with reserved javascript words as parameters" do
|
45
|
-
expect(evaljs("Routes.object_path(1, 2)")).to eq(
|
45
|
+
expect(evaljs("Routes.object_path(1, 2)")).to eq(test_routes.object_path(1,2))
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should support routes with trailing_slash" do
|
49
|
-
expect(evaljs("Routes.inbox_path(1, {trailing_slash: true})")).to eq(
|
49
|
+
expect(evaljs("Routes.inbox_path(1, {trailing_slash: true})")).to eq(test_routes.inbox_path(1, trailing_slash: true))
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should support url anchor given as parameter" do
|
53
|
-
expect(evaljs("Routes.inbox_path(1, {anchor: 'hello'})")).to eq(
|
53
|
+
expect(evaljs("Routes.inbox_path(1, {anchor: 'hello'})")).to eq(test_routes.inbox_path(1, :anchor => "hello"))
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should support url anchor and get parameters" do
|
57
|
-
expect(evaljs("Routes.inbox_path(1, {expanded: true, anchor: 'hello'})")).to eq(
|
57
|
+
expect(evaljs("Routes.inbox_path(1, {expanded: true, anchor: 'hello'})")).to eq(test_routes.inbox_path(1, :expanded => true, :anchor => "hello"))
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should use irregular ActiveSupport pluralizations" do
|
61
|
-
expect(evaljs("Routes.budgies_path()")).to eq(
|
62
|
-
expect(evaljs("Routes.budgie_path(1)")).to eq(
|
61
|
+
expect(evaljs("Routes.budgies_path()")).to eq(test_routes.budgies_path)
|
62
|
+
expect(evaljs("Routes.budgie_path(1)")).to eq(test_routes.budgie_path(1))
|
63
63
|
expect(evaljs("Routes.budgy_path")).to eq(nil)
|
64
|
-
expect(evaljs("Routes.budgie_descendents_path(1)")).to eq(
|
64
|
+
expect(evaljs("Routes.budgie_descendents_path(1)")).to eq(test_routes.budgie_descendents_path(1))
|
65
65
|
end
|
66
66
|
|
67
67
|
describe "when route has defaults" do
|
68
68
|
it "should support route default format" do
|
69
|
-
expect(evaljs("Routes.api_purchases_path()")).to eq(
|
69
|
+
expect(evaljs("Routes.api_purchases_path()")).to eq(test_routes.api_purchases_path)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'should support route default subdomain' do
|
73
|
-
expect(evaljs("Routes.backend_root_path()")).to eq(
|
73
|
+
expect(evaljs("Routes.backend_root_path()")).to eq(test_routes.backend_root_path)
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should support default format override" do
|
77
|
-
expect(evaljs("Routes.api_purchases_path({format: 'xml'})")).to eq(
|
77
|
+
expect(evaljs("Routes.api_purchases_path({format: 'xml'})")).to eq(test_routes.api_purchases_path(format: 'xml'))
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should support default format override by passing it in args" do
|
81
|
-
expect(evaljs("Routes.api_purchases_path('xml')")).to eq(
|
81
|
+
expect(evaljs("Routes.api_purchases_path('xml')")).to eq(test_routes.api_purchases_path('xml'))
|
82
82
|
end
|
83
83
|
|
84
84
|
it "doesn't apply defaults to path" do
|
85
|
-
expect(evaljs("Routes.with_defaults_path()")).to eq(
|
85
|
+
expect(evaljs("Routes.with_defaults_path()")).to eq(test_routes.with_defaults_path)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -92,7 +92,7 @@ describe JsRoutes, "compatibility with Rails" do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should support root route" do
|
95
|
-
expect(evaljs("Routes.blog_app_path()")).to eq(
|
95
|
+
expect(evaljs("Routes.blog_app_path()")).to eq(test_routes.blog_app_path())
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should support route with parameters" do
|
@@ -102,47 +102,47 @@ describe JsRoutes, "compatibility with Rails" do
|
|
102
102
|
expect(evaljs("Routes.blog_app_root_path()")).to eq(blog_routes.root_path)
|
103
103
|
end
|
104
104
|
it "should support single route mapping" do
|
105
|
-
expect(evaljs("Routes.support_path({page: 3})")).to eq(
|
105
|
+
expect(evaljs("Routes.support_path({page: 3})")).to eq(test_routes.support_path(:page => 3))
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
it "shouldn't require the format" do
|
110
|
-
expect(evaljs("Routes.json_only_path({format: 'json'})")).to eq(
|
110
|
+
expect(evaljs("Routes.json_only_path({format: 'json'})")).to eq(test_routes.json_only_path(:format => 'json'))
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should serialize object with empty string value" do
|
114
|
-
expect(evaljs("Routes.inboxes_path({a: '', b: 1})")).to eq(
|
114
|
+
expect(evaljs("Routes.inboxes_path({a: '', b: 1})")).to eq(test_routes.inboxes_path(:a => '', :b => 1))
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should support utf-8 route" do
|
118
|
-
expect(evaljs("Routes.hello_path()")).to eq(
|
118
|
+
expect(evaljs("Routes.hello_path()")).to eq(test_routes.hello_path)
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should support root_path" do
|
122
|
-
expect(evaljs("Routes.root_path()")).to eq(
|
122
|
+
expect(evaljs("Routes.root_path()")).to eq(test_routes.root_path)
|
123
123
|
end
|
124
124
|
|
125
125
|
describe "get paramters" do
|
126
126
|
it "should support simple get parameters" do
|
127
|
-
expect(evaljs("Routes.inbox_path(1, {format: 'json', lang: 'ua', q: 'hello'})")).to eq(
|
127
|
+
expect(evaljs("Routes.inbox_path(1, {format: 'json', lang: 'ua', q: 'hello'})")).to eq(test_routes.inbox_path(1, :lang => "ua", :q => "hello", :format => "json"))
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should support array get parameters" do
|
131
|
-
expect(evaljs("Routes.inbox_path(1, {hello: ['world', 'mars']})")).to eq(
|
131
|
+
expect(evaljs("Routes.inbox_path(1, {hello: ['world', 'mars']})")).to eq(test_routes.inbox_path(1, :hello => [:world, :mars]))
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should support nested get parameters" do
|
135
135
|
expect(evaljs("Routes.inbox_path(1, {format: 'json', env: 'test', search: { category_ids: [2,5], q: 'hello'}})")).to eq(
|
136
|
-
|
136
|
+
test_routes.inbox_path(1, :env => 'test', :search => {:category_ids => [2,5], :q => "hello"}, :format => "json")
|
137
137
|
)
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should support null and undefined parameters" do
|
141
|
-
expect(evaljs("Routes.inboxes_path({uri: null, key: undefined})")).to eq(
|
141
|
+
expect(evaljs("Routes.inboxes_path({uri: null, key: undefined})")).to eq(test_routes.inboxes_path(:uri => nil, :key => nil))
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should escape get parameters" do
|
145
|
-
expect(evaljs("Routes.inboxes_path({uri: 'http://example.com'})")).to eq(
|
145
|
+
expect(evaljs("Routes.inboxes_path({uri: 'http://example.com'})")).to eq(test_routes.inboxes_path(:uri => 'http://example.com'))
|
146
146
|
end
|
147
147
|
|
148
148
|
end
|
@@ -150,61 +150,61 @@ describe JsRoutes, "compatibility with Rails" do
|
|
150
150
|
|
151
151
|
context "routes globbing" do
|
152
152
|
it "should be supported as parameters" do
|
153
|
-
expect(evaljs("Routes.book_path('thrillers', 1)")).to eq(
|
153
|
+
expect(evaljs("Routes.book_path('thrillers', 1)")).to eq(test_routes.book_path('thrillers', 1))
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should support routes globbing as array" do
|
157
|
-
expect(evaljs("Routes.book_path(['thrillers'], 1)")).to eq(
|
157
|
+
expect(evaljs("Routes.book_path(['thrillers'], 1)")).to eq(test_routes.book_path(['thrillers'], 1))
|
158
158
|
end
|
159
159
|
|
160
160
|
it "should bee support routes globbing as array" do
|
161
|
-
expect(evaljs("Routes.book_path([1, 2, 3], 1)")).to eq(
|
161
|
+
expect(evaljs("Routes.book_path([1, 2, 3], 1)")).to eq(test_routes.book_path([1, 2, 3], 1))
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should bee support routes globbing as hash" do
|
165
|
-
expect(evaljs("Routes.book_path('a_test/b_test/c_test', 1)")).to eq(
|
165
|
+
expect(evaljs("Routes.book_path('a_test/b_test/c_test', 1)")).to eq(test_routes.book_path('a_test/b_test/c_test', 1))
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should support routes globbing as array with optional params" do
|
169
|
-
expect(evaljs("Routes.book_path([1, 2, 3, 5], 1, {c: '1'})")).to eq(
|
169
|
+
expect(evaljs("Routes.book_path([1, 2, 3, 5], 1, {c: '1'})")).to eq(test_routes.book_path([1, 2, 3, 5], 1, { :c => "1" }))
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should support routes globbing in book_title route as array" do
|
173
|
-
expect(evaljs("Routes.book_title_path('john', ['thrillers', 'comedian'])")).to eq(
|
173
|
+
expect(evaljs("Routes.book_title_path('john', ['thrillers', 'comedian'])")).to eq(test_routes.book_title_path('john', ['thrillers', 'comedian']))
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should support routes globbing in book_title route as array with optional params" do
|
177
|
-
expect(evaljs("Routes.book_title_path('john', ['thrillers', 'comedian'], {some_key: 'some_value'})")).to eq(
|
177
|
+
expect(evaljs("Routes.book_title_path('john', ['thrillers', 'comedian'], {some_key: 'some_value'})")).to eq(test_routes.book_title_path('john', ['thrillers', 'comedian'], {:some_key => 'some_value'}))
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should support required paramters given as options hash" do
|
181
|
-
expect(evaljs("Routes.search_path({q: 'hello'})")).to eq(
|
181
|
+
expect(evaljs("Routes.search_path({q: 'hello'})")).to eq(test_routes.search_path(:q => 'hello'))
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should support nested object null parameters" do
|
185
|
-
expect(evaljs("Routes.inboxes_path({hello: {world: null}})")).to eq(
|
185
|
+
expect(evaljs("Routes.inboxes_path({hello: {world: null}})")).to eq(test_routes.inboxes_path(:hello => {:world => nil}))
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
189
|
context "using optional path fragments" do
|
190
190
|
context "including not optional parts" do
|
191
191
|
it "should include everything that is not optional" do
|
192
|
-
expect(evaljs("Routes.foo_path()")).to eq(
|
192
|
+
expect(evaljs("Routes.foo_path()")).to eq(test_routes.foo_path)
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
196
|
context "but not including them" do
|
197
197
|
it "should not include the optional parts" do
|
198
|
-
expect(evaljs("Routes.things_path()")).to eq(
|
199
|
-
expect(evaljs("Routes.things_path({ q: 'hello' })")).to eq(
|
198
|
+
expect(evaljs("Routes.things_path()")).to eq(test_routes.things_path)
|
199
|
+
expect(evaljs("Routes.things_path({ q: 'hello' })")).to eq(test_routes.things_path(q: 'hello'))
|
200
200
|
end
|
201
201
|
|
202
202
|
it "should not require the optional parts as arguments" do
|
203
|
-
expect(evaljs("Routes.thing_path(null, 5)")).to eq(
|
203
|
+
expect(evaljs("Routes.thing_path(null, 5)")).to eq(test_routes.thing_path(nil, 5))
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should treat undefined as non-given optional part" do
|
207
|
-
expect(evaljs("Routes.thing_path(5, {optional_id: undefined})")).to eq(
|
207
|
+
expect(evaljs("Routes.thing_path(5, {optional_id: undefined})")).to eq(test_routes.thing_path(5, :optional_id => nil))
|
208
208
|
end
|
209
209
|
|
210
210
|
it "should raise error when passing non-full list of arguments and some query params" do
|
@@ -213,16 +213,16 @@ describe JsRoutes, "compatibility with Rails" do
|
|
213
213
|
end
|
214
214
|
|
215
215
|
it "should treat null as non-given optional part" do
|
216
|
-
expect(evaljs("Routes.thing_path(5, {optional_id: null})")).to eq(
|
216
|
+
expect(evaljs("Routes.thing_path(5, {optional_id: null})")).to eq(test_routes.thing_path(5, :optional_id => nil))
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should work when passing required params in options" do
|
220
|
-
expect(evaljs("Routes.thing_deep_path({second_required: 1, third_required: 2})")).to eq(
|
220
|
+
expect(evaljs("Routes.thing_deep_path({second_required: 1, third_required: 2})")).to eq(test_routes.thing_deep_path(second_required: 1, third_required: 2))
|
221
221
|
end
|
222
222
|
|
223
223
|
it "should skip leading and trailing optional parts" do
|
224
224
|
skip if Rails.version < '4'
|
225
|
-
expect(evaljs("Routes.thing_deep_path(1, 2)")).to eq(
|
225
|
+
expect(evaljs("Routes.thing_deep_path(1, 2)")).to eq(test_routes.thing_deep_path(1, 2))
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
@@ -237,29 +237,29 @@ describe JsRoutes, "compatibility with Rails" do
|
|
237
237
|
end
|
238
238
|
|
239
239
|
it "should include the optional parts" do
|
240
|
-
expect(evaljs("Routes.things_path({optional_id: 5})")).to eq(
|
241
|
-
expect(evaljs("Routes.things_path(5)")).to eq(
|
242
|
-
expect(evaljs("Routes.thing_deep_path(1, { third_required: 3, second_required: 2 })")).to eq(
|
243
|
-
expect(evaljs("Routes.thing_deep_path(1, { third_required: 3, second_required: 2, forth_optional: 4 })")).to eq(
|
244
|
-
expect(evaljs("Routes.thing_deep_path(2, { third_required: 3, first_optional: 1 })")).to eq(
|
245
|
-
expect(evaljs("Routes.thing_deep_path(3, { first_optional: 1, second_required: 2 })")).to eq(
|
246
|
-
expect(evaljs("Routes.thing_deep_path(3, { first_optional: 1, second_required: 2, forth_optional: 4 })")).to eq(
|
247
|
-
expect(evaljs("Routes.thing_deep_path(4, { first_optional: 1, second_required: 2, third_required: 3 })")).to eq(
|
248
|
-
expect(evaljs("Routes.thing_deep_path(1, 2, { third_required: 3 })")).to eq(
|
249
|
-
expect(evaljs("Routes.thing_deep_path(1,2, {third_required: 3, q: 'bogdan'})")).to eq(
|
250
|
-
expect(evaljs("Routes.thing_deep_path(1, 2, { forth_optional: 4, third_required: 3 })")).to eq(
|
251
|
-
expect(evaljs("Routes.thing_deep_path(1, 3, { second_required: 2 })")).to eq(
|
252
|
-
expect(evaljs("Routes.thing_deep_path(1, 4, { second_required: 2, third_required: 3 })")).to eq(
|
253
|
-
expect(evaljs("Routes.thing_deep_path(2, 3, { first_optional: 1 })")).to eq(
|
254
|
-
expect(evaljs("Routes.thing_deep_path(2, 3, { first_optional: 1, forth_optional: 4 })")).to eq(
|
255
|
-
expect(evaljs("Routes.thing_deep_path(2, 4, { first_optional: 1, third_required: 3 })")).to eq(
|
256
|
-
expect(evaljs("Routes.thing_deep_path(3, 4, { first_optional: 1, second_required: 2 })")).to eq(
|
257
|
-
expect(evaljs("Routes.thing_deep_path(1, 2, 3)")).to eq(
|
258
|
-
expect(evaljs("Routes.thing_deep_path(1, 2, 3, { forth_optional: 4 })")).to eq(
|
259
|
-
expect(evaljs("Routes.thing_deep_path(1, 2, 4, { third_required: 3 })")).to eq(
|
260
|
-
expect(evaljs("Routes.thing_deep_path(1, 3, 4, { second_required: 2 })")).to eq(
|
261
|
-
expect(evaljs("Routes.thing_deep_path(2, 3, 4, { first_optional: 1 })")).to eq(
|
262
|
-
expect(evaljs("Routes.thing_deep_path(1, 2, 3, 4)")).to eq(
|
240
|
+
expect(evaljs("Routes.things_path({optional_id: 5})")).to eq(test_routes.things_path(:optional_id => 5))
|
241
|
+
expect(evaljs("Routes.things_path(5)")).to eq(test_routes.things_path(5))
|
242
|
+
expect(evaljs("Routes.thing_deep_path(1, { third_required: 3, second_required: 2 })")).to eq(test_routes.thing_deep_path(1, third_required: 3, second_required: 2))
|
243
|
+
expect(evaljs("Routes.thing_deep_path(1, { third_required: 3, second_required: 2, forth_optional: 4 })")).to eq(test_routes.thing_deep_path(1, third_required: 3, second_required: 2, forth_optional: 4))
|
244
|
+
expect(evaljs("Routes.thing_deep_path(2, { third_required: 3, first_optional: 1 })")).to eq(test_routes.thing_deep_path(2, third_required: 3, first_optional: 1))
|
245
|
+
expect(evaljs("Routes.thing_deep_path(3, { first_optional: 1, second_required: 2 })")).to eq(test_routes.thing_deep_path(3, first_optional: 1, second_required: 2))
|
246
|
+
expect(evaljs("Routes.thing_deep_path(3, { first_optional: 1, second_required: 2, forth_optional: 4 })")).to eq(test_routes.thing_deep_path(3, first_optional: 1, second_required: 2, forth_optional: 4))
|
247
|
+
expect(evaljs("Routes.thing_deep_path(4, { first_optional: 1, second_required: 2, third_required: 3 })")).to eq(test_routes.thing_deep_path(4, first_optional: 1, second_required: 2, third_required: 3))
|
248
|
+
expect(evaljs("Routes.thing_deep_path(1, 2, { third_required: 3 })")).to eq(test_routes.thing_deep_path(1, 2, third_required: 3))
|
249
|
+
expect(evaljs("Routes.thing_deep_path(1,2, {third_required: 3, q: 'bogdan'})")).to eq(test_routes.thing_deep_path(1,2, {third_required: 3, q: 'bogdan'}))
|
250
|
+
expect(evaljs("Routes.thing_deep_path(1, 2, { forth_optional: 4, third_required: 3 })")).to eq(test_routes.thing_deep_path(1, 2, forth_optional: 4, third_required: 3))
|
251
|
+
expect(evaljs("Routes.thing_deep_path(1, 3, { second_required: 2 })")).to eq(test_routes.thing_deep_path(1, 3, second_required: 2))
|
252
|
+
expect(evaljs("Routes.thing_deep_path(1, 4, { second_required: 2, third_required: 3 })")).to eq(test_routes.thing_deep_path(1, 4, second_required: 2, third_required: 3))
|
253
|
+
expect(evaljs("Routes.thing_deep_path(2, 3, { first_optional: 1 })")).to eq(test_routes.thing_deep_path(2, 3, first_optional: 1))
|
254
|
+
expect(evaljs("Routes.thing_deep_path(2, 3, { first_optional: 1, forth_optional: 4 })")).to eq(test_routes.thing_deep_path(2, 3, first_optional: 1, forth_optional: 4))
|
255
|
+
expect(evaljs("Routes.thing_deep_path(2, 4, { first_optional: 1, third_required: 3 })")).to eq(test_routes.thing_deep_path(2, 4, first_optional: 1, third_required: 3))
|
256
|
+
expect(evaljs("Routes.thing_deep_path(3, 4, { first_optional: 1, second_required: 2 })")).to eq(test_routes.thing_deep_path(3, 4, first_optional: 1, second_required: 2))
|
257
|
+
expect(evaljs("Routes.thing_deep_path(1, 2, 3)")).to eq(test_routes.thing_deep_path(1, 2, 3))
|
258
|
+
expect(evaljs("Routes.thing_deep_path(1, 2, 3, { forth_optional: 4 })")).to eq(test_routes.thing_deep_path(1, 2, 3, forth_optional: 4))
|
259
|
+
expect(evaljs("Routes.thing_deep_path(1, 2, 4, { third_required: 3 })")).to eq(test_routes.thing_deep_path(1, 2, 4, third_required: 3))
|
260
|
+
expect(evaljs("Routes.thing_deep_path(1, 3, 4, { second_required: 2 })")).to eq(test_routes.thing_deep_path(1, 3, 4, second_required: 2))
|
261
|
+
expect(evaljs("Routes.thing_deep_path(2, 3, 4, { first_optional: 1 })")).to eq(test_routes.thing_deep_path(2, 3, 4, first_optional: 1))
|
262
|
+
expect(evaljs("Routes.thing_deep_path(1, 2, 3, 4)")).to eq(test_routes.thing_deep_path(1, 2, 3, 4))
|
263
263
|
|
264
264
|
end
|
265
265
|
|
@@ -267,7 +267,7 @@ describe JsRoutes, "compatibility with Rails" do
|
|
267
267
|
if Rails.version <= "5.0.0"
|
268
268
|
# this type of routing is deprecated
|
269
269
|
it "should include everything that is not optional" do
|
270
|
-
expect(evaljs("Routes.classic_path({controller: 'classic', action: 'edit'})")).to eq(
|
270
|
+
expect(evaljs("Routes.classic_path({controller: 'classic', action: 'edit'})")).to eq(test_routes.classic_path(controller: :classic, action: :edit))
|
271
271
|
end
|
272
272
|
end
|
273
273
|
end
|
@@ -311,7 +311,7 @@ describe JsRoutes, "compatibility with Rails" do
|
|
311
311
|
evaljs("Array.prototype.indexOf = null")
|
312
312
|
end
|
313
313
|
it "should still work correctly" do
|
314
|
-
expect(evaljs("Routes.inboxes_path()")).to eq(
|
314
|
+
expect(evaljs("Routes.inboxes_path()")).to eq(test_routes.inboxes_path())
|
315
315
|
end
|
316
316
|
end
|
317
317
|
|
@@ -321,63 +321,63 @@ describe JsRoutes, "compatibility with Rails" do
|
|
321
321
|
let(:inbox) { klass.new(1,"my") }
|
322
322
|
|
323
323
|
it "should support 0 as a to_param option" do
|
324
|
-
expect(evaljs("Routes.inbox_path({to_param: 0})")).to eq(
|
324
|
+
expect(evaljs("Routes.inbox_path({to_param: 0})")).to eq(test_routes.inbox_path(0))
|
325
325
|
end
|
326
326
|
|
327
327
|
it "should check for options special key" do
|
328
|
-
expect(evaljs("Routes.inbox_path({id: 7, q: 'hello', _options: true})")).to eq(
|
328
|
+
expect(evaljs("Routes.inbox_path({id: 7, q: 'hello', _options: true})")).to eq(test_routes.inbox_path(id: 7, q: 'hello'))
|
329
329
|
expect {
|
330
330
|
evaljs("Routes.inbox_path({to_param: 7, _options: true})")
|
331
331
|
}.to raise_error(js_error_class)
|
332
|
-
expect(evaljs("Routes.inbox_message_path(5, {id: 7, q: 'hello', _options: true})")).to eq(
|
332
|
+
expect(evaljs("Routes.inbox_message_path(5, {id: 7, q: 'hello', _options: true})")).to eq(test_routes.inbox_message_path(5, id: 7, q: 'hello'))
|
333
333
|
end
|
334
334
|
|
335
335
|
it "should check for options special key" do
|
336
336
|
end
|
337
337
|
|
338
338
|
it "should support 0 as an id option" do
|
339
|
-
expect(evaljs("Routes.inbox_path({id: 0})")).to eq(
|
339
|
+
expect(evaljs("Routes.inbox_path({id: 0})")).to eq(test_routes.inbox_path(0))
|
340
340
|
end
|
341
341
|
|
342
342
|
it "should use id property of the object in path" do
|
343
|
-
expect(evaljs("Routes.inbox_path({id: 1})")).to eq(
|
343
|
+
expect(evaljs("Routes.inbox_path({id: 1})")).to eq(test_routes.inbox_path(1))
|
344
344
|
end
|
345
345
|
|
346
346
|
it "should prefer to_param property over id property" do
|
347
|
-
expect(evaljs("Routes.inbox_path({id: 1, to_param: 'my'})")).to eq(
|
347
|
+
expect(evaljs("Routes.inbox_path({id: 1, to_param: 'my'})")).to eq(test_routes.inbox_path(inbox))
|
348
348
|
end
|
349
349
|
|
350
350
|
it "should call to_param if it is a function" do
|
351
|
-
expect(evaljs("Routes.inbox_path({id: 1, to_param: function(){ return 'my';}})")).to eq(
|
351
|
+
expect(evaljs("Routes.inbox_path({id: 1, to_param: function(){ return 'my';}})")).to eq(test_routes.inbox_path(inbox))
|
352
352
|
end
|
353
353
|
|
354
354
|
it "should call id if it is a function" do
|
355
|
-
expect(evaljs("Routes.inbox_path({id: function() { return 1;}})")).to eq(
|
355
|
+
expect(evaljs("Routes.inbox_path({id: function() { return 1;}})")).to eq(test_routes.inbox_path(1))
|
356
356
|
end
|
357
357
|
|
358
358
|
it "should support options argument" do
|
359
359
|
expect(evaljs(
|
360
360
|
"Routes.inbox_message_path({id:1, to_param: 'my'}, {id:2}, {custom: true, format: 'json'})"
|
361
|
-
)).to eq(
|
361
|
+
)).to eq(test_routes.inbox_message_path(inbox, 2, :custom => true, :format => "json"))
|
362
362
|
end
|
363
363
|
|
364
364
|
context "when globbing" do
|
365
365
|
it "should prefer to_param property over id property" do
|
366
|
-
expect(evaljs("Routes.book_path({id: 1, to_param: 'my'}, 1)")).to eq(
|
366
|
+
expect(evaljs("Routes.book_path({id: 1, to_param: 'my'}, 1)")).to eq(test_routes.book_path(inbox, 1))
|
367
367
|
end
|
368
368
|
|
369
369
|
it "should call to_param if it is a function" do
|
370
|
-
expect(evaljs("Routes.book_path({id: 1, to_param: function(){ return 'my';}}, 1)")).to eq(
|
370
|
+
expect(evaljs("Routes.book_path({id: 1, to_param: function(){ return 'my';}}, 1)")).to eq(test_routes.book_path(inbox, 1))
|
371
371
|
end
|
372
372
|
|
373
373
|
it "should call id if it is a function" do
|
374
|
-
expect(evaljs("Routes.book_path({id: function() { return 'technical';}}, 1)")).to eq(
|
374
|
+
expect(evaljs("Routes.book_path({id: function() { return 'technical';}}, 1)")).to eq(test_routes.book_path('technical', 1))
|
375
375
|
end
|
376
376
|
|
377
377
|
it "should support options argument" do
|
378
378
|
expect(evaljs(
|
379
379
|
"Routes.book_path({id:1, to_param: 'my'}, {id:2}, {custom: true, format: 'json'})"
|
380
|
-
)).to eq(
|
380
|
+
)).to eq(test_routes.book_path(inbox, 2, :custom => true, :format => "json"))
|
381
381
|
end
|
382
382
|
end
|
383
383
|
end
|
@@ -78,7 +78,7 @@ describe "after Rails initialization" do
|
|
78
78
|
Rails.application.config.assets.initialize_on_precompile = true
|
79
79
|
end
|
80
80
|
it "should render some javascript" do
|
81
|
-
expect(evaluate(ctx, 'js-routes.js')).to match(/
|
81
|
+
expect(evaluate(ctx, 'js-routes.js')).to match(/routes = /)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
context "and not initialize on precompile" do
|
@@ -89,7 +89,7 @@ describe "after Rails initialization" do
|
|
89
89
|
if 3 == Rails::VERSION::MAJOR
|
90
90
|
expect { evaluate(ctx, 'js-routes.js') }.to raise_error(/Cannot precompile/)
|
91
91
|
else
|
92
|
-
expect(evaluate(ctx, 'js-routes.js')).to match(/
|
92
|
+
expect(evaluate(ctx, 'js-routes.js')).to match(/routes = /)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -34,8 +34,8 @@ def evaljs(string, force = false)
|
|
34
34
|
jscontext(force).eval(string)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
App.routes.url_helpers
|
37
|
+
def test_routes
|
38
|
+
::App.routes.url_helpers
|
39
39
|
end
|
40
40
|
|
41
41
|
def blog_routes
|
@@ -55,7 +55,7 @@ module BlogEngine
|
|
55
55
|
end
|
56
56
|
|
57
57
|
|
58
|
-
class App < Rails::Application
|
58
|
+
class ::App < Rails::Application
|
59
59
|
# Enable the asset pipeline
|
60
60
|
config.assets.enabled = true
|
61
61
|
# initialize_on_precompile
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.12.
|
131
|
+
version: 0.12.3
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.12.
|
138
|
+
version: 0.12.3
|
139
139
|
description: Generates javascript file that defines all Rails named routes as javascript
|
140
140
|
helpers
|
141
141
|
email: agresso@gmail.com
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
version: '0'
|
203
203
|
requirements: []
|
204
204
|
rubyforge_project:
|
205
|
-
rubygems_version: 2.
|
205
|
+
rubygems_version: 2.6.7
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: Brings Rails named routes to javascript
|