fix(weight): Allow non-string values in titles

This commit is contained in:
Pixelastic 2015-07-10 11:55:54 +02:00
parent 164c3d0359
commit c76457bde3
3 changed files with 22 additions and 6 deletions

View File

@ -7,11 +7,8 @@ Gem::Specification.new do |s|
'`jekyll algolia push`'
s.authors = ['Tim Carry']
s.email = 'tim@pixelastic.com'
s.files = [
'lib/algoliasearch-jekyll.rb',
'lib/push.rb',
'lib/record_extractor.rb'
]
s.files = ['lib/*.rb']
s.add_development_dependency('jekyll', ['~> 2.5'])
s.add_development_dependency('rspec', ['~> 3.0'])
s.add_development_dependency('guard-rspec', ['~> 4.6'])

View File

@ -147,7 +147,7 @@ class AlgoliaSearchRecordExtractor
# Get list of unique words in headings
title_words = %i(title h1 h2 h3 h4 h5 h6)
.select { |title| data.key?(title) }
.map { |title| data[title].split(/\W+/) }
.map { |title| data[title].to_s.split(/\W+/) }
.flatten
.compact
.map(&:downcase)

View File

@ -349,6 +349,25 @@ describe(AlgoliaSearchRecordExtractor) do
# Then
expect(actual).to eq 1
end
it 'should still work with non-string keys' do
# Given
data = {
title: nil,
h1: [],
h2: {},
h3: true,
h4: false,
h5: 'foo bar',
text: 'foo bar'
}
# When
actual = test_page.weight(data)
# Then
expect(actual).to eq 2
end
end
describe 'custom_hook_each' do