startback-jobs 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -2
  3. data/lib/startback/ext/support/operation_runner.rb +17 -0
  4. data/lib/startback/ext/web/api.rb +12 -0
  5. data/lib/startback/ext.rb +2 -2
  6. data/lib/startback/jobs/agent.rb +15 -0
  7. data/lib/startback/jobs/api.rb +12 -0
  8. data/lib/startback/jobs/event/job_created.rb +8 -0
  9. data/lib/startback/jobs/event/job_ran.rb +8 -0
  10. data/lib/startback/jobs/event.rb +8 -0
  11. data/lib/startback/jobs/model/job.rb +35 -0
  12. data/lib/startback/jobs/model.rb +12 -0
  13. data/lib/startback/jobs/operation/create_job.rb +37 -0
  14. data/lib/startback/jobs/operation/run_job.rb +35 -0
  15. data/lib/startback/jobs/operation.rb +8 -0
  16. data/lib/startback/jobs/services.rb +25 -0
  17. data/lib/startback/jobs/support/job_result/embedded.rb +15 -0
  18. data/lib/startback/jobs/support/job_result/not_ready.rb +15 -0
  19. data/lib/startback/jobs/support/job_result/redirect.rb +32 -0
  20. data/lib/startback/jobs/support/job_result.rb +31 -0
  21. data/lib/startback/jobs/support.rb +1 -0
  22. data/lib/startback/jobs.fio +44 -0
  23. data/lib/startback/jobs.rb +23 -0
  24. data/spec/spec_helper.rb +26 -33
  25. data/spec/unit/api/test_job_result.rb +121 -0
  26. data/spec/unit/model/test_job.rb +23 -0
  27. data/spec/unit/operation/test_create_job.rb +42 -0
  28. data/spec/unit/operation/test_run_job.rb +37 -0
  29. data/spec/unit/test_finitio_schema.rb +20 -0
  30. data/tasks/test.rake +0 -1
  31. metadata +29 -92
  32. data/README.md +0 -13
  33. data/lib/startback/audit/prometheus.rb +0 -87
  34. data/lib/startback/audit/shared.rb +0 -17
  35. data/lib/startback/audit/trailer.rb +0 -129
  36. data/lib/startback/audit.rb +0 -3
  37. data/lib/startback/caching/entity_cache.rb +0 -157
  38. data/lib/startback/caching/no_store.rb +0 -28
  39. data/lib/startback/caching/store.rb +0 -34
  40. data/lib/startback/context/h_factory.rb +0 -43
  41. data/lib/startback/context/middleware.rb +0 -53
  42. data/lib/startback/context.rb +0 -122
  43. data/lib/startback/errors.rb +0 -197
  44. data/lib/startback/event/agent.rb +0 -84
  45. data/lib/startback/event/bus/bunny/async.rb +0 -162
  46. data/lib/startback/event/bus/bunny.rb +0 -1
  47. data/lib/startback/event/bus/memory/async.rb +0 -45
  48. data/lib/startback/event/bus/memory/sync.rb +0 -35
  49. data/lib/startback/event/bus/memory.rb +0 -2
  50. data/lib/startback/event/bus.rb +0 -100
  51. data/lib/startback/event/engine.rb +0 -94
  52. data/lib/startback/event/ext/context.rb +0 -5
  53. data/lib/startback/event/ext/operation.rb +0 -13
  54. data/lib/startback/event.rb +0 -47
  55. data/lib/startback/ext/date_time.rb +0 -9
  56. data/lib/startback/ext/time.rb +0 -9
  57. data/lib/startback/model.rb +0 -6
  58. data/lib/startback/operation/error_operation.rb +0 -19
  59. data/lib/startback/operation/multi_operation.rb +0 -28
  60. data/lib/startback/operation.rb +0 -78
  61. data/lib/startback/services.rb +0 -11
  62. data/lib/startback/support/data_object.rb +0 -71
  63. data/lib/startback/support/env.rb +0 -41
  64. data/lib/startback/support/fake_logger.rb +0 -18
  65. data/lib/startback/support/hooks.rb +0 -48
  66. data/lib/startback/support/log_formatter.rb +0 -34
  67. data/lib/startback/support/logger.rb +0 -34
  68. data/lib/startback/support/operation_runner.rb +0 -150
  69. data/lib/startback/support/robustness.rb +0 -157
  70. data/lib/startback/support/transaction_manager.rb +0 -25
  71. data/lib/startback/support/transaction_policy.rb +0 -33
  72. data/lib/startback/support/world.rb +0 -54
  73. data/lib/startback/support.rb +0 -26
  74. data/lib/startback/version.rb +0 -8
  75. data/lib/startback/web/api.rb +0 -99
  76. data/lib/startback/web/auto_caching.rb +0 -85
  77. data/lib/startback/web/catch_all.rb +0 -52
  78. data/lib/startback/web/cors_headers.rb +0 -80
  79. data/lib/startback/web/health_check.rb +0 -49
  80. data/lib/startback/web/magic_assets/ng_html_transformer.rb +0 -80
  81. data/lib/startback/web/magic_assets/rake_tasks.rb +0 -64
  82. data/lib/startback/web/magic_assets.rb +0 -98
  83. data/lib/startback/web/middleware.rb +0 -13
  84. data/lib/startback/web/prometheus.rb +0 -16
  85. data/lib/startback/web/shield.rb +0 -58
  86. data/lib/startback.rb +0 -43
  87. data/spec/unit/audit/test_prometheus.rb +0 -72
  88. data/spec/unit/audit/test_trailer.rb +0 -105
  89. data/spec/unit/caching/test_entity_cache.rb +0 -136
  90. data/spec/unit/context/test_abstraction_factory.rb +0 -64
  91. data/spec/unit/context/test_dup.rb +0 -42
  92. data/spec/unit/context/test_fork.rb +0 -37
  93. data/spec/unit/context/test_h_factory.rb +0 -31
  94. data/spec/unit/context/test_middleware.rb +0 -45
  95. data/spec/unit/context/test_with_world.rb +0 -20
  96. data/spec/unit/context/test_world.rb +0 -17
  97. data/spec/unit/event/bus/memory/test_async.rb +0 -43
  98. data/spec/unit/event/bus/memory/test_sync.rb +0 -43
  99. data/spec/unit/support/hooks/test_after_hook.rb +0 -54
  100. data/spec/unit/support/hooks/test_before_hook.rb +0 -54
  101. data/spec/unit/support/operation_runner/test_around_run.rb +0 -156
  102. data/spec/unit/support/operation_runner/test_before_after_call.rb +0 -48
  103. data/spec/unit/support/test_data_object.rb +0 -156
  104. data/spec/unit/support/test_env.rb +0 -75
  105. data/spec/unit/support/test_robusteness.rb +0 -229
  106. data/spec/unit/support/test_transaction_manager.rb +0 -64
  107. data/spec/unit/support/test_world.rb +0 -72
  108. data/spec/unit/test_event.rb +0 -62
  109. data/spec/unit/test_operation.rb +0 -55
  110. data/spec/unit/test_support.rb +0 -40
  111. data/spec/unit/web/fixtures/assets/app/hello.es6 +0 -4
  112. data/spec/unit/web/fixtures/assets/app/hello.html +0 -1
  113. data/spec/unit/web/fixtures/assets/index.es6 +0 -1
  114. data/spec/unit/web/test_api.rb +0 -82
  115. data/spec/unit/web/test_auto_caching.rb +0 -81
  116. data/spec/unit/web/test_catch_all.rb +0 -77
  117. data/spec/unit/web/test_cors_headers.rb +0 -88
  118. data/spec/unit/web/test_healthcheck.rb +0 -59
  119. data/spec/unit/web/test_magic_assets.rb +0 -82
