picky 2.1.2 → 2.2.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 (82) hide show
  1. data/{lib → aux}/picky/cli.rb +50 -38
  2. data/bin/picky +1 -1
  3. data/lib/picky/application.rb +5 -2
  4. data/lib/picky/index/base.rb +88 -25
  5. data/lib/picky/index/memory.rb +8 -8
  6. data/lib/picky/index/redis.rb +8 -8
  7. data/lib/picky/index_bundle.rb +2 -2
  8. data/lib/picky/indexing/indexes.rb +6 -6
  9. data/lib/picky/internals/calculations/location.rb +54 -42
  10. data/lib/picky/internals/index/backend.rb +21 -21
  11. data/lib/picky/internals/index/file/text.rb +11 -11
  12. data/lib/picky/internals/index/files.rb +6 -6
  13. data/lib/picky/internals/index/redis.rb +14 -14
  14. data/lib/picky/internals/indexed/bundle/base.rb +2 -2
  15. data/lib/picky/internals/indexed/bundle/redis.rb +3 -3
  16. data/lib/picky/internals/indexed/category.rb +8 -9
  17. data/lib/picky/internals/indexed/wrappers/bundle/calculation.rb +25 -23
  18. data/lib/picky/internals/indexed/wrappers/bundle/location.rb +36 -34
  19. data/lib/picky/internals/indexed/wrappers/bundle/wrapper.rb +35 -33
  20. data/lib/picky/internals/indexed/wrappers/category/location.rb +27 -0
  21. data/lib/picky/internals/indexers/base.rb +28 -0
  22. data/lib/picky/internals/indexers/parallel.rb +64 -0
  23. data/lib/picky/internals/indexers/serial.rb +20 -29
  24. data/lib/picky/internals/indexing/bundle/base.rb +2 -2
  25. data/lib/picky/internals/indexing/bundle/super_base.rb +3 -3
  26. data/lib/picky/internals/indexing/category.rb +30 -27
  27. data/lib/picky/internals/indexing/index.rb +82 -27
  28. data/lib/picky/internals/indexing/wrappers/category/location.rb +27 -0
  29. data/lib/picky/internals/query/indexes.rb +1 -1
  30. data/lib/picky/internals/query/qualifiers.rb +7 -6
  31. data/lib/picky/internals/query/weights.rb +6 -0
  32. data/lib/picky/internals/shared/category.rb +52 -0
  33. data/lib/picky/internals/tokenizers/base.rb +1 -1
  34. data/lib/picky/internals/tokenizers/location.rb +54 -0
  35. data/lib/picky/loader.rb +16 -3
  36. data/lib/picky/no_source_specified_exception.rb +3 -0
  37. data/lib/picky/search.rb +44 -5
  38. data/lib/picky/sources/base.rb +2 -2
  39. data/lib/picky/sources/couch.rb +1 -1
  40. data/lib/picky/sources/csv.rb +1 -1
  41. data/lib/picky/sources/db.rb +9 -9
  42. data/lib/picky/sources/delicious.rb +1 -1
  43. data/lib/picky/sources/wrappers/base.rb +12 -13
  44. data/lib/picky/sources/wrappers/location.rb +24 -54
  45. data/lib/tasks/search.rake +4 -5
  46. data/lib/tasks/todo.rake +1 -1
  47. data/spec/{lib → aux/picky}/cli_spec.rb +13 -8
  48. data/spec/lib/application_spec.rb +21 -16
  49. data/spec/lib/index/base_spec.rb +74 -27
  50. data/spec/lib/index/redis_spec.rb +1 -1
  51. data/spec/lib/index_bundle_spec.rb +1 -1
  52. data/spec/lib/indexing/indexes_spec.rb +5 -5
  53. data/spec/lib/internals/calculations/location_spec.rb +14 -3
  54. data/spec/lib/internals/index/files_spec.rb +2 -3
  55. data/spec/lib/internals/index/redis_spec.rb +122 -49
  56. data/spec/lib/internals/indexed/bundle/memory_spec.rb +4 -6
  57. data/spec/lib/internals/indexed/bundle/redis_spec.rb +2 -3
  58. data/spec/lib/internals/indexed/wrappers/bundle/calculation_spec.rb +3 -3
  59. data/spec/lib/internals/indexed/wrappers/bundle/wrapper_spec.rb +3 -3
  60. data/spec/lib/internals/indexers/parallel_spec.rb +36 -0
  61. data/spec/lib/internals/indexers/serial_spec.rb +6 -14
  62. data/spec/lib/internals/indexing/bundle/memory_partial_generation_speed_spec.rb +2 -3
  63. data/spec/lib/internals/indexing/bundle/memory_spec.rb +5 -6
  64. data/spec/lib/internals/indexing/bundle/redis_spec.rb +5 -6
  65. data/spec/lib/internals/indexing/category_spec.rb +21 -6
  66. data/spec/lib/internals/indexing/index_spec.rb +43 -7
  67. data/spec/lib/query/indexes_spec.rb +1 -1
  68. data/spec/lib/search_spec.rb +51 -2
  69. data/spec/lib/sources/couch_spec.rb +6 -6
  70. data/spec/lib/sources/csv_spec.rb +4 -4
  71. data/spec/lib/sources/db_spec.rb +13 -14
  72. data/spec/lib/sources/delicious_spec.rb +3 -3
  73. data/spec/lib/sources/wrappers/base_spec.rb +9 -10
  74. data/spec/lib/sources/wrappers/location_spec.rb +11 -23
  75. metadata +14 -15
  76. data/lib/picky/auxiliary/terminal.rb +0 -219
  77. data/lib/picky/internals/configuration/index.rb +0 -67
  78. data/lib/picky/internals/indexers/no_source_specified_error.rb +0 -7
  79. data/lib/picky/internals/indexing/categories.rb +0 -46
  80. data/spec/lib/auxiliary/terminal_spec.rb +0 -150
  81. data/spec/lib/internals/configuration/index_spec.rb +0 -80
  82. data/spec/lib/internals/indexing/categories_spec.rb +0 -49
