cable_ready 5.0.0.pre3 → 5.0.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/Gemfile.lock +6 -6
  4. data/README.md +6 -2
  5. data/app/helpers/cable_ready_helper.rb +15 -2
  6. data/app/models/concerns/cable_ready/updatable/collection_updatable_callbacks.rb +19 -0
  7. data/app/models/concerns/cable_ready/updatable/collections_registry.rb +33 -0
  8. data/app/models/concerns/cable_ready/updatable/model_updatable_callbacks.rb +28 -0
  9. data/app/models/concerns/cable_ready/updatable.rb +98 -0
  10. data/app/models/concerns/extend_has_many.rb +13 -0
  11. data/lib/cable_ready/channels.rb +1 -1
  12. data/lib/cable_ready/compoundable.rb +1 -1
  13. data/lib/cable_ready/version.rb +1 -1
  14. data/lib/generators/cable_ready/{stream_from_generator.rb → helpers_generator.rb} +1 -1
  15. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  16. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  17. data/test/dummy/app/controllers/application_controller.rb +2 -0
  18. data/test/dummy/app/helpers/application_helper.rb +2 -0
  19. data/test/dummy/app/jobs/application_job.rb +7 -0
  20. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  21. data/test/dummy/app/models/application_record.rb +3 -0
  22. data/test/dummy/app/models/global_idable_entity.rb +16 -0
  23. data/test/dummy/app/models/post.rb +4 -0
  24. data/test/dummy/app/models/section.rb +6 -0
  25. data/test/dummy/app/models/team.rb +6 -0
  26. data/test/dummy/app/models/topic.rb +4 -0
  27. data/test/dummy/app/models/user.rb +7 -0
  28. data/test/dummy/config/application.rb +22 -0
  29. data/test/dummy/config/boot.rb +5 -0
  30. data/test/dummy/config/environment.rb +5 -0
  31. data/test/dummy/config/environments/development.rb +76 -0
  32. data/test/dummy/config/environments/production.rb +120 -0
  33. data/test/dummy/config/environments/test.rb +59 -0
  34. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  35. data/test/dummy/config/initializers/assets.rb +12 -0
  36. data/test/dummy/config/initializers/backtrace_silencers.rb +8 -0
  37. data/test/dummy/config/initializers/cable_ready.rb +18 -0
  38. data/test/dummy/config/initializers/content_security_policy.rb +28 -0
  39. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  40. data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  41. data/test/dummy/config/initializers/inflections.rb +16 -0
  42. data/test/dummy/config/initializers/mime_types.rb +4 -0
  43. data/test/dummy/config/initializers/permissions_policy.rb +11 -0
  44. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  45. data/test/dummy/config/puma.rb +43 -0
  46. data/test/dummy/config/routes.rb +3 -0
  47. data/test/dummy/db/migrate/20210902154139_create_users.rb +9 -0
  48. data/test/dummy/db/migrate/20210902154153_create_posts.rb +10 -0
  49. data/test/dummy/db/migrate/20210904081930_create_topics.rb +9 -0
  50. data/test/dummy/db/migrate/20210904093607_create_sections.rb +9 -0
  51. data/test/dummy/db/migrate/20210913191735_create_teams.rb +8 -0
  52. data/test/dummy/db/migrate/20210913191759_add_team_reference_to_users.rb +5 -0
  53. data/test/dummy/db/schema.rb +49 -0
  54. data/test/dummy/test/models/post_test.rb +7 -0
  55. data/test/dummy/test/models/section_test.rb +7 -0
  56. data/test/dummy/test/models/team_test.rb +7 -0
  57. data/test/dummy/test/models/topic_test.rb +7 -0
  58. data/test/dummy/test/models/user_test.rb +7 -0
  59. data/test/lib/cable_ready/compoundable_test.rb +26 -0
  60. data/test/lib/cable_ready/helper_test.rb +25 -0
  61. data/test/lib/cable_ready/identifiable_test.rb +0 -6
  62. data/test/lib/cable_ready/updatable_test.rb +112 -0
  63. data/test/test_helper.rb +4 -1
  64. metadata +123 -13
  65. data/cable_ready.gemspec +0 -27
  66. data/package.json +0 -41
  67. data/yarn.lock +0 -2562
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class CableReady::UpdatableTest < ActiveSupport::TestCase
6
+ test "includes the module automatically in associated models" do
7
+ user = User.create(name: "John Doe")
8
+
9
+ post = user.posts.build
10
+ assert post.class < CableReady::Updatable
11
+ end
12
+
13
+ test "updates the collection when an item is added" do
14
+ mock_server = mock("server")
15
+ mock_server.expects(:broadcast).with(User, {}).once
16
+ mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {}).once
17
+
18
+ ActionCable.stubs(:server).returns(mock_server)
19
+ user = User.create(name: "John Doe")
20
+
21
+ user.posts.create(title: "Lorem")
22
+ end
23
+
24
+ test "updates the collection when an item is destroyed" do
25
+ user = User.create(name: "John Doe")
26
+ post = user.posts.create(title: "Lorem")
27
+
28
+ mock_server = mock("server")
29
+ mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {}).once
30
+
31
+ ActionCable.stubs(:server).returns(mock_server)
32
+
33
+ post.destroy
34
+ end
35
+
36
+ test "updates the collection when an item is updated" do
37
+ user = User.create(name: "John Doe")
38
+ post = user.posts.create(title: "Lorem")
39
+
40
+ mock_server = mock("server")
41
+ mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {}).once
42
+
43
+ ActionCable.stubs(:server).returns(mock_server)
44
+
45
+ post.update(title: "Ipsum")
46
+ end
47
+
48
+ test "updates the model when it is updated" do
49
+ user = User.create(name: "John Doe")
50
+
51
+ mock_server = mock("server")
52
+ mock_server.expects(:broadcast).with(User, {}).once
53
+ mock_server.expects(:broadcast).with(user.to_global_id, {}).once
54
+
55
+ ActionCable.stubs(:server).returns(mock_server)
56
+
57
+ user.update(name: "Jane Doe")
58
+ end
59
+
60
+ test "updates the parent when it is touched" do
61
+ team = Team.create
62
+ user = team.users.create(name: "Ada Lovelace")
63
+
64
+ mock_server = mock("server")
65
+ mock_server.expects(:broadcast).with(User, {}).once
66
+ mock_server.expects(:broadcast).with(user.to_global_id, {}).once
67
+ mock_server.expects(:broadcast).with("gid://dummy/Team/1:users", {}).once
68
+ mock_server.expects(:broadcast).with(Team, {}).once
69
+ mock_server.expects(:broadcast).with(team.to_global_id, {}).once
70
+
71
+ ActionCable.stubs(:server).returns(mock_server)
72
+
73
+ user.update(name: "Jane Doe")
74
+ end
75
+
76
+ test "respects :on to specify persistence methods" do
77
+ mock_server = mock("server")
78
+
79
+ ActionCable.stubs(:server).returns(mock_server)
80
+
81
+ mock_server.expects(:broadcast).with(Topic, {}).once
82
+ topic = Topic.create(title: "Reactive Rails with Hotwire")
83
+
84
+ mock_server.expects(:broadcast).with(topic.to_global_id, {}).never
85
+ topic.update(title: "Reactive Rails with CableReady")
86
+ end
87
+
88
+ test "respects :if on enable_updates" do
89
+ mock_server = mock("server")
90
+
91
+ ActionCable.stubs(:server).returns(mock_server)
92
+
93
+ section = Section.create
94
+ section.updates_enabled = true
95
+
96
+ mock_server.expects(:broadcast).with(Section, {}).once
97
+ mock_server.expects(:broadcast).with(section.to_global_id, {}).once
98
+ section.update(title: "First Section")
99
+ end
100
+
101
+ test "updates any GlobalID-able entity" do
102
+ entity = GlobalIdableEntity.new
103
+
104
+ mock_server = mock("server")
105
+ mock_server.expects(:broadcast).with(GlobalIdableEntity, {}).once
106
+ mock_server.expects(:broadcast).with(entity.to_global_id, {}).once
107
+
108
+ ActionCable.stubs(:server).returns(mock_server)
109
+
110
+ entity.fake_update
111
+ end
112
+ end
data/test/test_helper.rb CHANGED
@@ -3,10 +3,13 @@
3
3
  # Configure Rails Environment
