elasticsearch-rails 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +7 -7
- data/README.md +1 -0
- data/Rakefile +15 -12
- data/elasticsearch-rails.gemspec +1 -1
- data/lib/elasticsearch/rails/version.rb +1 -1
- data/lib/rails/templates/03-expert.rb +1 -2
- data/lib/rails/templates/seeds.rb +2 -1
- data/spec/instrumentation_spec.rb +81 -0
- data/spec/lograge_spec.rb +17 -0
- data/spec/spec_helper.rb +45 -0
- metadata +13 -14
- data/test/test_helper.rb +0 -64
- data/test/unit/instrumentation/instrumentation_test.rb +0 -61
- data/test/unit/instrumentation/lograge_test.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9facdda3d11d901cd6b8af2d11b62d0974f97264b10729c0e2405a814d19e17
|
4
|
+
data.tar.gz: ff4a3bb45141d484135e080bd1712ab3c23b757943a46625f06f208b7b9694b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00cd626f58dcf386def45b82d29cf3eea798e043ae3345ef610a86dfb6e76e7df83025bba18eeba7f2228c947c67cfe8a881474dd8a125db88297f9bca2378df
|
7
|
+
data.tar.gz: 00a182d1f145c48115887e6c394ef567b97319b51b7591a79fc48f0a471600f8d784c20450a3526858d773fe15b70a3a2dd1727b785925a46c71bd7f9b2b2cf4
|
data/Gemfile
CHANGED
@@ -3,12 +3,12 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in elasticsearch-rails.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
# TODO: Figure out how to specify dependency on local elasticsearch-model without endless "Resolving dependencies"
|
7
|
-
# if File.exists? File.expand_path("../../elasticsearch-model", __FILE__)
|
8
|
-
# gem 'elasticsearch-model', :path => File.expand_path("../../elasticsearch-model", __FILE__), :require => true
|
9
|
-
# end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
6
|
gem 'elasticsearch-model', :path => File.expand_path("../../elasticsearch-model", __FILE__), :require => false
|
14
7
|
gem 'elasticsearch-persistence', :path => File.expand_path("../../elasticsearch-persistence", __FILE__), :require => false
|
8
|
+
|
9
|
+
|
10
|
+
group :development, :testing do
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'pry-nav'
|
13
|
+
gem 'sqlite3' unless defined?(JRUBY_VERSION)
|
14
|
+
end
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -7,24 +7,27 @@ task :test => 'test:unit'
|
|
7
7
|
# ----- Test tasks ------------------------------------------------------------
|
8
8
|
|
9
9
|
require 'rake/testtask'
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
|
10
12
|
namespace :test do
|
11
|
-
Rake::TestTask.new(:unit) do |test|
|
12
|
-
test.libs << 'lib' << 'test'
|
13
|
-
test.test_files = FileList["test/unit/**/*_test.rb"]
|
14
|
-
test.verbose = false
|
15
|
-
test.warning = false
|
16
|
-
end
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
|
+
|
16
|
+
Rake::TestTask.new(:all) do |test|
|
21
17
|
test.verbose = false
|
22
18
|
test.warning = false
|
19
|
+
test.deps = [ :spec ] unless defined?(JRUBY_VERSION)
|
23
20
|
end
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
namespace :bundle do
|
24
|
+
desc 'Install gem dependencies'
|
25
|
+
task :install do
|
26
|
+
puts '-'*80
|
27
|
+
Bundler.with_clean_env do
|
28
|
+
sh 'bundle install'
|
29
|
+
end
|
30
|
+
puts '-'*80
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
data/elasticsearch-rails.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
|
24
24
|
s.required_ruby_version = ">= 1.9.3"
|
25
25
|
|
26
|
-
s.add_development_dependency "bundler"
|
26
|
+
s.add_development_dependency "bundler"
|
27
27
|
s.add_development_dependency "rake", "~> 11.1"
|
28
28
|
|
29
29
|
s.add_development_dependency "elasticsearch-extensions"
|
@@ -270,9 +270,8 @@ Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL
|
|
270
270
|
if Rails.env.development?
|
271
271
|
tracer = ActiveSupport::Logger.new('log/elasticsearch.log')
|
272
272
|
tracer.level = Logger::DEBUG
|
273
|
+
Elasticsearch::Model.client.transport.tracer = tracer
|
273
274
|
end
|
274
|
-
|
275
|
-
Elasticsearch::Model.client.transport.tracer = tracer
|
276
275
|
CODE
|
277
276
|
|
278
277
|
git add: "config/initializers"
|
@@ -3,7 +3,8 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
Zlib::GzipReader.open(File.expand_path('../articles.yml.gz', __FILE__)) do |gzip|
|
5
5
|
puts "Reading articles from gzipped YAML..."
|
6
|
-
@documents = YAML.load_documents(gzip.read)
|
6
|
+
@documents = YAML.respond_to?(:load_documents) ? YAML.load_documents(gzip.read) :
|
7
|
+
YAML.load_stream(gzip.read)
|
7
8
|
end
|
8
9
|
|
9
10
|
# Truncate the default ActiveRecord logger output
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'ActiveSupport::Instrumentation integration' do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
class DummyInstrumentationModel
|
7
|
+
extend Elasticsearch::Model::Searching::ClassMethods
|
8
|
+
|
9
|
+
def self.index_name; 'foo'; end
|
10
|
+
def self.document_type; 'bar'; end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
remove_classes(DummyInstrumentationModel)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:response_document) do
|
19
|
+
{ 'took' => '5ms',
|
20
|
+
'hits' => { 'total' => 123,
|
21
|
+
'max_score' => 456,
|
22
|
+
'hits' => [] } }
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:search) do
|
26
|
+
Elasticsearch::Model::Searching::SearchRequest.new(DummyInstrumentationModel, 'foo')
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:client) do
|
30
|
+
double('client', search: response_document)
|
31
|
+
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
allow(DummyInstrumentationModel).to receive(:client).and_return(client)
|
35
|
+
Elasticsearch::Rails::Instrumentation::Railtie.run_initializers
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'SearchRequest#execute!' do
|
39
|
+
|
40
|
+
it 'wraps the method with instrumentation' do
|
41
|
+
expect(search).to respond_to(:execute_without_instrumentation!)
|
42
|
+
expect(search).to respond_to(:execute_with_instrumentation!)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'Model#search' do
|
47
|
+
|
48
|
+
before do
|
49
|
+
expect(ActiveSupport::Notifications).to receive(:instrument).with('search.elasticsearch',
|
50
|
+
{ klass: 'DummyInstrumentationModel',
|
51
|
+
name: 'Search',
|
52
|
+
search: { body: query,
|
53
|
+
index: 'foo',
|
54
|
+
type: 'bar' } }).and_return({})
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:query) do
|
58
|
+
{ query: { match: { foo: 'bar' } } }
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:logged_message) do
|
62
|
+
@logger.logged(:debug).first
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'publishes a notification' do
|
66
|
+
expect(DummyInstrumentationModel.search(query).response).to eq({})
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when a message is logged', unless: defined?(RUBY_VERSION) && RUBY_VERSION > '2.2' do
|
70
|
+
|
71
|
+
let(:query) do
|
72
|
+
{ query: { match: { moo: 'bam' } } }
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'prints the debug information to the log' do
|
76
|
+
expect(logged_message).to match(/DummyInstrumentationModel Search \(\d+\.\d+ms\)/)
|
77
|
+
expect(logged_message).to match(/body\: \{query\: \{match\: \{moo\: "bam"\}\}\}\}/)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'action_pack'
|
3
|
+
require 'lograge'
|
4
|
+
require 'elasticsearch/rails/lograge'
|
5
|
+
|
6
|
+
describe 'ActiveSupport::Instrumentation integration' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
Elasticsearch::Rails::Lograge::Railtie.run_initializers
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'customizes the Lograge configuration' do
|
13
|
+
expect(Elasticsearch::Rails::Lograge::Railtie.initializers
|
14
|
+
.select { |i| i.name == 'elasticsearch.lograge' }
|
15
|
+
.first).not_to be_nil
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'pry-nav'
|
2
|
+
require 'active_record'
|
3
|
+
require 'elasticsearch/model'
|
4
|
+
require 'elasticsearch/rails'
|
5
|
+
require 'rails/railtie'
|
6
|
+
require 'elasticsearch/rails/instrumentation'
|
7
|
+
|
8
|
+
|
9
|
+
unless defined?(ELASTICSEARCH_URL)
|
10
|
+
ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.formatter = 'documentation'
|
15
|
+
config.color = true
|
16
|
+
|
17
|
+
config.before(:suite) do
|
18
|
+
require 'ansi'
|
19
|
+
tracer = ::Logger.new(STDERR)
|
20
|
+
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
|
21
|
+
Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL,
|
22
|
+
tracer: (ENV['QUIET'] ? nil : tracer)
|
23
|
+
|
24
|
+
unless ActiveRecord::Base.connected?
|
25
|
+
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ":memory:" )
|
26
|
+
end
|
27
|
+
|
28
|
+
if ::ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks) && ::ActiveRecord::VERSION::MAJOR.to_s < '5'
|
29
|
+
::ActiveRecord::Base.raise_in_transactional_callbacks = true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Remove all classes.
|
35
|
+
#
|
36
|
+
# @param [ Array<Class> ] classes The list of classes to remove.
|
37
|
+
#
|
38
|
+
# @return [ true ]
|
39
|
+
#
|
40
|
+
# @since 6.0.1
|
41
|
+
def remove_classes(*classes)
|
42
|
+
classes.each do |_class|
|
43
|
+
Object.send(:remove_const, _class.name.to_sym) if defined?(_class)
|
44
|
+
end and true
|
45
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -289,9 +289,9 @@ files:
|
|
289
289
|
- lib/rails/templates/searchable.dsl.rb
|
290
290
|
- lib/rails/templates/searchable.rb
|
291
291
|
- lib/rails/templates/seeds.rb
|
292
|
-
-
|
293
|
-
-
|
294
|
-
-
|
292
|
+
- spec/instrumentation_spec.rb
|
293
|
+
- spec/lograge_spec.rb
|
294
|
+
- spec/spec_helper.rb
|
295
295
|
homepage: https://github.com/elasticsearch/elasticsearch-rails/
|
296
296
|
licenses:
|
297
297
|
- Apache 2
|
@@ -312,12 +312,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
312
312
|
- !ruby/object:Gem::Version
|
313
313
|
version: '0'
|
314
314
|
requirements: []
|
315
|
-
|
316
|
-
rubygems_version: 2.7.7
|
315
|
+
rubygems_version: 3.0.4
|
317
316
|
signing_key:
|
318
317
|
specification_version: 4
|
319
318
|
summary: Ruby on Rails integrations for Elasticsearch.
|
320
319
|
test_files:
|
321
|
-
-
|
322
|
-
-
|
323
|
-
-
|
320
|
+
- spec/instrumentation_spec.rb
|
321
|
+
- spec/lograge_spec.rb
|
322
|
+
- spec/spec_helper.rb
|
data/test/test_helper.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
2
|
-
|
3
|
-
exit(0) if RUBY_1_8
|
4
|
-
|
5
|
-
require 'simplecov' and SimpleCov.start { add_filter "/test|test_/" } if ENV["COVERAGE"]
|
6
|
-
|
7
|
-
# Register `at_exit` handler for integration tests shutdown.
|
8
|
-
# MUST be called before requiring `test/unit`.
|
9
|
-
at_exit { Elasticsearch::Test::IntegrationTestCase.__run_at_exit_hooks }
|
10
|
-
|
11
|
-
puts '-'*80
|
12
|
-
|
13
|
-
if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
|
14
|
-
require 'test-unit'
|
15
|
-
require 'mocha/test_unit'
|
16
|
-
else
|
17
|
-
require 'minitest/autorun'
|
18
|
-
require 'mocha/mini_test'
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'shoulda-context'
|
22
|
-
|
23
|
-
require 'turn' unless ENV["TM_FILEPATH"] || ENV["NOTURN"] || defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
|
24
|
-
|
25
|
-
require 'ansi'
|
26
|
-
require 'oj' unless defined?(JRUBY_VERSION)
|
27
|
-
|
28
|
-
require 'rails/version'
|
29
|
-
require 'active_record'
|
30
|
-
require 'active_model'
|
31
|
-
|
32
|
-
require 'elasticsearch/model'
|
33
|
-
require 'elasticsearch/rails'
|
34
|
-
|
35
|
-
require 'elasticsearch/extensions/test/cluster'
|
36
|
-
require 'elasticsearch/extensions/test/startup_shutdown'
|
37
|
-
|
38
|
-
module Elasticsearch
|
39
|
-
module Test
|
40
|
-
class IntegrationTestCase < ::Test::Unit::TestCase
|
41
|
-
extend Elasticsearch::Extensions::Test::StartupShutdown
|
42
|
-
|
43
|
-
startup { Elasticsearch::Extensions::Test::Cluster.start(nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running? }
|
44
|
-
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? }
|
45
|
-
context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
|
46
|
-
|
47
|
-
def setup
|
48
|
-
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ":memory:" )
|
49
|
-
logger = ::Logger.new(STDERR)
|
50
|
-
logger.formatter = lambda { |s, d, p, m| "#{m.ansi(:faint, :cyan)}\n" }
|
51
|
-
ActiveRecord::Base.logger = logger unless ENV['QUIET']
|
52
|
-
|
53
|
-
ActiveRecord::LogSubscriber.colorize_logging = false
|
54
|
-
ActiveRecord::Migration.verbose = false
|
55
|
-
|
56
|
-
tracer = ::Logger.new(STDERR)
|
57
|
-
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
|
58
|
-
|
59
|
-
Elasticsearch::Model.client = Elasticsearch::Client.new host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
|
60
|
-
tracer: (ENV['QUIET'] ? nil : tracer)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'rails/railtie'
|
4
|
-
require 'active_support/log_subscriber/test_helper'
|
5
|
-
|
6
|
-
require 'elasticsearch/rails/instrumentation'
|
7
|
-
|
8
|
-
class Elasticsearch::Rails::InstrumentationTest < Test::Unit::TestCase
|
9
|
-
include ActiveSupport::LogSubscriber::TestHelper
|
10
|
-
|
11
|
-
context "ActiveSupport::Instrumentation integration" do
|
12
|
-
class ::DummyInstrumentationModel
|
13
|
-
extend Elasticsearch::Model::Searching::ClassMethods
|
14
|
-
|
15
|
-
def self.index_name; 'foo'; end
|
16
|
-
def self.document_type; 'bar'; end
|
17
|
-
end
|
18
|
-
|
19
|
-
RESPONSE = { 'took' => '5ms', 'hits' => { 'total' => 123, 'max_score' => 456, 'hits' => [] } }
|
20
|
-
|
21
|
-
setup do
|
22
|
-
@search = Elasticsearch::Model::Searching::SearchRequest.new ::DummyInstrumentationModel, '*'
|
23
|
-
|
24
|
-
@client = stub('client', search: RESPONSE)
|
25
|
-
DummyInstrumentationModel.stubs(:client).returns(@client)
|
26
|
-
|
27
|
-
Elasticsearch::Rails::Instrumentation::Railtie.run_initializers
|
28
|
-
end
|
29
|
-
|
30
|
-
should "wrap SearchRequest#execute! with instrumentation" do
|
31
|
-
s = Elasticsearch::Model::Searching::SearchRequest.new ::DummyInstrumentationModel, 'foo'
|
32
|
-
assert_respond_to s, :execute_without_instrumentation!
|
33
|
-
assert_respond_to s, :execute_with_instrumentation!
|
34
|
-
end
|
35
|
-
|
36
|
-
should "publish the notification" do
|
37
|
-
@query = { query: { match: { foo: 'bar' } } }
|
38
|
-
|
39
|
-
ActiveSupport::Notifications.expects(:instrument).with do |name, payload|
|
40
|
-
assert_equal "search.elasticsearch", name
|
41
|
-
assert_equal 'DummyInstrumentationModel', payload[:klass]
|
42
|
-
assert_equal @query, payload[:search][:body]
|
43
|
-
true
|
44
|
-
end
|
45
|
-
|
46
|
-
s = ::DummyInstrumentationModel.search @query
|
47
|
-
s.response
|
48
|
-
end
|
49
|
-
|
50
|
-
should "print the debug information to the Rails log" do
|
51
|
-
s = ::DummyInstrumentationModel.search query: { match: { moo: 'bam' } }
|
52
|
-
s.response
|
53
|
-
|
54
|
-
logged = @logger.logged(:debug).first
|
55
|
-
|
56
|
-
assert_not_nil logged
|
57
|
-
assert_match /DummyInstrumentationModel Search \(\d+\.\d+ms\)/, logged
|
58
|
-
assert_match /body\: \{query\: \{match\: \{moo\: "bam"\}\}\}\}/, logged
|
59
|
-
end unless defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
|
60
|
-
end
|
61
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'rails/railtie'
|
4
|
-
require 'action_pack'
|
5
|
-
require 'lograge'
|
6
|
-
|
7
|
-
require 'elasticsearch/rails/lograge'
|
8
|
-
|
9
|
-
class Elasticsearch::Rails::LogrageTest < Test::Unit::TestCase
|
10
|
-
context "Lograge integration" do
|
11
|
-
setup do
|
12
|
-
Elasticsearch::Rails::Lograge::Railtie.run_initializers
|
13
|
-
end
|
14
|
-
|
15
|
-
should "customize the Lograge configuration" do
|
16
|
-
assert_not_nil Elasticsearch::Rails::Lograge::Railtie.initializers
|
17
|
-
.select { |i| i.name == 'elasticsearch.lograge' }
|
18
|
-
.first
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|