picky 3.2.0 → 3.3.0

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.
Files changed (85) hide show
  1. data/aux/picky/cli.rb +3 -1
  2. data/lib/picky/backends/backend.rb +16 -0
  3. data/lib/picky/backends/file/basic.rb +18 -9
  4. data/lib/picky/backends/file/json.rb +1 -0
  5. data/lib/picky/backends/file.rb +8 -4
  6. data/lib/picky/backends/helpers/file.rb +6 -0
  7. data/lib/picky/backends/memory/basic.rb +10 -2
  8. data/lib/picky/backends/memory/json.rb +1 -6
  9. data/lib/picky/backends/memory/marshal.rb +1 -6
  10. data/lib/picky/backends/memory/text.rb +1 -0
  11. data/lib/picky/backends/memory.rb +8 -4
  12. data/lib/picky/backends/redis/basic.rb +12 -9
  13. data/lib/picky/backends/redis.rb +10 -4
  14. data/lib/picky/bundle.rb +14 -0
  15. data/lib/picky/bundle_indexed.rb +110 -0
  16. data/lib/picky/bundle_indexing.rb +177 -0
  17. data/lib/picky/bundle_realtime.rb +80 -0
  18. data/lib/picky/categories.rb +5 -1
  19. data/lib/picky/category.rb +12 -20
  20. data/lib/picky/category_indexed.rb +3 -6
  21. data/lib/picky/category_indexing.rb +19 -18
  22. data/lib/picky/category_realtime.rb +5 -10
  23. data/lib/picky/extensions/symbol.rb +1 -1
  24. data/lib/picky/generators/partial/default.rb +1 -1
  25. data/lib/picky/generators/partial/postfix.rb +30 -0
  26. data/lib/picky/generators/partial/substring.rb +8 -2
  27. data/lib/picky/index.rb +3 -3
  28. data/lib/picky/index_indexing.rb +3 -2
  29. data/lib/picky/indexers/base.rb +0 -8
  30. data/lib/picky/indexers/parallel.rb +1 -1
  31. data/lib/picky/loader.rb +15 -15
  32. data/lib/picky/query/qualifier_category_mapper.rb +1 -1
  33. data/lib/picky/rack/harakiri.rb +3 -1
  34. data/lib/picky/sources/db.rb +11 -0
  35. data/lib/picky/statistics.rb +2 -2
  36. data/lib/picky/tokenizer.rb +1 -1
  37. data/lib/picky/tokenizers/location.rb +1 -1
  38. data/lib/picky/wrappers/bundle/calculation.rb +45 -0
  39. data/lib/picky/wrappers/bundle/delegators.rb +69 -0
  40. data/lib/picky/wrappers/bundle/exact_partial.rb +38 -0
  41. data/lib/picky/{indexed/wrappers → wrappers}/bundle/location.rb +6 -4
  42. data/lib/picky/wrappers/bundle/wrapper.rb +29 -0
  43. data/lib/picky/wrappers/category/exact_first.rb +55 -0
  44. data/lib/picky/wrappers/category/location.rb +33 -0
  45. data/lib/picky/{sources/wrappers → wrappers/sources}/base.rb +7 -3
  46. data/lib/picky/{sources/wrappers → wrappers/sources}/location.rb +3 -3
  47. data/lib/picky.rb +10 -11
  48. data/spec/aux/picky/cli_spec.rb +5 -5
  49. data/spec/lib/backends/backend_spec.rb +39 -0
  50. data/spec/lib/backends/file/basic_spec.rb +59 -0
  51. data/spec/lib/backends/file_spec.rb +105 -0
  52. data/spec/lib/backends/memory/basic_spec.rb +43 -15
  53. data/spec/lib/backends/memory_spec.rb +108 -54
  54. data/spec/lib/backends/redis/basic_spec.rb +81 -57
  55. data/spec/lib/backends/redis_spec.rb +120 -66
  56. data/spec/lib/category_indexed_spec.rb +12 -12
  57. data/spec/lib/category_indexing_spec.rb +23 -23
  58. data/spec/lib/category_spec.rb +14 -14
  59. data/spec/lib/cores_spec.rb +2 -2
  60. data/spec/lib/extensions/object_spec.rb +7 -7
  61. data/spec/lib/generators/partial/postfix_spec.rb +131 -0
  62. data/spec/lib/generators/partial/substring_spec.rb +29 -4
  63. data/spec/lib/generators/weights_generator_spec.rb +3 -3
  64. data/spec/lib/index_indexing_spec.rb +11 -15
  65. data/spec/lib/index_spec.rb +8 -8
  66. data/spec/lib/indexed/bundle_realtime_spec.rb +18 -18
  67. data/spec/lib/indexed/bundle_spec.rb +21 -21
  68. data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +9 -9
  69. data/spec/lib/indexed/wrappers/bundle/wrapper_spec.rb +8 -8
  70. data/spec/lib/indexed/wrappers/exact_first_spec.rb +16 -16
  71. data/spec/lib/indexers/base_spec.rb +6 -25
  72. data/spec/lib/indexes_spec.rb +33 -22
  73. data/spec/lib/indexing/bundle_partial_generation_speed_spec.rb +2 -2
  74. data/spec/lib/indexing/bundle_spec.rb +27 -28
  75. data/spec/lib/sources/wrappers/base_spec.rb +7 -7
  76. data/spec/lib/sources/wrappers/location_spec.rb +8 -8
  77. metadata +48 -38
  78. data/lib/picky/indexed/bundle.rb +0 -125
  79. data/lib/picky/indexed/bundle_realtime.rb +0 -76
  80. data/lib/picky/indexed/wrappers/bundle/calculation.rb +0 -47
  81. data/lib/picky/indexed/wrappers/bundle/wrapper.rb +0 -47
  82. data/lib/picky/indexed/wrappers/category/location.rb +0 -31
  83. data/lib/picky/indexed/wrappers/exact_first.rb +0 -59
  84. data/lib/picky/indexing/bundle.rb +0 -183
  85. data/lib/picky/indexing/wrappers/category/location.rb +0 -29
