actioncable-next 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c81ab3f657804e4fac5db9405fd406cd1502ca7d8f032982be4f477b0a2d2592
4
- data.tar.gz: 12ddd7b9e9867e15bbb6639242190efa93e5ede81daabc5404f16be7694ecd2e
3
+ metadata.gz: 4218440a66ebe42d3a2f0e3acddb8ee929308296e9bef6b7efe6028e1ea00c89
4
+ data.tar.gz: 4474877342a6bb7520ca7b114aed1f0fec551bb2df5d0041bbf445fca3372775
5
5
  SHA512:
6
- metadata.gz: a40b2e434160d34681cae2a21147751e85a058934960835bb26010c6bcc2db86053e267380f921b1ab446d16e7fcacaf9d766e03f33527a140ae9d5328125b43
7
- data.tar.gz: 20b4e2ff4761febf560ed3db8e536a32532478f7d9ba9c6e671308ba513316d128df56a3744a0688a70ce44ea17509e3fee5161139a7f8abe490a0dd94056968
6
+ metadata.gz: 22bf0972d72b0b016b620b748c6d5b7aa783e7ad298786c2da92aa47e3af704b5e14aab94c0267375c7a26554dc166e41bc8c47de8b127d32657b3c7b9652a7c
7
+ data.tar.gz: f908764444fb87f16f9d52e693325bfb52469cfec7ef16484f95d984227591b65908b5b1cdafb4fef9818653f4abede75e54567a2d41f6b80e0d6919a09343a2
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## main
4
4
 
5
+ ## 0.3.2
6
+
7
+ - Add `#advance_time` test helper to channels to test periodic timers.
8
+
5
9
  ## 0.3.0
6
10
 
7
11
  - Sync with upstream (Rails 8.1.1).
data/README.md CHANGED
@@ -13,7 +13,7 @@ Add this line to your application's Gemfile **before Rails or Action Cable**:
13
13
  ```ruby
14
14
  gem "actioncable-next"
15
15
 
16
- gem "rails", "~> 7.0"
16
+ gem "rails", ">= 7.0"
17
17
  ```
18
18
 
19
19
  Then, you can use Action Cable as before. Under the hood, the new implementation would be used.
@@ -238,6 +238,15 @@ module ActionCable
238
238
  subscription.perform_action(data.stringify_keys.merge("action" => action.to_s))
239
239
  end
240
240
 
241
+ # Advance the virtual clock used by `periodically` timers.
242
+ #
243
+ # subscribe
244
+ # advance_time 5.seconds
245
+ # assert_equal 1, subscription.tick_count
246
+ def advance_time(seconds)
247
+ testserver.advance_time(seconds)
248
+ end
249
+
241
250
  # Returns messages transmitted into channel
242
251
  def transmissions
243
252
  # Return only directly sent message (via #transmit)
@@ -100,15 +100,44 @@ module ActionCable
100
100
  def close
101
101
  @closed = true
102
102
  end
103
+
104
+ def perform_work(receiver, method_name, *args)
105
+ receiver.public_send(method_name, *args)
106
+ end
107
+ end
108
+
109
+ class TestTimer
110
+ attr_reader :interval
111
+
112
+ def initialize(interval, &block)
113
+ @interval = interval
114
+ @block = block
115
+ @elapsed = 0
116
+ @shutdown = false
117
+ end
118
+
119
+ def shutdown
120
+ @shutdown = true
121
+ end
122
+
123
+ def advance(seconds)
124
+ return if @shutdown
125
+ @elapsed += seconds
126
+ while @elapsed >= @interval
127
+ @elapsed -= @interval
128
+ @block&.call
129
+ end
130
+ end
103
131
  end
104
132
 
105
133
  # TestServer provides test pub/sub and executor implementations
106
134
  class TestServer
107
- attr_reader :streams, :config
135
+ attr_reader :streams, :config, :timers
108
136
 
109
137
  def initialize(server)
110
138
  @streams = Hash.new { |h, k| h[k] = [] }
111
139
  @config = server.config
140
+ @timers = []
112
141
  end
113
142
 
114
143
  alias_method :pubsub, :itself
@@ -118,8 +147,14 @@ module ActionCable
118
147
 
119
148
  # Inline async calls
120
149
  def post(&work) = work.call
121
- # We don't support timers in unit tests yet
122
- def timer(_every) = nil
150
+
151
+ def timer(every, &block)
152
+ TestTimer.new(every, &block).tap { |t| @timers << t }
153
+ end
154
+
155
+ def advance_time(seconds)
156
+ @timers.each { |timer| timer.advance(seconds) }
157
+ end
123
158
 
124
159
  #== Pub/sub interface ==
125
160
  def subscribe(stream, callback, success_callback = nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionCableNext
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actioncable-next
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pratik Naik
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-10-31 00:00:00.000000000 Z
13
+ date: 2026-04-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -167,7 +167,7 @@ licenses:
167
167
  - MIT
168
168
  metadata:
169
169
  bug_tracker_uri: https://github.com/anycable/actioncable-next
170
- changelog_uri: https://github.com/anycable/actioncable-next/blob/v0.3.1/CHANGELOG.md
170
+ changelog_uri: https://github.com/anycable/actioncable-next/blob/v0.3.2/CHANGELOG.md
171
171
  source_code_uri: https://github.com/anycable/actioncable-next
172
172
  rubygems_mfa_required: 'true'
173
173
  post_install_message: