thinking-sphinx 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 (124) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -2
  3. data/Appraisals +13 -0
  4. data/Gemfile +2 -1
  5. data/HISTORY +19 -0
  6. data/README.textile +3 -2
  7. data/gemfiles/rails_3_2.gemfile +2 -1
  8. data/gemfiles/rails_4_0.gemfile +2 -1
  9. data/gemfiles/rails_4_1.gemfile +2 -1
  10. data/gemfiles/rails_4_2.gemfile +2 -1
  11. data/gemfiles/rails_5_0.gemfile +12 -0
  12. data/lib/thinking_sphinx.rb +2 -0
  13. data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
  14. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
  15. data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
  16. data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
  17. data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
  18. data/lib/thinking_sphinx/configuration.rb +3 -2
  19. data/lib/thinking_sphinx/connection.rb +23 -10
  20. data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
  21. data/lib/thinking_sphinx/errors.rb +25 -0
  22. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
  23. data/lib/thinking_sphinx/railtie.rb +1 -1
  24. data/lib/thinking_sphinx/rake_interface.rb +71 -23
  25. data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
  26. data/lib/thinking_sphinx/real_time/populator.rb +3 -3
  27. data/lib/thinking_sphinx/tasks.rb +7 -8
  28. data/lib/thinking_sphinx/wildcard.rb +1 -1
  29. data/spec/acceptance/association_scoping_spec.rb +5 -5
  30. data/spec/acceptance/attribute_access_spec.rb +4 -4
  31. data/spec/acceptance/attribute_updates_spec.rb +3 -3
  32. data/spec/acceptance/batch_searching_spec.rb +4 -4
  33. data/spec/acceptance/big_integers_spec.rb +6 -6
  34. data/spec/acceptance/connection_spec.rb +23 -0
  35. data/spec/acceptance/excerpts_spec.rb +8 -8
  36. data/spec/acceptance/facets_spec.rb +13 -13
  37. data/spec/acceptance/geosearching_spec.rb +8 -8
  38. data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
  39. data/spec/acceptance/index_options_spec.rb +16 -16
  40. data/spec/acceptance/indexing_spec.rb +3 -3
  41. data/spec/acceptance/paginating_search_results_spec.rb +3 -3
  42. data/spec/acceptance/real_time_updates_spec.rb +4 -4
  43. data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
  44. data/spec/acceptance/search_counts_spec.rb +2 -2
  45. data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
  46. data/spec/acceptance/searching_across_models_spec.rb +6 -6
  47. data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
  48. data/spec/acceptance/searching_on_fields_spec.rb +9 -9
  49. data/spec/acceptance/searching_with_filters_spec.rb +16 -16
  50. data/spec/acceptance/searching_with_sti_spec.rb +9 -9
  51. data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
  52. data/spec/acceptance/sorting_search_results_spec.rb +6 -6
  53. data/spec/acceptance/specifying_sql_spec.rb +62 -62
  54. data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
  55. data/spec/acceptance/sql_deltas_spec.rb +7 -7
  56. data/spec/acceptance/support/database_cleaner.rb +1 -1
  57. data/spec/acceptance/support/sphinx_controller.rb +4 -1
  58. data/spec/acceptance/support/sphinx_helpers.rb +4 -0
  59. data/spec/acceptance/suspended_deltas_spec.rb +9 -9
  60. data/spec/internal/app/indices/article_index.rb +2 -2
  61. data/spec/internal/app/indices/book_index.rb +2 -1
  62. data/spec/internal/app/indices/product_index.rb +0 -2
  63. data/spec/internal/app/models/categorisation.rb +8 -1
  64. data/spec/spec_helper.rb +2 -0
  65. data/spec/support/json_column.rb +5 -1
  66. data/spec/support/multi_schema.rb +3 -1
  67. data/spec/support/sphinx_yaml_helpers.rb +1 -1
  68. data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
  69. data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
  70. data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
  71. data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
  72. data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
  73. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
  74. data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
  75. data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
  76. data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
  77. data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
  78. data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
  79. data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
  80. data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
  81. data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
  82. data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
  83. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
  84. data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
  85. data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
  86. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
  87. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
  88. data/spec/thinking_sphinx/configuration_spec.rb +81 -81
  89. data/spec/thinking_sphinx/connection_spec.rb +13 -13
  90. data/spec/thinking_sphinx/deletion_spec.rb +11 -11
  91. data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
  92. data/spec/thinking_sphinx/deltas_spec.rb +12 -12
  93. data/spec/thinking_sphinx/errors_spec.rb +30 -30
  94. data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
  95. data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
  96. data/spec/thinking_sphinx/index_set_spec.rb +7 -7
  97. data/spec/thinking_sphinx/index_spec.rb +24 -24
  98. data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
  99. data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
  100. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
  101. data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
  102. data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
  103. data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
  104. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
  105. data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
  106. data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
  107. data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
  108. data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
  109. data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
  110. data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
  111. data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
  112. data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
  113. data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
  114. data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
  115. data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
  116. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
  117. data/spec/thinking_sphinx/scopes_spec.rb +5 -5
  118. data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
  119. data/spec/thinking_sphinx/search/query_spec.rb +10 -10
  120. data/spec/thinking_sphinx/search_spec.rb +28 -28
  121. data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
  122. data/spec/thinking_sphinx_spec.rb +6 -6
  123. data/thinking-sphinx.gemspec +4 -4
  124. metadata +12 -9
