forked from woahdae/tire
/
test_helper.rb
59 lines (44 loc) · 1.39 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'rubygems'
require 'pathname'
require 'test/unit'
require 'yajl/json_gem'
require 'sqlite3'
require 'shoulda'
require 'turn' unless ENV["TM_FILEPATH"]
require 'mocha'
require 'tire'
Dir[File.dirname(__FILE__) + '/models/**/*.rb'].each { |m| require m }
class Test::Unit::TestCase
def mock_response(body, code=200)
stub(:body => body, :code => code)
end
def fixtures_path
Pathname( File.expand_path( 'fixtures', File.dirname(__FILE__) ) )
end
def fixture_file(path)
File.read File.expand_path( path, fixtures_path )
end
end
module Test::Integration
URL = "http://localhost:9200"
def setup
begin; Object.send(:remove_const, :Rails); rescue; end
begin
::RestClient.get URL
rescue Errno::ECONNREFUSED
abort "\n\n#{'-'*87}\n[ABORTED] You have to run ElasticSearch on #{URL} for integration tests\n#{'-'*87}\n\n"
end
::RestClient.delete "#{URL}/articles-test" rescue nil
::RestClient.post "#{URL}/articles-test", ''
fixtures_path.join('articles').entries.each do |f|
filename = f.to_s
next if filename =~ /^\./
::RestClient.put "#{URL}/articles-test/article/#{File.basename(filename, '.*')}",
fixtures_path.join('articles').join(f).read
end
::RestClient.post "#{URL}/articles-test/_refresh", ''
end
def teardown
::RestClient.delete "#{URL}/articles-test" rescue nil
end
end