@@ -30,7 +30,7 @@ module Sources
30
30
 
31
31
  # Harvests the data to index.
32
32
  #
33
- def harvest _, category
33
+ def harvest category
34
34
  get_data do |indexed_id, data|
35
35
  text = data[category.from]
36
36
  next unless text
@@ -1,28 +1,27 @@
1
1
  module Sources
2
-
2
+
3
3
  # Source wrappers can be used to rewrite data before it goes into the index.
4
4
  #
5
5
  # For example if you want to normalize data.
6
6
  #
7
7
  module Wrappers # :nodoc:all
8
-
8
+
9
9
  class Base
10
-
11
- attr_reader :backend, :category
12
-
10
+
11
+ attr_reader :source
12
+
13
13
  # Wraps an indexing category.
14
14
  #
15
- def initialize category
16
- @category = category
17
- @backend = category.source
15
+ def initialize source
16
+ @source = source
18
17
  end
19
-
18
+
20
19
  # Default is delegation for all methods
21
20
  #
22
- delegate :harvest, :connect_backend, :take_snapshot, :key_format, :to => :backend
23
-
21
+ delegate :harvest, :connect_backend, :take_snapshot, :key_format, :to => :source
22
+
24
23
  end
25
-
24
+
26
25
  end
27
-
26
+
28
27
  end
@@ -1,82 +1,52 @@
1
1
  module Sources
2
-
2
+
3
3
  module Wrappers
4
-
4
+
5
+ # Should this actually just be a tokenizer?
6
+ #
5
7
  class Location < Base
6
-
7
- attr_reader :precision, :grid
8
-
9
- # TODO Save min and grid!
10
- #
11
- def initialize category, options = {}
12
- super category
13
-
14
- @precision = extract_precision options
15
- @calculation = Calculations::Location.new extract_user_grid(options), @precision
16
- end
17
-
18
- #
19
- #
20
- def extract_user_grid options
21
- options[:grid] || raise("Option :grid needs to be passed to a location.")
8
+
9
+ attr_reader :calculation
10
+
11
+ def initialize source, grid, precision = 1
12
+ super source
13
+ @calculation = Internals::Calculations::Location.new grid, precision
22
14
  end