4
4
  ENV["RAILS_ENV"] = "test"
5
5
 
6
+ require_relative "../test/dummy/config/environment"
7
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
8
+
6
9
  require "mocha"
7
10
  require "rails"
8
- require "rails/generators"
9
11
  require "rails/test_help"
12
+ require "rails/generators"
10
13
  require "minitest/mock"
11
14
  require "mocha/minitest"
12
15
  require "pry"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cable_ready
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.pre3
4
+ version: 5.0.0.pre4
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-08-22 00:00:00.000000000 Z
11
+ date: 2021-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -136,7 +136,21 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description:
139
+ - !ruby/object:Gem::Dependency
140
+ name: sqlite3
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'
153
+ description:
140
154
  email:
141
155
  - natehop@gmail.com
142
156
  executables: []
@@ -154,11 +168,15 @@ files:
154
168
  - app/channels/cable_ready/stream.rb
155
169
  - app/helpers/cable_ready_helper.rb
156
170
  - app/jobs/cable_ready_broadcast_job.rb
171
+ - app/models/concerns/cable_ready/updatable.rb
172
+ - app/models/concerns/cable_ready/updatable/collection_updatable_callbacks.rb
173
+ - app/models/concerns/cable_ready/updatable/collections_registry.rb
174
+ - app/models/concerns/cable_ready/updatable/model_updatable_callbacks.rb
175
+ - app/models/concerns/extend_has_many.rb
157
176
  - bin/console
