slate_algolia 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +9 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +5 -0
- data/CONTRIBUTING.md +9 -0
- data/Gemfile +3 -2
- data/README.md +60 -4
- data/Rakefile +5 -12
- data/lib/slate_algolia/extension.rb +94 -69
- data/lib/slate_algolia/index.rb +62 -45
- data/lib/slate_algolia/parser.rb +73 -52
- data/lib/slate_algolia.rb +4 -2
- data/slate_algolia.gemspec +12 -13
- data/spec/extension_spec.rb +64 -0
- data/spec/fixtures/base/build/index.html +309 -0
- data/spec/fixtures/base/config.rb +2 -0
- data/spec/fixtures/base/source/includes/_errors.md +20 -0
- data/spec/fixtures/base/source/index.html.md +188 -0
- data/spec/fixtures/base/source/layouts/layout.html.erb +81 -0
- data/spec/index_spec.rb +131 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/fixture.rb +17 -0
- data/spec/support/given.rb +26 -0
- metadata +24 -4
- data/features/support/env.rb +0 -4
data/spec/index_spec.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Middleman::SlateAlgolia::Index do
|
4
|
+
before :each do
|
5
|
+
stub_request(:any, %r{.*\.algolia(net\.com|\.net)\/*})
|
6
|
+
.to_return(body: '{"hits":[]}')
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
WebMock.reset!
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'initialize' do
|
14
|
+
it 'creates an Algolia Index with the specified name' do
|
15
|
+
expect(Algolia::Index).to receive(:new).with('test')
|
16
|
+
|
17
|
+
Middleman::SlateAlgolia::Index.new(
|
18
|
+
application_id: '',
|
19
|
+
api_key: '',
|
20
|
+
name: 'test'
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'uses the defined API keys for the Algolia Index' do
|
25
|
+
expect(Algolia).to receive(:init).with(application_id: 'id', api_key: 'key').and_call_original
|
26
|
+
|
27
|
+
Middleman::SlateAlgolia::Index.new(
|
28
|
+
application_id: 'id',
|
29
|
+
api_key: 'key',
|
30
|
+
name: ''
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'flush_queue' do
|
36
|
+
it 'calls before_index for each record' do
|
37
|
+
dbl = double
|
38
|
+
index = Middleman::SlateAlgolia::Index.new(
|
39
|
+
application_id: '',
|
40
|
+
api_key: '',
|
41
|
+
dry_run: false,
|
42
|
+
before_index: proc do |record|
|
43
|
+
# Verify is not a real method. Just a fake thing on a double
|
44
|
+
dbl.verify(record)
|
45
|
+
end
|
46
|
+
)
|
47
|
+
|
48
|
+
index.queue_object(objectID: 1)
|
49
|
+
index.queue_object(objectID: 2)
|
50
|
+
|
51
|
+
expect(dbl).to receive(:verify).with(objectID: 1)
|
52
|
+
expect(dbl).to receive(:verify).with(objectID: 2)
|
53
|
+
|
54
|
+
index.flush_queue
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'replaces records via the before_index hook' do
|
58
|
+
index = Middleman::SlateAlgolia::Index.new(
|
59
|
+
application_id: '',
|
60
|
+
api_key: '',
|
61
|
+
dry_run: false,
|
62
|
+
before_index: proc do |record|
|
63
|
+
{ objectID: record[:objectID] * 2 }
|
64
|
+
end
|
65
|
+
)
|
66
|
+
|
67
|
+
index.queue_object(objectID: 1)
|
68
|
+
index.queue_object(objectID: 2)
|
69
|
+
|
70
|
+
expect(index.instance_variable_get('@index')).to receive(:add_objects)
|
71
|
+
.with(
|
72
|
+
[
|
73
|
+
{ objectID: 2 },
|
74
|
+
{ objectID: 4 }
|
75
|
+
]
|
76
|
+
)
|
77
|
+
|
78
|
+
index.flush_queue
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'creates new records if before_index returns an array' do
|
82
|
+
index = Middleman::SlateAlgolia::Index.new(
|
83
|
+
application_id: '',
|
84
|
+
api_key: '',
|
85
|
+
dry_run: false,
|
86
|
+
before_index: proc do |record|
|
87
|
+
[record, { objectID: record[:objectID] * 4 }]
|
88
|
+
end
|
89
|
+
)
|
90
|
+
|
91
|
+
index.queue_object(objectID: 1)
|
92
|
+
index.queue_object(objectID: 2)
|
93
|
+
|
94
|
+
expect(index.instance_variable_get('@index')).to receive(:add_objects)
|
95
|
+
.with(
|
96
|
+
[
|
97
|
+
{ objectID: 1 },
|
98
|
+
{ objectID: 4 },
|
99
|
+
{ objectID: 2 },
|
100
|
+
{ objectID: 8 }
|
101
|
+
]
|
102
|
+
)
|
103
|
+
|
104
|
+
index.flush_queue
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'reuses the existing record if the before_index hook has no return' do
|
108
|
+
index = Middleman::SlateAlgolia::Index.new(
|
109
|
+
application_id: '',
|
110
|
+
api_key: '',
|
111
|
+
dry_run: false,
|
112
|
+
before_index: proc do |record|
|
113
|
+
# Wassup!
|
114
|
+
end
|
115
|
+
)
|
116
|
+
|
117
|
+
index.queue_object(objectID: 1)
|
118
|
+
index.queue_object(objectID: 2)
|
119
|
+
|
120
|
+
expect(index.instance_variable_get('@index')).to receive(:add_objects)
|
121
|
+
.with(
|
122
|
+
[
|
123
|
+
{ objectID: 1 },
|
124
|
+
{ objectID: 2 }
|
125
|
+
]
|
126
|
+
)
|
127
|
+
|
128
|
+
index.flush_queue
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'middleman'
|
9
|
+
require 'slate_algolia'
|
10
|
+
require 'webmock/rspec'
|
11
|
+
|
12
|
+
require_relative 'support/given'
|
13
|
+
require_relative 'support/fixture'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.run_all_when_everything_filtered = true
|
17
|
+
config.filter_run :focus
|
18
|
+
|
19
|
+
# Run specs in random order to surface order dependencies. If you find an
|
20
|
+
# order dependency and want to debug it, you can fix the order by providing
|
21
|
+
# the seed, which is printed after each run.
|
22
|
+
# --seed 1234
|
23
|
+
config.order = 'random'
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Fixture
|
3
|
+
class << self
|
4
|
+
def app(&block)
|
5
|
+
ENV['MM_ROOT'] = Given::TMP
|
6
|
+
|
7
|
+
if Middleman::Application.respond_to?(:server)
|
8
|
+
app = Middleman::Application.server.inst do
|
9
|
+
instance_eval(&block) if block
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
app
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Given
|
2
|
+
ROOT = File.expand_path('../..', __dir__)
|
3
|
+
TMP = File.join(ROOT, 'tmp')
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def fixture(fixture)
|
7
|
+
cleanup!
|
8
|
+
|
9
|
+
`rsync -av ./spec/fixtures/#{fixture}/ #{TMP}/`
|
10
|
+
Dir.chdir(TMP)
|
11
|
+
end
|
12
|
+
|
13
|
+
def file(name, content)
|
14
|
+
file_path = File.join(TMP, name)
|
15
|
+
FileUtils.mkdir_p(File.dirname(file_path))
|
16
|
+
File.open(file_path, 'w') do |file|
|
17
|
+
file.write(content)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def cleanup!
|
22
|
+
Dir.chdir(ROOT)
|
23
|
+
`rm -rf #{TMP}`
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slate_algolia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Wegner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -77,19 +77,30 @@ executables: []
|
|
77
77
|
extensions: []
|
78
78
|
extra_rdoc_files: []
|
79
79
|
files:
|
80
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
80
81
|
- ".gitignore"
|
82
|
+
- ".rubocop.yml"
|
81
83
|
- CONTRIBUTING.md
|
82
84
|
- Gemfile
|
83
85
|
- LICENSE
|
84
86
|
- README.md
|
85
87
|
- Rakefile
|
86
|
-
- features/support/env.rb
|
87
88
|
- lib/middleman_extension.rb
|
88
89
|
- lib/slate_algolia.rb
|
89
90
|
- lib/slate_algolia/extension.rb
|
90
91
|
- lib/slate_algolia/index.rb
|
91
92
|
- lib/slate_algolia/parser.rb
|
92
93
|
- slate_algolia.gemspec
|
94
|
+
- spec/extension_spec.rb
|
95
|
+
- spec/fixtures/base/build/index.html
|
96
|
+
- spec/fixtures/base/config.rb
|
97
|
+
- spec/fixtures/base/source/includes/_errors.md
|
98
|
+
- spec/fixtures/base/source/index.html.md
|
99
|
+
- spec/fixtures/base/source/layouts/layout.html.erb
|
100
|
+
- spec/index_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- spec/support/fixture.rb
|
103
|
+
- spec/support/given.rb
|
93
104
|
homepage:
|
94
105
|
licenses: []
|
95
106
|
metadata: {}
|
@@ -114,4 +125,13 @@ signing_key:
|
|
114
125
|
specification_version: 4
|
115
126
|
summary: Quickly and easily index Slate Docs in Algolia
|
116
127
|
test_files:
|
117
|
-
-
|
128
|
+
- spec/extension_spec.rb
|
129
|
+
- spec/fixtures/base/build/index.html
|
130
|
+
- spec/fixtures/base/config.rb
|
131
|
+
- spec/fixtures/base/source/includes/_errors.md
|
132
|
+
- spec/fixtures/base/source/index.html.md
|
133
|
+
- spec/fixtures/base/source/layouts/layout.html.erb
|
134
|
+
- spec/index_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
- spec/support/fixture.rb
|
137
|
+
- spec/support/given.rb
|
data/features/support/env.rb
DELETED