@@ -1,58 +0,0 @@
1
- module Startback
2
- module Web
3
- #
4
- # This Rack middleware catches all known exceptions raised by sublayers
5
- # in the Rack chain. Those exceptions are converted to proper HTTP error
6
- # codes and friendly error messages encoded in json.
7
- #
8
- # Please check the Errors module about status codes used for each Startback
9
- # error.
10
- #
11
- # This class aims at being used as top level of a Rack chain.
12
- #
13
- # Examples:
14
- #
15
- # Rack::Builder.new do
16
- # use Startback::Web::Shield
17
- # end
18
- #
19
- class Shield < Rack::Robustness
20
- include Errors
21
-
22
- self.no_catch_all
23
- self.content_type 'application/json'
24
-
25
- # Decoding errors from json and csv are considered user's fault
26
- self.on(Finitio::TypeError){ 400 }
27
- self.on(::NotImplementedError){ 501 }
28
-
29
- # Various other codes for the framework specific error classes
30
- self.on(Startback::Errors::Error) {|ex|
31
- ex.class.status
32
- }
33
-
34
- # A bit of logic to choose the best error message for the user
35
- # according to the error class
36
- self.body{|ex|
37
- body_for(ex).to_json
38
- }
39
-
40
- def body_for(ex)
41
- ex = ex.root_cause if ex.is_a?(Finitio::TypeError)
42
- body = { code: ex.class.name, description: ex.message }
43
- return body unless ex.is_a?(Startback::Errors::Error)
44
- return body unless ex.has_causes?
45
-
46
- body[:causes] = ex.causes
47
- .filter{|cause|
48
- cause.is_a?(Startback::Errors::Error)
49
- }
50
- .map{|cause|
51
- body_for(cause)
52
- }
53
- body
54
- end
55
-
56
- end # class Shield
57
- end # module Web
58
- end # module Startback
data/lib/startback.rb DELETED
@@ -1,43 +0,0 @@
1
- require 'sinatra'
2
- require 'rack/robustness'
3
- require 'finitio'
4
- require 'logger'
5
- require 'path'
6
- require 'ostruct'
7
- require 'benchmark'
8
-
9
- # Provides a reusable backend framework for backend components written
10
- # in ruby.
11
- #
12
- # The framework installs conventions regarding:
13
- #
14
- # - The exposition of web service APIs (Framework::Api, on top of Sinatra)
15
- # - Operations (Framework::Operation)
16
- # - Error handling (Framework::Errors) and their handling in web APIs
17
- # (based on Rack::Robustness)
18
- # - General code support (Framework::Support modules & classes).
19
- #
20
- # Please refer to the documentation of those main abstractions for details.
21
- #
22
- module Startback
23
-
24
- # Simply checks that a path exists of raise an error
25
- def self._!(path)
26
- Path(path).tap do |p|
27
- raise "Missing #{p.basename}." unless p.exists?
28
- end
29
- end
30
-
31
- require_relative 'startback/version'
32
- require_relative 'startback/ext'
33
- require_relative 'startback/errors'
34
- require_relative 'startback/support'
35
- require_relative 'startback/model'
36
- require_relative 'startback/context'
37
- require_relative 'startback/operation'
38
- require_relative 'startback/services'
39
-
40
- # Logger instance to use for the application
41
- LOGGER = ::Startback::Support::Logger.new
42
-
43
- end # module Startback
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
- require 'startback/audit'
3
- module Startback
4
- module Audit
5
- describe Prometheus do
6
-
7
- EXPORTER = Prometheus.new({
8
- prefix: "hello",
9
- labels: {
10
- app_version: "1.0"
11
- }
12
- })
13
-
14
- class Runner
15
- include Startback::Support::OperationRunner
16
-
17
- class IdealOp < Startback::Operation
18
- def call
19
- 42
20
- end
21
- end
22
-
23
- class ExceptionalOp < Startback::Operation
24
- def call
25
- raise "Oops"
26
- end
27
- end
28
-
29
- around_run(EXPORTER)
30
- def test
31
- run IdealOp.new
32
- end
33
- def test_exp
34
- run ExceptionalOp.new
35
- end
36
- end
37
-
38
- describe 'The ideal case' do
39
- before do
40
- expect(EXPORTER.calls).to receive(:observe).with(
41
- kind_of(Numeric),
42
- hash_including(labels: {
43
- operation: "Startback::Audit::Runner::IdealOp",
44
- startback_version: Startback::VERSION,
45
- app_version: "1.0"
46
- }))
47
- expect(EXPORTER.errors).not_to receive(:increment)
48
- end
49
- it 'runs the operation' do
50
- expect(Runner.new.test).to eql(42)
51
- end
52
- end
53
-
54
- describe 'The exceptional case' do
55
- before do
56
- expect(EXPORTER.errors).to receive(:increment).with(
57
- hash_including(labels: {
58
- operation: "Startback::Audit::Runner::ExceptionalOp",
59
- startback_version: Startback::VERSION,
60
- app_version: "1.0"
61
- })
62
- )
63
- expect(EXPORTER.calls).not_to receive(:observe)
64
- end
65
- it 'let errors bubble up' do
66
- expect { Runner.new.test_exp }.to raise_error(/Oops/)
67
- end
68
- end
69
-
70
- end
71
- end
72
- end
@@ -1,105 +0,0 @@
1
- require 'spec_helper'
2
- require 'startback/audit'
3
- module Startback
4
- module Audit
5
- describe Trailer do
6
-
7
- let(:trailer) {
8
- Trailer.new("/tmp/trail.log")
9
- }
10
-
11
- describe "op_name" do
12
-
13
- def op_name(op, trailer = self.trailer)
14
- trailer.send(:op_name, op)
15
- end
16
-
17
- it 'uses op_name in priority if provided' do
18
- op = OpenStruct.new(op_name: "foo")
19
- expect(op_name(op)).to eql("foo")
20
- end
21
- end
22
-
23
- describe "op_data" do
24
-
25
- def op_data(op, trailer = self.trailer)
26
- trailer.send(:op_data, op)
27
- end
28
-
29
- it 'uses op_data in priority if provided' do
30
- op = OpenStruct.new(op_data: { foo: "bar" }, input: 12, request: 13)
31
- expect(op_data(op)).to eql({ foo: "bar" })
32
- end
33
-
34
- it 'uses to_trail then' do
35
- op = OpenStruct.new(to_trail: { foo: "bar" }, input: 12, request: 13)
36
- expect(op_data(op)).to eql({ foo: "bar" })
37
- end
38
-
39
- it 'uses input then' do
40
- op = OpenStruct.new(input: { foo: "bar" }, request: 13)
41
- expect(op_data(op)).to eql({ foo: "bar" })
42
- end
43
-
44
- it 'uses request then' do
45
- op = OpenStruct.new(request: { foo: "bar" })
46
- expect(op_data(op)).to eql({ foo: "bar" })
47
- end
48
-
49
- it 'applies default blacklists for security reasons' do
50
- op = OpenStruct.new(input: {
51
- token: "will not be dumped",
52
- a_token: "will not be dumped",
53
- AToken: "will not be dumped",
54
- password: "will not be dumped",
55
- secret: "will not be dumped",
56
- credentials: "will not be dumped",
57
- foo: "bar"
58
- })
59
- expect(op_data(op)).to eql({
60
- foo: "bar"
61
- })
62
- end
63
-
64
- it 'applies default blacklists to data arrays too' do
65
- op = OpenStruct.new(input: [{
66
- token: "will not be dumped",
67
- a_token: "will not be dumped",
68
- AToken: "will not be dumped",
69
- password: "will not be dumped",
70
- secret: "will not be dumped",
71
- credentials: "will not be dumped",
72
- foo: "bar"
73
- }])
74
- expect(op_data(op)).to eql([{
75
- foo: "bar"
76
- }])
77
- end
78
-
79
- it 'uses the stop words provided at construction' do
80
- t = Trailer.new("/tmp/trail.log", blacklist: "hello and world")
81
- op = OpenStruct.new(request: { Hello: "bar", World: "foo", foo: "bar" })
82
- expect(op_data(op, t)).to eql({ foo: "bar" })
83
- end
84
-
85
- end
86
-
87
- describe "op_context" do
88
-
89
- def op_context(op, trailer = self.trailer)
90
- trailer.send(:op_context, op)
91
- end
92
-
93
- it 'applies default blacklists for security reasons' do
94
- op = OpenStruct.new(context: {
95
- token: "will not be dumped",
96
- foo: "bar"
97
- })
98
- expect(op_context(op)).to eql({ foo: "bar" })
99
- end
100
-
101
- end
102
-
103
- end
104
- end
105
- end
@@ -1,136 +0,0 @@
1
- require 'spec_helper'
2
- require 'startback/caching/entity_cache'
3
- require 'startback/caching/store'
4
- module Startback
5
- module Caching
6
- describe EntityCache do
7
-
8
- class BaseCache < EntityCache
9
-
10
- def initialize(context = nil)
11
- super(Store.new, context)
12
- @called = 0
13
- @last_key = nil
14
- end
15
- attr_reader :called, :last_key
16
-
17
- protected
18
-
19
- def primary_key(ckey)
20
- case ckey
21
- when Integer then "a key"
22
- when String then ckey
23
- else
24
- raise "Invalid key `#{ckey}`"
25
- end
26
- end
27
-
28
- # We use the deprecated methods below to test
29
- # backward compatibility with 0.5.0.
30
-
31
- def full_key(key)
32
- { k: key }
33
- end
34
-
35
- def load_raw_data(key)
36
- @called += 1
37
- @last_key = key
38
- "a value"
39
- end
40
-
41
- end
42
-
43
- class ShortCache < BaseCache
44
- self.default_ttl = 1
45
- end
46
-
47
- class InvalidatingCache < BaseCache
48
-
49
- protected
50
-
51
- def valid?(key, value)
52
- false
53
- end
54
-
55
- end
56
-
57
- let(:cache) {
58
- BaseCache.new
59
- }
60
-
61
- describe "default_ttl" do
62
-
63
- it 'has a default ttl of one hour' do
64
- expect(BaseCache.default_ttl).to eql(3600)
65
- end
66
-
67
- it 'allows overriding it' do
68
- expect(ShortCache.default_ttl).to eql(1)
69
- end
70
-
71
- it 'is accessible as default_caching_options on the instance' do
72
- expect(cache.send(:default_caching_options)).to eql({ttl: 3600})
73
- end
74
-
75
- end
76
-
77
- describe "get" do
78
-
79
- subject{
80
- cache.get("a key")
81
- }
82
-
83
- it 'yields to load_raw_data only once with the short key' do
84
- expect(subject).to eql("a value")
85
- expect(subject).to eql("a value")
86
- expect(cache.called).to eql(1)
87
- expect(cache.last_key).to eql("a key")
88
- end
89
-
90
- end
91
-
92
- describe "primary_key" do
93
-
94
- subject{
95
- cache.get(12)
96
- }
97
-
98
- it 'allows using candidate keys' do
99
- expect(subject).to eql("a value")
100
- expect(subject).to eql("a value")
101
- expect(cache.called).to eql(1)
102
- expect(cache.last_key).to eql("a key")
103
- end
104
-
105
- end
106
-
107
- describe "invalidate" do
108
-
109
- it 'strips the key on the store, yielding a cache miss' do
110
- expect(cache.get("a key")).to eql("a value")
111
- cache.invalidate("a key")
112
- expect(cache.get("a key")).to eql("a value")
113
- expect(cache.called).to eql(2)
114
- expect(cache.last_key).to eql("a key")
115
- end
116
-
117
- end
118
-
119
- describe "valid? override" do
120
-
121
- let(:cache) {
122
- InvalidatingCache.new
123
- }
124
-
125
- it 'yields to load_raw_data only once with the extend key' do
126
- expect(cache.get("a key")).to eql("a value")
127
- expect(cache.get("a key")).to eql("a value")
128
- expect(cache.called).to eql(2)
129
- expect(cache.last_key).to eql("a key")
130
- end
131
-
132
- end
133
-
134
- end
135
- end
136
- end
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- describe Context, "factor" do
5
-
6
- let(:context) {
7
- Context.new
8
- }
9
-
10
- class ContextRelatedAbstraction
11
-
12
- def initialize(context)
13
- @context = context
14
- end
15
- attr_reader :context
16
-
17
- end
18
-
19
- class ContextRelatedAbstractionWithArgs
20
-
21
- def initialize(arg1, arg2, context)
22
- @arg1 = arg1
23
- @arg2 = arg2
24
- @context = context
25
- end
26
- attr_reader :arg1, :arg2, :context
27
-
28
- end
29
-
30
- it 'is a factory for other context-related abstractions' do
31
- got = context.factor(ContextRelatedAbstraction)
32
- expect(got).to be_a(ContextRelatedAbstraction)
33
- expect(got.context).to be(context)
34
-
35
- got2 = context.factor(ContextRelatedAbstraction)
36
- expect(got2).to be(got)
37
- end
38
-
39
- it 'is takes cares of abstraction arguments' do
40
- got = context.factor(ContextRelatedAbstractionWithArgs, 12, 14)
41
- expect(got).to be_a(ContextRelatedAbstractionWithArgs)
42
- expect(got.context).to be(context)
43
- expect(got.arg1).to eql(12)
44
- expect(got.arg2).to eql(14)
45
- end
46
-
47
- it 'is caches even in presence ofabstraction arguments' do
48
- got = context.factor(ContextRelatedAbstractionWithArgs, 12, 14)
49
- expect(got).to be_a(ContextRelatedAbstractionWithArgs)
50
-
51
- got2 = context.factor(ContextRelatedAbstractionWithArgs, 12, 14)
52
- expect(got2).to be(got)
53
- end
54
-
55
- it 'is distinguishes different abstraction arguments' do
56
- got = context.factor(ContextRelatedAbstractionWithArgs, 12, 14)
57
- expect(got).to be_a(ContextRelatedAbstractionWithArgs)
58
-
59
- got2 = context.factor(ContextRelatedAbstractionWithArgs, 17, 14)
60
- expect(got2).not_to be(got)
61
- end
62
-
63
- end
64
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- describe Context, "dup" do
5
-
6
- let(:context) {
7
- SubContext.new.tap{|s| s.foo = "bar" }
8
- }
9
-
10
- class ContextRelatedAbstraction
11
-
12
- def initialize(context)
13
- @context = context
14
- end
15
- attr_reader :context
16
-
17
- end
18
-
19
- it 'yields a dup of the original context' do
20
- seen = false
21
- got = context.dup{|x|
22
- seen = x
23
- expect(x).not_to be(context)
24
- }
25
- expect(seen).to be(got)
26
- expect(got).to be_a(SubContext)
27
- expect(got).not_to be(context)
28
- expect(got.foo).to eql("bar")
29
- end
30
-
31
- it 'cleans all factored cache' do
32
- cra = context.factor(ContextRelatedAbstraction)
33
- expect(cra).to be_a(ContextRelatedAbstraction)
34
- cra2 = context.factor(ContextRelatedAbstraction)
35
- expect(cra2).to be(cra)
36
- cra3 = context.dup.factor(ContextRelatedAbstraction)
37
- expect(cra3).not_to be(cra)
38
- expect(cra3).not_to be(cra2)
39
- end
40
-
41
- end
42
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- describe Context, "fork" do
5
-
6
- it 'is a simple dup without args' do
7
- context = SubContext.new
8
- context.foo = ['hello']
9
-
10
- forked = context.fork
11
- expect(forked).not_to be(context)
12
- expect(forked.foo).to eql(['hello'])
13
- expect(forked.foo).to be(context.foo)
14
- end
15
-
16
- it 'yields the context if a block is provided' do
17
- context = SubContext.new
18
-
19
- seen = false
20
- context.fork({ 'foo' => 'hello' }) do |forked|
21
- expect(forked).not_to be(context)
22
- expect(forked.foo).to eql('hello')
23
- seen = true
24
- end
25
- expect(seen).to eql(true)
26
- end
27
-
28
- it 'uses the factory on the hash provided' do
29
- context = SubContext.new
30
-
31
- forked = context.fork({ 'foo' => 'hello' })
32
- expect(forked).not_to be(context)
33
- expect(forked.foo).to eql('hello')
34
- end
35
-
36
- end
37
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- describe Context, "h information contract" do
5
-
6
- it "has a to_json that dumps it" do
7
- expect(Context.new.to_json).to eql("{}")
8
- end
9
-
10
- it 'allows installing factories' do
11
- expect(Context.h_factories).to be_empty
12
- expect(SubContext.h_factories.size).to eql(2)
13
- end
14
-
15
- it 'has a `to_h` information contract that works as expected' do
16
- context = SubContext.new.tap{|c|
17
- c.foo = "Hello"
18
- c.bar = "World"
19
- }
20
- expect(context.to_h).to eql({ "foo" => "Hello", "bar" => "World" })
21
- end
22
-
23
- it 'has a `h` information contract that works as expected' do
24
- context = SubContext.h({ "foo" => "Hello", "bar" => "World" })
25
- expect(context).to be_a(SubContext)
26
- expect(context.foo).to eql("Hello")
27
- expect(context.bar).to eql("World")
28
- end
29
-
30
- end
31
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- class Context
5
-
6
- class MyContextSubClass < Context
7
- end
8
-
9
- describe Middleware do
10
- include Rack::Test::Methods
11
-
12
- def app
13
- build_args = self.build_args
14
- Rack::Builder.new do
15
- use Middleware, *build_args
16
- run ->(env){
17
- ctx = env[Startback::Context::Middleware::RACK_ENV_KEY]
18
- [200, {}, ctx.class.to_s]
19
- }
20
- end
21
- end
22
-
23
- context 'when used without context' do
24
- let(:build_args){ [] }
25
-
26
- it 'sets the default context class' do
27
- get '/'
28
- expect(last_response.status).to eql(200)
29
- expect(last_response.body).to eql("Startback::Context")
30
- end
31
- end
32
-
33
- context 'when specifying the context class' do
34
- let(:build_args){ [MyContextSubClass.new] }
35
-
36
- it 'sets the default context class' do
37
- get '/'
38
- expect(last_response.status).to eql(200)
39
- expect(last_response.body).to eql("Startback::Context::MyContextSubClass")
40
- end
41
- end
42
-
43
- end
44
- end # module Web
45
- end # module Startback
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- describe Context, "with_world" do
5
-
6
- let(:who) do
7
- Object.new
8
- end
9
-
10
- let(:context) do
11
- SubContext.new.with_world(hello: who)
12
- end
13
-
14
- it 'works as expected' do
15
- got = context.world.hello
16
- expect(got).to be(who)
17
- end
18
-
19
- end
20
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Startback
4
- describe Context, "world" do
5
-
6
- let(:context) do
7
- SubContext.new
8
- end
9
-
10
- it 'works as expected' do
11
- got = context.world.partner
12
- expect(got).not_to be_nil
13
- expect(context.world.partner).to be(got)
14
- end
15
-
16
- end
17
- end