@@ -0,0 +1,69 @@
1
+ module Picky
2
+
3
+ module Wrappers
4
+
5
+ module Bundle
6
+
7
+ module Delegator
8
+
9
+ delegate :inverted,
10
+ :weights,
11
+ :similarity,
12
+ :configuration,
13
+
14
+ :backup,
15
+ :restore,
16
+ :delete,
17
+
18
+ :raise_unless_cache_exists,
19
+ :raise_unless_index_exists,
20
+ :raise_unless_similarity_exists,
21
+
22
+ :similar,
23
+
24
+ :to => :bundle
25
+
26
+ end
27
+
28
+ module IndexingDelegator
29
+
30
+ delegate :[]=,
31
+ :analyze,
32
+ :dump,
33
+ :empty,
34
+ :empty_configuration,
35
+ :generate_caches_from_memory,
36
+ :generate_caches_from_source,
37
+ :generate_partial_from,
38
+ :retrieve,
39
+ :size,
40
+ :to => :bundle
41
+
42
+ end
43
+
44
+ module IndexedDelegator
45
+
46
+ delegate :[],
47
+ :clear,
48
+ :clear_inverted,
49
+ :clear_weights,
50
+ :clear_similarity,
51
+ :clear_configuration,
52
+ :identifier,
53
+ :ids,
54
+ :load,
55
+ :load_inverted,
56
+ :load_weights,
57
+ :load_similarity,
58
+ :load_configuration,
59
+ :name,
60
+ :weight,
61
+ :to => :bundle
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ #
3
+ module Picky
4
+
5
+ module Wrappers
6
+
7
+ module Bundle
8
+
9
+ # This index combines a partial and exact
10
+ # bundle such that a partial index will not
11
+ # be dumped or generated.
12
+ #
13
+ class ExactPartial
14
+
15
+ attr_reader :bundle
16
+
17
+ include Delegator
18
+ include IndexedDelegator
19
+
20
+ def initialize bundle
21
+ @bundle = bundle
22
+ end
23
+
24
+ def clear; end
25
+ def dump; end
26
+ def empty_configuration; end
27
+ def generate_caches_from_memory; end
28
+ def generate_partial_from arg; end
29
+ def index; end
30
+ def load; end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -1,6 +1,5 @@
1
1
  module Picky
2
2
 
3
- module Indexed
4
3
  module Wrappers
5
4
 
6
5
  module Bundle
@@ -30,17 +29,20 @@ module Picky
30
29
  # Load first the bundle, then extract the config.
31
30
  #
32
31
  bundle.load
