Skip to content

Commit 45eba52

Browse files
committed
[RAILS] Added test helper for elasticsearch-rails
1 parent 16a41e8 commit 45eba52

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

elasticsearch-rails/elasticsearch-rails.gemspec

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Gem::Specification.new do |s|
2424
s.add_development_dependency "bundler", "~> 1.3"
2525
s.add_development_dependency "rake"
2626

27+
s.add_development_dependency "elasticsearch-extensions"
28+
29+
s.add_development_dependency "oj"
30+
s.add_development_dependency "rails", "> 3.0"
2731
s.add_development_dependency "shoulda-context"
2832
s.add_development_dependency "mocha"
2933
s.add_development_dependency "turn"
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
require 'test/unit'
14+
require 'shoulda-context'
15+
require 'mocha/setup'
16+
require 'turn' unless ENV["TM_FILEPATH"] || ENV["NOTURN"] || RUBY_1_8
17+
18+
require 'ansi'
19+
require 'oj'
20+
21+
require 'rails/version'
22+
require 'active_record'
23+
require 'active_model'
24+
25+
require 'elasticsearch/model'
26+
require 'elasticsearch/rails'
27+
28+
require 'elasticsearch/extensions/test/cluster'
29+
require 'elasticsearch/extensions/test/startup_shutdown'
30+
31+
module Elasticsearch
32+
module Test
33+
class IntegrationTestCase < ::Test::Unit::TestCase
34+
extend Elasticsearch::Extensions::Test::StartupShutdown
35+
36+
startup { Elasticsearch::Extensions::Test::Cluster.start(nodes: 1) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running? }
37+
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? }
38+
context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
39+
40+
def setup
41+
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ":memory:" )
42+
logger = ::Logger.new(STDERR)
43+
logger.formatter = lambda { |s, d, p, m| "#{m.ansi(:faint, :cyan)}\n" }
44+
ActiveRecord::Base.logger = logger unless ENV['QUIET']
45+
46+
ActiveRecord::LogSubscriber.colorize_logging = false
47+
ActiveRecord::Migration.verbose = false
48+
49+
tracer = ::Logger.new(STDERR)
50+
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
51+
52+
Elasticsearch::Model.client = Elasticsearch::Client.new host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
53+
tracer: (ENV['QUIET'] ? nil : tracer)
54+
end
55+
end
56+
end
57+
end

0 commit comments

Comments
 (0)