@@ -3,7 +3,7 @@ RSpec.configure do |config|
3
3
  DatabaseCleaner.strategy = :truncation
4
4
  end
5
5
 
6
- config.after(:each) do
6
+ config.after(:each) do |example|
7
7
  if example.example_group_instance.class.metadata[:live]
8
8
  DatabaseCleaner.clean
9
9
  end
@@ -31,7 +31,10 @@ class SphinxController
31
31
  end
32
32
 
33
33
  def stop
34
- config.controller.stop
34
+ while config.controller.running? do
35
+ config.controller.stop
36
+ sleep(0.1)
37
+ end
35
38
  end
36
39
 
37
40
  def index(*indices)
@@ -27,4 +27,8 @@ RSpec.configure do |config|
27
27
  config.after :all do |group|
28
28
  sphinx.stop if group.class.metadata[:live]
29
29
  end
30
+
31
+ config.after :suite do
32
+ SphinxController.new.stop
33
+ end
30
34
  end
@@ -5,50 +5,50 @@ describe 'Suspend deltas for a given action', :live => true do
5
5
  book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
6
6
  index
7
7
 
8
- Book.search('Harry').to_a.should == [book]
8
+ expect(Book.search('Harry').to_a).to eq([book])
9
9
 
10
10
  ThinkingSphinx::Deltas.suspend :book do
11
11
  book.reload.update_attributes(:author => 'Terry Pratchett')
12
12
  sleep 0.25
13
13
 
14
- Book.search('Terry').to_a.should == []
14
+ expect(Book.search('Terry').to_a).to eq([])
15
15
  end
16
16
 
17
17
  sleep 0.25
18
- Book.search('Terry').to_a.should == [book]
18
+ expect(Book.search('Terry').to_a).to eq([book])
19
19
  end
20
20
 
21
21
  it "returns core records even though they are no longer valid" do
22
22
  book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
23
23
  index
24
24
 
25
- Book.search('Harry').to_a.should == [book]
25
+ expect(Book.search('Harry').to_a).to eq([book])
26
26
 
27
27
  ThinkingSphinx::Deltas.suspend :book do
28
28
  book.reload.update_attributes(:author => 'Terry Pratchett')
29
29
  sleep 0.25
30
30
 
31
- Book.search('Terry').to_a.should == []
31
+ expect(Book.search('Terry').to_a).to eq([])
32
32
  end
33
33
 
34
34
  sleep 0.25
35
- Book.search('Harry').to_a.should == [book]
35
+ expect(Book.search('Harry').to_a).to eq([book])
36
36
  end
37
37
 
38
38
  it "marks core records as deleted" do
39
39
  book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
40
40
  index
41
41
 
42
- Book.search('Harry').to_a.should == [book]
42
+ expect(Book.search('Harry').to_a).to eq([book])
43
43
 
44
44
  ThinkingSphinx::Deltas.suspend_and_update :book do
45
45
  book.reload.update_attributes(:author => 'Terry Pratchett')
46
46
  sleep 0.25
47
47
 
48
- Book.search('Terry').to_a.should == []
48
+ expect(Book.search('Terry').to_a).to eq([])
49
49
  end
50
50
 
51
51
  sleep 0.25
