/
env.rb
66 lines (53 loc) · 1.24 KB
/
env.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
60
61
62
63
64
65
66
ENV['RACK_ENV'] = 'test'
# NOTE: This must come before the require 'webrat', otherwise
# sinatra will look in the wrong place for its views.
require File.dirname(__FILE__) + '/../../eee'
# RSpec matchers
require 'spec/expectations'
# Webrat
require 'webrat'
Webrat.configure do |config|
config.mode = :sinatra
end
World do
session = Webrat::SinatraSession.new
session.extend(Webrat::Matchers)
session.extend(Webrat::HaveTagMatcher)
session
end
Before do
RestClient.put @@db, { }
# TODO need to accomplish this via CouchDB migrations
lucene_index_function = <<_JS
function(doc) {
var ret = new Document();
function idx(obj) {
for (var key in obj) {
switch (typeof obj[key]) {
case 'object':
idx(obj[key]);
break;
case 'function':
break;
default:
ret.field(key, obj[key]);
ret.field('all', obj[key]);
break;
}
}
}
idx(doc);
ret.field('date', doc['date'], 'yes');
ret.field('title', doc['title'], 'yes');
return ret;
}
_JS
doc = { 'transform' => lucene_index_function }
RestClient.put "#{@@db}/_design/lucene",
doc.to_json,
:content_type => 'application/json'
end
After do
RestClient.delete @@db
sleep 0.5
end