stimulus_reflex 3.5.0.pre9 → 3.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of stimulus_reflex might be problematic. Click here for more details.

Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/Gemfile.lock +122 -127
  4. data/README.md +13 -19
  5. data/app/assets/javascripts/stimulus_reflex.js +1017 -523
  6. data/app/assets/javascripts/stimulus_reflex.umd.js +940 -496
  7. data/app/channels/stimulus_reflex/channel.rb +9 -24
  8. data/bin/console +0 -2
  9. data/bin/standardize +2 -1
  10. data/lib/generators/stimulus_reflex/stimulus_reflex_generator.rb +68 -9
  11. data/lib/generators/stimulus_reflex/templates/app/controllers/examples_controller.rb.tt +9 -0
  12. data/lib/generators/stimulus_reflex/templates/app/javascript/channels/consumer.js.tt +6 -0
  13. data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.esbuild.tt +4 -0
  14. data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.importmap.tt +2 -0
  15. data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.shakapacker.tt +5 -0
  16. data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.vite.tt +1 -0
  17. data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.webpacker.tt +5 -0
  18. data/lib/generators/stimulus_reflex/templates/app/javascript/config/cable_ready.js.tt +4 -0
  19. data/lib/generators/stimulus_reflex/templates/app/javascript/config/index.js.tt +2 -0
  20. data/lib/generators/stimulus_reflex/templates/app/javascript/config/mrujs.js.tt +9 -0
  21. data/lib/generators/stimulus_reflex/templates/app/javascript/config/stimulus_reflex.js.tt +5 -0
  22. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +141 -0
  23. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application.js.tt +11 -0
  24. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application_controller.js.tt +74 -0
  25. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.esbuild.tt +7 -0
  26. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.importmap.tt +5 -0
  27. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.shakapacker.tt +5 -0
  28. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.vite.tt +5 -0
  29. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.webpacker.tt +5 -0
  30. data/{test/tmp/app/reflexes/user_reflex.rb → lib/generators/stimulus_reflex/templates/app/reflexes/%file_name%_reflex.rb.tt} +38 -9
  31. data/lib/generators/stimulus_reflex/templates/app/reflexes/application_reflex.rb.tt +27 -0
  32. data/lib/generators/stimulus_reflex/templates/app/views/examples/show.html.erb.tt +207 -0
  33. data/lib/generators/stimulus_reflex/templates/config/initializers/cable_ready.rb +27 -0
  34. data/lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb +18 -13
  35. data/lib/generators/stimulus_reflex/templates/esbuild.config.mjs.tt +94 -0
  36. data/lib/install/action_cable.rb +155 -0
  37. data/lib/install/broadcaster.rb +90 -0
  38. data/lib/install/bundle.rb +56 -0
  39. data/lib/install/compression.rb +41 -0
  40. data/lib/install/config.rb +87 -0
  41. data/lib/install/development.rb +110 -0
  42. data/lib/install/esbuild.rb +114 -0
  43. data/lib/install/example.rb +22 -0
  44. data/lib/install/importmap.rb +133 -0
  45. data/lib/install/initializers.rb +25 -0
  46. data/lib/install/mrujs.rb +133 -0
  47. data/lib/install/npm_packages.rb +25 -0
  48. data/lib/install/reflexes.rb +25 -0
  49. data/lib/install/shakapacker.rb +64 -0
  50. data/lib/install/spring.rb +54 -0
  51. data/lib/install/updatable.rb +34 -0
  52. data/lib/install/vite.rb +64 -0
  53. data/lib/install/webpacker.rb +90 -0
  54. data/lib/install/yarn.rb +55 -0
  55. data/lib/stimulus_reflex/broadcasters/broadcaster.rb +15 -8
  56. data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +7 -8
  57. data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +10 -10
  58. data/lib/stimulus_reflex/broadcasters/update.rb +3 -0
  59. data/lib/stimulus_reflex/cable_readiness.rb +29 -0
  60. data/lib/stimulus_reflex/cable_ready_channels.rb +6 -5
  61. data/lib/stimulus_reflex/callbacks.rb +17 -1
  62. data/lib/stimulus_reflex/concern_enhancer.rb +6 -4
  63. data/lib/stimulus_reflex/configuration.rb +12 -2
  64. data/lib/stimulus_reflex/dataset.rb +11 -1
  65. data/lib/stimulus_reflex/engine.rb +16 -9
  66. data/lib/stimulus_reflex/html/document.rb +59 -0
  67. data/lib/stimulus_reflex/html/document_fragment.rb +13 -0
  68. data/lib/stimulus_reflex/importmap.rb +6 -3
  69. data/lib/stimulus_reflex/installer.rb +274 -0
  70. data/lib/stimulus_reflex/open_struct_fix.rb +2 -0
  71. data/lib/stimulus_reflex/reflex.rb +40 -31
  72. data/lib/stimulus_reflex/reflex_data.rb +19 -3
  73. data/lib/stimulus_reflex/reflex_factory.rb +6 -3
  74. data/lib/stimulus_reflex/request_parameters.rb +2 -0
  75. data/lib/stimulus_reflex/utils/logger.rb +10 -0
  76. data/lib/stimulus_reflex/utils/sanity_checker.rb +8 -48
  77. data/lib/stimulus_reflex/version.rb +1 -1
  78. data/lib/stimulus_reflex/version_checker.rb +54 -0
  79. data/lib/stimulus_reflex.rb +2 -0
  80. data/lib/tasks/stimulus_reflex/stimulus_reflex.rake +250 -0
  81. data/package.json +36 -28
  82. data/{rollup.config.js → rollup.config.mjs} +6 -24
  83. data/stimulus_reflex.gemspec +16 -19
  84. data/yarn.lock +1331 -748
  85. metadata +129 -79
  86. data/LATEST +0 -1
  87. data/app/assets/javascripts/stimulus_reflex.min.js +0 -2
  88. data/app/assets/javascripts/stimulus_reflex.min.js.map +0 -1
  89. data/app/assets/javascripts/stimulus_reflex.umd.min.js +0 -905
  90. data/app/assets/javascripts/stimulus_reflex.umd.min.js.map +0 -1
  91. data/lib/generators/stimulus_reflex/initializer_generator.rb +0 -14
  92. data/test/broadcasters/broadcaster_test.rb +0 -11
  93. data/test/broadcasters/broadcaster_test_case.rb +0 -39
  94. data/test/broadcasters/nothing_broadcaster_test.rb +0 -31
  95. data/test/broadcasters/page_broadcaster_test.rb +0 -79
  96. data/test/broadcasters/selector_broadcaster_test.rb +0 -173
  97. data/test/callbacks_test.rb +0 -652
  98. data/test/concern_enhancer_test.rb +0 -54
  99. data/test/element_test.rb +0 -254
  100. data/test/generators/stimulus_reflex_generator_test.rb +0 -58
  101. data/test/reflex_test.rb +0 -43
  102. data/test/test_helper.rb +0 -71
  103. data/test/tmp/app/reflexes/application_reflex.rb +0 -12
  104. data/yarn-error.log +0 -4964