33
- # THINK Can I move the to_f to the backend?
34
- #
35
32
  minimum = bundle[:location_minimum] && bundle[:location_minimum].to_f || raise("Configuration :location_minimum for #{bundle.identifier} missing. Did you run rake index already?")
36
33
  @calculation.minimum = minimum
37
34
  end
38
35
 
36
+ # Do not generate a partial.
37
+ #
38
+ def generate_partial_from unimportant
39
+ # Nothing.
40
+ end
41
+
39
42
  end
40
43
 
41
44
  end
42
45
 
43
- end
44
46
  end
45
47
 
46
48
  end
@@ -0,0 +1,29 @@
1
+ module Picky
2
+
3
+ module Wrappers
4
+
5
+ # Per Bundle wrappers.
6
+ #
7
+ module Bundle
8
+
9
+ # Base wrapper. Just delegates all methods to the bundle.
10
+ #
11
+ class Wrapper
12
+
13
+ include Delegator
14
+ include IndexingDelegator
15
+ include IndexedDelegator
16
+
17
+ attr_reader :bundle
18
+
19
+ def initialize bundle
20
+ @bundle = bundle
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ #
3
+ module Picky
4
+
5
+ module Wrappers
6
+
7
+ # This index combines an exact and partial index.
8
+ # It serves to order the results such that exact hits are found first.
9
+ #
10
+ class ExactFirst < Bundle
11
+
12
+ delegate :similar,
13
+ :identifier,
14
+ :name,
15
+ :to => :@exact
16
+ delegate :index,
17
+ :category,
18
+ :weight,
19
+ :generate_partial_from,
20
+ :generate_caches_from_memory,
21
+ :generate_derived,
22
+ :dump,
23
+ :load,
24
+ :to => :@partial
25
+
26
+ def initialize category
27
+ @exact = category.exact
28
+ @partial = category.partial
29
+ end
30
+
31
+ def self.wrap index_or_category
32
+ if index_or_category.respond_to? :categories
33
+ wrap_each_of index_or_category.categories
34
+ index_or_category
35
+ else
36
+ new index_or_category
37
+ end
38
+ end
39
+ def self.wrap_each_of categories
40
+ categories.categories.collect! { |category| new(category) }
41
+ end
42
+
43
+ def ids text
44
+ @exact.ids(text) + @partial.ids(text)
45
+ end
46
+
47
+ def weight text
48
+ [@exact.weight(text) || 0, @partial.weight(text) || 0].max
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,33 @@
1
+ module Picky
2
+ module Wrappers
3
+ module Category
4
+
5
+ module Location
6
+
7
+ # THINK Is this the best way to do this?
8
+ #
9
+ def self.wrap category, grid, precision = 1
10
+ wrapped_exact = Wrappers::Bundle::Location.new category.exact, grid: grid, precision: precision
11
+ new_source = Wrappers::Sources::Location.new category.source, grid, precision
12
+
13
+ category.class_eval do
14
+ define_method :exact do
15
+ wrapped_exact
16
+ end
17
+ define_method :partial do
18
+ wrapped_exact
19
+ end
20
+ def tokenizer
21
+ @tokenizer ||= Tokenizer.new
22
+ end
23
+ define_method :source do
24
+ new_source
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -1,12 +1,12 @@
1
1
  module Picky
2
2
 
3
- module Sources
3
+ module Wrappers
4
4
 
5
5
  # Source wrappers can be used to rewrite data before it goes into the index.
6
6
  #
7
7
  # For example if you want to normalize data.
8
8
  #
9
- module Wrappers # :nodoc:all
9
+ module Sources # :nodoc:all
10
10
 
11
11
  class Base
12
12
 
@@ -20,7 +20,11 @@ module Picky
20
20
 
21
21
  # Default is delegation for all methods
22
22
  #
23
- delegate :harvest, :connect_backend, :take_snapshot, :key_format, :to => :source
23
+ delegate :harvest,
24
+ :connect_backend,
25
+ :take_snapshot,
26
+ :key_format,
27
+ :to => :source
24
28
 
25
29
  end
26
30
 
@@ -1,8 +1,8 @@
1
1
  module Picky
2
2
 
3
- module Sources
3
+ module Wrappers
4
4
 
5
- module Wrappers
5
+ module Sources
6
6
 
7
7
  # Should this actually just be a tokenizer?
8
8
  #
@@ -44,7 +44,7 @@ module Picky
44
44
 
45
45
  # TODO Move to the right place.
46
46
  #
