contentful-scheduler-custom 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +26 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +178 -0
- data/Rakefile +7 -0
- data/contentful-scheduler.gemspec +35 -0
- data/example/Gemfile +7 -0
- data/example/Gemfile.lock +83 -0
- data/example/Procfile +4 -0
- data/example/Rakefile +45 -0
- data/example/config.ru +13 -0
- data/lib/contentful/scheduler.rb +57 -0
- data/lib/contentful/scheduler/controller.rb +30 -0
- data/lib/contentful/scheduler/queue.rb +147 -0
- data/lib/contentful/scheduler/tasks.rb +1 -0
- data/lib/contentful/scheduler/tasks/publish.rb +21 -0
- data/lib/contentful/scheduler/version.rb +5 -0
- data/spec/contentful/scheduler/controller_spec.rb +46 -0
- data/spec/contentful/scheduler/queue_spec.rb +257 -0
- data/spec/contentful/scheduler/tasks/publish_spec.rb +42 -0
- data/spec/contentful/scheduler_spec.rb +141 -0
- data/spec/spec_helper.rb +60 -0
- metadata +244 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class MockEntry
|
4
|
+
def publish
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class MockClient
|
9
|
+
def entries
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class MockEntries
|
14
|
+
def find
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Contentful::Scheduler::Tasks::Publish do
|
19
|
+
let(:mock_client) { MockClient.new }
|
20
|
+
let(:mock_entries) { MockEntries.new }
|
21
|
+
let(:mock_entry) { MockEntry.new }
|
22
|
+
|
23
|
+
before :each do
|
24
|
+
::Contentful::Scheduler.class_variable_set(:@@config, {management_token: 'foobar'})
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'class methods' do
|
28
|
+
it '::perform' do
|
29
|
+
expect(::Contentful::Management::Client).to receive(:new).with(
|
30
|
+
'foobar',
|
31
|
+
raise_errors: true,
|
32
|
+
application_name: 'contentful-scheduler',
|
33
|
+
application_version: Contentful::Scheduler::VERSION
|
34
|
+
) { mock_client }
|
35
|
+
expect(mock_client).to receive(:entries) { mock_entries }
|
36
|
+
expect(mock_entries).to receive(:find).with('foo', 'bar') { mock_entry }
|
37
|
+
expect(mock_entry).to receive(:publish)
|
38
|
+
|
39
|
+
described_class.perform('foo', 'bar', ::Contentful::Scheduler.config[:management_token])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class DummyServer
|
4
|
+
def join; end
|
5
|
+
end
|
6
|
+
|
7
|
+
class DummyLogger
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Contentful::Scheduler do
|
11
|
+
let(:config) {
|
12
|
+
{
|
13
|
+
redis: {
|
14
|
+
host: 'localhost',
|
15
|
+
port: 12341,
|
16
|
+
password: 'foobar'
|
17
|
+
},
|
18
|
+
spaces: {},
|
19
|
+
management_token: 'foo'
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
before :each do
|
24
|
+
described_class.class_variable_set(:@@config, nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'static methods' do
|
28
|
+
describe '::config=' do
|
29
|
+
describe 'failures' do
|
30
|
+
it 'fails if :redis is not configured' do
|
31
|
+
expect { described_class.config = {} }.to raise_error ":redis configuration missing"
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'fails if :spaces are not configured' do
|
35
|
+
expect { described_class.config = {redis: nil} }.to raise_error ":spaces configuration missing"
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'fails if :management_token is not configured' do
|
39
|
+
expect { described_class.config = {redis: nil, spaces: {example_space: {}}} }.to raise_error ":management_token missing for space: example_space"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'success' do
|
44
|
+
it 'sets a resque redis config' do
|
45
|
+
expect(Resque).to receive(:redis=).with(config[:redis])
|
46
|
+
|
47
|
+
described_class.config = config
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'sets global config' do
|
51
|
+
described_class.config = config
|
52
|
+
|
53
|
+
expect(described_class.config).to eq config
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '::config' do
|
59
|
+
it 'fetches the config' do
|
60
|
+
expect(described_class.config).to eq nil
|
61
|
+
|
62
|
+
allow(Resque).to receive(:redis=)
|
63
|
+
|
64
|
+
described_class.config = config
|
65
|
+
|
66
|
+
expect(described_class.config).to eq config
|
67
|
+
end
|
68
|
+
|
69
|
+
it ':port defaults to 32123' do
|
70
|
+
described_class.config = config
|
71
|
+
|
72
|
+
expect(described_class.config[:port]).to eq 32123
|
73
|
+
end
|
74
|
+
|
75
|
+
it ':port to ENV["PORT"] if available and :port not set' do
|
76
|
+
ENV['PORT'] = '8000'
|
77
|
+
|
78
|
+
described_class.config = config
|
79
|
+
|
80
|
+
expect(described_class.config[:port]).to eq 8000
|
81
|
+
|
82
|
+
ENV['PORT'] = nil
|
83
|
+
end
|
84
|
+
|
85
|
+
it ':port can be set' do
|
86
|
+
described_class.config = {port: 10101}.merge(config)
|
87
|
+
|
88
|
+
expect(described_class.config[:port]).to eq 10101
|
89
|
+
end
|
90
|
+
|
91
|
+
it ':logger can be set' do
|
92
|
+
described_class.config = {logger: DummyLogger.new}.merge(config)
|
93
|
+
|
94
|
+
expect(described_class.config[:logger]).to be_a DummyLogger
|
95
|
+
end
|
96
|
+
|
97
|
+
it ':logger defaults to NullLogger' do
|
98
|
+
described_class.config = config
|
99
|
+
|
100
|
+
expect(described_class.config[:logger]).to be_a ::Contentful::Webhook::Listener::Support::NullLogger
|
101
|
+
end
|
102
|
+
|
103
|
+
it ':endpoint can be set' do
|
104
|
+
described_class.config = {endpoint: '/foobar'}.merge(config)
|
105
|
+
|
106
|
+
expect(described_class.config[:endpoint]).to eq '/foobar'
|
107
|
+
end
|
108
|
+
|
109
|
+
it ':endpoint defaults to "/scheduler"' do
|
110
|
+
described_class.config = config
|
111
|
+
|
112
|
+
expect(described_class.config[:endpoint]).to eq '/scheduler'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '::start' do
|
117
|
+
it 'fails when not configured' do
|
118
|
+
expect { described_class.start }.to raise_error "Scheduler not configured"
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'runs when config set' do
|
122
|
+
allow(Resque).to receive(:redis=)
|
123
|
+
expect(::Contentful::Webhook::Listener::Server).to receive(:start) { DummyServer.new }
|
124
|
+
|
125
|
+
described_class.config = config
|
126
|
+
described_class.start
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'can be configured by a block' do
|
130
|
+
allow(Resque).to receive(:redis=)
|
131
|
+
expect(::Contentful::Webhook::Listener::Server).to receive(:start) { DummyServer.new }
|
132
|
+
|
133
|
+
described_class.start do |config|
|
134
|
+
config[:redis] = {}
|
135
|
+
config[:spaces] = {}
|
136
|
+
config[:management_token] = ''
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
7
|
+
require 'contentful/scheduler'
|
8
|
+
require 'contentful/webhook/listener'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
class MockServer
|
12
|
+
def [](key)
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class MockRequest
|
18
|
+
end
|
19
|
+
|
20
|
+
class MockResponse
|
21
|
+
attr_accessor :status, :body
|
22
|
+
end
|
23
|
+
|
24
|
+
class RequestDummy
|
25
|
+
attr_reader :headers, :body
|
26
|
+
|
27
|
+
def initialize(headers, body)
|
28
|
+
@headers = headers || {}
|
29
|
+
@body = JSON.dump(body)
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](key)
|
33
|
+
headers[key]
|
34
|
+
end
|
35
|
+
|
36
|
+
def each
|
37
|
+
headers.each do |h, v|
|
38
|
+
yield(h, v)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Contentful::Webhook::Listener::Controllers::Wait
|
44
|
+
@@sleeping = false
|
45
|
+
|
46
|
+
def sleep(time)
|
47
|
+
@@sleeping = true
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.sleeping
|
51
|
+
value = @@sleeping
|
52
|
+
@@sleeping = false
|
53
|
+
value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
RSpec.configure do |config|
|
58
|
+
config.filter_run :focus => true
|
59
|
+
config.run_all_when_everything_filtered = true
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contentful-scheduler-custom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Contentful GmbH (David Litvak Bruno0
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: contentful-webhook-listener
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: contentful-management
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: resque
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.27.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.27.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: resque-scheduler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.2.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.2.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redis
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: chronic
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: guard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: guard-rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: simplecov
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: Customizable Scheduler for Contentful Entries.
|
182
|
+
email:
|
183
|
+
- david.litvak@contentful.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".rspec"
|
190
|
+
- ".travis.yml"
|
191
|
+
- CHANGELOG.md
|
192
|
+
- CODE_OF_CONDUCT.md
|
193
|
+
- Gemfile
|
194
|
+
- Guardfile
|
195
|
+
- LICENSE.txt
|
196
|
+
- README.md
|
197
|
+
- Rakefile
|
198
|
+
- contentful-scheduler.gemspec
|
199
|
+
- example/Gemfile
|
200
|
+
- example/Gemfile.lock
|
201
|
+
- example/Procfile
|
202
|
+
- example/Rakefile
|
203
|
+
- example/config.ru
|
204
|
+
- lib/contentful/scheduler.rb
|
205
|
+
- lib/contentful/scheduler/controller.rb
|
206
|
+
- lib/contentful/scheduler/queue.rb
|
207
|
+
- lib/contentful/scheduler/tasks.rb
|
208
|
+
- lib/contentful/scheduler/tasks/publish.rb
|
209
|
+
- lib/contentful/scheduler/version.rb
|
210
|
+
- spec/contentful/scheduler/controller_spec.rb
|
211
|
+
- spec/contentful/scheduler/queue_spec.rb
|
212
|
+
- spec/contentful/scheduler/tasks/publish_spec.rb
|
213
|
+
- spec/contentful/scheduler_spec.rb
|
214
|
+
- spec/spec_helper.rb
|
215
|
+
homepage: https://www.contentful.com
|
216
|
+
licenses:
|
217
|
+
- MIT
|
218
|
+
metadata: {}
|
219
|
+
post_install_message:
|
220
|
+
rdoc_options: []
|
221
|
+
require_paths:
|
222
|
+
- lib
|
223
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - ">="
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '0'
|
228
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
|
+
requirements:
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: '0'
|
233
|
+
requirements: []
|
234
|
+
rubyforge_project:
|
235
|
+
rubygems_version: 2.5.1
|
236
|
+
signing_key:
|
237
|
+
specification_version: 4
|
238
|
+
summary: Customizable Scheduler for Contentful Entries.
|
239
|
+
test_files:
|
240
|
+
- spec/contentful/scheduler/controller_spec.rb
|
241
|
+
- spec/contentful/scheduler/queue_spec.rb
|
242
|
+
- spec/contentful/scheduler/tasks/publish_spec.rb
|
243
|
+
- spec/contentful/scheduler_spec.rb
|
244
|
+
- spec/spec_helper.rb
|