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,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
@@ -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
@@ -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
@@ -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,4 +0,0 @@
1
- let test = (x) => {
2
- console.log("Hello " + x)
3
- }
4
- test("world")
@@ -1 +0,0 @@
1
- <p>Hello {{who}}</p>
@@ -1 +0,0 @@
1
- //= require_tree ./app
@@ -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
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
- require 'startback/web/auto_caching'
3
-
4
- module Startback
5
- module Web
6
- describe AutoCaching do
7
- include Rack::Test::Methods
8
-
9
- context 'when used without options' do
10
- def app
11
- Rack::Builder.new do
12
- use AutoCaching
13
- run ->(env){ [200, {}, ["Hello error"]] }
14
- end
15
- end
16
-
17
- it 'sets the development Cache-Control since this is a test' do
18
- get '/'
19
- expect(last_response['Cache-Control']). to eql("no-cache, no-store, max-age=0, must-revalidate")
20
- end
21
- end
22
-
23
- context 'when forcing production' do
24
- def app
25
- Rack::Builder.new do
26
- use AutoCaching, false
27
- run ->(env){ [200, {}, ["Hello error"]] }
28
- end
29
- end
30
-
31
- it 'sets the production Cache-Control' do
32
- get '/'
33
- expect(last_response['Cache-Control']). to eql("public, must-revalidate, max-age=3600, s-max-age=3600")
34
- end
35
- end
36
-
37
- context 'when forcing development headers' do
38
- def app
39
- Rack::Builder.new do
40
- use AutoCaching, development: { "Cache-Control" => "no-cache" }
41
- run ->(env){ [200, {}, ["Hello error"]] }
42
- end
43
- end
44
-
45
- it 'sets the production Cache-Control' do
46
- get '/'
47
- expect(last_response['Cache-Control']). to eql("no-cache")
48
- end
49
- end
50
-
51
- context 'when setting the Cache-Control header only' do
52
- def app
53
- Rack::Builder.new do
54
- use AutoCaching, development: "no-cache"
55
- run ->(env){ [200, {}, ["Hello error"]] }
56
- end
57
- end
58
-
59
- it 'sets the production Cache-Control' do
60
- get '/'
61
- expect(last_response['Cache-Control']). to eql("no-cache")
62
- end
63
- end
64
-
65
- context 'when a Cache-Control header is already set by the app' do
66
- def app
67
- Rack::Builder.new do
68
- use AutoCaching
69
- run ->(env){ [200, {"Cache-Control" => "priority"}, ["Hello error"]] }
70
- end
71
- end
72
-
73
- it 'sets the production Cache-Control' do
74
- get '/'
75
- expect(last_response['Cache-Control']). to eql("priority")
76
- end
77
- end
78
-
79
- end # CatchAll
80
- end # module Web
81
- end # module Startback