47
- category.indexing_exact[:location_minimum] = minimum
47
+ category.exact[:location_minimum] = minimum
48
48
  end
49
49
 
50
50
  end
data/lib/picky.rb CHANGED
@@ -1,19 +1,12 @@
1
1
  module Picky
2
2
 
3
- # This is only used in the classic project style.
4
- #
5
- class << self
6
- attr_accessor :logger
7
- end
8
-
9
3
  # External libraries.
10
4
  #
11
- require 'rack'
12
- require 'rack_fast_escape'
13
- require 'text'
14
- require 'yajl'
15
5
  require 'active_support/core_ext'
16
- require 'active_record'
6
+ require 'text'
7
+ require 'yajl' # TODO Maybe replace by multi_json.
8
+ require 'rack' # TODO Remove.
9
+ require 'rack_fast_escape' # TODO Remove.
17
10
 
18
11
  # Require the constants.
19
12
  #
@@ -32,4 +25,10 @@ module Picky
32
25
  #
33
26
  require ::File.expand_path '../picky/sinatra', __FILE__
34
27
 
28
+ # This is only used in the classic project style.
29
+ #
30
+ class << self
31
+ attr_accessor :logger
32
+ end
33
+
35
34
  end
@@ -11,7 +11,7 @@ describe Picky::CLI do
11
11
  describe '.mapping' do
12
12
  it 'returns the right mapping' do