@@ -1,652 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "test_helper"
4
-
5
- # standard:disable Lint/ConstantDefinitionInBlock
6
-
7
- class CallbacksTest < ActionCable::Channel::TestCase
8
- tests StimulusReflex::Channel
9
-
10
- setup do
11
- stub_connection(session_id: SecureRandom.uuid)
12
- def connection.env
13
- @env ||= {}
14
- end
15
- end
16
-
17
- test "basic before_reflex works" do
18
- class BeforeCallbackReflex < StimulusReflex::Reflex
19
- before_reflex :init_counter
20
-
21
- def increment
22
- @count += 1
23
- end
24
-
25
- private
26
-
27
- def init_counter
28
- @count = 5
29
- end
30
- end
31
-
32
- reflex = BeforeCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
33
- reflex.process(:increment)
34
- assert_equal 6, reflex.instance_variable_get("@count")
35
- end
36
-
37
- test "before_reflex with block works" do
38
- class BeforeBlockCallbackReflex < StimulusReflex::Reflex
39
- before_reflex do
40
- @count = 5
41
- end
42
-
43
- def increment
44
- @count += 1
45
- end
46
- end
47
-
48
- reflex = BeforeBlockCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
49
- reflex.process(:increment)
50
- assert_equal 6, reflex.instance_variable_get("@count")
51
- end
52
-
53
- test "basic after_reflex works" do
54
- class AfterCallbackReflex < StimulusReflex::Reflex
55
- after_reflex :reset
56
-
57
- def increment
58
- @count = 5
59
- end
60
-
61
- private
62
-
63
- def reset
64
- @count = 1
65
- end
66
- end
67
-
68
- reflex = AfterCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
69
- reflex.process(:increment)
70
- assert_equal 1, reflex.instance_variable_get("@count")
71
- end
72
-
73
- test "after_reflex with block works" do
74
- class AfterBlockCallbackReflex < StimulusReflex::Reflex
75
- after_reflex do
76
- @count = 1
77
- end
78
-
79
- def increment
80
- @count = 5
81
- end
82
- end
83
-
84
- reflex = AfterBlockCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
85
- reflex.process(:increment)
86
- assert_equal 1, reflex.instance_variable_get("@count")
87
- end
88
-
89
- test "basic around_reflex works" do
90
- class AroundCallbackReflex < StimulusReflex::Reflex
91
- around_reflex :around
92
-
93
- def increment
94
- @count += 8
95
- end
96
-
97
- private
98
-
99
- def around
100
- @count = 2
101
- yield
102
- @count += 4
103
- end
104
- end
105
-
106
- reflex = AroundCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
107
- reflex.process(:increment)
108
- assert_equal 14, reflex.instance_variable_get("@count")
109
- end
110
-
111
- test "execute methods in order" do
112
- class CallbackOrderReflex < StimulusReflex::Reflex
113
- before_reflex :one
114
- before_reflex :two, :three
115
-
116
- def increment
117
- end
118
-
119
- private
120
-
121
- def one
122
- @count = 1
123
- end
124
-
125
- def two
126
- @count = 2 if @count == 1
127
- end
128
-
129
- def three
130
- @count = 3 if @count == 2
131
- end
132
- end
133
-
134
- reflex = CallbackOrderReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
135
- reflex.process(:increment)
136
- assert_equal 3, reflex.instance_variable_get("@count")
137
- end
138
-
139
- test "basic if option works" do
140
- class IfCallbackReflex < StimulusReflex::Reflex
141
- before_reflex :init, if: :present
142
- around_reflex :around, if: :blank
143
- after_reflex :after, if: :present
144
-
145
- def increment
146
- @count += 8
147
- end
148
-
149
- private
150
-
151
- def present
152
- true
153
- end
154
-
155
- def blank
156
- false
157
- end
158
-
159
- def init
160
- @count = 5
161
- end
162
-
163
- def around
164
- @count += 2
165
- yield
166
- @count += 4
167
- end
168
-
169
- def after
170
- @count += 10
171
- end
172
- end
173
-
174
- reflex = IfCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
175
- reflex.process(:increment)
176
- assert_equal 23, reflex.instance_variable_get("@count")
177
- end
178
-
179
- test "if option with proc/lambda works" do
180
- class IfProcCallbackReflex < StimulusReflex::Reflex
181
- before_reflex :init, if: -> { true }
182
- around_reflex :around, if: lambda { false }
183
- after_reflex :after, if: proc { true }
184
-
185
- def increment
186
- @count += 8
187
- end
188
-
189
- private
190
-
191
- def init
192
- @count = 5
193
- end
194
-
195
- def around
196
- @count += 2
197
- yield
198
- @count += 4
199
- end
200
-
201
- def after
202
- @count += 10
203
- end
204
- end
205
-
206
- reflex = IfProcCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
207
- reflex.process(:increment)
208
- assert_equal 23, reflex.instance_variable_get("@count")
209
- end
210
-
211
- test "basic unless option works" do
212
- class UnlessCallbackReflex < StimulusReflex::Reflex
213
- before_reflex :init, unless: :blank
214
- around_reflex :around, unless: :present
215
- after_reflex :after, unless: :blank
216
-
217
- def increment
218
- @count += 8
219
- end
220
-
221
- private
222
-
223
- def present
224
- true
225
- end
226
-
227
- def blank
228
- false
229
- end
230
-
231
- def init
232
- @count = 5
233
- end
234
-
235
- def around
236
- @count += 2
237
- yield
238
- @count += 4
239
- end
240
-
241
- def after
242
- @count += 10
243
- end
244
- end
245
-
246
- reflex = UnlessCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
247
- reflex.process(:increment)
248
- assert_equal 23, reflex.instance_variable_get("@count")
249
- end
250
-
251
- test "unless option with proc/lambda works" do
252
- class UnlessProcCallbackReflex < StimulusReflex::Reflex
253
- before_reflex :init, unless: -> { false }
254
- around_reflex :around, unless: lambda { true }
255
- after_reflex :after, unless: proc { false }
256
-
257
- def increment
258
- @count += 8
259
- end
260
-
261
- private
262
-
263
- def init
264
- @count = 5
265
- end
266
-
267
- def around
268
- @count += 2
269
- yield
270
- @count += 4
271
- end
272
-
273
- def after
274
- @count += 10
275
- end
276
- end
277
-
278
- reflex = UnlessProcCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
279
- reflex.process(:increment)
280
- assert_equal 23, reflex.instance_variable_get("@count")
281
- end
282
-
283
- test "only option works" do
284
- class OnlyCallbackReflex < StimulusReflex::Reflex
285
- before_reflex :init
286
- before_reflex :increment_bonus, only: :increment
287
- before_reflex :decrement_bonus, only: [:decrement]
288
-
289
- def increment
290
- @count += 1
291
- end
292
-
293
- def decrement
294
- @count -= 1
295
- end
296
-
297
- private
298
-
299
- def init
300
- @count = 0
301
- end
302
-
303
- def increment_bonus
304
- @count += 5
305
- end
306
-
307
- def decrement_bonus
308
- @count -= 7
309
- end
310
- end
311
-
312
- reflex = OnlyCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :decrement, client_attributes: {version: StimulusReflex::VERSION})
313
- reflex.process(:decrement)
314
- assert_equal(-8, reflex.instance_variable_get("@count"))
315
- end
316
-
317
- test "except option works" do
318
- class ExceptCallbackReflex < StimulusReflex::Reflex
319
- before_reflex :init
320
- before_reflex :increment_bonus, except: [:decrement]
321
- before_reflex :decrement_bonus, except: :increment
322
-
323
- def increment
324
- @count += 1
325
- end
326
-
327
- def decrement
328
- @count -= 1
329
- end
330
-
331
- private
332
-
333
- def init
334
- @count = 0
335
- end
336
-
337
- def increment_bonus
338
- @count += 5
339
- end
340
-
341
- def decrement_bonus
342
- @count -= 7
343
- end
344
- end
345
-
346
- reflex = ExceptCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
347
- reflex.process(:increment)
348
- assert_equal 6, reflex.instance_variable_get("@count")
349
-
350
- reflex = ExceptCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :decrement, client_attributes: {version: StimulusReflex::VERSION})
351
- reflex.process(:decrement)
352
- assert_equal(-8, reflex.instance_variable_get("@count"))
353
- end
354
-
355
- test "skip_before_reflex works" do
356
- class SkipBeforeCallbackReflex < StimulusReflex::Reflex
357
- before_reflex :blowup
358
- before_reflex :init_counter
359
- before_reflex :bonus
360
-
361
- skip_before_reflex :blowup
362
- skip_before_reflex :init_counter, if: -> { false }
363
- skip_before_reflex :bonus, if: -> { true }
364
-
365
- def increment
366
- @count += 1
367
- end
368
-
369
- private
370
-
371
- def blowup
372
- raise StandardError
373
- end
374
-
375
- def init_counter
376
- @count = 5
377
- end
378
-
379
- def bonus
380
- @count += 100
381
- end
382
- end
383
-
384
- reflex = SkipBeforeCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
385
- reflex.process(:increment)
386
- assert_equal 6, reflex.instance_variable_get("@count")
387
- end
388
-
389
- test "skip_after_reflex works" do
390
- class SkipAfterCallbackReflex < StimulusReflex::Reflex
391
- after_reflex :blowup
392
- after_reflex :reset
393
- after_reflex :clear
394
-
395
- skip_after_reflex :blowup
396
- skip_after_reflex :reset, if: -> { false }
397
- skip_after_reflex :clear, if: -> { true }
398
-
399
- def increment
400
- @count = 0
401
- end
402
-
403
- private
404
-
405
- def blowup
406
- raise StandardError
407
- end
408
-
409
- def reset
410
- @count += 1
411
- end
412
-
413
- def clear
414
- @count += 10
415
- end
416
- end
417
-
418
- reflex = SkipAfterCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
419
- reflex.process(:increment)
420
- assert_equal 1, reflex.instance_variable_get("@count")
421
- end
422
-
423
- test "skip_around_reflex works" do
424
- class SkipAroundCallbackReflex < StimulusReflex::Reflex
425
- around_reflex :blowup
426
- around_reflex :around
427
- around_reflex :bonus
428
-
429
- skip_around_reflex :blowup
430
- skip_around_reflex :around, if: -> { false }
431
- skip_around_reflex :bonus, if: -> { true }
432
-
433
- def increment
434
- @count += 2
435
- end
436
-
437
- private
438
-
439
- def blowup
440
- raise StandardError
441
- end
442
-
443
- def around
444
- @count = 1
445
- yield
446
- @count += 4
447
- end
448
-
449
- def bonus
450
- @count += 100
451
- yield
452
- @count += 1000
453
- end
454
- end
455
-
456
- reflex = SkipAroundCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
457
- reflex.process(:increment)
458
- assert_equal 7, reflex.instance_variable_get("@count")
459
- end
460
-
461
- test "skip_before_reflex works in inherited reflex" do
462
- class SkipApplicationReflex < StimulusReflex::Reflex
463
- before_reflex :blowup
464
- before_reflex :init_counter
465
-
466
- private
467
-
468
- def blowup
469
- raise StandardError
470
- end
471
-
472
- def init_counter
473
- @count = 5
474
- end
475
- end
476
-
477
- class InheritedSkipApplicationReflex < SkipApplicationReflex
478
- skip_before_reflex :blowup
479
-
480
- def increment
481
- @count += 1
482
- end
483
- end
484
-
485
- reflex = InheritedSkipApplicationReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
486
- reflex.process(:increment)
487
- assert_equal 6, reflex.instance_variable_get("@count")
488
- end
489
-
490
- test "basic prepend_before_reflex works" do
491
- class SimplePrependBeforeCallbackReflex < StimulusReflex::Reflex
492
- before_reflex :two
493
- prepend_before_reflex :one
494
-
495
- def increment
496
- @count += 1 if @count == 2
497
- end
498
-
499
- private
500
-
501
- def one
502
- @count = 1
503
- end
504
-
505
- def two
506
- @count += 1 if @count == 1
507
- end
508
- end
509
-
510
- reflex = SimplePrependBeforeCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
511
- reflex.process(:increment)
512
- assert_equal 3, reflex.instance_variable_get("@count")
513
- end
514
-
515
- test "prepend_before_reflex with block works" do
516
- class BlockPrependBeforeCallbackReflex < StimulusReflex::Reflex
517
- before_reflex do
518
- @count += 1 if @count == 1
519
- end
520
-
521
- prepend_before_reflex do
522
- @count = 1
523
- end
524
-
525
- def increment
526
- @count += 1 if @count == 2
527
- end
528
- end
529
-
530
- reflex = BlockPrependBeforeCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
531
- reflex.process(:increment)
532
- assert_equal 3, reflex.instance_variable_get("@count")
533
- end
534
-
535
- test "basic prepend_before_reflex works in inherited reflex" do
536
- class PrependBeforeCallbackReflex < StimulusReflex::Reflex
537
- before_reflex :two
538
-
539
- def increment
540
- @count += 5 if @count == 4
541
- end
542
-
543
- private
544
-
545
- def two
546
- @count += 3 if @count == 1
547
- end
548
- end
549
-
550
- class InheritedPrependBeforeCallbackReflex < PrependBeforeCallbackReflex
551
- prepend_before_reflex :one
552
-
553
- private
554
-
555
- def one
556
- @count = 1
557
- end
558
- end
559
-
560
- reflex = InheritedPrependBeforeCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
561
- reflex.process(:increment)
562
- assert_equal 9, reflex.instance_variable_get("@count")
563
- end
564
-
565
- test "basic prepend_around_reflex works" do
566
- class SimplePrependAroundCallbackReflex < StimulusReflex::Reflex
567
- around_reflex :two
568
- prepend_around_reflex :one
569
-
570
- def increment
571
- @count += 10
572
- end
573
-
574
- private
575
-
576
- def one
577
- @count = 1
578
- yield
579
- @count += 3 if @count == 23
580
- end
581
-
582
- def two
583
- @count += 5 if @count == 1
584
- yield
585
- @count += 7 if @count == 16
586
- end
587
- end
588
-
589
- reflex = SimplePrependAroundCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
590
- reflex.process(:increment)
591
- assert_equal 26, reflex.instance_variable_get("@count")
592
- end
593
-
594
- test "basic prepend_after_reflex works" do
595
- class SimplePrependAfterCallbackReflex < StimulusReflex::Reflex
596
- after_reflex :two
597
- prepend_after_reflex :one
598
-
599
- def increment
600
- @count = 1
601
- end
602
-
603
- private
604
-
605
- def one
606
- @count += 3 if @count == 6
607
- end
608
-
609
- def two
610
- @count += 5 if @count == 1
611
- end
612
- end
613
-
614
- reflex = SimplePrependAfterCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
615
- reflex.process(:increment)
616
- assert_equal 9, reflex.instance_variable_get("@count")
617
- end
618
-
619
- test "append before_, around_ and after_reflex works" do
620
- class AppendCallbackReflex < StimulusReflex::Reflex
621
- append_before_reflex :before
622
- append_around_reflex :around
623
- append_after_reflex :after
624
-
625
- def increment
626
- @count += 5 if @count == 4
627
- end
628
-
629
- private
630
-
631
- def before
632
- @count = 1 unless @counts
633
- end
634
-
635
- def around
636
- @count += 3 if @count == 1
637
- yield
638
- @count += 9 if @count == 16
639
- end
640
-
641
- def after
642
- @count += 7 if @count == 9
643
- end
644
- end
645
-
646
- reflex = AppendCallbackReflex.new(subscribe, url: "https://test.stimulusreflex.com", method_name: :increment, client_attributes: {version: StimulusReflex::VERSION})
647
- reflex.process(:increment)
648
- assert_equal 25, reflex.instance_variable_get("@count")
649
- end
650
- end
651
-
652
- # standard:enable Lint/ConstantDefinitionInBlock
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "test_helper"
4
-
5
- class StimulusReflex::ConcernTest < ActiveSupport::TestCase
6
- module TestConcern
7
- extend ActiveSupport::Concern
8
- include StimulusReflex::ConcernEnhancer
9
- end
10
-
11
- class TestReflex < StimulusReflex::Reflex
12
- include TestConcern
13
-
14
- def initialize
15
- end
16
- end
17
-
18
- class TestController < ActionController::Base
19
- include TestConcern
20
- end
21
-
22
- class TestModel < ActiveRecord::Base
23
- include TestConcern
24
- end
25
-
26
- test "included in a reflex it stubs controller and model methods" do
27
- assert_nil TestReflex.helper_method
28
- assert_nil TestReflex.before_action
29
- assert_nil TestReflex.around_action
30
- assert_nil TestReflex.after_action
31
-
32
- assert_nil TestReflex.before_save
33
- assert_nil TestReflex.around_save
34
- assert_nil TestReflex.after_save
35
-
36
- refute_nil TestReflex.before_reflex
37
- end
38
-
39
- test "included in a controller it stubs reflex methods" do
40
- assert_nil TestController.before_reflex
41
- assert_nil TestController.around_reflex
42
- assert_nil TestController.after_reflex
43
-
44
- refute_nil TestController.before_action
45
- end
46
-
47
- test "included in a model it stubs reflex methods" do
48
- assert_nil TestModel.before_reflex
49
- assert_nil TestModel.around_reflex
50
- assert_nil TestModel.after_reflex
51
-
52
- refute_nil TestModel.after_save
53
- end
54
- end