158
177
  - bin/loc
159
178
  - bin/setup
160
179
  - bin/standardize
161
- - cable_ready.gemspec
162
180
  - lib/cable_ready.rb
163
181
  - lib/cable_ready/broadcaster.rb
164
182
  - lib/cable_ready/cable_car.rb
@@ -172,22 +190,67 @@ files:
172
190
  - lib/cable_ready/stream_identifier.rb
173
191
  - lib/cable_ready/version.rb
174
192
  - lib/generators/cable_ready/channel_generator.rb
193
+ - lib/generators/cable_ready/helpers_generator.rb
175
194
  - lib/generators/cable_ready/initializer_generator.rb
176
- - lib/generators/cable_ready/stream_from_generator.rb
177
195
  - lib/generators/cable_ready/templates/config/initializers/cable_ready.rb
178
- - package.json
196
+ - test/dummy/app/channels/application_cable/channel.rb
197
+ - test/dummy/app/channels/application_cable/connection.rb
198
+ - test/dummy/app/controllers/application_controller.rb
199
+ - test/dummy/app/helpers/application_helper.rb
200
+ - test/dummy/app/jobs/application_job.rb
201
+ - test/dummy/app/mailers/application_mailer.rb
202
+ - test/dummy/app/models/application_record.rb
203
+ - test/dummy/app/models/global_idable_entity.rb
204
+ - test/dummy/app/models/post.rb
205
+ - test/dummy/app/models/section.rb
206
+ - test/dummy/app/models/team.rb
207
+ - test/dummy/app/models/topic.rb
208
+ - test/dummy/app/models/user.rb
209
+ - test/dummy/config/application.rb
210
+ - test/dummy/config/boot.rb
211
+ - test/dummy/config/environment.rb
212
+ - test/dummy/config/environments/development.rb
213
+ - test/dummy/config/environments/production.rb
214
+ - test/dummy/config/environments/test.rb
215
+ - test/dummy/config/initializers/application_controller_renderer.rb
216
+ - test/dummy/config/initializers/assets.rb
217
+ - test/dummy/config/initializers/backtrace_silencers.rb
218
+ - test/dummy/config/initializers/cable_ready.rb
219
+ - test/dummy/config/initializers/content_security_policy.rb
220
+ - test/dummy/config/initializers/cookies_serializer.rb
221
+ - test/dummy/config/initializers/filter_parameter_logging.rb
222
+ - test/dummy/config/initializers/inflections.rb
223
+ - test/dummy/config/initializers/mime_types.rb
224
+ - test/dummy/config/initializers/permissions_policy.rb
225
+ - test/dummy/config/initializers/wrap_parameters.rb
226
+ - test/dummy/config/puma.rb
227
+ - test/dummy/config/routes.rb
228
+ - test/dummy/db/migrate/20210902154139_create_users.rb
229
+ - test/dummy/db/migrate/20210902154153_create_posts.rb
230
+ - test/dummy/db/migrate/20210904081930_create_topics.rb
231
+ - test/dummy/db/migrate/20210904093607_create_sections.rb
232
+ - test/dummy/db/migrate/20210913191735_create_teams.rb
233
+ - test/dummy/db/migrate/20210913191759_add_team_reference_to_users.rb
234
+ - test/dummy/db/schema.rb
235
+ - test/dummy/test/models/post_test.rb
236
+ - test/dummy/test/models/section_test.rb
237
+ - test/dummy/test/models/team_test.rb
238
+ - test/dummy/test/models/topic_test.rb
239
+ - test/dummy/test/models/user_test.rb
179
240
  - test/lib/cable_ready/cable_car_test.rb