23
- # Extracts an amount of grids that this
24
- # Precision is given in a value.
25
- # 1 is low (up to 16.6% error), 5 is very high (up to 5% error).
26
- #
27
- # We don't recommend using values higher than 5.
28
- #
29
- # Default is 1.
15
+
16
+ # Yield the data (id, text for id) for the given category.
30
17
  #
31
- def extract_precision options
32
- options[:precision] || 1
33
- end
34
-
35
- # Yield the data (id, text for id) for the given type and category.
36
- #
37
- def harvest type, category
18
+ def harvest category
38
19
  minimum = 1.0/0
39
-
20
+
40
21
  # Cache. TODO Make option?
41
22
  #
42
23
  locations = []
43
-
24
+
44
25
  # Gather min/max.
45
26
  #
46
- backend.harvest type, category do |indexed_id, location|
27
+ source.harvest category do |indexed_id, location|
47
28
  location = location.to_f
48
29
  minimum = location if location < minimum
49
30
  locations << [indexed_id, location]
50
31
  end
51
-
52
- @calculation.minimum = minimum
53
-
32
+
33
+ calculation.minimum = minimum
34
+
54
35
  # Recalculate locations.
55
36
  #
56
37
  locations.each do |indexed_id, location|
57
- locations_for(@calculation.recalculate(location)).each do |new_location|
38
+ calculation.recalculated_range(location).each do |new_location|
58
39
  yield indexed_id, new_location.to_s
59
40
  end
60
41
  end
61
-
42
+
62
43
  # TODO Move to the right place.
63
44
  #
64
45
  category.exact[:location_minimum] = minimum
65
46
  end
66
-
67
- # Put location onto multiple places on a grid.
68
- #
69
- # Note: Always returns an integer.
70
- #
71
- def locations_for repositioned_location
72
- min_location = repositioned_location - precision
73
- max_location = repositioned_location + precision
74
-
75
- (min_location..max_location).to_a
76
- end
77
-
47
+
78
48
  end
79
-
49
+
80
50
  end
81
-
51
+
82
52
  end
@@ -2,9 +2,8 @@
2
2
  #
3
3
  desc 'Simple terminal search - pass it an URL to search on, e.g. /books.'
4
4
  task :search do
5
- load File.expand_path '../../picky/auxiliary/terminal.rb', __FILE__
6
- url_or_path = ARGV[1] || raise("Usage:\n rake search <URL> [<result ids>]\n E.g. rake search /books\n rake search localhost:8080/books 10")
7
- ids = ARGV[2]
8
- terminal = Terminal.new url_or_path, ids
9
- terminal.run
5
+ puts <<-DEPRECATED
6
+ Deprecated. New usage:
7
+ picky search <URL> [<result id amount = 20>]
8
+ DEPRECATED
10
9
  end
data/lib/tasks/todo.rake CHANGED
@@ -1,5 +1,5 @@
1
1
  desc "Finds where Picky still needs input from you."
2
- task :'to#{}do' do
2
+ task :"to#{}do" do
3
3
  if system "grep -e 'TODO.*' -n --color=always -R *"
4
4
  puts "Picky needs a bit of input from you there. Thanks."
5
5
  else
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  # We need to load the CLI file explicitly as the CLI is not loaded with the Loader (not needed in the server, only for script runs).
6
6
  #
7
- require File.expand_path '../../../lib/picky/cli', __FILE__
7
+ require File.expand_path '../../../../aux/picky/cli', __FILE__
8
8
 
9
9
  # TODO Finish this prototype Spec, redesign.
10
10
  #
@@ -15,8 +15,9 @@ describe Picky::CLI do
15
15
  Picky::CLI.mapping.should == {
16
16
  :generate => [Picky::CLI::Generate, :"{sinatra_client,unicorn_server,empty_unicorn_server}", :app_directory_name],
17
17
  :help => [Picky::CLI::Help],
18
- :stats => [Picky::CLI::Statistics, :"logfile (e.g. log/search.log)", "port (default: 4567)"],
19
- :live => [Picky::CLI::Live, "host:port/path (default: localhost:8080/admin)", "port (default: 4568)"]
18
+ :live => [Picky::CLI::Live, "host:port/path (default: localhost:8080/admin)", "port (default: 4568)"],
19
+ :search => [Picky::CLI::Search, :url_or_path, 'amount of ids (default 20)'],
20
+ :stats => [Picky::CLI::Statistics, :"logfile (e.g. log/search.log)", "port (default: 4567)"]
20
21
  }