52
- Book.search('Harry').to_a.should be_empty
52
+ expect(Book.search('Harry').to_a).to be_empty
53
53
  end
54
54
  end
@@ -5,7 +5,7 @@ ThinkingSphinx::Index.define :article, :with => :active_record do
5
5
 
6
6
  has published, user_id
7
7
  has taggings.tag_id, :as => :tag_ids, :source => :query
8
- has taggings.created_at, :as => :taggings_at
8
+ has taggings.created_at, :as => :taggings_at, :type => :timestamp
9
9
 
10
10
  set_property :min_infix_len => 4
11
11
  set_property :enable_star => true
@@ -18,7 +18,7 @@ ThinkingSphinx::Index.define :article, :with => :active_record,
18
18
 
19
19
  has published, user_id
20
20
  has taggings.tag_id, :as => :tag_ids
21
- has taggings.created_at, :as => :taggings_at
21
+ has taggings.created_at, :as => :taggings_at, :type => :timestamp
22
22
 
23
23
  set_property :morphology => 'stem_en'
24
24
  end
@@ -4,5 +4,6 @@ ThinkingSphinx::Index.define :book, :with => :active_record, :delta => true do
4
4
  indexes [title, author], :as => :info
5
5
  indexes blurb_file, :file => true
6
6
 
7
- has year, created_at
7
+ has year
8
+ has created_at, :type => :timestamp
8
9
  end
@@ -8,8 +8,6 @@ ThinkingSphinx::Index.define :product, :with => :real_time do
8
8
  end
9
9
 
10
10
  if multi_schema.active?
11
- multi_schema.create 'thinking_sphinx'
12
-
13
11
  ThinkingSphinx::Index.define(:product,
14
12
  :name => :product_two, :offset_as => :product_two, :with => :real_time
15
13
  ) do
@@ -2,5 +2,12 @@ class Categorisation < ActiveRecord::Base
2
2
  belongs_to :category
3
3
  belongs_to :product
4
4
 
5
- after_save ThinkingSphinx::RealTime.callback_for(:product, [:product])
5
+ after_commit :update_product
6
+
7
+ private
8
+
9
+ def update_product
10
+ product.reload
11
+ ThinkingSphinx::RealTime.callback_for(:product, [:product]).after_save self
12
+ end
6
13
  end
data/spec/spec_helper.rb CHANGED
@@ -10,6 +10,8 @@ require 'thinking_sphinx/railtie'
10
10
 
11
11
  Combustion.initialize! :active_record
12
12
 
13
+ MultiSchema.new.create 'thinking_sphinx'
14
+
13
15
  Dir["#{root}/support/**/*.rb"].each { |file| require file }
14
16
 
15
17
  RSpec.configure do |config|
@@ -6,7 +6,7 @@ class JSONColumn
6
6
  end
7
7
 
8
8
  def call
9
- postgresql? && column?
9
+ sphinx? && postgresql? && column?
10
10
  end
11
11
 
12
12
  private
@@ -26,4 +26,8 @@ class JSONColumn
26
26
  def postgresql?
27
27
  ENV['DATABASE'] == 'postgresql'
28
28
  end
29
+
30
+ def sphinx?
31
+ ENV['SPHINX_VERSION'].nil? || ENV['SPHINX_VERSION'].to_f > 2.0
32
+ end
29
33
  end
@@ -4,12 +4,14 @@ class MultiSchema
4
4
  end
5
5
 
6
6
  def create(schema_name)
7
+ return unless active?
8
+
7
9
  unless connection.schema_exists? schema_name
8
10
  connection.execute %Q{CREATE SCHEMA "#{schema_name}"}
9
11
  end
10
12
 
11
13
  switch schema_name
12
- silence_stream(STDOUT) { load Rails.root.join('db', 'schema.rb') }
14
+ load Rails.root.join('db', 'schema.rb')
13
15
  end
14
16
 
15
17
  def current
@@ -1,6 +1,6 @@
1
1
  module SphinxYamlHelpers
2
2
  def write_configuration(hash)
3
- File.stub :read => {'test' => hash}.to_yaml, :exists? => true
3
+ allow(File).to receive_messages :read => {'test' => hash}.to_yaml, :exists? => true
4
4
  end
5
5
  end
6
6
 
@@ -6,7 +6,7 @@ describe ThinkingSphinx::ActiveRecord::Association do
6
6
 
