startback-websocket 0.14.0 → 0.14.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 +4 -4
- data/Gemfile +3 -2
- data/README.md +64 -9
- data/lib/startback/ext/context.rb +6 -0
- data/lib/startback/ext.rb +1 -2
- data/lib/startback/websocket/app.rb +82 -0
- data/lib/startback/websocket/hub/app.rb +28 -0
- data/lib/startback/websocket/hub/builder.rb +55 -0
- data/lib/startback/websocket/hub/errors.rb +9 -0
- data/lib/startback/websocket/hub/message.rb +29 -0
- data/lib/startback/websocket/hub/middleware/command_handler.rb +34 -0
- data/lib/startback/websocket/hub/middleware/room_handler.rb +30 -0
- data/lib/startback/websocket/hub/middleware.rb +12 -0
- data/lib/startback/websocket/hub/participant.rb +16 -0
- data/lib/startback/websocket/hub/room.rb +46 -0
- data/lib/startback/websocket/hub.rb +15 -0
- data/lib/startback/websocket.rb +8 -0
- data/spec/spec_helper.rb +21 -32
- data/spec/unit/hub/test_builder.rb +141 -0
- data/spec/unit/hub/test_room.rb +27 -0
- data/spec/unit/test_app.rb +35 -0
- data/tasks/test.rake +0 -1
- metadata +20 -91
- data/lib/startback/audit/prometheus.rb +0 -87
- data/lib/startback/audit/shared.rb +0 -17
- data/lib/startback/audit/trailer.rb +0 -129
- data/lib/startback/audit.rb +0 -3
- data/lib/startback/caching/entity_cache.rb +0 -157
- data/lib/startback/caching/no_store.rb +0 -28
- data/lib/startback/caching/store.rb +0 -34
- data/lib/startback/context/h_factory.rb +0 -43
- data/lib/startback/context/middleware.rb +0 -53
- data/lib/startback/context.rb +0 -122
- data/lib/startback/errors.rb +0 -197
- data/lib/startback/event/agent.rb +0 -84
- data/lib/startback/event/bus/bunny/async.rb +0 -162
- data/lib/startback/event/bus/bunny.rb +0 -1
- data/lib/startback/event/bus/memory/async.rb +0 -45
- data/lib/startback/event/bus/memory/sync.rb +0 -35
- data/lib/startback/event/bus/memory.rb +0 -2
- data/lib/startback/event/bus.rb +0 -100
- data/lib/startback/event/engine.rb +0 -94
- data/lib/startback/event/ext/context.rb +0 -5
- data/lib/startback/event/ext/operation.rb +0 -13
- data/lib/startback/event.rb +0 -47
- data/lib/startback/ext/date_time.rb +0 -9
- data/lib/startback/ext/time.rb +0 -9
- data/lib/startback/model.rb +0 -6
- data/lib/startback/operation/error_operation.rb +0 -19
- data/lib/startback/operation/multi_operation.rb +0 -28
- data/lib/startback/operation.rb +0 -78
- data/lib/startback/services.rb +0 -11
- data/lib/startback/support/data_object.rb +0 -71
- data/lib/startback/support/env.rb +0 -41
- data/lib/startback/support/fake_logger.rb +0 -18
- data/lib/startback/support/hooks.rb +0 -48
- data/lib/startback/support/log_formatter.rb +0 -34
- data/lib/startback/support/logger.rb +0 -34
- data/lib/startback/support/operation_runner.rb +0 -150
- data/lib/startback/support/robustness.rb +0 -157
- data/lib/startback/support/transaction_manager.rb +0 -25
- data/lib/startback/support/transaction_policy.rb +0 -33
- data/lib/startback/support/world.rb +0 -54
- data/lib/startback/support.rb +0 -26
- data/lib/startback/version.rb +0 -8
- data/lib/startback/web/api.rb +0 -99
- data/lib/startback/web/auto_caching.rb +0 -85
- data/lib/startback/web/catch_all.rb +0 -52
- data/lib/startback/web/cors_headers.rb +0 -80
- data/lib/startback/web/health_check.rb +0 -49
- data/lib/startback/web/magic_assets/ng_html_transformer.rb +0 -80
- data/lib/startback/web/magic_assets/rake_tasks.rb +0 -64
- data/lib/startback/web/magic_assets.rb +0 -98
- data/lib/startback/web/middleware.rb +0 -13
- data/lib/startback/web/prometheus.rb +0 -16
- data/lib/startback/web/shield.rb +0 -58
- data/lib/startback.rb +0 -43
- data/spec/unit/audit/test_prometheus.rb +0 -72
- data/spec/unit/audit/test_trailer.rb +0 -105
- data/spec/unit/caching/test_entity_cache.rb +0 -136
- data/spec/unit/context/test_abstraction_factory.rb +0 -64
- data/spec/unit/context/test_dup.rb +0 -42
- data/spec/unit/context/test_fork.rb +0 -37
- data/spec/unit/context/test_h_factory.rb +0 -31
- data/spec/unit/context/test_middleware.rb +0 -45
- data/spec/unit/context/test_with_world.rb +0 -20
- data/spec/unit/context/test_world.rb +0 -17
- data/spec/unit/event/bus/memory/test_async.rb +0 -43
- data/spec/unit/event/bus/memory/test_sync.rb +0 -43
- data/spec/unit/support/hooks/test_after_hook.rb +0 -54
- data/spec/unit/support/hooks/test_before_hook.rb +0 -54
- data/spec/unit/support/operation_runner/test_around_run.rb +0 -156
- data/spec/unit/support/operation_runner/test_before_after_call.rb +0 -48
- data/spec/unit/support/test_data_object.rb +0 -156
- data/spec/unit/support/test_env.rb +0 -75
- data/spec/unit/support/test_robusteness.rb +0 -229
- data/spec/unit/support/test_transaction_manager.rb +0 -64
- data/spec/unit/support/test_world.rb +0 -72
- data/spec/unit/test_event.rb +0 -62
- data/spec/unit/test_operation.rb +0 -55
- data/spec/unit/test_support.rb +0 -40
- data/spec/unit/web/fixtures/assets/app/hello.es6 +0 -4
- data/spec/unit/web/fixtures/assets/app/hello.html +0 -1
- data/spec/unit/web/fixtures/assets/index.es6 +0 -1
- data/spec/unit/web/test_api.rb +0 -82
- data/spec/unit/web/test_auto_caching.rb +0 -81
- data/spec/unit/web/test_catch_all.rb +0 -77
- data/spec/unit/web/test_cors_headers.rb +0 -88
- data/spec/unit/web/test_healthcheck.rb +0 -59
- data/spec/unit/web/test_magic_assets.rb +0 -82
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
module Startback
|
|
3
|
-
module Support
|
|
4
|
-
describe Env do
|
|
5
|
-
include Env
|
|
6
|
-
|
|
7
|
-
before do
|
|
8
|
-
ENV['FOO'] = 'BAR'
|
|
9
|
-
ENV['FOOL'] = ''
|
|
10
|
-
ENV['FOOLISH'] = ' BAR '
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
after do
|
|
14
|
-
ENV.delete('FOO')
|
|
15
|
-
ENV.delete('FOOL')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe "env" do
|
|
19
|
-
it 'returns an env variable' do
|
|
20
|
-
expect(env('FOO')).to eql('BAR')
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'returns nil otherwise' do
|
|
24
|
-
expect(env('BAR')).to be_nil
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'strips the value' do
|
|
28
|
-
expect(env('FOOLISH')).to eql('BAR')
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it 'yields the block if any' do
|
|
32
|
-
expect(env('FOO'){|x| x.downcase }).to eql('bar')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it 'support a default value' do
|
|
36
|
-
expect(env('BAR', 'BAZ')).to eql('BAZ')
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'yields the block with the default if any' do
|
|
40
|
-
expect(env('BAR', 'BAZ'){|x| x.downcase }).to eql('baz')
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'returns nil when empty' do
|
|
44
|
-
expect(env('FOOL')).to be_nil
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it 'yields the block with the default if empty' do
|
|
48
|
-
expect(env('FOOL', 'BAZ'){|x| x.downcase }).to eql('baz')
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
describe "env!" do
|
|
53
|
-
it 'returns an env variable' do
|
|
54
|
-
expect(env!('FOO')).to eql('BAR')
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it 'strips the value' do
|
|
58
|
-
expect(env!('FOOLISH')).to eql('BAR')
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it 'raise otherwise' do
|
|
62
|
-
expect{ env!('BAR') }.to raise_error(Startback::Errors::Error, /BAR/)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'raise on empty' do
|
|
66
|
-
expect{ env!('FOOL') }.to raise_error(Startback::Errors::Error, /FOOL/)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'yields the block if any' do
|
|
70
|
-
expect(env('FOO'){|x| x.downcase }).to eql('bar')
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
module Startback
|
|
3
|
-
module Support
|
|
4
|
-
describe Robustness do
|
|
5
|
-
|
|
6
|
-
let(:the_logger) {
|
|
7
|
-
FakeLogger.new
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
let(:context_with_logger) {
|
|
11
|
-
Context.new.tap{|c| c.logger = the_logger }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
describe "monitor" do
|
|
15
|
-
include Robustness
|
|
16
|
-
|
|
17
|
-
it 'works' do
|
|
18
|
-
x = monitor("test", context_with_logger) do
|
|
19
|
-
12
|
|
20
|
-
end
|
|
21
|
-
expect(x).to eql(12)
|
|
22
|
-
expect(the_logger.last_msg.keys).to eql([:op, :op_took])
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
end # monitor
|
|
26
|
-
|
|
27
|
-
describe "stop_errors" do
|
|
28
|
-
include Robustness
|
|
29
|
-
|
|
30
|
-
it 'works and logs the error' do
|
|
31
|
-
x = nil
|
|
32
|
-
expect {
|
|
33
|
-
x = stop_errors("test", context_with_logger) do
|
|
34
|
-
raise "Test"
|
|
35
|
-
end
|
|
36
|
-
}.not_to raise_error
|
|
37
|
-
expect(x).to be(nil)
|
|
38
|
-
expect(the_logger.last_msg.keys).to eql([:op, :op_took, :error])
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'returns the result if no error' do
|
|
42
|
-
x = nil
|
|
43
|
-
expect {
|
|
44
|
-
x = stop_errors("test", context_with_logger) do
|
|
45
|
-
12
|
|
46
|
-
end
|
|
47
|
-
}.not_to raise_error
|
|
48
|
-
expect(x).to eql(12)
|
|
49
|
-
expect(the_logger.last_msg).to be_nil
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe "try_max_times" do
|
|
55
|
-
include Robustness
|
|
56
|
-
|
|
57
|
-
it 'fails if n errors are seen' do
|
|
58
|
-
seen = 0
|
|
59
|
-
expect {
|
|
60
|
-
try_max_times(2, "test", context_with_logger) do
|
|
61
|
-
seen += 1
|
|
62
|
-
raise "Test"
|
|
63
|
-
end
|
|
64
|
-
}.to raise_error("Test")
|
|
65
|
-
expect(seen).to eql(2)
|
|
66
|
-
expect(the_logger.last_msg.keys).to eql([:op, :op_took, :error])
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'suceeds if an attemps succeeds' do
|
|
70
|
-
seen = 0
|
|
71
|
-
result = nil
|
|
72
|
-
expect {
|
|
73
|
-
result = try_max_times(2, "test", context_with_logger) do
|
|
74
|
-
seen += 1
|
|
75
|
-
raise "Test" if seen == 1
|
|
76
|
-
12
|
|
77
|
-
end
|
|
78
|
-
}.not_to raise_error
|
|
79
|
-
expect(result).to eql(12)
|
|
80
|
-
expect(seen).to eql(2)
|
|
81
|
-
expect(the_logger.last_msg.keys).to eql([:op, :op_took, :error])
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it 'suceeds if first attemps succeeds' do
|
|
85
|
-
result = nil
|
|
86
|
-
expect {
|
|
87
|
-
result = try_max_times(2, "test", context_with_logger) do
|
|
88
|
-
12
|
|
89
|
-
end
|
|
90
|
-
}.not_to raise_error
|
|
91
|
-
expect(result).to eql(12)
|
|
92
|
-
expect(the_logger.last_msg).to be_nil
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
describe "parse_args" do
|
|
98
|
-
include Robustness::Tools
|
|
99
|
-
|
|
100
|
-
it 'works fine with full op and no context' do
|
|
101
|
-
log_msg_src = {
|
|
102
|
-
op: "AnOp",
|
|
103
|
-
op_data: { foo: "bar" }
|
|
104
|
-
}
|
|
105
|
-
log_msg, logger = parse_args(log_msg_src)
|
|
106
|
-
expect(log_msg).to eql(log_msg_src)
|
|
107
|
-
expect(logger).to be_a(::Logger)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it 'works fine with an string and a method name' do
|
|
111
|
-
expected = {
|
|
112
|
-
op: "AClass#method"
|
|
113
|
-
}
|
|
114
|
-
log_msg, logger = parse_args("AClass", "method")
|
|
115
|
-
expect(log_msg).to eql(expected)
|
|
116
|
-
expect(logger).to be_a(::Logger)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it 'works fine with an string, a method name, and a message' do
|
|
120
|
-
expected = {
|
|
121
|
-
op: "AClass#method",
|
|
122
|
-
op_data: { message: "Hello world" }
|
|
123
|
-
}
|
|
124
|
-
log_msg, logger = parse_args("AClass", "method", "Hello world")
|
|
125
|
-
expect(log_msg).to eql(expected)
|
|
126
|
-
expect(logger).to be_a(::Logger)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it 'works fine with a string only' do
|
|
130
|
-
expected = {
|
|
131
|
-
op: "a message"
|
|
132
|
-
}
|
|
133
|
-
log_msg, logger = parse_args("a message")
|
|
134
|
-
expect(log_msg).to eql(expected)
|
|
135
|
-
expect(logger).to be_a(::Logger)
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it 'works fine with a Exception only' do
|
|
139
|
-
exception = StandardError.new('hello')
|
|
140
|
-
expected = {
|
|
141
|
-
error: exception
|
|
142
|
-
}
|
|
143
|
-
log_msg, logger = parse_args(exception)
|
|
144
|
-
expect(log_msg).to eql(expected)
|
|
145
|
-
expect(logger).to be_a(::Logger)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
it 'works fine with a string and a context with logger' do
|
|
149
|
-
expected = {
|
|
150
|
-
op: "a message"
|
|
151
|
-
}
|
|
152
|
-
log_msg, logger = parse_args("a message", context_with_logger)
|
|
153
|
-
expect(log_msg).to eql(expected)
|
|
154
|
-
expect(logger).to be(the_logger)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it 'works fine with a string and an extra hash' do
|
|
158
|
-
expected = {
|
|
159
|
-
op: "a message",
|
|
160
|
-
op_took: 16
|
|
161
|
-
}
|
|
162
|
-
log_msg, logger = parse_args("a message", op_took: 16)
|
|
163
|
-
expect(log_msg).to eql(expected)
|
|
164
|
-
expect(logger).to be_a(::Logger)
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it 'works fine with a module and method' do
|
|
168
|
-
expected = {
|
|
169
|
-
op: "Startback#foo"
|
|
170
|
-
}
|
|
171
|
-
log_msg, logger = parse_args(Startback, "foo")
|
|
172
|
-
expect(log_msg).to eql(expected)
|
|
173
|
-
expect(logger).to be_a(::Logger)
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
it 'works fine with a class and method' do
|
|
177
|
-
expected = {
|
|
178
|
-
op: "Startback::Event#foo"
|
|
179
|
-
}
|
|
180
|
-
log_msg, logger = parse_args(Startback::Event, "foo")
|
|
181
|
-
expect(log_msg).to eql(expected)
|
|
182
|
-
expect(logger).to be_a(::Logger)
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
it 'works fine with an instance and method' do
|
|
186
|
-
expected = {
|
|
187
|
-
op: "Startback::Event#foo"
|
|
188
|
-
}
|
|
189
|
-
log_msg, logger = parse_args(Startback::Event.new(nil, nil), "foo")
|
|
190
|
-
expect(log_msg).to eql(expected)
|
|
191
|
-
expect(logger).to be_a(::Logger)
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
it 'when a hash is passed as last arg' do
|
|
195
|
-
expected = {
|
|
196
|
-
op: "hello#foo",
|
|
197
|
-
op_took: 16
|
|
198
|
-
}
|
|
199
|
-
log_msg, logger = parse_args("hello", "foo", op_took: 16)
|
|
200
|
-
expect(log_msg).to eql(expected)
|
|
201
|
-
expect(logger).to be_a(::Logger)
|
|
202
|
-
end
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
describe "logger_for" do
|
|
206
|
-
include Robustness::Tools
|
|
207
|
-
|
|
208
|
-
it 'works on a logger' do
|
|
209
|
-
expect(logger_for(the_logger)).to be(the_logger)
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it 'works on a Context responding to logger' do
|
|
213
|
-
expect(logger_for(context_with_logger)).to be(the_logger)
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
it 'works on an object having a Context responding to logger' do
|
|
217
|
-
x = OpenStruct.new(context: context_with_logger)
|
|
218
|
-
expect(logger_for(x)).to eql(the_logger)
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
it 'works on an object having a Context but no logger' do
|
|
222
|
-
x = OpenStruct.new(context: Context.new)
|
|
223
|
-
expect(logger_for(x)).to be_a(::Logger)
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
module Startback
|
|
3
|
-
module Support
|
|
4
|
-
describe TransactionManager do
|
|
5
|
-
subject do
|
|
6
|
-
TransactionManager.new(db).call(nil, op) do
|
|
7
|
-
op.call
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
class FakeDatabase
|
|
12
|
-
def initialize
|
|
13
|
-
@called = false
|
|
14
|
-
end
|
|
15
|
-
attr_reader :called
|
|
16
|
-
|
|
17
|
-
def transaction
|
|
18
|
-
@called = true
|
|
19
|
-
yield
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
let(:db) do
|
|
24
|
-
FakeDatabase.new
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'when called with a default operation' do
|
|
28
|
-
class OperationNotManagingTransactions < Startback::Operation
|
|
29
|
-
def call
|
|
30
|
-
12
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
let(:op) do
|
|
35
|
-
OperationNotManagingTransactions.new
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'calls db.transaction' do
|
|
39
|
-
expect(subject).to eql(12)
|
|
40
|
-
expect(db.called).to eql(true)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'when called with an operation that manages the transactions itself' do
|
|
45
|
-
class OperationManagingTransactions < Startback::Operation
|
|
46
|
-
self.transaction_policy = :within_call
|
|
47
|
-
|
|
48
|
-
def call
|
|
49
|
-
12
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
let(:op) do
|
|
54
|
-
OperationManagingTransactions.new
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it 'calls db.transaction' do
|
|
58
|
-
expect(subject).to eql(12)
|
|
59
|
-
expect(db.called).to eql(false)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Startback
|
|
4
|
-
module Support
|
|
5
|
-
describe World do
|
|
6
|
-
|
|
7
|
-
let(:world) do
|
|
8
|
-
World.new
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe 'with' do
|
|
12
|
-
subject do
|
|
13
|
-
world.with(foo: :bar, bar: :baz)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'returns a new world instance' do
|
|
17
|
-
expect(subject).to be_a(World)
|
|
18
|
-
expect(subject).not_to be(world)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it 'gives access to those variables' do
|
|
22
|
-
expect(subject.foo).to eql(:bar)
|
|
23
|
-
expect(subject[:bar]).to eql(:baz)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe 'dup' do
|
|
28
|
-
let(:world) do
|
|
29
|
-
World.new(foo: :bar)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
subject do
|
|
33
|
-
world.dup
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'returns another instance' do
|
|
37
|
-
expect(subject).to be_a(World)
|
|
38
|
-
expect(subject).not_to be(world)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'keeps variables' do
|
|
42
|
-
expect(subject.foo).to eql(:bar)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe 'class factory' do
|
|
47
|
-
subject do
|
|
48
|
-
world.factory(:foo) do
|
|
49
|
-
hello
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def hello
|
|
54
|
-
OpenStruct.new(bar: 12)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it 'returns a world instance' do
|
|
58
|
-
expect(subject).to be_a(World)
|
|
59
|
-
expect(subject).not_to be(world)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it 'installs the factory' do
|
|
63
|
-
bound = subject.with_scope(self)
|
|
64
|
-
got = bound.foo
|
|
65
|
-
expect(got).to be_a(OpenStruct)
|
|
66
|
-
expect(got.bar).to eql(12)
|
|
67
|
-
expect(bound.foo).to be(got)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
data/spec/unit/test_event.rb
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Startback
|
|
4
|
-
describe Event do
|
|
5
|
-
|
|
6
|
-
subject{
|
|
7
|
-
Event.new("User::Changed", { "foo" => "bar" })
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
it 'presents an ostruct on top of its data' do
|
|
11
|
-
expect(subject.data.foo).to eql("bar")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "the json information contract" do
|
|
15
|
-
|
|
16
|
-
JSON_SRC = <<-JSON.gsub(/\s+/, "")
|
|
17
|
-
{
|
|
18
|
-
"type": "User::Changed",
|
|
19
|
-
"data": {
|
|
20
|
-
"foo": "bar"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
JSON
|
|
24
|
-
|
|
25
|
-
it 'has a to_json method that works as expected' do
|
|
26
|
-
expect(subject.to_json).to eql(JSON_SRC)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'has a to_json that dumps the context if any' do
|
|
30
|
-
evt = Event.new("User::Changed", { "foo" => "bar" }, { "baz": "context" })
|
|
31
|
-
expect(evt.to_json).to eql(<<-JSON.gsub(/\s+/, ""))
|
|
32
|
-
{
|
|
33
|
-
"type": "User::Changed",
|
|
34
|
-
"data": {
|
|
35
|
-
"foo": "bar"
|
|
36
|
-
},
|
|
37
|
-
"context": {
|
|
38
|
-
"baz": "context"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
JSON
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
it 'has a json class method that works as expected' do
|
|
46
|
-
evt = Event.json(JSON_SRC, nil)
|
|
47
|
-
expect(evt).to be_a(Event)
|
|
48
|
-
expect(evt.type).to eql("User::Changed")
|
|
49
|
-
expect(evt.data).to eql(subject.data)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'accepts an explicit context as second argument' do
|
|
53
|
-
c = SubContext.new.tap{|x| x.foo = 'hello' }
|
|
54
|
-
evt = Event.json(JSON_SRC, c)
|
|
55
|
-
expect(evt.context).not_to be(c)
|
|
56
|
-
expect(evt.context).to be_a(SubContext)
|
|
57
|
-
expect(evt.context.foo).to eql('hello')
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
end
|
|
62
|
-
end # module Startback
|
data/spec/unit/test_operation.rb
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Startback
|
|
4
|
-
describe Operation do
|
|
5
|
-
|
|
6
|
-
class FooOp < Operation
|
|
7
|
-
|
|
8
|
-
def initialize(foo = :bar)
|
|
9
|
-
@foo = foo
|
|
10
|
-
end
|
|
11
|
-
attr_accessor :foo
|
|
12
|
-
|
|
13
|
-
def call
|
|
14
|
-
@foo
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it 'can be bound, which returns a new operation' do
|
|
20
|
-
foo1 = FooOp.new
|
|
21
|
-
foo1.foo = :bar1
|
|
22
|
-
|
|
23
|
-
foo2 = foo1.bind({ db: :bar })
|
|
24
|
-
expect(foo2.foo).to eql(:bar1)
|
|
25
|
-
expect(foo2.db).to eql(:bar)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe Operation::MultiOperation do
|
|
31
|
-
|
|
32
|
-
it 'lets chain with +' do
|
|
33
|
-
mop = Operation::MultiOperation.new
|
|
34
|
-
mop2 = (mop + FooOp.new)
|
|
35
|
-
|
|
36
|
-
expect(mop == mop2).to eql(false)
|
|
37
|
-
expect(mop.size).to eql(0)
|
|
38
|
-
expect(mop2.size).to eql(1)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'calls and collects the result on call' do
|
|
42
|
-
mop = Operation::MultiOperation.new + FooOp.new(:hello) + FooOp.new(:world)
|
|
43
|
-
expect(mop.call).to eql([:hello, :world])
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'binds every sub operation recursively' do
|
|
47
|
-
mop = Operation::MultiOperation.new + FooOp.new(:hello) + FooOp.new(:world)
|
|
48
|
-
mop2 = mop.bind({requester: :bar})
|
|
49
|
-
|
|
50
|
-
expect(mop == mop2).to eql(false)
|
|
51
|
-
expect(mop2.ops.all?{|op| op.requester == :bar })
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
end # module Startback
|
data/spec/unit/test_support.rb
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Startback
|
|
4
|
-
describe Support do
|
|
5
|
-
include Support
|
|
6
|
-
|
|
7
|
-
describe "deep_merge" do
|
|
8
|
-
|
|
9
|
-
it 'works as expected' do
|
|
10
|
-
h1 = {
|
|
11
|
-
:foo => "bar",
|
|
12
|
-
:bar => "unchanged",
|
|
13
|
-
:baz => {
|
|
14
|
-
"hello" => "world",
|
|
15
|
-
"changed" => "yes"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
h2 = {
|
|
19
|
-
:foo => "baz",
|
|
20
|
-
:baz => {
|
|
21
|
-
"eloy" => "tom",
|
|
22
|
-
"changed" => "no"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
expected = {
|
|
26
|
-
:foo => "baz",
|
|
27
|
-
:bar => "unchanged",
|
|
28
|
-
:baz => {
|
|
29
|
-
"hello" => "world",
|
|
30
|
-
"eloy" => "tom",
|
|
31
|
-
"changed" => "no"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
expect(deep_merge(h1, h2)).to eql(expected)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<p>Hello {{who}}</p>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//= require_tree ./app
|
data/spec/unit/web/test_api.rb
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'startback/web/api'
|
|
3
|
-
|
|
4
|
-
module Startback
|
|
5
|
-
module Web
|
|
6
|
-
describe Api do
|
|
7
|
-
include Rack::Test::Methods
|
|
8
|
-
|
|
9
|
-
class JsonDto
|
|
10
|
-
def to(accept, content_type)
|
|
11
|
-
["application/json", %Q{{"foo":"bar"}}]
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
class PathDto
|
|
16
|
-
def to(accept, content_type)
|
|
17
|
-
["text/plain", Path.file]
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class DtoAble
|
|
22
|
-
def initialize(dto)
|
|
23
|
-
@dto = dto
|
|
24
|
-
end
|
|
25
|
-
def to_dto(context)
|
|
26
|
-
@dto
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class TestedApi < ::Startback::Web::Api
|
|
31
|
-
get '/no-such-one' do
|
|
32
|
-
serve("Something", nil)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
get '/entity' do
|
|
36
|
-
serve('Entity', {foo: "bar"})
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
get '/path' do
|
|
40
|
-
serve('Path', Path.file)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
get '/dto-able' do
|
|
44
|
-
serve('DTO', DtoAble.new(JsonDto.new))
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
get '/dto-path' do
|
|
48
|
-
serve('DTO', DtoAble.new(PathDto.new))
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
let(:app) {
|
|
53
|
-
TestedApi
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
it 'convert nil to 404' do
|
|
57
|
-
get '/no-such-one'
|
|
58
|
-
expect(last_response.status).to eql(404)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it 'supports serving entities' do
|
|
62
|
-
get '/entity'
|
|
63
|
-
expect(last_response.body).to eql(%Q{{"foo":"bar"}})
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it 'supports serving paths' do
|
|
67
|
-
get '/path'
|
|
68
|
-
expect(last_response.body).to eql(Path.file.read)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'supports serving DTO-able objects' do
|
|
72
|
-
get '/dto-able'
|
|
73
|
-
expect(last_response.body).to eql(%Q{{"foo":"bar"}})
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'supports serving DTO-able objects eventually returning paths' do
|
|
77
|
-
get '/dto-path'
|
|
78
|
-
expect(last_response.body).to eql(Path.file.read)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end # module Web
|
|
82
|
-
end # module Startback
|