standard_procedure_operations 0.7.0 → 0.7.1

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: d5804e91c48ca11b9306c1d8d2c3006df7916dcd3e768629cf492b1daa409725
4
- data.tar.gz: 2c0f4a513bb1bd685f44daf46f28e7ecb2ac0909a703ae79240ff0587fc74d1c
3
+ metadata.gz: 4d3727c9772fdc1cd01eb3438c01f0fdea6ea03b02e9ab631363bc20fac73ffc
4
+ data.tar.gz: 8d75786ef589b7029d49d743a25c7e38723124d9cf095e59cae072969a61ad0e
5
5
  SHA512:
6
- metadata.gz: 1f8335c58e7df31046d08ab67cf99d7bf1cd0a1a52aa24433b79932f418c9d0de945d702d7039eabb6e66ed4a94484a2aa3d9bdb415d60859b9007feff9c64e2
7
- data.tar.gz: 8cb8aa2940d5b4658582c14aef3db7d715c3c6af2f66b1bd838514ad11e67a6edbc8a9b95eb9cd8e57fc8293156365acaf95e017d8d13572fe5d1259c2b27269
6
+ metadata.gz: 58662325c764ab6fcbca8f047d4077a773e980bfcfda739d0a1076e8b9f5b579744de1938d2119897b33091a5de579e5d6747bd090f80a4f27a2237b287f4253
7
+ data.tar.gz: 1aff44b8fd34fe03bc92e1da8ab56db4f80b29cc5fc3a1e659022c2be61b8caf9ed92e23ce2572be58421f1a6ad03e96360a2f504424b1b00860a9ddd67b5d51
data/README.md CHANGED
@@ -280,7 +280,30 @@ However, it also means that your database table could fill up with junk that you
280
280
 
281
281
  ## Testing
282
282
 
283
- TBD
283
+ Because the flow for a task may be complex, it's best to test each state in isolation. To help with this, there is a `test` method on the `Operations::Task` class, which creates a task, in your desired state, then runs the appropriate handler. Then you can check that it has done what you expect.
284
+
285
+ ```ruby
286
+ class WeekendChecker < Operations::Task
287
+ has_attribute :day_of_week, :string, default: "Monday"
288
+ validates :day_of_week, presence: true
289
+ starts_with :is_it_the_weekend?
290
+
291
+ decision :is_it_the_weekend? do
292
+ condition { %w[Saturday Sunday].include? day_of_week }
293
+ if_true :weekend
294
+ if_false :weekday
295
+ end
296
+
297
+ result :weekend
298
+ result :weekday
299
+ end
300
+
301
+ task = WeekendChecker.verify :is_it_the_weekend?, day_of_week: "Saturday"
302
+ expect(task).to be_in :weekend
303
+
304
+ task = WeekendChecker.verify :is_it_the_weekend?, day_of_week: "Wednesday"
305
+ expect(task).to be_in :weekday
306
+ ```
284
307
 
285
308
  ## Installation
286
309
  Step 1: Add the gem to your Rails application's Gemfile:
@@ -0,0 +1,11 @@
1
+ module Operations::Task::Testing
2
+ extend ActiveSupport::Concern
3
+
4
+ class_methods do
5
+ def test state, **attributes
6
+ create!(current_state: state, **attributes).tap do |task|
7
+ task.call_handler
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,6 +3,8 @@ module Operations
3
3
  include HasAttributes
4
4
  include Plan
5
5
  include Index
6
+ include Testing
7
+
6
8
  scope :ready_to_wake, -> { ready_to_wake_at(Time.current) }
7
9
  scope :ready_to_wake_at, ->(time) { where(wakes_at: ..time) }
8
10
  scope :expired, -> { expires_at(Time.current) }
@@ -26,7 +28,7 @@ module Operations
26
28
  def call(immediate: false)
27
29
  while active?
28
30
  Rails.logger.debug { "--- #{self}: #{current_state}" }
29
- (handler_for(current_state).immediate? || immediate) ? handler_for(current_state).call(self) : go_to_sleep!
31
+ (handler_for(current_state).immediate? || immediate) ? call_handler : go_to_sleep!
30
32
  end
31
33
  rescue => ex
32
34
  record_error! ex
@@ -41,6 +43,8 @@ module Operations
41
43
 
42
44
  def record_error!(exception) = update!(task_status: "failed", exception_class: exception.class.to_s, exception_message: exception.message.to_s, exception_backtrace: exception.backtrace)
43
45
 
46
+ def call_handler = handler_for(current_state).call(self)
47
+
44
48
  private def go_to_sleep! = update!(default_times.merge(task_status: "waiting"))
45
49
 
46
50
  private def activate_and_call
@@ -1,3 +1,3 @@
1
1
  module Operations
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_procedure_operations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahoul Baruah
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-07-02 00:00:00.000000000 Z
10
+ date: 2025-07-04 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -60,6 +60,7 @@ files:
60
60
  - app/models/operations/task/plan/result_handler.rb
61
61
  - app/models/operations/task/plan/wait_handler.rb
62
62
  - app/models/operations/task/runner.rb
63
+ - app/models/operations/task/testing.rb
63
64
  - app/models/operations/task_participant.rb
64
65
  - config/routes.rb
65
66
  - db/migrate/20250701190516_rename_existing_operations_tables.rb