7
7
  describe '#stack' do
8
8
  it "returns the column's stack and name" do
9
- association.stack.should == [:users, :post]
9
+ expect(association.stack).to eq([:users, :post])
10
10
  end
11
11
  end
12
12
  end
@@ -23,52 +23,55 @@ describe ThinkingSphinx::ActiveRecord::Attribute::Type do
23
23
  before :each do
24
24
  column.__stack << :foo
25
25
 
26
- model.stub :reflect_on_association => association
26
+ allow(model).to receive(:reflect_on_association).and_return(association)
27
27
  end
28
28
 
29
29
  it "returns true if there are has_many associations" do
30
- association.stub :macro => :has_many
30
+ allow(association).to receive(:macro).and_return(:has_many)
31
31
 
32
- type.should be_multi
32
+ expect(type).to be_multi
33
33
  end
34
34
 
35
35
  it "returns true if there are has_and_belongs_to_many associations" do
36
- association.stub :macro => :has_and_belongs_to_many
36
+ allow(association).to receive(:macro).and_return(:has_and_belongs_to_many)
37
37
 
38
- type.should be_multi
38
+ expect(type).to be_multi
39
39
  end
40
40
 
41
41
  it "returns false if there are no associations" do
42
42
  column.__stack.clear
43
43
 
44
- type.should_not be_multi
44
+ expect(type).not_to be_multi
45
45
  end
46
46
 
47
47
  it "returns false if there are only belongs_to associations" do
48
- association.stub :macro => :belongs_to
48
+ allow(association).to receive(:macro).and_return(:belongs_to)
49
49
 
50
- type.should_not be_multi
50
+ expect(type).not_to be_multi
51
51
  end
52
52
 
53
53
  it "returns false if there are only has_one associations" do
54
- association.stub :macro => :has_one
54
+ allow(association).to receive(:macro).and_return(:has_one)
55
55
 
56
- type.should_not be_multi
56
+ expect(type).not_to be_multi
57
57
  end
58
58
 
59
59
  it "returns true if deeper associations have many" do
60
60
  column.__stack << :bar
61
61
  deep_association = double(:klass => double, :macro => :has_many)
62
- association.stub :macro => :belongs_to,
63
- :klass => double(:reflect_on_association => deep_association)
64
62
 
65
- type.should be_multi
63
+ allow(association).to receive(:macro).and_return(:belongs_to)
64
+ allow(association).to receive(:klass).and_return(
65
+ double(:reflect_on_association => deep_association)
66
+ )
67
+
68
+ expect(type).to be_multi
66
69
  end
67
70
 
68
71
  it "respects the provided setting" do
69
72
  attribute.options[:multi] = true
70
73
 
71
- type.should be_multi
74
+ expect(type).to be_multi
72
75
  end
73
76
  end
74
77
 
@@ -76,79 +79,79 @@ describe ThinkingSphinx::ActiveRecord::Attribute::Type do
76
79
  it "returns the type option provided" do
77
80
  attribute.options[:type] = :datetime
78
81
 
79
- type.type.should == :datetime
82
+ expect(type.type).to eq(:datetime)
80
83
  end
81
84
 
82
85
  it "detects integer types from the database" do
83
- db_column.stub!(:type => :integer, :sql_type => 'integer(11)')
86
+ allow(db_column).to receive_messages(:type => :integer, :sql_type => 'integer(11)')
84
87
 
85
- type.type.should == :integer
88
+ expect(type.type).to eq(:integer)
86
89
  end
87
90
 
88
91
  it "detects boolean types from the database" do
89
- db_column.stub!(:type => :boolean)
92
+ allow(db_column).to receive_messages(:type => :boolean)
90
93
 
91
- type.type.should == :boolean
94
+ expect(type.type).to eq(:boolean)
92
95
  end
93
96
 
94
97
  it "detects datetime types from the database as timestamps" do
95
- db_column.stub!(:type => :datetime)
98
+ allow(db_column).to receive_messages(:type => :datetime)
96
99
 
97
- type.type.should == :timestamp
100
+ expect(type.type).to eq(:timestamp)
98
101
  end
99
102
 
100
103
  it "detects date types from the database as timestamps" do
101
- db_column.stub!(:type => :date)
104
+ allow(db_column).to receive_messages(:type => :date)
102
105
 