21
22
  end
22
23
  end
@@ -34,8 +35,9 @@ describe Picky::CLI do
34
35
  Possible commands:
35
36
  picky generate {sinatra_client,unicorn_server,empty_unicorn_server} app_directory_name
36
37
  picky help
37
- picky stats logfile (e.g. log/search.log) [port (default: 4567)]
38
38
  picky live [host:port/path (default: localhost:8080/admin)] [port (default: 4568)]
39
+ picky search url_or_path [amount of ids (default 20)]
40
+ picky stats logfile (e.g. log/search.log) [port (default: 4567)]
39
41
  HELP
40
42
  cli.execute 'help'
41
43
  end
@@ -56,12 +58,15 @@ HELP
56
58
  it 'returns Help for help' do
57
59
  cli.executor_class_for(:help).should == [Picky::CLI::Help]
58
60
  end
59
- it 'returns Statistics for stats' do
60
- cli.executor_class_for(:stats).should == [Picky::CLI::Statistics, :"logfile (e.g. log/search.log)", "port (default: 4567)"]
61
- end
62
61
  it 'returns Live for live' do
63
62
  cli.executor_class_for(:live).should == [Picky::CLI::Live, "host:port/path (default: localhost:8080/admin)", "port (default: 4568)"]
64
63
  end
64
+ it 'returns Search for stats' do
65
+ cli.executor_class_for(:search).should == [Picky::CLI::Search, :url_or_path, "amount of ids (default 20)"]
66
+ end
67
+ it 'returns Statistics for stats' do
68
+ cli.executor_class_for(:stats).should == [Picky::CLI::Statistics, :"logfile (e.g. log/search.log)", "port (default: 4567)"]
69
+ end
65
70
  it 'returns Help for silly input' do
66
71
  cli.executor_class_for(:gagagagagagaga).should == [Picky::CLI::Help]
67
72
  end
@@ -76,7 +81,7 @@ HELP
76
81
  let(:executor) { described_class.new }
77
82
  describe 'usage' do
78
83
  it 'calls puts with an usage' do
79
- executor.should_receive(:puts).once.with "Usage\n picky some_name param1 [param2]"
84
+ executor.should_receive(:puts).once.with "Usage:\n picky some_name param1 [param2]"
80
85
 
81
86
  executor.usage :some_name, [:param1, 'param2']
82
87
  end
@@ -8,7 +8,7 @@ describe Application do
8
8
  it "should run ok" do
