stealth 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/VERSION +1 -1
- data/lib/stealth/controller/catch_all.rb +2 -2
- data/lib/stealth/controller/controller.rb +1 -1
- data/spec/controller/catch_all_spec.rb +101 -0
- data/spec/controller/controller_spec.rb +51 -0
- data/spec/controller/replies_spec.rb +15 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb5b41def6c4e13619ace50cff93ef042e41907d847d5bc391342a07b659c12f
|
4
|
+
data.tar.gz: edff40b0be61bb0ce35db7376b85fcbeb287daadb0a936266c0fb3ba2a442b11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d41a57396b557409239312b03ed2009630a0b8d9396f97a5b5582ef6a9d7a68fc76696bf3ea7629a1af9fab3f3ccb9b2dd0b53db8f32cb9376c7b7769b289a75
|
7
|
+
data.tar.gz: 490adbca626688b0af47b89d857cf7bb14a307b49b1a6b92012d49b2eec5d5fc09f5176a5976b493f772af1c6fdc8c91cd8995d7cc08f8843db853135a09dd1c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stealth (1.0.
|
4
|
+
stealth (1.0.3)
|
5
5
|
activerecord (~> 5.2)
|
6
6
|
activesupport (~> 5.2)
|
7
7
|
multi_json (~> 1.12)
|
@@ -56,7 +56,7 @@ GEM
|
|
56
56
|
mock_redis (0.17.3)
|
57
57
|
multi_json (1.13.1)
|
58
58
|
mustermann (1.0.2)
|
59
|
-
nokogiri (1.8.
|
59
|
+
nokogiri (1.8.4)
|
60
60
|
mini_portile2 (~> 2.3.0)
|
61
61
|
oj (3.5.0)
|
62
62
|
puma (3.11.4)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
@@ -13,10 +13,10 @@ module Stealth
|
|
13
13
|
error_level = fetch_error_level
|
14
14
|
Stealth::Logger.l(topic: "catch_all", message: "CatchAll #{calculate_catch_all_state(error_level)} triggered for #{error_slug}: #{reason}")
|
15
15
|
|
16
|
-
if defined?(CatchAllsController) &&
|
16
|
+
if defined?(CatchAllsController) && FlowMap.flow_spec[:catch_all].present?
|
17
17
|
catch_all_state = calculate_catch_all_state(error_level)
|
18
18
|
|
19
|
-
if
|
19
|
+
if FlowMap.flow_spec[:catch_all].states.keys.include?(catch_all_state.to_sym)
|
20
20
|
step_to flow: 'catch_all', state: catch_all_state
|
21
21
|
else
|
22
22
|
# We are out of bounds, do nothing to prevent an infinite loop
|
@@ -63,7 +63,7 @@ module Stealth
|
|
63
63
|
flow_controller.send(@action_name)
|
64
64
|
run_catch_all(reason: 'Did not send replies, update session, or step') unless flow_controller.progressed?
|
65
65
|
rescue StandardError => e
|
66
|
-
Stealth::Logger.l(topic: "catch_all", message: e.backtrace)
|
66
|
+
Stealth::Logger.l(topic: "catch_all", message: e.backtrace.join("\n"))
|
67
67
|
run_catch_all(reason: e.message)
|
68
68
|
end
|
69
69
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '/spec_helper'))
|
5
|
+
|
6
|
+
describe "Stealth::Controller::CatchAll" do
|
7
|
+
|
8
|
+
class VadersController < Stealth::Controller
|
9
|
+
def my_action
|
10
|
+
raise "oops"
|
11
|
+
end
|
12
|
+
|
13
|
+
def my_action2
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def my_action3
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class StubbedCatchAllsController < Stealth::Controller
|
23
|
+
def level1
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def level2
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def level3
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class FlowMap
|
37
|
+
include Stealth::Flow
|
38
|
+
|
39
|
+
flow :vader do
|
40
|
+
state :my_action
|
41
|
+
state :my_action2
|
42
|
+
state :my_action3
|
43
|
+
end
|
44
|
+
|
45
|
+
flow :catch_all do
|
46
|
+
state :level1
|
47
|
+
state :level2
|
48
|
+
state :level3
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:facebook_message) { SampleMessage.new(service: 'facebook') }
|
53
|
+
let(:controller) { VadersController.new(service_message: facebook_message.message_with_text) }
|
54
|
+
|
55
|
+
describe "when a CatchAll flow is defined" do
|
56
|
+
before(:each) do
|
57
|
+
stub_const("CatchAllsController", StubbedCatchAllsController)
|
58
|
+
end
|
59
|
+
|
60
|
+
after(:each) do
|
61
|
+
$redis.flushdb
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should step_to catch_all->level1 when a StandardError is raised" do
|
65
|
+
controller.action(action: :my_action)
|
66
|
+
expect(controller.current_session.flow_string).to eq("catch_all")
|
67
|
+
expect(controller.current_session.state_string).to eq("level1")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should step_to catch_all->level1 when an action doesn't progress the flow" do
|
71
|
+
controller.action(action: :my_action2)
|
72
|
+
expect(controller.current_session.flow_string).to eq("catch_all")
|
73
|
+
expect(controller.current_session.state_string).to eq("level1")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should step_to catch_all->level2 when an action raises back to back" do
|
77
|
+
controller.step_to flow: :vader, state: :my_action
|
78
|
+
controller.step_to flow: :vader, state: :my_action
|
79
|
+
expect(controller.current_session.flow_string).to eq("catch_all")
|
80
|
+
expect(controller.current_session.state_string).to eq("level2")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should step_to catch_all->level3 when an action raises back to back to back" do
|
84
|
+
controller.step_to flow: :vader, state: :my_action
|
85
|
+
controller.step_to flow: :vader, state: :my_action
|
86
|
+
controller.step_to flow: :vader, state: :my_action
|
87
|
+
expect(controller.current_session.flow_string).to eq("catch_all")
|
88
|
+
expect(controller.current_session.state_string).to eq("level3")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should just stop after the maximum number of catch_all levels have been reached" do
|
92
|
+
controller.step_to flow: :vader, state: :my_action
|
93
|
+
controller.step_to flow: :vader, state: :my_action
|
94
|
+
controller.step_to flow: :vader, state: :my_action
|
95
|
+
controller.step_to flow: :vader, state: :my_action
|
96
|
+
expect(controller.current_session.flow_string).to eq("vader")
|
97
|
+
expect(controller.current_session.state_string).to eq("my_action")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
@@ -345,4 +345,55 @@ describe "Stealth::Controller" do
|
|
345
345
|
end
|
346
346
|
end
|
347
347
|
|
348
|
+
describe "progressed?" do
|
349
|
+
it "should be truthy if an action calls step_to" do
|
350
|
+
expect(controller.progressed?).to be_falsey
|
351
|
+
controller.step_to flow: "mr_robot"
|
352
|
+
expect(controller.progressed?).to be_truthy
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should be falsey if an action only calls step_to_at" do
|
356
|
+
expect(controller.progressed?).to be_falsey
|
357
|
+
|
358
|
+
expect(Stealth::ScheduledReplyJob).to receive(:perform_at)
|
359
|
+
controller.step_to_at (DateTime.now + 10.hours), flow: 'mr_robot'
|
360
|
+
|
361
|
+
expect(controller.progressed?).to be_falsey
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should be falsey if an action only calls step_to_in" do
|
365
|
+
expect(controller.progressed?).to be_falsey
|
366
|
+
|
367
|
+
expect(Stealth::ScheduledReplyJob).to receive(:perform_in)
|
368
|
+
controller.step_to_in 100.seconds, flow: 'mr_robot'
|
369
|
+
|
370
|
+
expect(controller.progressed?).to be_falsey
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should be truthy if an action calls update_session_to" do
|
374
|
+
expect(controller.progressed?).to be_falsey
|
375
|
+
controller.update_session_to flow: "mr_robot"
|
376
|
+
expect(controller.progressed?).to be_truthy
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should be truthy if an action sends replies" do
|
380
|
+
expect(controller.progressed?).to be_falsey
|
381
|
+
|
382
|
+
# Stub out a service reply -- we just want send_replies to succeed here
|
383
|
+
stubbed_service_reply = double("service_reply")
|
384
|
+
allow(controller).to receive(:action_replies).and_return([], :erb)
|
385
|
+
allow(stubbed_service_reply).to receive(:replies).and_return([])
|
386
|
+
allow(Stealth::ServiceReply).to receive(:new).and_return(stubbed_service_reply)
|
387
|
+
|
388
|
+
controller.send_replies
|
389
|
+
expect(controller.progressed?).to be_truthy
|
390
|
+
end
|
391
|
+
|
392
|
+
it "should be falsey otherwise" do
|
393
|
+
expect(controller.progressed?).to be_falsey
|
394
|
+
controller.action(action: :other_action)
|
395
|
+
expect(controller.progressed?).to be_falsey
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
348
399
|
end
|
@@ -34,6 +34,21 @@ describe "Stealth::Controller replies" do
|
|
34
34
|
def say_offer
|
35
35
|
send_replies
|
36
36
|
end
|
37
|
+
|
38
|
+
def say_uh_oh
|
39
|
+
send_replies
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "missing reply" do
|
44
|
+
it "should raise a Stealth::Errors::ReplyNotFound" do
|
45
|
+
allow(controller.current_session).to receive(:flow_string).and_return("message")
|
46
|
+
allow(controller.current_session).to receive(:state_string).and_return("say_uh_oh")
|
47
|
+
|
48
|
+
expect {
|
49
|
+
controller.send_replies
|
50
|
+
}.to raise_error(Stealth::Errors::ReplyNotFound)
|
51
|
+
end
|
37
52
|
end
|
38
53
|
|
39
54
|
describe "class attributes" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stealth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauricio Gomes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -284,6 +284,7 @@ files:
|
|
284
284
|
- logo.svg
|
285
285
|
- spec/configuration_spec.rb
|
286
286
|
- spec/controller/callbacks_spec.rb
|
287
|
+
- spec/controller/catch_all_spec.rb
|
287
288
|
- spec/controller/controller_spec.rb
|
288
289
|
- spec/controller/helpers_spec.rb
|
289
290
|
- spec/controller/replies_spec.rb
|
@@ -332,6 +333,7 @@ summary: Ruby framework for conversational bots
|
|
332
333
|
test_files:
|
333
334
|
- spec/configuration_spec.rb
|
334
335
|
- spec/controller/callbacks_spec.rb
|
336
|
+
- spec/controller/catch_all_spec.rb
|
335
337
|
- spec/controller/controller_spec.rb
|
336
338
|
- spec/controller/helpers_spec.rb
|
337
339
|
- spec/controller/replies_spec.rb
|