103
- type.type.should == :timestamp
106
+ expect(type.type).to eq(:timestamp)
104
107
  end
105
108
 
106
109
  it "detects string types from the database" do
107
- db_column.stub!(:type => :string)
110
+ allow(db_column).to receive_messages(:type => :string)
108
111
 
109
- type.type.should == :string
112
+ expect(type.type).to eq(:string)
110
113
  end
111
114
 
112
115
  it "detects text types from the database as strings" do
113
- db_column.stub!(:type => :text)
116
+ allow(db_column).to receive_messages(:type => :text)
114
117
 
115
- type.type.should == :string
118
+ expect(type.type).to eq(:string)
116
119
  end
117
120
 
118
121
  it "detects float types from the database" do
119
- db_column.stub!(:type => :float)
122
+ allow(db_column).to receive_messages(:type => :float)
120
123
 
121
- type.type.should == :float
124
+ expect(type.type).to eq(:float)
122
125
  end
123
126
 
124
127
  it "detects decimal types from the database as floats" do
125
- db_column.stub!(:type => :decimal)
128
+ allow(db_column).to receive_messages(:type => :decimal)
126
129
 
127
- type.type.should == :float
130
+ expect(type.type).to eq(:float)
128
131
  end
129
132
 
130
133
  it "detects big ints as big ints" do
131
- db_column.stub :type => :bigint
134
+ allow(db_column).to receive_messages :type => :bigint
132
135
 
133
- type.type.should == :bigint
136
+ expect(type.type).to eq(:bigint)
134
137
  end
135
138
 
136
139
  it "detects large integers as big ints" do
137
- db_column.stub :type => :integer, :sql_type => 'bigint(20)'
140
+ allow(db_column).to receive_messages :type => :integer, :sql_type => 'bigint(20)'
138
141
 
139
- type.type.should == :bigint
142
+ expect(type.type).to eq(:bigint)
140
143
  end
141
144
 
142
145
  it "detects JSON" do
143
- db_column.stub :type => :json
146
+ allow(db_column).to receive_messages :type => :json
144
147
 
145
- type.type.should == :json
148
+ expect(type.type).to eq(:json)
146
149
  end
147
150
 
148
151
  it "respects provided type setting" do
149
152
  attribute.options[:type] = :timestamp
150
153
 
151
- type.type.should == :timestamp
154
+ expect(type.type).to eq(:timestamp)
152
155
  end
153
156
 
154
157
  it 'raises an error if the database column does not exist' do
@@ -16,34 +16,34 @@ describe ThinkingSphinx::ActiveRecord::Base do
16
16
 
17
17
  describe '.facets' do
18
18
  it "returns a new search object" do
19
- model.facets.should be_a(ThinkingSphinx::FacetSearch)
19
+ expect(model.facets).to be_a(ThinkingSphinx::FacetSearch)
20
20
  end
21
21
 
22
22
  it "passes through arguments to the search object" do
23
- model.facets('pancakes').query.should == 'pancakes'
23
+ expect(model.facets('pancakes').query).to eq('pancakes')
24
24
  end
25
25
 
26
26
  it "scopes the search to a given model" do
27
- model.facets('pancakes').options[:classes].should == [model]
27
+ expect(model.facets('pancakes').options[:classes]).to eq([model])
28
28
  end
29
29
 
30
30
  it "merges the :classes option with the model" do
31
- model.facets('pancakes', :classes => [sub_model]).
32
- options[:classes].should == [sub_model, model]
31
+ expect(model.facets('pancakes', :classes => [sub_model]).
32
+ options[:classes]).to eq([sub_model, model])
33
33
  end
34
34
 
35
35
  it "applies the default scope if there is one" do
36
- model.stub :default_sphinx_scope => :default,
36
+ allow(model).to receive_messages :default_sphinx_scope => :default,
37
37
  :sphinx_scopes => {:default => Proc.new { {:order => :created_at} }}
38
38
 
39
- model.facets.options[:order].should == :created_at
39
+ expect(model.facets.options[:order]).to eq(:created_at)
40
40
  end
41
41
 
42
42
  it "does not apply a default scope if one is not set" do
43
- model.stub :default_sphinx_scope => nil,
43
+ allow(model).to receive_messages :default_sphinx_scope => nil,
44
44
  :default => {:order => :created_at}
45
45
 
46
- model.facets.options[:order].should be_nil
46
+ expect(model.facets.options[:order]).to be_nil
47
47
  end
