diff --git a/Rakefile b/Rakefile index 4d49a8f34..55c294486 100644 --- a/Rakefile +++ b/Rakefile @@ -38,14 +38,16 @@ def admin_client if test_suite == 'security' transport_options.merge!(:ssl => { verify: false, - ca_path: CERT_DIR }) + ca_path: defined?(CERT_DIR) ? CERT_DIR : nil + }.compact) password = ENV['ELASTIC_PASSWORD'] user = ENV['ELASTIC_USER'] || 'elastic' - url = "https://#{user}:#{password}@#{host}:#{port}" + url = "https://#{user}:#{password}@#{host || 'localhost'}:#{port || 9200}" else url = "http://#{host || 'localhost'}:#{port || 9200}" end + ENV['ELASTICSEARCH_URL'] ||= url Elasticsearch::Client.new(host: url, transport_options: transport_options) end end @@ -140,7 +142,7 @@ namespace :test do end desc "Run all tests in all subprojects" - task all: :wait_for_green do + task all: :wait_for_green_or_yellow do subprojects.each do |project| puts '-'*80 sh "cd #{project} && " + @@ -151,20 +153,20 @@ namespace :test do end end -desc "Wait for elasticsearch cluster to be in green state" -task :wait_for_green do +desc "Wait for elasticsearch cluster to be in green or yellow state" +task :wait_for_green_or_yellow do require 'elasticsearch' ready = nil 5.times do |i| begin - puts "Attempting to wait for green status: #{i + 1}" - if admin_client.cluster.health(wait_for_status: 'green', timeout: '50s') + puts "Attempting to wait for green or yellow status: #{i + 1}" + if admin_client.cluster.health(wait_for_status: 'yellow', timeout: '50s') ready = true break end rescue Elastic::Transport::Transport::Errors::RequestTimeout => ex - puts "Couldn't confirm green status.\n#{ex.inspect}." + puts "Couldn't confirm green or yellow status.\n#{ex.inspect}." rescue Faraday::ConnectionFailed => ex puts "Couldn't connect to Elasticsearch.\n#{ex.inspect}." sleep(30) diff --git a/elasticsearch-model/lib/elasticsearch/model/proxy.rb b/elasticsearch-model/lib/elasticsearch/model/proxy.rb index 63645ffdc..8a93bc359 100644 --- a/elasticsearch-model/lib/elasticsearch/model/proxy.rb +++ b/elasticsearch-model/lib/elasticsearch/model/proxy.rb @@ -111,7 +111,7 @@ def initialize(target) @target = target end - def ruby2_keywords(*) # :nodoc: + def self.ruby2_keywords(*) # :nodoc: end if RUBY_VERSION < "2.7" # Delegate methods to `@target`. As per [the Ruby 3.0 explanation for keyword arguments](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/), the only way to work on Ruby <2.7, and 2.7, and 3.0+ is to use `ruby2_keywords`. diff --git a/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/import_spec.rb b/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/import_spec.rb index a23e58c37..73be18c59 100644 --- a/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/import_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/import_spec.rb @@ -52,6 +52,10 @@ it 'imports all documents' do expect(ImportArticle.search('*').results.total).to eq(10) end + + it "does not pollute the model's namespace" do + expect(ImportArticle.methods).not_to include(:__transform) + end end context 'when batch size is specified' do diff --git a/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb b/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb index 68fc2c242..b4c0d299d 100644 --- a/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb @@ -591,7 +591,7 @@ class ::DummyIndexingModelForRecreate context 'when the index is not found' do let(:logger) { nil } - let(:client) { Elasticsearch::Client.new(logger: logger) } + let(:client) { Elasticsearch::Client.new(logger: logger, transport_options: { ssl: { verify: false } }) } before do expect(DummyIndexingModelForRecreate).to receive(:client).at_most(3).times.and_return(client) diff --git a/elasticsearch-model/spec/spec_helper.rb b/elasticsearch-model/spec/spec_helper.rb index d3a1e303f..7c4f21a4a 100644 --- a/elasticsearch-model/spec/spec_helper.rb +++ b/elasticsearch-model/spec/spec_helper.rb @@ -31,6 +31,10 @@ require 'yaml' require 'active_record' +# Load all of ActiveSupport to be sure of complete compatibility - +# see https://github.com/elastic/elasticsearch-rails/pull/1075 for details +require 'active_support/all' + unless defined?(ELASTICSEARCH_URL) ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}" end @@ -45,7 +49,8 @@ tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" } Elasticsearch::Model.client = Elasticsearch::Client.new( host: ELASTICSEARCH_URL, - tracer: (ENV['QUIET'] ? nil : tracer) + tracer: (ENV['QUIET'] ? nil : tracer), + transport_options: { :ssl => { verify: false } } ) puts "Elasticsearch Version: #{Elasticsearch::Model.client.info['version']}" diff --git a/elasticsearch-persistence/spec/spec_helper.rb b/elasticsearch-persistence/spec/spec_helper.rb index e577d3808..bf9ac3e07 100644 --- a/elasticsearch-persistence/spec/spec_helper.rb +++ b/elasticsearch-persistence/spec/spec_helper.rb @@ -36,7 +36,8 @@ # # @since 6.0.0 DEFAULT_CLIENT = Elasticsearch::Client.new(host: ELASTICSEARCH_URL, - tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR))) + tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR)), + transport_options: { :ssl => { verify: false } }) class MyTestRepository include Elasticsearch::Persistence::Repository diff --git a/elasticsearch-rails/spec/spec_helper.rb b/elasticsearch-rails/spec/spec_helper.rb index e0a299964..ccc28f345 100644 --- a/elasticsearch-rails/spec/spec_helper.rb +++ b/elasticsearch-rails/spec/spec_helper.rb @@ -36,7 +36,8 @@ tracer = ::Logger.new(STDERR) tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" } Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL, - tracer: (ENV['QUIET'] ? nil : tracer) + tracer: (ENV['QUIET'] ? nil : tracer), + transport_options: { :ssl => { verify: false } } puts "Elasticsearch Version: #{Elasticsearch::Model.client.info['version']}" unless ActiveRecord::Base.connected?