wcc-contentful-middleman 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wcc/contentful/middleman/extension.rb +6 -6
- data/lib/wcc/contentful/middleman/version.rb +1 -1
- data/wcc-contentful-middleman.gemspec +5 -5
- metadata +12 -25
- data/spec/fixtures/contentful/content_types_mgmt_api.json +0 -4384
- data/spec/fixtures/contentful/contentful-schema.json +0 -4511
- data/spec/fixtures/contentful/sync.json +0 -1547
- data/spec/fixtures/contentful/sync_empty.json +0 -7
- data/spec/spec_helper.rb +0 -98
- data/spec/support/fixtures_helper.rb +0 -31
- data/spec/wcc/contentful/middleman/extension_spec.rb +0 -69
data/spec/spec_helper.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'simplecov'
|
4
|
-
|
5
|
-
SimpleCov.start do
|
6
|
-
root File.expand_path('../..', __dir__)
|
7
|
-
add_filter '/spec/'
|
8
|
-
coverage_dir "#{File.expand_path('..', __dir__)}/coverage"
|
9
|
-
end
|
10
|
-
|
11
|
-
require 'bundler/setup'
|
12
|
-
require 'dotenv/load'
|
13
|
-
require 'webmock/rspec'
|
14
|
-
require 'httplog'
|
15
|
-
|
16
|
-
WebMock.disable_net_connect!(allow_localhost: true)
|
17
|
-
|
18
|
-
# override env vars for testing
|
19
|
-
ENV['CONTENTFUL_SPACE_ID'] = 'test1xab'
|
20
|
-
ENV['CONTENTFUL_ACCESS_TOKEN'] = 'test1234'
|
21
|
-
ENV['CONTENTFUL_MANAGEMENT_TOKEN'] = 'CFPAT-test1234'
|
22
|
-
ENV['CONTENTFUL_PREVIEW_TOKEN'] = 'test123456'
|
23
|
-
|
24
|
-
require 'wcc/contentful'
|
25
|
-
require 'wcc/contentful/middleman'
|
26
|
-
|
27
|
-
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
28
|
-
|
29
|
-
RSpec.shared_context 'Contentful config' do
|
30
|
-
let(:contentful_access_token) { ENV['CONTENTFUL_ACCESS_TOKEN'] || 'test1234' }
|
31
|
-
let(:contentful_management_token) { ENV['CONTENTFUL_MANAGEMENT_TOKEN'] || 'CFPAT-test1234' }
|
32
|
-
let(:contentful_preview_token) { ENV['CONTENTFUL_PREVIEW_TOKEN'] || 'test123456' }
|
33
|
-
let(:contentful_space_id) { ENV['CONTENTFUL_SPACE_ID'] || 'test1xab' }
|
34
|
-
|
35
|
-
def contentful_reset!
|
36
|
-
WCC::Contentful.instance_variable_set('@initialized', nil)
|
37
|
-
WCC::Contentful::Services.instance_variable_set(:@singleton__instance__, nil)
|
38
|
-
|
39
|
-
# clean out everything in the WCC::Contentful::Model generated namespace
|
40
|
-
consts = WCC::Contentful::Model.constants(false).map(&:to_s).uniq
|
41
|
-
consts.each do |c|
|
42
|
-
begin
|
43
|
-
WCC::Contentful::Model.send(:remove_const, c.split(':').last)
|
44
|
-
rescue StandardError => e
|
45
|
-
warn e
|
46
|
-
end
|
47
|
-
end
|
48
|
-
WCC::Contentful::Model.instance_variable_get('@registry').clear
|
49
|
-
Wisper.clear
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
RSpec.configure do |config|
|
54
|
-
# Enable flags like --only-failures and --next-failure
|
55
|
-
config.example_status_persistence_file_path = '.rspec_status'
|
56
|
-
|
57
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
58
|
-
config.disable_monkey_patching!
|
59
|
-
|
60
|
-
config.expect_with :rspec do |c|
|
61
|
-
c.syntax = :expect
|
62
|
-
end
|
63
|
-
|
64
|
-
# Time.zone ||= 'Central Time (US & Canada)'
|
65
|
-
|
66
|
-
config.include FixturesHelper
|
67
|
-
config.include_context 'Contentful config'
|
68
|
-
|
69
|
-
config.before(:each) do
|
70
|
-
WCC::Contentful.instance_variable_set('@configuration', nil)
|
71
|
-
WCC::Contentful.instance_variable_set('@initialized', nil)
|
72
|
-
WCC::Contentful::Services.instance_variable_set(:@singleton__instance__, nil)
|
73
|
-
|
74
|
-
# clean out everything in the WCC::Contentful::Model generated namespace
|
75
|
-
consts = WCC::Contentful::Model.constants(false).map(&:to_s).uniq
|
76
|
-
consts.each do |c|
|
77
|
-
begin
|
78
|
-
WCC::Contentful::Model.send(:remove_const, c.split(':').last)
|
79
|
-
rescue StandardError => e
|
80
|
-
warn e
|
81
|
-
end
|
82
|
-
end
|
83
|
-
WCC::Contentful::Model.instance_variable_get('@registry').clear
|
84
|
-
|
85
|
-
# set up initialization mocks
|
86
|
-
stub_request(:get, /https:\/\/cdn.contentful.com\/spaces\/.+\/sync/)
|
87
|
-
.to_return(body: load_fixture('contentful/sync_empty.json'))
|
88
|
-
|
89
|
-
WCC::Contentful.configure do |c|
|
90
|
-
c.schema_file = File.join(fixture_root, 'contentful/contentful-schema.json')
|
91
|
-
c.update_schema_file = :never
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
HttpLog.configure do |config|
|
97
|
-
config.compact_log = true
|
98
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module FixturesHelper
|
4
|
-
def load_fixture(file_name)
|
5
|
-
file = File.join(fixture_root, file_name)
|
6
|
-
return unless File.exist?(file)
|
7
|
-
|
8
|
-
File.read(file)
|
9
|
-
.gsub(/343qxys30lid/i, contentful_space_id)
|
10
|
-
.gsub('<CONTENTFUL_SPACE_ID>', contentful_space_id)
|
11
|
-
end
|
12
|
-
|
13
|
-
def fixture_root
|
14
|
-
"#{File.dirname(__FILE__)}/../fixtures"
|
15
|
-
end
|
16
|
-
|
17
|
-
def load_indexed_types(file_name = 'contentful/indexed_types_from_content_type_indexer.json')
|
18
|
-
serialized = JSON.parse(load_fixture(file_name))
|
19
|
-
WCC::Contentful::IndexedRepresentation.from_json(serialized)
|
20
|
-
end
|
21
|
-
|
22
|
-
def load_store_from_sync(file_name: 'contentful/sync_initial.json', store: nil)
|
23
|
-
sync_initial = JSON.parse(load_fixture(file_name).gsub(/343qxys30lid/, contentful_space_id))
|
24
|
-
|
25
|
-
store ||= WCC::Contentful::Store::MemoryStore.new
|
26
|
-
sync_initial.each do |_k, v|
|
27
|
-
store.index(v)
|
28
|
-
end
|
29
|
-
store
|
30
|
-
end
|
31
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'wcc/contentful/middleman/extension'
|
5
|
-
|
6
|
-
RSpec.describe WCC::Contentful::Middleman::Extension do
|
7
|
-
let(:app) {
|
8
|
-
double('app', after_configuration: nil, ready: nil)
|
9
|
-
}
|
10
|
-
|
11
|
-
describe '#initialize' do
|
12
|
-
before do
|
13
|
-
stub_request(:get, /https:\/\/cdn.contentful.com\/spaces\/.+\/sync/)
|
14
|
-
.to_return(body: load_fixture('contentful/sync.json'))
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'sets contentful config variables' do
|
18
|
-
described_class.new(app,
|
19
|
-
space: 'testspace',
|
20
|
-
access_token: 'testtoken1',
|
21
|
-
preview_token: 'testpreview1',
|
22
|
-
management_token: 'testmgmt1')
|
23
|
-
|
24
|
-
expect(WCC::Contentful.configuration.space).to eq('testspace')
|
25
|
-
expect(WCC::Contentful.configuration.access_token).to eq('testtoken1')
|
26
|
-
expect(WCC::Contentful.configuration.preview_token).to eq('testpreview1')
|
27
|
-
expect(WCC::Contentful.configuration.management_token).to eq('testmgmt1')
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'infers from environment variables' do
|
31
|
-
described_class.new(app)
|
32
|
-
|
33
|
-
expect(WCC::Contentful.configuration.space).to eq('test1xab')
|
34
|
-
expect(WCC::Contentful.configuration.access_token).to eq('test1234')
|
35
|
-
expect(WCC::Contentful.configuration.preview_token).to eq('test123456')
|
36
|
-
expect(WCC::Contentful.configuration.management_token).to eq('CFPAT-test1234')
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'sets configuration defaults' do
|
40
|
-
described_class.new(app)
|
41
|
-
|
42
|
-
# middleman uses memory store by default to sync all content over
|
43
|
-
store = WCC::Contentful::Services.instance.store.store
|
44
|
-
expect(store).to be_a WCC::Contentful::Store::MemoryStore
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'passes block' do
|
48
|
-
described_class.new(app) do |config|
|
49
|
-
config.environment = 'test123'
|
50
|
-
end
|
51
|
-
|
52
|
-
expect(WCC::Contentful.configuration.environment).to eq('test123')
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'initializes WCC::Contentful' do
|
56
|
-
expect(WCC::Contentful).to receive(:init!)
|
57
|
-
|
58
|
-
described_class.new(app)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'syncs over new content' do
|
62
|
-
described_class.new(app)
|
63
|
-
|
64
|
-
store = WCC::Contentful::Services.instance.store
|
65
|
-
homepage = store.find('4ssPJYNGPYQMMwo2gKmISo')
|
66
|
-
expect(homepage).to be_present
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|