48
48
  end
49
49
 
@@ -55,55 +55,55 @@ describe ThinkingSphinx::ActiveRecord::Base do
55
55
  end
56
56
 
57
57
  it "returns a new search object" do
58
- model.search.should be_a(ThinkingSphinx::Search)
58
+ expect(model.search).to be_a(ThinkingSphinx::Search)
59
59
  end
60
60
 
61
61
  it "passes through arguments to the search object" do
62
- model.search('pancakes').query.should == 'pancakes'
62
+ expect(model.search('pancakes').query).to eq('pancakes')
63
63
  end
64
64
 
65
65
  it "scopes the search to a given model" do
66
- model.search('pancakes').options[:classes].should == [model]
66
+ expect(model.search('pancakes').options[:classes]).to eq([model])
67
67
  end
68
68
 
69
69
  it "passes through options to the search object" do
70
- model.search('pancakes', populate: true).
71
- options[:populate].should be_true
70
+ expect(model.search('pancakes', populate: true).
71
+ options[:populate]).to be_truthy
72
72
  end
73
73
 
74
74
  it "should automatically populate when :populate is set to true" do
75
- stack.should_receive(:call).and_return(true)
75
+ expect(stack).to receive(:call).and_return(true)
76
76
 
77
77
  model.search('pancakes', populate: true)
78
78
  end
79
79
 
80
80
  it "merges the :classes option with the model" do
81
- model.search('pancakes', :classes => [sub_model]).
82
- options[:classes].should == [sub_model, model]
81
+ expect(model.search('pancakes', :classes => [sub_model]).
82
+ options[:classes]).to eq([sub_model, model])
83
83
  end
84
84
 
85
85
  it "respects provided middleware" do
86
- model.search(:middleware => ThinkingSphinx::Middlewares::RAW_ONLY).
87
- options[:middleware].should == ThinkingSphinx::Middlewares::RAW_ONLY
86
+ expect(model.search(:middleware => ThinkingSphinx::Middlewares::RAW_ONLY).
87
+ options[:middleware]).to eq(ThinkingSphinx::Middlewares::RAW_ONLY)
88
88
  end
89
89
 
90
90
  it "respects provided masks" do
91
- model.search(:masks => [ThinkingSphinx::Masks::PaginationMask]).
92
- masks.should == [ThinkingSphinx::Masks::PaginationMask]
91
+ expect(model.search(:masks => [ThinkingSphinx::Masks::PaginationMask]).
92
+ masks).to eq([ThinkingSphinx::Masks::PaginationMask])
93
93
  end
94
94
 
95
95
  it "applies the default scope if there is one" do
96
- model.stub :default_sphinx_scope => :default,
96
+ allow(model).to receive_messages :default_sphinx_scope => :default,
97
97
  :sphinx_scopes => {:default => Proc.new { {:order => :created_at} }}
98
98
 
99
- model.search.options[:order].should == :created_at
99
+ expect(model.search.options[:order]).to eq(:created_at)
100
100
  end
101
101
 
102
102
  it "does not apply a default scope if one is not set" do
103
- model.stub :default_sphinx_scope => nil,
103
+ allow(model).to receive_messages :default_sphinx_scope => nil,
104
104
  :default => {:order => :created_at}
105
105
 
106
- model.search.options[:order].should be_nil
106
+ expect(model.search.options[:order]).to be_nil
107
107
  end
108
108
  end
109
109
 
@@ -112,18 +112,18 @@ describe ThinkingSphinx::ActiveRecord::Base do
112
112
  :populated? => false) }
113
113
 
114
114
  before :each do
115
- ThinkingSphinx.stub :search => search
116
- FileUtils.stub :mkdir_p => true
115
+ allow(ThinkingSphinx).to receive_messages :search => search
116
+ allow(FileUtils).to receive_messages :mkdir_p => true
117
117
  end
118
118
 
119
119
  it "returns the search object's total entries count" do
120
- model.search_count.should == search.total_entries
120
+ expect(model.search_count).to eq(search.total_entries)
121
121
  end
122
122
 
123
123
  it "scopes the search to a given model" do
124
124
  model.search_count
125
125
 
126
- search.options[:classes].should == [model]
126
+ expect(search.options[:classes]).to eq([model])
127
127
  end
128
128
  end
129
129
  end