241
+ - test/lib/cable_ready/compoundable_test.rb
242
+ - test/lib/cable_ready/helper_test.rb
180
243
  - test/lib/cable_ready/identifiable_test.rb
181
244
  - test/lib/cable_ready/operation_builder_test.rb
245
+ - test/lib/cable_ready/updatable_test.rb
182
246
  - test/lib/generators/cable_ready/channel_generator_test.rb
183
247
  - test/support/generator_test_helpers.rb
184
248
  - test/test_helper.rb
185
- - yarn.lock
186
249
  homepage: https://github.com/stimulusreflex/cable_ready
187
250
  licenses:
188
251
  - MIT
189
252
  metadata: {}
190
- post_install_message:
253
+ post_install_message:
191
254
  rdoc_options: []
192
255
  require_paths:
193
256
  - lib
@@ -202,14 +265,61 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
265
  - !ruby/object:Gem::Version
203
266
  version: 1.3.1
204
267
  requirements: []
205
- rubygems_version: 3.2.3
206
- signing_key:
268
+ rubygems_version: 3.1.6
269
+ signing_key:
207
270
  specification_version: 4
208
271
  summary: Out-of-Band Server Triggered DOM Operations
209
272
  test_files:
273
+ - test/dummy/db/migrate/20210904093607_create_sections.rb
274
+ - test/dummy/db/migrate/20210913191759_add_team_reference_to_users.rb
275
+ - test/dummy/db/migrate/20210904081930_create_topics.rb
276
+ - test/dummy/db/migrate/20210913191735_create_teams.rb
277
+ - test/dummy/db/migrate/20210902154153_create_posts.rb
278
+ - test/dummy/db/migrate/20210902154139_create_users.rb
279
+ - test/dummy/db/schema.rb
280
+ - test/dummy/config/environment.rb
281
+ - test/dummy/config/routes.rb
282
+ - test/dummy/config/application.rb
283
+ - test/dummy/config/initializers/mime_types.rb
284
+ - test/dummy/config/initializers/content_security_policy.rb
285
+ - test/dummy/config/initializers/backtrace_silencers.rb
286
+ - test/dummy/config/initializers/permissions_policy.rb
287
+ - test/dummy/config/initializers/wrap_parameters.rb
288
+ - test/dummy/config/initializers/assets.rb
289
+ - test/dummy/config/initializers/inflections.rb
290
+ - test/dummy/config/initializers/filter_parameter_logging.rb
291
+ - test/dummy/config/initializers/cookies_serializer.rb
292
+ - test/dummy/config/initializers/application_controller_renderer.rb
293
+ - test/dummy/config/initializers/cable_ready.rb
294
+ - test/dummy/config/boot.rb
295
+ - test/dummy/config/puma.rb
296
+ - test/dummy/config/environments/test.rb
297
+ - test/dummy/config/environments/production.rb
298
+ - test/dummy/config/environments/development.rb
299
+ - test/dummy/app/channels/application_cable/channel.rb
300
+ - test/dummy/app/channels/application_cable/connection.rb
301
+ - test/dummy/app/jobs/application_job.rb
302
+ - test/dummy/app/helpers/application_helper.rb
303
+ - test/dummy/app/controllers/application_controller.rb
304
+ - test/dummy/app/models/user.rb
305
+ - test/dummy/app/models/section.rb
306
+ - test/dummy/app/models/post.rb
307
+ - test/dummy/app/models/team.rb
308
+ - test/dummy/app/models/topic.rb
309
+ - test/dummy/app/models/application_record.rb
310
+ - test/dummy/app/models/global_idable_entity.rb
311
+ - test/dummy/app/mailers/application_mailer.rb
312
+ - test/dummy/test/models/section_test.rb
313
+ - test/dummy/test/models/post_test.rb
314
+ - test/dummy/test/models/user_test.rb
315
+ - test/dummy/test/models/team_test.rb
316
+ - test/dummy/test/models/topic_test.rb
317
+ - test/support/generator_test_helpers.rb
318
+ - test/lib/generators/cable_ready/channel_generator_test.rb
210
319
  - test/lib/cable_ready/cable_car_test.rb
