stimulus_reflex 3.5.0.pre2 → 3.5.0.pre3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +56 -11
- data/Gemfile.lock +71 -66
- data/README.md +4 -3
- data/app/channels/stimulus_reflex/channel.rb +11 -11
- data/lib/generators/stimulus_reflex/stimulus_reflex_generator.rb +5 -4
- data/lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb +5 -0
- data/lib/stimulus_reflex/broadcasters/broadcaster.rb +18 -17
- data/lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb +6 -1
- data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +1 -3
- data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +2 -6
- data/lib/stimulus_reflex/configuration.rb +2 -1
- data/lib/stimulus_reflex/dataset.rb +34 -0
- data/lib/stimulus_reflex/element.rb +12 -46
- data/lib/stimulus_reflex/reflex.rb +7 -2
- data/lib/stimulus_reflex/utils/attribute_builder.rb +17 -0
- data/lib/stimulus_reflex/utils/logger.rb +6 -2
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/tasks/stimulus_reflex/install.rake +1 -1
- data/test/broadcasters/broadcaster_test.rb +0 -1
- data/test/broadcasters/broadcaster_test_case.rb +24 -0
- data/test/broadcasters/nothing_broadcaster_test.rb +14 -22
- data/test/broadcasters/page_broadcaster_test.rb +30 -32
- data/test/broadcasters/selector_broadcaster_test.rb +82 -88
- data/test/element_test.rb +73 -0
- data/test/generators/stimulus_reflex_generator_test.rb +8 -0
- data/test/reflex_test.rb +11 -0
- data/test/test_helper.rb +3 -1
- data/test/tmp/app/reflexes/demo_reflex.rb +0 -1
- metadata +36 -20
- data/package.json +0 -58
- data/stimulus_reflex.gemspec +0 -42
- data/yarn.lock +0 -4680
data/test/element_test.rb
CHANGED
@@ -178,4 +178,77 @@ class StimulusReflex::ElementTest < ActiveSupport::TestCase
|
|
178
178
|
assert_equal "19", overlapping_keys_element.dataset.duplicate_value
|
179
179
|
assert_equal ["20", "20", "21", "22"], overlapping_keys_element.dataset.duplicate_values
|
180
180
|
end
|
181
|
+
|
182
|
+
test "should return true for boolean data attributes" do
|
183
|
+
data = {
|
184
|
+
"dataset" => {
|
185
|
+
"dataset" => {
|
186
|
+
"data-short" => "t",
|
187
|
+
"data-long" => "true",
|
188
|
+
"data-num" => "1",
|
189
|
+
"data-empty" => ""
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
element_with_boolean_attributes = StimulusReflex::Element.new(data)
|
195
|
+
|
196
|
+
assert element_with_boolean_attributes.boolean[:short]
|
197
|
+
assert element_with_boolean_attributes.boolean[:long]
|
198
|
+
assert element_with_boolean_attributes.boolean[:num]
|
199
|
+
assert element_with_boolean_attributes.boolean[:empty]
|
200
|
+
|
201
|
+
assert element_with_boolean_attributes.dataset.boolean[:short]
|
202
|
+
assert element_with_boolean_attributes.dataset.boolean[:long]
|
203
|
+
assert element_with_boolean_attributes.dataset.boolean[:num]
|
204
|
+
assert element_with_boolean_attributes.dataset.boolean[:empty]
|
205
|
+
end
|
206
|
+
|
207
|
+
test "should return false for falsey data attributes" do
|
208
|
+
data = {
|
209
|
+
"dataset" => {
|
210
|
+
"dataset" => {
|
211
|
+
"data-short" => "f",
|
212
|
+
"data-long" => "false",
|
213
|
+
"data-num" => "0"
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
element_with_falsey_attributes = StimulusReflex::Element.new(data)
|
219
|
+
|
220
|
+
refute element_with_falsey_attributes.boolean[:short]
|
221
|
+
refute element_with_falsey_attributes.boolean[:long]
|
222
|
+
refute element_with_falsey_attributes.boolean[:num]
|
223
|
+
|
224
|
+
refute element_with_falsey_attributes.dataset.boolean[:short]
|
225
|
+
refute element_with_falsey_attributes.dataset.boolean[:long]
|
226
|
+
refute element_with_falsey_attributes.dataset.boolean[:num]
|
227
|
+
end
|
228
|
+
|
229
|
+
test "should return numeric values" do
|
230
|
+
data = {
|
231
|
+
"dataset" => {
|
232
|
+
"dataset" => {
|
233
|
+
"data-int" => "123",
|
234
|
+
"data-float" => "123.456",
|
235
|
+
"data-string" => "asdf"
|
236
|
+
}
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
element_with_numeric_attributes = StimulusReflex::Element.new(data)
|
241
|
+
|
242
|
+
assert_equal 123.0, element_with_numeric_attributes.numeric[:int]
|
243
|
+
assert_equal 123.456, element_with_numeric_attributes.numeric[:float]
|
244
|
+
assert_raises do
|
245
|
+
element_with_numeric_attributes.numeric[:string]
|
246
|
+
end
|
247
|
+
|
248
|
+
assert_equal 123.0, element_with_numeric_attributes.dataset.numeric[:int]
|
249
|
+
assert_equal 123.456, element_with_numeric_attributes.dataset.numeric[:float]
|
250
|
+
assert_raises do
|
251
|
+
element_with_numeric_attributes.dataset.numeric[:string]
|
252
|
+
end
|
253
|
+
end
|
181
254
|
end
|
@@ -25,6 +25,14 @@ class StimulusReflexGeneratorTest < Rails::Generators::TestCase
|
|
25
25
|
assert_file "app/reflexes/posts_reflex.rb", /PostsReflex/
|
26
26
|
end
|
27
27
|
|
28
|
+
test "skips stimulus controller and reflex if option provided" do
|
29
|
+
run_generator %w[users --skip-stimulus --skip-reflex --skip-app-controller --skip-app-reflex]
|
30
|
+
assert_no_file "app/javascript/controllers/application_controller.js"
|
31
|
+
assert_no_file "app/javascript/controllers/users_controller.js"
|
32
|
+
assert_no_file "app/reflexes/application_reflex.rb"
|
33
|
+
assert_no_file "app/reflexes/users_reflex.rb"
|
34
|
+
end
|
35
|
+
|
28
36
|
test "creates reflex with given reflex actions" do
|
29
37
|
run_generator %w[User update do_stuff DoMoreStuff]
|
30
38
|
assert_file "app/reflexes/user_reflex.rb" do |reflex|
|
data/test/reflex_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "test_helper"
|
4
|
+
require "mocha/minitest"
|
4
5
|
|
5
6
|
class StimulusReflex::ReflexTest < ActionCable::Channel::TestCase
|
6
7
|
tests StimulusReflex::Channel
|
@@ -29,4 +30,14 @@ class StimulusReflex::ReflexTest < ActionCable::Channel::TestCase
|
|
29
30
|
test "dom_id" do
|
30
31
|
assert @reflex.dom_id(TestModel.new(id: 123)) == "#test_model_123"
|
31
32
|
end
|
33
|
+
|
34
|
+
test "params behave like ActionController::Parameters" do
|
35
|
+
ActionDispatch::Request.any_instance.stubs(:parameters).returns({"a" => "1", "b" => "2", "c" => "3"})
|
36
|
+
reflex = StimulusReflex::Reflex.new(subscribe, url: "https://test.stimulusreflex.com")
|
37
|
+
|
38
|
+
deleted_param = reflex.params.delete("a")
|
39
|
+
|
40
|
+
assert deleted_param == "1"
|
41
|
+
assert reflex.params.to_unsafe_h == {"b" => "2", "c" => "3"}
|
42
|
+
end
|
32
43
|
end
|
data/test/test_helper.rb
CHANGED
@@ -2,12 +2,14 @@
|
|
2
2
|
|
3
3
|
ENV["RAILS_ENV"] ||= "test"
|
4
4
|
|
5
|
-
require "
|
5
|
+
require "mocha"
|
6
6
|
require "rails"
|
7
7
|
require "active_model"
|
8
8
|
require "active_record"
|
9
9
|
require "action_controller"
|
10
|
+
require "minitest/mock"
|
10
11
|
require "pry"
|
12
|
+
|
11
13
|
require_relative "../lib/stimulus_reflex"
|
12
14
|
|
13
15
|
class TestApp < Rails::Application
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stimulus_reflex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.0.
|
4
|
+
version: 3.5.0.pre3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 5.0.0.
|
75
|
+
version: 5.0.0.pre4
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 5.0.0.
|
82
|
+
version: 5.0.0.pre4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: bundler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: mocha
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: standardrb
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,7 +164,7 @@ dependencies:
|
|
150
164
|
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '1.0'
|
153
|
-
description:
|
167
|
+
description:
|
154
168
|
email:
|
155
169
|
- natehop@gmail.com
|
156
170
|
executables: []
|
@@ -189,19 +203,19 @@ files:
|
|
189
203
|
- lib/stimulus_reflex/callbacks.rb
|
190
204
|
- lib/stimulus_reflex/concern_enhancer.rb
|
191
205
|
- lib/stimulus_reflex/configuration.rb
|
206
|
+
- lib/stimulus_reflex/dataset.rb
|
192
207
|
- lib/stimulus_reflex/element.rb
|
193
208
|
- lib/stimulus_reflex/policies/reflex_invocation_policy.rb
|
194
209
|
- lib/stimulus_reflex/reflex.rb
|
195
210
|
- lib/stimulus_reflex/reflex_data.rb
|
196
211
|
- lib/stimulus_reflex/reflex_factory.rb
|
197
212
|
- lib/stimulus_reflex/request_parameters.rb
|
213
|
+
- lib/stimulus_reflex/utils/attribute_builder.rb
|
198
214
|
- lib/stimulus_reflex/utils/colorize.rb
|
199
215
|
- lib/stimulus_reflex/utils/logger.rb
|
200
216
|
- lib/stimulus_reflex/utils/sanity_checker.rb
|
201
217
|
- lib/stimulus_reflex/version.rb
|
202
218
|
- lib/tasks/stimulus_reflex/install.rake
|
203
|
-
- package.json
|
204
|
-
- stimulus_reflex.gemspec
|
205
219
|
- test/broadcasters/broadcaster_test.rb
|
206
220
|
- test/broadcasters/broadcaster_test_case.rb
|
207
221
|
- test/broadcasters/nothing_broadcaster_test.rb
|
@@ -215,7 +229,6 @@ files:
|
|
215
229
|
- test/test_helper.rb
|
216
230
|
- test/tmp/app/reflexes/application_reflex.rb
|
217
231
|
- test/tmp/app/reflexes/demo_reflex.rb
|
218
|
-
- yarn.lock
|
219
232
|
homepage: https://github.com/stimulusreflex/stimulus_reflex
|
220
233
|
licenses:
|
221
234
|
- MIT
|
@@ -226,6 +239,10 @@ metadata:
|
|
226
239
|
homepage_uri: https://github.com/stimulusreflex/stimulus_reflex
|
227
240
|
source_code_uri: https://github.com/stimulusreflex/stimulus_reflex
|
228
241
|
post_install_message: |+
|
242
|
+
Finish installation by running:
|
243
|
+
|
244
|
+
rake stimulus_reflex:install
|
245
|
+
|
229
246
|
Get support for StimulusReflex and CableReady on Discord:
|
230
247
|
|
231
248
|
https://discord.gg/stimulus-reflex
|
@@ -244,22 +261,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
261
|
- !ruby/object:Gem::Version
|
245
262
|
version: 1.3.1
|
246
263
|
requirements: []
|
247
|
-
rubygems_version: 3.
|
248
|
-
signing_key:
|
264
|
+
rubygems_version: 3.1.6
|
265
|
+
signing_key:
|
249
266
|
specification_version: 4
|
250
267
|
summary: Build reactive applications with the Rails tooling you already know and love.
|
251
268
|
test_files:
|
252
|
-
- test/
|
253
|
-
- test/
|
254
|
-
- test/broadcasters/nothing_broadcaster_test.rb
|
269
|
+
- test/generators/stimulus_reflex_generator_test.rb
|
270
|
+
- test/element_test.rb
|
255
271
|
- test/broadcasters/page_broadcaster_test.rb
|
272
|
+
- test/broadcasters/broadcaster_test_case.rb
|
273
|
+
- test/broadcasters/broadcaster_test.rb
|
256
274
|
- test/broadcasters/selector_broadcaster_test.rb
|
257
|
-
- test/
|
258
|
-
- test/concern_enhancer_test.rb
|
259
|
-
- test/element_test.rb
|
260
|
-
- test/generators/stimulus_reflex_generator_test.rb
|
275
|
+
- test/broadcasters/nothing_broadcaster_test.rb
|
261
276
|
- test/reflex_test.rb
|
262
277
|
- test/test_helper.rb
|
263
|
-
- test/
|
278
|
+
- test/callbacks_test.rb
|
264
279
|
- test/tmp/app/reflexes/demo_reflex.rb
|
265
|
-
|
280
|
+
- test/tmp/app/reflexes/application_reflex.rb
|
281
|
+
- test/concern_enhancer_test.rb
|
data/package.json
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "stimulus_reflex",
|
3
|
-
"version": "3.5.0-pre1",
|
4
|
-
"description": "Build reactive applications with the Rails tooling you already know and love.",
|
5
|
-
"keywords": [
|
6
|
-
"ruby",
|
7
|
-
"rails",
|
8
|
-
"websockets",
|
9
|
-
"actioncable",
|
10
|
-
"turbolinks",
|
11
|
-
"reactive",
|
12
|
-
"cable",
|
13
|
-
"ujs",
|
14
|
-
"ssr",
|
15
|
-
"stimulus",
|
16
|
-
"reflex",
|
17
|
-
"stimulus_reflex",
|
18
|
-
"dom",
|
19
|
-
"morphdom"
|
20
|
-
],
|
21
|
-
"homepage": "https://docs.stimulusreflex.com/",
|
22
|
-
"bugs": {
|
23
|
-
"url": "https://github.com/stimulusreflex/stimulus_reflex/issues"
|
24
|
-
},
|
25
|
-
"repository": {
|
26
|
-
"type": "git",
|
27
|
-
"url": "git+https://github.com:stimulusreflex/stimulus_reflex.git"
|
28
|
-
},
|
29
|
-
"license": "MIT",
|
30
|
-
"author": "Nathan Hopkins <natehop@gmail.com>",
|
31
|
-
"sideEffects": false,
|
32
|
-
"main": "./javascript/stimulus_reflex.js",
|
33
|
-
"module": "./javascript/stimulus_reflex.js",
|
34
|
-
"scripts": {
|
35
|
-
"prettier-standard:check": "yarn run prettier-standard --check ./javascript/*.js ./javascript/**/*.js",
|
36
|
-
"prettier-standard:format": "yarn run prettier-standard ./javascript/*.js ./javascript/**/*.js",
|
37
|
-
"test": "yarn run mocha --require @babel/register --require jsdom-global/register --require esm ./javascript/test"
|
38
|
-
},
|
39
|
-
"peerDependencies": {
|
40
|
-
"stimulus": ">= 1.1"
|
41
|
-
},
|
42
|
-
"dependencies": {
|
43
|
-
"@rails/actioncable": ">= 6.0",
|
44
|
-
"cable_ready": "5.0.0-pre2"
|
45
|
-
},
|
46
|
-
"devDependencies": {
|
47
|
-
"@babel/core": "^7.6.2",
|
48
|
-
"@babel/preset-env": "^7.6.2",
|
49
|
-
"@babel/register": "^7.6.2",
|
50
|
-
"assert": "^2.0.0",
|
51
|
-
"esm": "^3.2.25",
|
52
|
-
"jsdom": "^16.0.1",
|
53
|
-
"jsdom-global": "^3.0.2",
|
54
|
-
"mocha": "^8.0.1",
|
55
|
-
"prettier-standard": "^16.1.0",
|
56
|
-
"stimulus": ">= 1.1"
|
57
|
-
}
|
58
|
-
}
|
data/stimulus_reflex.gemspec
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path("../lib/stimulus_reflex/version", __FILE__)
|
4
|
-
|
5
|
-
Gem::Specification.new do |gem|
|
6
|
-
gem.name = "stimulus_reflex"
|
7
|
-
gem.license = "MIT"
|
8
|
-
gem.version = StimulusReflex::VERSION
|
9
|
-
gem.authors = ["Nathan Hopkins"]
|
10
|
-
gem.email = ["natehop@gmail.com"]
|
11
|
-
gem.homepage = "https://github.com/stimulusreflex/stimulus_reflex"
|
12
|
-
gem.summary = "Build reactive applications with the Rails tooling you already know and love."
|
13
|
-
gem.post_install_message = <<~MESSAGE
|
14
|
-
Get support for StimulusReflex and CableReady on Discord:
|
15
|
-
|
16
|
-
https://discord.gg/stimulus-reflex
|
17
|
-
|
18
|
-
MESSAGE
|
19
|
-
|
20
|
-
gem.metadata = {
|
21
|
-
"bug_tracker_uri" => "https://github.com/stimulusreflex/stimulus_reflex/issues",
|
22
|
-
"changelog_uri" => "https://github.com/stimulusreflex/stimulus_reflex/CHANGELOG.md",
|
23
|
-
"documentation_uri" => "https://docs.stimulusreflex.com",
|
24
|
-
"homepage_uri" => gem.homepage,
|
25
|
-
"source_code_uri" => gem.homepage
|
26
|
-
}
|
27
|
-
|
28
|
-
gem.files = Dir["app/**/*", "lib/**/*", "bin/*", "[A-Z]*"]
|
29
|
-
gem.test_files = Dir["test/**/*.rb"]
|
30
|
-
|
31
|
-
gem.add_dependency "rack"
|
32
|
-
gem.add_dependency "nokogiri"
|
33
|
-
gem.add_dependency "rails", ">= 5.2"
|
34
|
-
gem.add_dependency "redis"
|
35
|
-
gem.add_dependency "cable_ready", "5.0.0.pre2"
|
36
|
-
|
37
|
-
gem.add_development_dependency "bundler", "~> 2.0"
|
38
|
-
gem.add_development_dependency "pry-nav"
|
39
|
-
gem.add_development_dependency "pry"
|
40
|
-
gem.add_development_dependency "rake"
|
41
|
-
gem.add_development_dependency "standardrb", "~> 1.0"
|
42
|
-
end
|