9
9
  lambda {
10
10
  class MinimalTestApplication < Application
11
- books = Index::Memory.new :books, Sources::DB.new('SELECT id, title FROM books', :file => 'app/db.yml')
11
+ books = Index::Memory.new :books, source: Sources::DB.new('SELECT id, title FROM books', :file => 'app/db.yml')
12
12
  books.define_category :title
13
13
 
14
14
  rack_adapter.stub! :exclaim # Stopping it from exclaiming.
@@ -24,23 +24,23 @@ describe Application do
24
24
  # Here we just test if the API can be called ok.
25
25
  #
26
26
  class TestApplication < Application
27
- default_indexing removes_characters: /[^a-zA-Z0-9\s\/\-\"\&\.]/,
28
- stopwords: /\b(and|the|of|it|in|for)\b/,
29
- splits_text_on: /[\s\/\-\"\&\.]/,
30
- removes_characters_after_splitting: /[\.]/,
31
- normalizes_words: [[/\$(\w+)/i, '\1 dollars']],
32
- reject_token_if: lambda { |token| token.blank? || token == :amistad }
27
+ indexing removes_characters: /[^a-zA-Z0-9\s\/\-\"\&\.]/,
28
+ stopwords: /\b(and|the|of|it|in|for)\b/,
29
+ splits_text_on: /[\s\/\-\"\&\.]/,
30
+ removes_characters_after_splitting: /[\.]/,
31
+ normalizes_words: [[/\$(\w+)/i, '\1 dollars']],
32
+ rejects_token_if: lambda { |token| token.blank? || token == :amistad }
33
33
 
34
- default_querying removes_characters: /[^a-zA-Z0-9äöü\s\/\-\,\&\"\~\*\:]/,
35
- stopwords: /\b(and|the|of|it|in|for)\b/,
36
- splits_text_on: /[\s\/\-\,\&]+/,
37
- normalizes_words: [[/Deoxyribonucleic Acid/i, 'DNA']],
38
-
39
- substitutes_characters_with: CharacterSubstituters::WestEuropean.new,
40
- maximum_tokens: 5
34
+ searching removes_characters: /[^a-zA-Z0-9äöü\s\/\-\,\&\"\~\*\:]/,
35
+ stopwords: /\b(and|the|of|it|in|for)\b/,
36
+ splits_text_on: /[\s\/\-\,\&]+/,
37
+ normalizes_words: [[/Deoxyribonucleic Acid/i, 'DNA']],
38
+
39
+ substitutes_characters_with: CharacterSubstituters::WestEuropean.new,
40
+ maximum_tokens: 5 # TODO maximum_words?
41
41
 
42
42
  books_index = Index::Memory.new :books,
43
- Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml')
43
+ source: Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml')
44
44
  books_index.define_category :title,
45
45
  similarity: Similarity::DoubleMetaphone.new(3) # Up to three similar title word indexed.
46
46
  books_index.define_category :author,
@@ -48,7 +48,9 @@ describe Application do
48
48
  books_index.define_category :isbn,
49
49
  partial: Partial::None.new # Partially searching on an ISBN makes not much sense.
50
50
 
51
- geo_index = Index::Memory.new :geo, Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',') do
51
+ geo_index = Index::Memory.new :geo do
52
+ source Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',')
53
+ indexing removes_characters: /[^a-z]/
52
54
  category :location,
53
55
  similarity: Similarity::Metaphone.new(4)
54
56
  ranged_category :north1, 1, precision: 3, from: :north
@@ -58,6 +60,9 @@ describe Application do
58
60
  rack_adapter.stub! :exclaim # Stopping it from exclaiming.
59
61
 
60
62
  route %r{^/books} => Search.new(books_index)
63
+ route %r{^/buks} => Search.new(books_index) do
64
+ searching removes_characters: /[buks]/
65
+ end
61
66
  end
62
67
  }.should_not raise_error
63
68
  end
@@ -4,80 +4,127 @@ require 'spec_helper'
4
4
 
5
5
  describe Index::Base do
6
6
 
7
- let(:some_source) { stub :source, :harvest => nil }
7
+ let(:some_source) { stub :source, :harvest => nil, :inspect => 'some_source' }
8
8
 
9
9
  context 'initializer' do
10
10
  it 'works' do
11
- expect { described_class.new :some_index_name, some_source }.to_not raise_error
11
+ expect { described_class.new :some_index_name, source: some_source }.to_not raise_error
12
12
  end
13
13
  it 'fails correctly' do
14
- expect { described_class.new 0, some_source }.to raise_error(<<-ERROR
15
- The index identifier (you gave "0") for Index::Memory/Index::Redis should be a String/Symbol,
16
- Examples:
17
- Index::Memory.new(:my_cool_index, ...) # Recommended
18
- Index::Redis.new("a-redis-index", ...)
19
- ERROR
20
- )
14
+ expect { described_class.new 0, some_source }.to raise_error
21
15
  end
22
16
  it 'fails correctly' do
23
- expect { described_class.new :some_index_name, :some_source }.to raise_error(<<-ERROR
24
- The index "some_index_name" should use a data source that responds to the method #harvest, which yields(id, text).
25
- Or it could use one of the built-in sources:
26
- Sources::DB,
27
- Sources::CSV,
28
- Sources::Delicious,
29
- Sources::Couch
17
+ expect { described_class.new :some_index_name, source: :some_source }.to raise_error
18
+ end
19
+ it 'fails with a good message deprecated way of source passing is used' do
20
+ expect { described_class.new :some_index_name, some_source }.to raise_error(<<-ERROR
21
+
22
+
23
+ Sources are not passed in as second parameter for Index::Base anymore, but either
24
+ * as :source option:
25
+ Index::Base.new(:some_index_name, source: some_source)
26
+ or
27
+ * given to the #source method inside the config block:
28
+ Index::Base.new(:some_index_name) do
29
+ source some_source
30
+ end
31
+
32
+ Sorry about that breaking change (in 2.2.0), didn't want to go to 3.0.0 yet!
33
+
34
+ All the best
35
+ -- Picky
36
+
37
+
30
38
  ERROR
31
39
  )
32
40
  end
41
+ it 'does not fail' do
42
+ expect { described_class.new :some_index_name, source: [] }.to_not raise_error
43
+ end
33
44
  it 'registers with the indexes' do
34
45
  @api = described_class.allocate
35
46
 
36
47
  ::Indexes.should_receive(:register).once.with @api
37
48
 
38
- @api.send :initialize, :some_index_name, some_source
49
+ @api.send :initialize, :some_index_name, source: some_source
39
50
  end
40
51
  end
41
52
 
42
53
  context 'unit' do
43
- before(:each) do
44
- @api = described_class.new :some_index_name, some_source
54
+ let(:api) { described_class.new :some_index_name, source: some_source }
55
+
56
+ describe 'define_source' do
57
+ it 'delegates to the internal indexing' do
58
+ indexing = stub :indexing
59
+ api.stub! :internal_indexing => indexing
60
+
61
+ indexing.should_receive(:define_source).once.with :some_source
62
+
63
+ api.define_source :some_source
64
+ end
65
+ it 'has an alias' do
66
+ indexing = stub :indexing
67
+ api.stub! :internal_indexing => indexing
68
+
69
+ indexing.should_receive(:define_source).once.with :some_source
70
+
71
+ api.source :some_source
72
+ end
73
+ end
74
+
75
+ describe 'define_indexing' do
76
+ it 'delegates to the internal indexing' do
77
+ indexing = stub :indexing
78
+ api.stub! :internal_indexing => indexing
79
+
80
+ indexing.should_receive(:define_indexing).once.with :some_options
81
+
82
+ api.define_indexing :some_options
83
+ end
84
+ it 'has an alias' do
85
+ indexing = stub :indexing
86
+ api.stub! :internal_indexing => indexing
87
+
88
+ indexing.should_receive(:define_indexing).once.with :some_options
89
+
90
+ api.indexing :some_options
91
+ end
45
92
  end
46
93
 
47
94
  describe 'define_category' do
48
95
  context 'with block' do
49
96
  it 'returns itself' do
50
- @api.define_category(:some_name){ |indexing, indexed| }.should == @api
97
+ api.define_category(:some_name){ |indexing, indexed| }.should == api
51
98
  end
52
99
  it 'takes a string' do
53
- lambda { @api.define_category('some_name'){ |indexing, indexed| } }.should_not raise_error
100
+ lambda { api.define_category('some_name'){ |indexing, indexed| } }.should_not raise_error
54
101
  end
55
102
  it 'yields both the indexing category and the indexed category' do
56
- @api.define_category(:some_name) do |indexing, indexed|
103
+ api.define_category(:some_name) do |indexing, indexed|
57
104
  indexing.should be_kind_of(Internals::Indexing::Category)
58
105
  indexed.should be_kind_of(Internals::Indexed::Category)
59
106
  end
60
107
  end
61
108
  it 'yields the indexing category which has the given name' do
62
- @api.define_category(:some_name) do |indexing, indexed|
109
+ api.define_category(:some_name) do |indexing, indexed|
63
110
  indexing.name.should == :some_name
64
111
  end
65
112
  end
66
113
  it 'yields the indexed category which has the given name' do
67
- @api.define_category(:some_name) do |indexing, indexed|
114
+ api.define_category(:some_name) do |indexing, indexed|
68
115
  indexed.name.should == :some_name
69
116
  end
70
117
  end
71
118
  end
72
119
  context 'without block' do
73
120
  it 'works' do
74
- lambda { @api.define_category(:some_name) }.should_not raise_error
121
+ lambda { api.define_category(:some_name) }.should_not raise_error
75
122
  end
76
123
  it 'takes a string' do
77
- lambda { @api.define_category('some_name').should == @api }.should_not raise_error
124
+ lambda { api.define_category('some_name').should == api }.should_not raise_error
78
125
  end
79
126
  it 'returns itself' do
80
- @api.define_category(:some_name).should == @api
127
+ api.define_category(:some_name).should == api
81
128
  end
82
129
  end
83
130
  end
@@ -8,7 +8,7 @@ describe Index::Redis do
8
8
 
9
9
  describe 'initialize' do
10
10
  it 'works' do
11
- described_class.new :some_name, some_source
11
+ described_class.new :some_name, source: some_source
12
12
  end
13
13
  end
14
14
 
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe IndexBundle do
6
6
 
7
- let(:some_index) { stub :index, :name => :some_index, :indexed => :indexed_index, :indexing => :indexing_index }
7
+ let(:some_index) { stub :index, :name => :some_index, :internal_indexed => :indexed_index, :internal_indexing => :indexing_index }
8
8
  let(:indexes) { described_class.new }
9
9
  let(:indexed) { stub :indexed, :register => nil }
10
10
  let(:indexing) { stub :indexing, :register => nil }
@@ -23,7 +23,7 @@ describe Indexing::Indexes do
23
23
  indexes.should_receive(:find).once.with(:index, :category).and_return @index1
24
24
  end
25
25
  it 'indexes' do
26
- @index1.should_receive(:index).once.with
26
+ @index1.should_receive(:index!).once.with
27
27
 
28
28
  indexes.generate_index_only :index, :category
29
29
  end
@@ -64,10 +64,10 @@ describe Indexing::Indexes do
64
64
  describe 'index_for_tests' do
65
65
  it 'takes a snapshot, then indexes and caches each' do
66
66
  indexes.should_receive(:take_snapshot).once.with.ordered
67
- @index1.should_receive(:index).once.with.ordered
68
- @index1.should_receive(:cache).once.with.ordered
69
- @index2.should_receive(:index).once.with.ordered
70
- @index2.should_receive(:cache).once.with.ordered
67
+ @index1.should_receive(:index!).once.with.ordered
68
+ @index1.should_receive(:cache!).once.with.ordered
69
+ @index2.should_receive(:index!).once.with.ordered
70
+ @index2.should_receive(:cache!).once.with.ordered
71
71
 
72
72
  indexes.index_for_tests
73
73
  end
@@ -1,12 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Calculations::Location do
3
+ describe Internals::Calculations::Location do
4
4
 
5
5
  context 'with precision 1' do
6
6
  before(:each) do
7
- @calculation = Calculations::Location.new 1.5, 1
7
+ @calculation = described_class.new 1.5, 1
8
8
  @calculation.minimum = 42.7
9
9
  end
10
+ describe 'recalculated_range' do
11
+ it 'returns the right range' do
12
+ @calculation.recalculated_range(40.0).should == (-2..0)
13
+ end
14
+ it 'returns the right range' do
15
+ @calculation.recalculated_range(41.0).should == (-1..1)
16
+ end
17
+ it 'returns the right range' do
18
+ @calculation.recalculated_range(0).should == (-42..-40)
19
+ end
20
+ end
10
21
  describe 'recalculate' do
11
22
  it 'sets the minimum close value to the minimum minus user grid' do
12
23
  @calculation.recalculate(41.2).should == 1
@@ -25,7 +36,7 @@ describe Calculations::Location do
25
36
 
26
37
  context 'with precision 3' do
27
38
  before(:each) do
28
- @calculation = Calculations::Location.new 1.5, 3
39
+ @calculation = described_class.new 1.5, 3
29
40
  @calculation.minimum = 42.7
30
41
  end
31
42
  describe 'recalculate' do
@@ -4,10 +4,9 @@ describe Internals::Index::Files do
4
4
 
5
5
  before(:each) do
6
6
  index = stub :index, :name => :some_index
7
- category = stub :category, :name => :some_category
8
- configuration = Configuration::Index.new index, category
7
+ category = Internals::Indexing::Category.new :some_category, index
9
8
 
10
- @files = described_class.new :some_name, configuration
9
+ @files = described_class.new :some_name, category
11
10
 
12
11
  @prepared = @files.prepared
13
12