13
13
  Picky::CLI.mapping.should == {
14
- :generate => [Picky::CLI::Generate, :"{sinatra_client,unicorn_server,empty_unicorn_server}", :app_directory_name],
14
+ :generate => [Picky::CLI::Generate, :"{client,server,sinatra_client,unicorn_server,all_in_one}", :app_directory_name],
15
15
  :help => [Picky::CLI::Help],
16
16
  :live => [Picky::CLI::Live, "host:port/path (default: localhost:8080/admin)", "port (default: 4568)"],
17
17
  :search => [Picky::CLI::Search, :url_or_path, 'amount of ids (default 20)'],
@@ -31,7 +31,7 @@ describe Picky::CLI do
31
31
  it 'calls help correctly' do
32
32
  Kernel.should_receive(:puts).once.with <<-HELP
33
33
  Possible commands:
34
- picky generate {sinatra_client,unicorn_server,empty_unicorn_server} app_directory_name
34
+ picky generate {client,server,sinatra_client,unicorn_server,all_in_one} app_directory_name
35
35
  picky help
36
36
  picky live [host:port/path (default: localhost:8080/admin)] [port (default: 4568)]
37
37
  picky search url_or_path [amount of ids (default 20)]
@@ -51,7 +51,7 @@ HELP
51
51
  cli.executor_class_for.should == [Picky::CLI::Help]
52
52
  end
53
53
  it 'returns Generator for generate' do
54
- cli.executor_class_for(:generate).should == [Picky::CLI::Generate, :'{sinatra_client,unicorn_server,empty_unicorn_server}', :"app_directory_name"]
54
+ cli.executor_class_for(:generate).should == [Picky::CLI::Generate, :'{client,server,sinatra_client,unicorn_server,all_in_one}', :"app_directory_name"]
55
55
  end
56
56
  it 'returns Help for help' do
57
57
  cli.executor_class_for(:help).should == [Picky::CLI::Help]
@@ -72,11 +72,11 @@ HELP
72
72
  end
73
73
 
74
74
  describe Picky::CLI::Live do
75
- let(:executor) { described_class.new }
75
+ let(:executor) { Picky::CLI::Live.new }
76
76
  end
77
77
 
78
78
  describe Picky::CLI::Base do
79
- let(:executor) { described_class.new }
79
+ let(:executor) { Picky::CLI::Base.new }
80
80
  describe 'usage' do
81
81
  it 'calls puts with an usage' do
82
82
  executor.should_receive(:puts).once.with "Usage:\n picky some_name param1 [param2]"
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Backends::Backend do
4
+
5
+ context 'without options' do
6
+ let(:backend) { described_class.new }
7
+
8
+ describe 'extract_lambda_or' do
9
+ it 'returns a given non-lambda' do
10
+ backend.extract_lambda_or(:thing).should == :thing
11
+ end
12
+ it 'calls a given lambda with the given args' do
13
+ lam = ->() do
14
+ :lam
15
+ end
16
+
17
+ backend.extract_lambda_or(lam).should == :lam
18
+ end
19
+ it 'calls a given lambda with the given args' do
20
+ lam = ->(arg1) do
21
+ arg1.should == 1
22
+ :lam
23
+ end
24
+
25
+ backend.extract_lambda_or(lam, 1).should == :lam
26
+ end
27
+ it 'calls a given lambda with the given args' do
28
+ lam = ->(arg1, arg2) do
29
+ arg1.should == 1
30
+ arg2.should == 2
31
+ :lam
32
+ end
33
+
34
+ backend.extract_lambda_or(lam, 1, 2).should == :lam
35
+ end
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Backends::File::Basic do
4
+
5
+ context 'without options' do
6
+ let(:basic) { described_class.new 'some/cache/path/to/file' }
7
+
8
+ describe 'empty' do
9
+ it 'returns the container that is used for indexing' do
10
+ basic.empty.should == {}
11
+ end
12
+ end
13
+
14
+ describe 'initial' do
15
+ it 'returns the container that is used for indexing' do
16
+ basic.initial.should == nil
17
+ end
18
+ end
19
+
20
+ describe 'backup_file_path_of' do
21
+ it 'returns a backup path relative to the path' do
22
+ basic.backup_file_path_of('some/path/to/some.memory.index').should == 'some/path/to/backup/some.memory.index'
23
+ end
24
+ end
25
+
26
+ describe 'backup_directory' do
27
+ it "returns the cache path's backup path" do
28
+ basic.backup_directory('some/cache/path/to/file').should == 'some/cache/path/to/backup'
29
+ end
30
+ end
31
+
32
+ describe 'to_s' do
33
+ it 'returns the cache path with the default file extension' do
34
+ basic.to_s.should == 'Picky::Backends::File::Basic(some/cache/path/to/file.file.index,some/cache/path/to/file.file_mapping.index.memory.json)'
35
+ end
36
+ end
37
+ end
38
+
39
+ context 'with options' do
40
+ let(:basic) do
41
+ described_class.new 'some/cache/path/to/file',
42
+ empty: [],
43
+ initial: []
44
+ end
45
+
46
+ describe 'empty' do
47
+ it 'returns the container that is used for indexing' do
48
+ basic.empty.should == []
49
+ end
50
+ end
51
+
52
+ describe 'initial' do
53
+ it 'returns the container that is used for indexing' do
54
+ basic.initial.should == []
55
+ end
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Backends::File do
4
+
5
+ context 'with options' do
6
+ before(:each) do
7
+ @backend = described_class.new inverted: Picky::Backends::File::Basic.new(:unimportant),
8
+ weights: Picky::Backends::File::Basic.new(:unimportant),
9
+ similarity: Picky::Backends::File::Basic.new(:unimportant),
10
+ configuration: Picky::Backends::File::Basic.new(:unimportant)
11
+
12
+ @backend.stub! :timed_exclaim
13
+ end
14
+
15
+ describe 'create_...' do
16
+ [
17
+ [:inverted, Picky::Backends::File::Basic],
18
+ [:weights, Picky::Backends::File::Basic],
19
+ [:similarity, Picky::Backends::File::Basic],
20
+ [:configuration, Picky::Backends::File::Basic]
21
+ ].each do |type, kind|
22
+ it "creates and returns a(n) #{type} index" do
23
+ @backend.send(:"create_#{type}",
24
+ stub(type, :index_path => "spec/test_directory/index/test/some_index/some_category_some_bundle_#{type}")
25
+ ).should be_kind_of(kind)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ context 'without options' do
32
+ before(:each) do
33
+ @backend = described_class.new
34
+
35
+ @backend.stub! :timed_exclaim
36
+ end
37
+
38
+ describe 'create_...' do
39
+ [
40
+ [:inverted, Picky::Backends::File::JSON],
41
+ [:weights, Picky::Backends::File::JSON],
42
+ [:similarity, Picky::Backends::File::JSON],
43
+ [:configuration, Picky::Backends::File::JSON]
44
+ ].each do |type, kind|
45
+ it "creates and returns a(n) #{type} index" do
46
+ @backend.send(:"create_#{type}",
47
+ stub(type, :index_path => "spec/test_directory/index/test/some_index/some_category_some_bundle_#{type}")
48
+ ).should be_kind_of(kind)
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "ids" do
54
+ before(:each) do
55
+ @combination1 = stub :combination1
56
+ @combination2 = stub :combination2
57
+ @combination3 = stub :combination3
58
+ @combinations = [@combination1, @combination2, @combination3]
59
+ end
60
+ it "should intersect correctly" do
61
+ @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
62
+ @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
63
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
64
+
65
+ @backend.ids(@combinations, :any, :thing).should == (1..10).to_a
66
+ end
67
+ it "should intersect symbol_keys correctly" do
68
+ @combination1.should_receive(:ids).once.with.and_return (:'00001'..:'10000').to_a
69
+ @combination2.should_receive(:ids).once.with.and_return (:'00001'..:'00100').to_a
70
+ @combination3.should_receive(:ids).once.with.and_return (:'00001'..:'00010').to_a
71
+
72
+ @backend.ids(@combinations, :any, :thing).should == (:'00001'..:'0010').to_a
73
+ end
74
+ it "should intersect correctly when intermediate intersect result is empty" do
75
+ @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
76
+ @combination2.should_receive(:ids).once.with.and_return (11..100).to_a
77
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
78
+
79
+ @backend.ids(@combinations, :any, :thing).should == []
80
+ end
81
+ it "should be fast" do
82
+ @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
83
+ @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
84
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
85
+
86
+ performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.004
87
+ end
88
+ it "should be fast" do
89
+ @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
90
+ @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
91
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
92
+
93
+ performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.00015
94
+ end
95
+ it "should be fast" do
96
+ @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
97
+ @combination2.should_receive(:ids).once.with.and_return (901..1000).to_a
98
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
99
+
100
+ performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.0001
101
+ end
102
+ end
103
+ end
104
+
105
+ end
@@ -2,29 +2,57 @@ require 'spec_helper'
2
2
 
3
3
  describe Picky::Backends::Memory::Basic do
4
4
 
5
- let(:basic) { described_class.new 'some/cache/path/to/file' }
5
+ context 'without options' do
6
+ let(:basic) { described_class.new 'some/cache/path/to/file' }
6
7
 
7
- describe 'empty' do
8
- it 'returns the container that is used for indexing' do
9
- basic.empty.should == {}
8
+ describe 'empty' do
9
+ it 'returns the container that is used for indexing' do
10
+ basic.empty.should == {}
11
+ end
12
+ end
13
+
14
+ describe 'initial' do
15
+ it 'returns the container that is used for indexing' do
16
+ basic.initial.should == {}
17
+ end
10
18
  end
11
- end
12
19
 
13
- describe 'backup_file_path_of' do
14
- it 'returns a backup path relative to the path' do
15
- basic.backup_file_path_of('some/path/to/some.memory.index').should == 'some/path/to/backup/some.memory.index'
20
+ describe 'backup_file_path_of' do
21
+ it 'returns a backup path relative to the path' do
22
+ basic.backup_file_path_of('some/path/to/some.memory.index').should == 'some/path/to/backup/some.memory.index'
23
+ end
24
+ end
25
+
26
+ describe 'backup_directory' do
27
+ it "returns the cache path's backup path" do
28
+ basic.backup_directory('some/cache/path/to/file').should == 'some/cache/path/to/backup'
29
+ end
16
30
  end
17
- end
18
31
 
19
- describe 'backup_directory' do
20
- it "returns the cache path's backup path" do
21
- basic.backup_directory('some/cache/path/to/file').should == 'some/cache/path/to/backup'
32
+ describe 'to_s' do
33
+ it 'returns the cache path with the default file extension' do
34
+ basic.to_s.should == 'Picky::Backends::Memory::Basic(some/cache/path/to/file.memory.index)'
35
+ end
22
36
  end
23
37
  end
24
38
 
25
- describe 'to_s' do
26
- it 'returns the cache path with the default file extension' do
27
- basic.to_s.should == 'Picky::Backends::Memory::Basic(some/cache/path/to/file.memory.index)'
39
+ context 'with options' do
40
+ let(:basic) do
41
+ described_class.new 'some/cache/path/to/file',
42
+ empty: [],
43
+ initial: []
44
+ end
45
+
46
+ describe 'empty' do
47
+ it 'returns the container that is used for indexing' do
48
+ basic.empty.should == []
49
+ end
50
+ end
51
+
52
+ describe 'initial' do
53
+ it 'returns the container that is used for indexing' do
54
+ basic.initial.should == []
55
+ end
28
56
  end
29
57
  end
30
58