320
+ - test/lib/cable_ready/helper_test.rb
211
321
  - test/lib/cable_ready/identifiable_test.rb
322
+ - test/lib/cable_ready/compoundable_test.rb
212
323
  - test/lib/cable_ready/operation_builder_test.rb
213
- - test/lib/generators/cable_ready/channel_generator_test.rb
214
- - test/support/generator_test_helpers.rb
324
+ - test/lib/cable_ready/updatable_test.rb
215
325
  - test/test_helper.rb
data/cable_ready.gemspec DELETED
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../lib/cable_ready/version", __FILE__)
4
-
5
- Gem::Specification.new do |gem|
6
- gem.name = "cable_ready"
7
- gem.license = "MIT"
8
- gem.version = CableReady::VERSION
9
- gem.authors = ["Nathan Hopkins"]
10
- gem.email = ["natehop@gmail.com"]
11
- gem.homepage = "https://github.com/stimulusreflex/cable_ready"
12
- gem.summary = "Out-of-Band Server Triggered DOM Operations"
13
-
14
- gem.files = Dir["lib/**/*.rb", "app/**/*.rb", "bin/*", "[A-Z]*"]
15
- gem.test_files = Dir["test/**/*.rb"]
16
-
17
- gem.add_dependency "rails", ">= 5.2"
18
- gem.add_dependency "thread-local", ">= 1.1.0"
19
-
20
- gem.add_development_dependency "github_changelog_generator"
21
- gem.add_development_dependency "magic_frozen_string_literal"
22
- gem.add_development_dependency "pry"
23
- gem.add_development_dependency "pry-nav"
24
- gem.add_development_dependency "rake"
25
- gem.add_development_dependency "standardrb"
26
- gem.add_development_dependency "mocha"
27
- end
data/package.json DELETED
@@ -1,41 +0,0 @@
1
- {
2
- "name": "cable_ready",
3
- "version": "5.0.0-pre2",
4
- "description": "CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby.",
5
- "keywords": [
6
- "ruby",
7
- "rails",
8
- "websockets",
9
- "actioncable",
10
- "cable",
11
- "ssr",
12
- "stimulus_reflex",
13
- "client-side",
14
- "dom"
15
- ],
16
- "homepage": "https://cableready.stimulusreflex.com/",
17
- "bugs": {
18
- "url": "https://github.com/stimulusreflex/cable_ready/issues"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com:stimulusreflex/cable_ready.git"
23
- },
24
- "license": "MIT",
25
- "author": "Nathan Hopkins <natehop@gmail.com>",
26
- "main": "./javascript/index.js",
27
- "module": "./javascript/index.js",
28
- "sideEffects": false,
29
- "scripts": {
30
- "lint": "yarn run prettier-standard:check",
31
- "format": "yarn run prettier-standard:format",
32
- "prettier-standard:check": "yarn run prettier-standard --check ./javascript/**/*.js",
33
- "prettier-standard:format": "yarn run prettier-standard ./javascript/**/*.js"
34
- },
35
- "dependencies": {
36
- "morphdom": "^2.6.1"
37
- },
38
- "devDependencies": {
39
- "prettier-standard": "^16.1.0"
40
- }
41
- }