picky 4.0.0pre1 → 4.0.0pre2
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.
- data/aux/picky/cli.rb +6 -2
- data/lib/picky.rb +10 -8
- data/lib/picky/backends/backend.rb +37 -0
- data/lib/picky/backends/file.rb +0 -20
- data/lib/picky/backends/memory.rb +0 -29
- data/lib/picky/backends/redis.rb +74 -15
- data/lib/picky/backends/redis/list.rb +1 -1
- data/lib/picky/backends/sqlite.rb +0 -27
- data/lib/picky/bundle.rb +2 -2
- data/lib/picky/bundle_indexed.rb +1 -1
- data/lib/picky/bundle_indexing.rb +1 -1
- data/lib/picky/categories_indexed.rb +1 -11
- data/lib/picky/category.rb +4 -4
- data/lib/picky/category/location.rb +25 -0
- data/lib/picky/category_realtime.rb +4 -3
- data/lib/picky/console.rb +1 -1
- data/lib/picky/constants.rb +1 -1
- data/lib/picky/ext/maybe_compile.rb +2 -2
- data/lib/picky/extensions/object.rb +3 -2
- data/lib/picky/generators/aliases.rb +7 -2
- data/lib/picky/generators/partial/default.rb +1 -0
- data/lib/picky/generators/similarity/default.rb +1 -0
- data/lib/picky/generators/similarity/phonetic.rb +13 -2
- data/lib/picky/generators/strategy.rb +0 -2
- data/lib/picky/generators/weights/constant.rb +1 -2
- data/lib/picky/generators/weights/default.rb +1 -0
- data/lib/picky/generators/weights/dynamic.rb +1 -1
- data/lib/picky/generators/weights/logarithmic.rb +1 -1
- data/lib/picky/generators/weights/{runtime.rb → stub.rb} +1 -3
- data/lib/picky/index.rb +3 -3
- data/lib/picky/index_indexing.rb +0 -2
- data/lib/picky/index_realtime.rb +1 -1
- data/lib/picky/indexers/base.rb +7 -0
- data/lib/picky/indexers/parallel.rb +2 -4
- data/lib/picky/indexers/serial.rb +2 -0
- data/lib/picky/indexes_indexing.rb +1 -1
- data/lib/picky/interfaces/live_parameters/master_child.rb +175 -0
- data/lib/picky/interfaces/live_parameters/unicorn.rb +37 -0
- data/lib/picky/loader.rb +238 -259
- data/lib/picky/query/allocation.rb +19 -10
- data/lib/picky/query/combination.rb +7 -1
- data/lib/picky/query/combinations.rb +1 -6
- data/lib/picky/query/token.rb +26 -36
- data/lib/picky/results.rb +18 -17
- data/lib/picky/scheduler.rb +2 -1
- data/lib/picky/search.rb +1 -1
- data/lib/picky/sinatra.rb +6 -6
- data/lib/picky/statistics.rb +2 -0
- data/lib/picky/tokenizer.rb +8 -8
- data/lib/picky/wrappers/bundle/calculation.rb +4 -4
- data/lib/picky/wrappers/bundle/location.rb +1 -2
- data/lib/tasks/framework.rake +1 -1
- data/lib/tasks/statistics.rake +1 -1
- data/lib/tasks/try.rake +1 -1
- data/lib/tasks/try.rb +1 -1
- data/spec/aux/picky/cli_spec.rb +12 -12
- data/spec/ext/performant_spec.rb +16 -16
- data/spec/functional/backends/file_spec.rb +78 -7
- data/spec/functional/backends/memory_spec.rb +78 -7
- data/spec/functional/backends/redis_spec.rb +73 -13
- data/spec/functional/dynamic_weights_spec.rb +3 -4
- data/spec/functional/realtime_spec.rb +2 -2
- data/spec/functional/speed_spec.rb +2 -2
- data/spec/functional/terminate_early_spec.rb +3 -3
- data/spec/lib/analytics_spec.rb +1 -1
- data/spec/lib/analyzer_spec.rb +5 -3
- data/spec/lib/categories_indexed_spec.rb +38 -20
- data/spec/lib/category/location_spec.rb +30 -0
- data/spec/lib/character_substituters/west_european_spec.rb +1 -0
- data/spec/lib/extensions/hash_spec.rb +6 -5
- data/spec/lib/extensions/module_spec.rb +6 -6
- data/spec/lib/extensions/object_spec.rb +9 -8
- data/spec/lib/extensions/string_spec.rb +1 -1
- data/spec/lib/generators/similarity/phonetic_spec.rb +11 -0
- data/spec/lib/index_realtime_spec.rb +5 -5
- data/spec/lib/interfaces/{live_parameters_spec.rb → live_parameters/master_child_spec.rb} +26 -26
- data/spec/lib/interfaces/live_parameters/unicorn_spec.rb +160 -0
- data/spec/lib/loader_spec.rb +65 -25
- data/spec/lib/query/allocation_spec.rb +25 -22
- data/spec/lib/query/combinations_spec.rb +13 -36
- data/spec/lib/query/token_spec.rb +144 -131
- data/spec/lib/query/tokens_spec.rb +14 -0
- data/spec/lib/results_spec.rb +14 -8
- data/spec/lib/search_spec.rb +1 -1
- data/spec/lib/sinatra_spec.rb +8 -8
- metadata +28 -91
- data/lib/picky/adapters/rack.rb +0 -34
- data/lib/picky/adapters/rack/base.rb +0 -27
- data/lib/picky/adapters/rack/live_parameters.rb +0 -37
- data/lib/picky/adapters/rack/search.rb +0 -67
- data/lib/picky/application.rb +0 -268
- data/lib/picky/frontend_adapters/rack.rb +0 -161
- data/lib/picky/interfaces/live_parameters.rb +0 -187
- data/lib/picky/sources/base.rb +0 -92
- data/lib/picky/sources/couch.rb +0 -76
- data/lib/picky/sources/csv.rb +0 -83
- data/lib/picky/sources/db.rb +0 -189
- data/lib/picky/sources/delicious.rb +0 -63
- data/lib/picky/sources/mongo.rb +0 -80
- data/lib/picky/wrappers/category/location.rb +0 -38
- data/lib/tasks/routes.rake +0 -8
- data/spec/lib/adapters/rack/base_spec.rb +0 -24
- data/spec/lib/adapters/rack/live_parameters_spec.rb +0 -26
- data/spec/lib/adapters/rack/query_spec.rb +0 -39
- data/spec/lib/application_spec.rb +0 -155
- data/spec/lib/frontend_adapters/rack_spec.rb +0 -294
- data/spec/lib/sources/base_spec.rb +0 -53
- data/spec/lib/sources/couch_spec.rb +0 -114
- data/spec/lib/sources/csv_spec.rb +0 -89
- data/spec/lib/sources/db_spec.rb +0 -125
- data/spec/lib/sources/delicious_spec.rb +0 -94
- data/spec/lib/sources/mongo_spec.rb +0 -50
|
@@ -219,7 +219,7 @@ describe "Realtime Indexing" do
|
|
|
219
219
|
|
|
220
220
|
index.replace Book.new(1, "Title New", "Author New")
|
|
221
221
|
|
|
222
|
-
books.search('Nuw~').ids.should == [1
|
|
222
|
+
books.search('Nuw~').ids.should == [1]
|
|
223
223
|
end
|
|
224
224
|
it 'handles more complex cases' do
|
|
225
225
|
books.search('Now~').ids.should == []
|
|
@@ -443,7 +443,7 @@ describe "Realtime Indexing" do
|
|
|
443
443
|
|
|
444
444
|
index.replace Book.new("one", "Title New", "Author New")
|
|
445
445
|
|
|
446
|
-
books.search('Nuw~').ids.should == [:one
|
|
446
|
+
books.search('Nuw~').ids.should == [:one]
|
|
447
447
|
end
|
|
448
448
|
it 'handles more complex cases' do
|
|
449
449
|
books.search('Now~').ids.should == []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
#
|
|
3
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
describe "Speccing Ruby for speed" do
|
|
6
6
|
describe "various versions for allocation id concatenating – with symbols" do
|
|
@@ -91,5 +91,5 @@ describe "Speccing Ruby for speed" do
|
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
end
|
|
@@ -172,7 +172,7 @@ describe 'Search#terminate_early' do
|
|
|
172
172
|
fast = performance_of do
|
|
173
173
|
try_fast.search 'hello hello'
|
|
174
174
|
end
|
|
175
|
-
(slow/fast).should >= 1.
|
|
175
|
+
(slow/fast).should >= 1.2
|
|
176
176
|
|
|
177
177
|
try_slow = Picky::Search.new index
|
|
178
178
|
slow = performance_of do
|
|
@@ -184,7 +184,7 @@ describe 'Search#terminate_early' do
|
|
|
184
184
|
fast = performance_of do
|
|
185
185
|
try_fast.search 'hello hello hello'
|
|
186
186
|
end
|
|
187
|
-
(slow/fast).should >= 1.
|
|
187
|
+
(slow/fast).should >= 1.4
|
|
188
188
|
|
|
189
189
|
try_slow = Picky::Search.new index
|
|
190
190
|
slow = performance_of do
|
|
@@ -196,7 +196,7 @@ describe 'Search#terminate_early' do
|
|
|
196
196
|
fast = performance_of do
|
|
197
197
|
try_fast.search 'hello hello hello hello'
|
|
198
198
|
end
|
|
199
|
-
(slow/fast).should >=
|
|
199
|
+
(slow/fast).should >= 1.7
|
|
200
200
|
end
|
|
201
201
|
|
|
202
202
|
end
|
data/spec/lib/analytics_spec.rb
CHANGED
data/spec/lib/analyzer_spec.rb
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
#
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
|
+
require_relative '../../lib/picky/analyzer'
|
|
6
|
+
|
|
5
7
|
describe Analyzer do
|
|
6
|
-
|
|
8
|
+
|
|
7
9
|
let(:analyzer) { described_class.new }
|
|
8
|
-
|
|
10
|
+
|
|
9
11
|
context 'after initialize' do
|
|
10
12
|
it 'sets the comments' do
|
|
11
13
|
analyzer.comments.should == []
|
|
@@ -14,5 +16,5 @@ describe Analyzer do
|
|
|
14
16
|
analyzer.analysis.should == {}
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
|
-
|
|
19
|
+
|
|
18
20
|
end
|
|
@@ -1,26 +1,44 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Picky::Categories do
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
context "with real categories" do
|
|
6
6
|
before(:each) do
|
|
7
7
|
@index1 = Picky::Index.new :name
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
@category1 = Picky::Category.new :category1, @index1
|
|
10
|
+
@category2 = Picky::Category.new :category2, @index1
|
|
11
|
+
@category3 = Picky::Category.new :category3, @index1
|
|
12
|
+
|
|
9
13
|
@categories = described_class.new
|
|
10
|
-
@categories <<
|
|
11
|
-
@categories <<
|
|
12
|
-
@categories <<
|
|
14
|
+
@categories << @category1
|
|
15
|
+
@categories << @category2
|
|
16
|
+
@categories << @category3
|
|
13
17
|
end
|
|
14
18
|
describe "similar_possible_for" do
|
|
15
19
|
before(:each) do
|
|
16
20
|
@token = Picky::Query::Token.processed 'similar~', 'Similar~'
|
|
17
21
|
end
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
context 'with nothing similar' do
|
|
23
|
+
it "returns possible categories" do
|
|
24
|
+
@categories.similar_possible_for(@token).should == []
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
context 'with some similar' do
|
|
28
|
+
before(:each) do
|
|
29
|
+
@bundle1 = stub :bundle1, :similar => ['similar', 'text'], :weight => 1, :identifier => ''
|
|
30
|
+
@category1.stub! :bundle_for => @bundle1
|
|
31
|
+
end
|
|
32
|
+
# it "returns possible categories" do
|
|
33
|
+
# @categories.similar_possible_for(@token).should == [
|
|
34
|
+
# Picky::Query::Combination.new(Picky::Query::Token.new('similar', 'similar', @category1), @category1),
|
|
35
|
+
# Picky::Query::Combination.new(Picky::Query::Token.new('text', 'text', @category1), @category1)
|
|
36
|
+
# ]
|
|
37
|
+
# end
|
|
20
38
|
end
|
|
21
39
|
end
|
|
22
40
|
end
|
|
23
|
-
|
|
41
|
+
|
|
24
42
|
describe 'clear_categories' do
|
|
25
43
|
before(:each) do
|
|
26
44
|
@categories = described_class.new
|
|
@@ -31,34 +49,34 @@ describe Picky::Categories do
|
|
|
31
49
|
end
|
|
32
50
|
it "isn't clear anymore after adding" do
|
|
33
51
|
@categories << stub(:category, :name => :some_name)
|
|
34
|
-
|
|
52
|
+
|
|
35
53
|
@categories.categories.should_not be_empty
|
|
36
54
|
@categories.category_hash.should_not be_empty
|
|
37
55
|
end
|
|
38
56
|
it "is clear again after clearing" do
|
|
39
57
|
@categories << stub(:category, :name => :some_name)
|
|
40
|
-
|
|
58
|
+
|
|
41
59
|
@categories.clear_categories
|
|
42
|
-
|
|
60
|
+
|
|
43
61
|
@categories.categories.should be_empty
|
|
44
|
-
@categories.category_hash.should be_empty
|
|
62
|
+
@categories.category_hash.should be_empty
|
|
45
63
|
end
|
|
46
64
|
end
|
|
47
|
-
|
|
65
|
+
|
|
48
66
|
context 'without options' do
|
|
49
67
|
before(:each) do
|
|
50
68
|
@index1 = Picky::Index.new :some_index
|
|
51
|
-
|
|
69
|
+
|
|
52
70
|
@category1 = Picky::Category.new :category1, @index1
|
|
53
71
|
@category2 = Picky::Category.new :category2, @index1
|
|
54
72
|
@category3 = Picky::Category.new :category3, @index1
|
|
55
|
-
|
|
73
|
+
|
|
56
74
|
@categories = described_class.new
|
|
57
75
|
@categories << @category1
|
|
58
76
|
@categories << @category2
|
|
59
77
|
@categories << @category3
|
|
60
78
|
end
|
|
61
|
-
|
|
79
|
+
|
|
62
80
|
describe "possible_combinations" do
|
|
63
81
|
before(:each) do
|
|
64
82
|
@token = stub :token
|
|
@@ -69,7 +87,7 @@ describe Picky::Categories do
|
|
|
69
87
|
end
|
|
70
88
|
it "calls the right method" do
|
|
71
89
|
@categories.should_receive(:similar_possible_for).once.with @token
|
|
72
|
-
|
|
90
|
+
|
|
73
91
|
@categories.possible_combinations @token
|
|
74
92
|
end
|
|
75
93
|
end
|
|
@@ -79,12 +97,12 @@ describe Picky::Categories do
|
|
|
79
97
|
end
|
|
80
98
|
it "calls the right method" do
|
|
81
99
|
@categories.should_receive(:possible_for).once.with @token
|
|
82
|
-
|
|
100
|
+
|
|
83
101
|
@categories.possible_combinations @token
|
|
84
102
|
end
|
|
85
103
|
end
|
|
86
104
|
end
|
|
87
|
-
|
|
105
|
+
|
|
88
106
|
describe 'possible_for' do
|
|
89
107
|
context 'without preselected categories' do
|
|
90
108
|
context 'user defined exists' do
|
|
@@ -138,5 +156,5 @@ describe Picky::Categories do
|
|
|
138
156
|
end
|
|
139
157
|
|
|
140
158
|
end
|
|
141
|
-
|
|
159
|
+
|
|
142
160
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
#
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Picky::Category::Location do
|
|
6
|
+
|
|
7
|
+
let(:category) do
|
|
8
|
+
category = Class.new do
|
|
9
|
+
attr_accessor :exact, :partial
|
|
10
|
+
end.new
|
|
11
|
+
category.exact = :exact
|
|
12
|
+
described_class.install_on(category, 1, 1, 1)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe 'tokenizer' do
|
|
16
|
+
it 'installs a basic tokenizer' do
|
|
17
|
+
category.tokenizer.should be_kind_of(Picky::Tokenizer)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'bundles' do
|
|
22
|
+
it 'installs an exact bundle' do
|
|
23
|
+
category.exact.should be_kind_of(Picky::Wrappers::Bundle::Location)
|
|
24
|
+
end
|
|
25
|
+
it 'installs an partial bundle' do
|
|
26
|
+
category.partial.should be_kind_of(Picky::Wrappers::Bundle::Location)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
@@ -3,10 +3,10 @@ require 'spec_helper'
|
|
|
3
3
|
describe Hash do
|
|
4
4
|
|
|
5
5
|
describe "to_json" do
|
|
6
|
-
|
|
6
|
+
let(:obj) do
|
|
7
7
|
# A very realistic example.
|
|
8
8
|
#
|
|
9
|
-
|
|
9
|
+
{ :allocations => [
|
|
10
10
|
['c', 17.53, 275179, [["name","s*","s"]],[]],
|
|
11
11
|
['c', 15.01, 164576, [["category","s*","s"]],[]],
|
|
12
12
|
['p', 12.94, 415634, [["street","s*","s"]],[]],
|
|
@@ -27,13 +27,14 @@ describe Hash do
|
|
|
27
27
|
}
|
|
28
28
|
end
|
|
29
29
|
it "should be correct" do
|
|
30
|
-
|
|
30
|
+
obj.to_json.should == '{"allocations":[["c",17.53,275179,[["name","s*","s"]],[]],["c",15.01,164576,[["category","s*","s"]],[]],["p",12.94,415634,[["street","s*","s"]],[]],["p",12.89,398247,[["name","s*","s"]],[]],["p",12.67,318912,[["city","s*","s"]],[]],["p",12.37,235933,[["first_name","s*","s"]],[]],["p",11.76,128259,[["maiden_name","s*","s"]],[]],["p",11.73,124479,[["occupation","s*","s"]],[]],["c",11.35,84807,[["street","s*","s"]],[]],["c",11.15,69301,[["city","s*","s"]],[]],["p",4.34,77,[["street_number","s*","s"]],[]],["c",2.08,8,[["street_number","s*","s"]],[]],["c",1.61,5,[["adword","s*","s"]],[]]],"offset":0,"duration":0.04,"total":2215417}'
|
|
31
31
|
end
|
|
32
32
|
it "should take options" do
|
|
33
|
-
lambda {
|
|
33
|
+
lambda { obj.to_json(:some => :option) }.should_not raise_error
|
|
34
34
|
end
|
|
35
35
|
it "should be fast" do
|
|
36
|
-
|
|
36
|
+
obj.to_json # Prerun
|
|
37
|
+
performance_of { obj.to_json }.should < 0.000065
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
|
|
@@ -6,21 +6,21 @@ describe Module do
|
|
|
6
6
|
context "with correct params" do
|
|
7
7
|
before(:each) do
|
|
8
8
|
@klass = Class.new do
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
each_delegate :bli, :bla, :blu, :to => :@some_enumerable
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
def initialize some_enumerable
|
|
13
13
|
@some_enumerable = some_enumerable
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
it 'should send each a bli' do
|
|
19
19
|
bli = stub :bli
|
|
20
20
|
delegating = @klass.new [bli, bli, bli, bli]
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
bli.should_receive(:bli).exactly(4).times
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
delegating.bli
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -34,5 +34,5 @@ describe Module do
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
end
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Object do
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
context 'basic object' do
|
|
6
6
|
let(:object) { described_class.new }
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
describe "exclaim" do
|
|
9
9
|
it "delegates to puts" do
|
|
10
|
-
|
|
10
|
+
STDOUT.should_receive(:puts).once.with :bla
|
|
11
|
+
STDOUT.should_receive(:flush).once.with
|
|
11
12
|
|
|
12
13
|
object.exclaim :bla
|
|
13
14
|
end
|
|
@@ -24,17 +25,17 @@ describe Object do
|
|
|
24
25
|
|
|
25
26
|
describe 'warn_gem_missing' do
|
|
26
27
|
it 'should warn right' do
|
|
27
|
-
object.should_receive(:warn).once.with "gnorf gem missing!\nTo use gnarble gnarf, you need to:\n 1. Add the following line to Gemfile:\n gem 'gnorf'\n or\n require 'gnorf'\n for example
|
|
28
|
+
object.should_receive(:warn).once.with "gnorf gem missing!\nTo use gnarble gnarf, you need to:\n 1. Add the following line to Gemfile:\n gem 'gnorf'\n or\n require 'gnorf'\n for example at the top of your app.rb file.\n 2. Then, run:\n bundle update\n"
|
|
28
29
|
|
|
29
30
|
object.warn_gem_missing 'gnorf', 'gnarble gnarf'
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
|
-
|
|
34
|
+
|
|
34
35
|
describe 'indented_to_s' do
|
|
35
36
|
describe String do
|
|
36
37
|
let(:string) { String.new("Hello\nTest") }
|
|
37
|
-
|
|
38
|
+
|
|
38
39
|
it 'indents a default amount' do
|
|
39
40
|
string.indented_to_s.should == " Hello\n Test"
|
|
40
41
|
end
|
|
@@ -47,7 +48,7 @@ describe Object do
|
|
|
47
48
|
end
|
|
48
49
|
describe Array do
|
|
49
50
|
let(:array) { Array.new(["Hello", "Test"]) }
|
|
50
|
-
|
|
51
|
+
|
|
51
52
|
it 'indents a default amount' do
|
|
52
53
|
array.indented_to_s.should == " Hello\n Test"
|
|
53
54
|
end
|
|
@@ -56,5 +57,5 @@ describe Object do
|
|
|
56
57
|
end
|
|
57
58
|
end
|
|
58
59
|
end
|
|
59
|
-
|
|
60
|
+
|
|
60
61
|
end
|
|
@@ -13,7 +13,7 @@ describe String do
|
|
|
13
13
|
performance_of { @token.each_subtoken { |subtoken| } }.should < 0.00065
|
|
14
14
|
end
|
|
15
15
|
it 'is fast enough' do
|
|
16
|
-
performance_of { @token.each_intoken { |intoken| } }.should < 0.025
|
|
16
|
+
performance_of { @token.each_intoken { |intoken| } }.should < 0.025
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -10,6 +10,17 @@ describe Picky::Generators::Similarity::Phonetic do
|
|
|
10
10
|
}.to raise_error("In Picky 2.0+, the Similarity::Phonetic has been renamed to Similarity::DoubleMetaphone. Please use that one. Thanks!")
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
it "raises when you don't have the text gem" do
|
|
14
|
+
instance = Class.new(described_class).allocate
|
|
15
|
+
|
|
16
|
+
instance.should_receive(:require).any_number_of_times.and_raise LoadError
|
|
17
|
+
|
|
18
|
+
instance.should_receive(:warn).once.with "text gem missing!\nTo use a phonetic Similarity, you need to:\n 1. Add the following line to Gemfile:\n gem 'text'\n or\n require 'text'\n for example at the top of your app.rb file.\n 2. Then, run:\n bundle update\n"
|
|
19
|
+
instance.should_receive(:exit).once.with 1
|
|
20
|
+
|
|
21
|
+
instance.send :initialize
|
|
22
|
+
end
|
|
23
|
+
|
|
13
24
|
describe 'sort!' do
|
|
14
25
|
let(:phonetic) { described_class.allocate }
|
|
15
26
|
it 'sorts correctly' do
|
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
|
4
4
|
|
|
5
5
|
describe Picky::Index, "Realtime API" do
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
RealtimeThing = Struct.new :id, :text
|
|
8
8
|
|
|
9
9
|
let(:index) do
|
|
10
10
|
described_class.new :some_index_name do
|
|
@@ -13,22 +13,22 @@ describe Picky::Index, "Realtime API" do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'offers an add method' do
|
|
16
|
-
index.add
|
|
16
|
+
index.add RealtimeThing.new(1, 'text')
|
|
17
17
|
end
|
|
18
18
|
it 'offers a remove method' do
|
|
19
19
|
index.remove 1
|
|
20
20
|
end
|
|
21
21
|
it 'offers a replace method' do
|
|
22
|
-
index.replace
|
|
22
|
+
index.replace RealtimeThing.new(1, 'text')
|
|
23
23
|
end
|
|
24
24
|
it 'offers a << method' do
|
|
25
|
-
index <<
|
|
25
|
+
index << RealtimeThing.new(1, 'text')
|
|
26
26
|
end
|
|
27
27
|
# it 'offers a >> method' do
|
|
28
28
|
# Thing.new(1, 'text') >> index # I mean, as long as we're dreaming.
|
|
29
29
|
# end
|
|
30
30
|
it 'offers an unshift method' do
|
|
31
|
-
index.unshift
|
|
31
|
+
index.unshift RealtimeThing.new(1, 'text')
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
end
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
#
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
|
-
describe Picky::Interfaces::LiveParameters do
|
|
6
|
-
|
|
5
|
+
describe Picky::Interfaces::LiveParameters::MasterChild do
|
|
6
|
+
|
|
7
7
|
before(:each) do
|
|
8
8
|
@parent = stub :parent
|
|
9
9
|
@child = stub :child
|
|
@@ -11,13 +11,13 @@ describe Picky::Interfaces::LiveParameters do
|
|
|
11
11
|
@parameters = described_class.new
|
|
12
12
|
@parameters.stub! :exclaim
|
|
13
13
|
end
|
|
14
|
-
|
|
15
|
-
describe Picky::Interfaces::LiveParameters::CouldNotUpdateConfigurationError do
|
|
14
|
+
|
|
15
|
+
describe Picky::Interfaces::LiveParameters::MasterChild::CouldNotUpdateConfigurationError do
|
|
16
16
|
before(:each) do
|
|
17
|
-
@error = Picky::Interfaces::LiveParameters::CouldNotUpdateConfigurationError.new :some_key, 'some message'
|
|
17
|
+
@error = Picky::Interfaces::LiveParameters::MasterChild::CouldNotUpdateConfigurationError.new :some_key, 'some message'
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
describe 'querying_removes_characters' do
|
|
22
22
|
it 'works' do
|
|
23
23
|
expect do
|
|
@@ -39,7 +39,7 @@ describe Picky::Interfaces::LiveParameters do
|
|
|
39
39
|
end.to_not raise_error
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
describe 'parameters' do
|
|
44
44
|
context 'all goes well' do
|
|
45
45
|
it 'does a few things in order' do
|
|
@@ -47,45 +47,45 @@ describe Picky::Interfaces::LiveParameters do
|
|
|
47
47
|
@parameters.should_receive(:try_updating_configuration_with).once.with(:a => :b).ordered
|
|
48
48
|
@parameters.should_receive(:write_parent).once.with(:a => :b).ordered
|
|
49
49
|
@parameters.should_receive(:extract_configuration).once.with().ordered
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
@parameters.parameters :a => :b
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
context 'updating failed' do
|
|
55
55
|
before(:each) do
|
|
56
|
-
@parameters.should_receive(:try_updating_configuration_with).and_raise Picky::Interfaces::LiveParameters::CouldNotUpdateConfigurationError.new(:a, 'hello')
|
|
56
|
+
@parameters.should_receive(:try_updating_configuration_with).and_raise Picky::Interfaces::LiveParameters::MasterChild::CouldNotUpdateConfigurationError.new(:a, 'hello')
|
|
57
57
|
end
|
|
58
58
|
it 'kills itself and returns' do
|
|
59
59
|
@parameters.should_receive(:close_child).once.ordered
|
|
60
60
|
@parameters.should_receive(:harakiri).once.ordered
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
@parameters.parameters( :a => :b ).should == { :a => :ERROR }
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
describe 'harakiri' do
|
|
68
68
|
before(:each) do
|
|
69
69
|
Process.stub! :pid => :some_pid
|
|
70
70
|
end
|
|
71
71
|
it 'kills itself' do
|
|
72
72
|
Process.should_receive(:kill).once.with :QUIT, :some_pid
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
@parameters.harakiri
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
describe 'write_parent' do
|
|
79
79
|
before(:each) do
|
|
80
80
|
Process.stub! :pid => :some_pid
|
|
81
81
|
end
|
|
82
82
|
it 'calls the parent' do
|
|
83
83
|
@parent.should_receive(:write).once.with "[:some_pid, {:a=>:b}];;;"
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
@parameters.write_parent :a => :b
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
describe 'close_child' do
|
|
90
90
|
context 'child is closed' do
|
|
91
91
|
before(:each) do
|
|
@@ -93,7 +93,7 @@ describe Picky::Interfaces::LiveParameters do
|
|
|
93
93
|
end
|
|
94
94
|
it 'does not receive close' do
|
|
95
95
|
@child.should_receive(:close).never
|
|
96
|
-
|
|
96
|
+
|
|
97
97
|
@parameters.close_child
|
|
98
98
|
end
|
|
99
99
|
end
|
|
@@ -103,12 +103,12 @@ describe Picky::Interfaces::LiveParameters do
|
|
|
103
103
|
end
|
|
104
104
|
it 'does receives close' do
|
|
105
105
|
@child.should_receive(:close).once.with()
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
@parameters.close_child
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
describe 'kill_worker' do
|
|
113
113
|
context 'all goes well' do
|
|
114
114
|
it 'uses Process.kill' do
|
|
@@ -120,14 +120,14 @@ describe Picky::Interfaces::LiveParameters do
|
|
|
120
120
|
context 'there is no such process' do
|
|
121
121
|
it 'uses Process.kill' do
|
|
122
122
|
Process.should_receive(:kill).and_raise Errno::ESRCH.new
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
@parameters.should_receive(:remove_worker).once.with :some_pid
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
@parameters.kill_worker :some_signal, :some_pid
|
|
127
127
|
end
|
|
128
128
|
end
|
|
129
129
|
end
|
|
130
|
-
|
|
130
|
+
|
|
131
131
|
describe 'kill_each_worker_except' do
|
|
132
132
|
context 'worker pid in the worker pids' do
|
|
133
133
|
before(:each) do
|
|
@@ -136,10 +136,10 @@ describe Picky::Interfaces::LiveParameters do
|
|
|
136
136
|
it 'kills each except the one' do
|
|
137
137
|
@parameters.should_receive(:kill_worker).once.with(:KILL, 1)
|
|
138
138
|
@parameters.should_receive(:kill_worker).once.with(:KILL, 2)
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
@parameters.should_receive(:kill_worker).once.with(:KILL, 4)
|
|
141
|
-
|
|
142
|
-
@parameters.kill_each_worker_except 3
|
|
141
|
+
|
|
142
|
+
@parameters.kill_each_worker_except 3
|
|
143
143
|
end
|
|
144
144
|
end
|
|
145
145
|
context 'worker pid not in the worker pids (unrealistic, but...)' do
|
|
@@ -151,10 +151,10 @@ describe Picky::Interfaces::LiveParameters do
|
|
|
151
151
|
@parameters.should_receive(:kill_worker).once.with(:KILL, 2)
|
|
152
152
|
@parameters.should_receive(:kill_worker).once.with(:KILL, 3)
|
|
153
153
|
@parameters.should_receive(:kill_worker).once.with(:KILL, 4)
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
@parameters.kill_each_worker_except 5
|
|
156
156
|
end
|
|
157
157
|
end
|
|
158
158
|
end
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
end
|