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
@@ -8,57 +8,57 @@ describe ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter do
8
8
 
9
9
  describe '#boolean_value' do
10
10
  it "returns 'TRUE' for true" do
11
- adapter.boolean_value(true).should == 'TRUE'
11
+ expect(adapter.boolean_value(true)).to eq('TRUE')
12
12
  end
13
13
 
14
14
  it "returns 'FALSE' for false" do
15
- adapter.boolean_value(false).should == 'FALSE'
15
+ expect(adapter.boolean_value(false)).to eq('FALSE')
16
16
  end
17
17
  end
18
18
 
19
19
  describe '#cast_to_string' do
20
20
  it "casts the clause to characters" do
21
- adapter.cast_to_string('foo').should == 'foo::varchar'
21
+ expect(adapter.cast_to_string('foo')).to eq('foo::varchar')
22
22
  end
23
23
  end
24
24
 
25
25
  describe '#cast_to_timestamp' do
26
26
  it "converts to int unix timestamps" do
27
- adapter.cast_to_timestamp('created_at').
28
- should == 'extract(epoch from created_at)::int'
27
+ expect(adapter.cast_to_timestamp('created_at')).
28
+ to eq('extract(epoch from created_at)::int')
29
29
  end
30
30
 
31
31
  it "converts to bigint unix timestamps" do
32
32
  ThinkingSphinx::Configuration.instance.settings['64bit_timestamps'] = true
33
33
 
34
- adapter.cast_to_timestamp('created_at').
35
- should == 'extract(epoch from created_at)::bigint'
34
+ expect(adapter.cast_to_timestamp('created_at')).
35
+ to eq('extract(epoch from created_at)::bigint')
36
36
  end
37
37
  end
38
38
 
39
39
  describe '#concatenate' do
40
40
  it "concatenates with the given separator" do
41
- adapter.concatenate('foo, bar, baz', ',').
42
- should == "COALESCE(foo, '') || ',' || COALESCE(bar, '') || ',' || COALESCE(baz, '')"
41
+ expect(adapter.concatenate('foo, bar, baz', ',')).
42
+ to eq("COALESCE(foo, '') || ',' || COALESCE(bar, '') || ',' || COALESCE(baz, '')")
43
43
  end
44
44
  end
45
45
 
46
46
  describe '#convert_nulls' do
47
47
  it "translates arguments to a COALESCE SQL call" do
48
- adapter.convert_nulls('id', 5).should == 'COALESCE(id, 5)'
48
+ expect(adapter.convert_nulls('id', 5)).to eq('COALESCE(id, 5)')
49
49
  end
50
50
  end
51
51
 
52
52
  describe '#convert_blank' do
53
53
  it "translates arguments to a COALESCE NULLIF SQL call" do
54
- adapter.convert_blank('id', 5).should == "COALESCE(NULLIF(id, ''), 5)"
54
+ expect(adapter.convert_blank('id', 5)).to eq("COALESCE(NULLIF(id, ''), 5)")
55
55
  end
56
56
  end
57
57
 
58
58
  describe '#group_concatenate' do
59
59
  it "group concatenates the clause with the given separator" do
60
- adapter.group_concatenate('foo', ',').
61
- should == "array_to_string(array_agg(DISTINCT foo), ',')"
60
+ expect(adapter.group_concatenate('foo', ',')).
61
+ to eq("array_to_string(array_agg(DISTINCT foo), ',')")
62
62
  end
63
63
  end
64
64
  end
@@ -5,21 +5,21 @@ describe ThinkingSphinx::ActiveRecord::DatabaseAdapters do
5
5
 
6
6
  describe '.adapter_for' do
7
7
  it "returns a MysqlAdapter object for :mysql" do
8
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
9
- stub(:adapter_type_for => :mysql)
8
+ allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters).
9
+ to receive_messages(:adapter_type_for => :mysql)
10
10
 
11
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.adapter_for(model).
12
- should be_a(
11
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.adapter_for(model)).
12
+ to be_a(
13
13
  ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter
14
14
  )
15
15
  end
16
16
 
17
17
  it "returns a PostgreSQLAdapter object for :postgresql" do
18
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
19
- stub(:adapter_type_for => :postgresql)
18
+ allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters).
19
+ to receive_messages(:adapter_type_for => :postgresql)
20
20
 
21
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.adapter_for(model).
22
- should be_a(
21
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.adapter_for(model)).
22
+ to be_a(
23
23
  ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter
24
24
  )
25
25
  end
@@ -29,21 +29,21 @@ describe ThinkingSphinx::ActiveRecord::DatabaseAdapters do
29
29
  adapter_instance = double('adapter instance')
30
30
 
31
31
  ThinkingSphinx::ActiveRecord::DatabaseAdapters.default = adapter_class
32
- adapter_class.stub!(:new => adapter_instance)
32
+ allow(adapter_class).to receive_messages(:new => adapter_instance)
33
33
 
34
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.adapter_for(model).
35
- should == adapter_instance
34
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.adapter_for(model)).
35
+ to eq(adapter_instance)
36
36
 
37
37
  ThinkingSphinx::ActiveRecord::DatabaseAdapters.default = nil
38
38
  end
39
39
 
40
40
  it "raises an exception for other responses" do
41
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
42
- stub(:adapter_type_for => :sqlite)
41
+ allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters).
42
+ to receive_messages(:adapter_type_for => :sqlite)
43
43
 
44
- lambda {
44
+ expect {
45
45
  ThinkingSphinx::ActiveRecord::DatabaseAdapters.adapter_for(model)
46
- }.should raise_error
46
+ }.to raise_error(ThinkingSphinx::InvalidDatabaseAdapter)
47
47
  end
48
48
  end
49
49
 
@@ -53,74 +53,74 @@ describe ThinkingSphinx::ActiveRecord::DatabaseAdapters do
53
53
  let(:model) { double('model', :connection => connection) }
54
54
 
55
55
  it "translates a normal MySQL adapter" do
56
- klass.stub(:name => 'ActiveRecord::ConnectionAdapters::MysqlAdapter')
56
+ allow(klass).to receive_messages(:name => 'ActiveRecord::ConnectionAdapters::MysqlAdapter')
57
57
 
58
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
59
- adapter_type_for(model).should == :mysql
58
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.
59
+ adapter_type_for(model)).to eq(:mysql)
60
60
  end
61
61
 
62
62
  it "translates a MySQL2 adapter" do
63
- klass.stub(:name => 'ActiveRecord::ConnectionAdapters::Mysql2Adapter')
63
+ allow(klass).to receive_messages(:name => 'ActiveRecord::ConnectionAdapters::Mysql2Adapter')
64
64
 
65
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
66
- adapter_type_for(model).should == :mysql
65
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.
66
+ adapter_type_for(model)).to eq(:mysql)
67
67
  end
68
68
 
69
69
  it "translates a normal PostgreSQL adapter" do
70
- klass.stub(:name => 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter')
70
+ allow(klass).to receive_messages(:name => 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter')
71
71
 
72
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
73
- adapter_type_for(model).should == :postgresql
72
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.
73
+ adapter_type_for(model)).to eq(:postgresql)
74
74
  end
75
75
 
76
76
  it "translates a JDBC MySQL adapter to MySQL" do
77
- klass.stub(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
78
- connection.stub(:config => {:adapter => 'jdbcmysql'})
77
+ allow(klass).to receive_messages(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
78
+ allow(connection).to receive_messages(:config => {:adapter => 'jdbcmysql'})
79
79
 
80
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
81
- adapter_type_for(model).should == :mysql
80
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.
81
+ adapter_type_for(model)).to eq(:mysql)
82
82
  end
83
83
 
84
84
  it "translates a JDBC PostgreSQL adapter to PostgreSQL" do
85
- klass.stub(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
86
- connection.stub(:config => {:adapter => 'jdbcpostgresql'})
85
+ allow(klass).to receive_messages(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
86
+ allow(connection).to receive_messages(:config => {:adapter => 'jdbcpostgresql'})
87
87
 
88
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
89
- adapter_type_for(model).should == :postgresql
88
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.
89
+ adapter_type_for(model)).to eq(:postgresql)
90
90
  end
91
91
 
92
92
  it "translates a JDBC adapter with MySQL connection string to MySQL" do
93
- klass.stub(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
94
- connection.stub(:config => {:adapter => 'jdbc',
93
+ allow(klass).to receive_messages(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
94
+ allow(connection).to receive_messages(:config => {:adapter => 'jdbc',
95
95
  :url => 'jdbc:mysql://127.0.0.1:3306/sphinx'})
96
96
 
97
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
98
- adapter_type_for(model).should == :mysql
97
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.
98
+ adapter_type_for(model)).to eq(:mysql)
99
99
  end
100
100
 
101
101
  it "translates a JDBC adapter with PostgresSQL connection string to PostgresSQL" do
102
- klass.stub(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
103
- connection.stub(:config => {:adapter => 'jdbc',
102
+ allow(klass).to receive_messages(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
103
+ allow(connection).to receive_messages(:config => {:adapter => 'jdbc',
104
104
  :url => 'jdbc:postgresql://127.0.0.1:3306/sphinx'})
105
105
 
106
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
107
- adapter_type_for(model).should == :postgresql
106
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.
107
+ adapter_type_for(model)).to eq(:postgresql)
108
108
  end
109
109
 
110
110
  it "returns other JDBC adapters without translation" do
111
- klass.stub(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
112
- connection.stub(:config => {:adapter => 'jdbcmssql'})
111
+ allow(klass).to receive_messages(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
112
+ allow(connection).to receive_messages(:config => {:adapter => 'jdbcmssql'})
113
113
 
114
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
115
- adapter_type_for(model).should == 'jdbcmssql'
114
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.
115
+ adapter_type_for(model)).to eq('jdbcmssql')
116
116
  end
117
117
 
118
118
  it "returns other unknown adapters without translation" do
119
- klass.stub(:name => 'ActiveRecord::ConnectionAdapters::FooAdapter')
119
+ allow(klass).to receive_messages(:name => 'ActiveRecord::ConnectionAdapters::FooAdapter')
120
120
 
121
- ThinkingSphinx::ActiveRecord::DatabaseAdapters.
122
- adapter_type_for(model).
123
- should == 'ActiveRecord::ConnectionAdapters::FooAdapter'
121
+ expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters.
122
+ adapter_type_for(model)).
123
+ to eq('ActiveRecord::ConnectionAdapters::FooAdapter')
124
124
  end
125
125
  end
126
126
  end
@@ -7,16 +7,16 @@ describe ThinkingSphinx::ActiveRecord::Field do
7
7
  let(:model) { double('model') }
8
8
 
9
9
  before :each do
10
- column.stub! :to_a => [column]
10
+ allow(column).to receive_messages :to_a => [column]
11
11
  end
12
12
 
13
13
  describe '#columns' do
14
14
  it 'returns the provided Column object' do
15
- field.columns.should == [column]
15
+ expect(field.columns).to eq([column])
16
16
  end
17
17
 
18
18
  it 'translates symbols to Column objects' do
19
- ThinkingSphinx::ActiveRecord::Column.should_receive(:new).with(:title).
19
+ expect(ThinkingSphinx::ActiveRecord::Column).to receive(:new).with(:title).
20
20
  and_return(column)
21
21
 
22
22
  ThinkingSphinx::ActiveRecord::Field.new model, :title
@@ -25,25 +25,25 @@ describe ThinkingSphinx::ActiveRecord::Field do
25
25
 
26
26
  describe '#file?' do
27
27
  it "defaults to false" do
28
- field.should_not be_file
28
+ expect(field).not_to be_file
29
29
  end
30
30
 
31
31
  it "is true if file option is set" do
32
32
  field = ThinkingSphinx::ActiveRecord::Field.new model, column,
33
33
  :file => true
34
- field.should be_file
34
+ expect(field).to be_file
35
35
  end
36
36
  end
37
37
 
38
38
  describe '#with_attribute?' do
39
39
  it "defaults to false" do
40
- field.should_not be_with_attribute
40
+ expect(field).not_to be_with_attribute
41
41
  end
42
42
 
43
43
  it "is true if the field is sortable" do
44
44
  field = ThinkingSphinx::ActiveRecord::Field.new model, column,
45
45
  :sortable => true
46
- field.should be_with_attribute
46
+ expect(field).to be_with_attribute
47
47
  end
48
48
  end
49
49
  end
@@ -12,12 +12,12 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
12
12
  let(:initialize_method) { double :arity => 4 }
13
13
 
14
14
  before :each do
15
- reflection.active_record.stub_chain(:connection, :quote_column_name).
15
+ allow(reflection.active_record).to receive_message_chain(:connection, :quote_column_name).
16
16
  and_return('"foo_type"')
17
17
  end
18
18
 
19
19
  it "uses the existing reflection's macro" do
20
- reflection_klass.should_receive(:new).
20
+ expect(reflection_klass).to receive(:new).
21
21
  with(:has_some, anything, anything, anything)
22
22
 
23
23
  ThinkingSphinx::ActiveRecord::FilterReflection.call(
@@ -27,10 +27,10 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
27
27
 
28
28
  it "uses the supplied name" do
29
29
  if defined?(ActiveRecord::Reflection::MacroReflection)
30
- reflection_klass.should_receive(:new).
30
+ expect(reflection_klass).to receive(:new).
31
31
  with('foo_bar', anything, anything, anything)
32
32
  else
33
- reflection_klass.should_receive(:new).
33
+ expect(reflection_klass).to receive(:new).
34
34
  with(anything, 'foo_bar', anything, anything)
35
35
  end
36
36
 
@@ -41,10 +41,10 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
41
41
 
42
42
  it "uses the existing reflection's parent" do
43
43
  if defined?(ActiveRecord::Reflection::MacroReflection)
44
- reflection_klass.should_receive(:new).
44
+ expect(reflection_klass).to receive(:new).
45
45
  with(anything, anything, anything, reflection.active_record)
46
46
  else
47
- reflection_klass.should_receive(:new).
47
+ expect(reflection_klass).to receive(:new).
48
48
  with(anything, anything, anything, reflection.active_record)
49
49
  end
50
50
 
@@ -55,12 +55,12 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
55
55
 
56
56
  it "removes the polymorphic setting from the options" do
57
57
  if defined?(ActiveRecord::Reflection::MacroReflection)
58
- reflection_klass.should_receive(:new) do |name, scope, options, parent|
59
- options[:polymorphic].should be_nil
58
+ expect(reflection_klass).to receive(:new) do |name, scope, options, parent|
59
+ expect(options[:polymorphic]).to be_nil
60
60
  end
61
61
  else
62
- reflection_klass.should_receive(:new) do |macro, name, options, parent|
63
- options[:polymorphic].should be_nil
62
+ expect(reflection_klass).to receive(:new) do |macro, name, options, parent|
63
+ expect(options[:polymorphic]).to be_nil
64
64
  end
65
65
  end
66
66
 
@@ -71,12 +71,12 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
71
71
 
72
72
  it "adds the class name option" do
73
73
  if defined?(ActiveRecord::Reflection::MacroReflection)
74
- reflection_klass.should_receive(:new) do |name, scope, options, parent|
75
- options[:class_name].should == 'Bar'
74
+ expect(reflection_klass).to receive(:new) do |name, scope, options, parent|
75
+ expect(options[:class_name]).to eq('Bar')
76
76
  end
77
77
  else
78
- reflection_klass.should_receive(:new) do |macro, name, options, parent|
79
- options[:class_name].should == 'Bar'
78
+ expect(reflection_klass).to receive(:new) do |macro, name, options, parent|
79
+ expect(options[:class_name]).to eq('Bar')
80
80
  end
81
81
  end
82
82
 
@@ -87,12 +87,12 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
87
87
 
88
88
  it "sets the foreign key if necessary" do
89
89
  if defined?(ActiveRecord::Reflection::MacroReflection)
90
- reflection_klass.should_receive(:new) do |name, scope, options, parent|
91
- options[:foreign_key].should == 'baz_id'
90
+ expect(reflection_klass).to receive(:new) do |name, scope, options, parent|
91
+ expect(options[:foreign_key]).to eq('baz_id')
92
92
  end
93
93
  else
94
- reflection_klass.should_receive(:new) do |macro, name, options, parent|
95
- options[:foreign_key].should == 'baz_id'
94
+ expect(reflection_klass).to receive(:new) do |macro, name, options, parent|
95
+ expect(options[:foreign_key]).to eq('baz_id')
96
96
  end
97
97
  end
98
98
 
@@ -105,12 +105,12 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
105
105
  options[:foreign_key] = 'qux_id'
106
106
 
107
107
  if defined?(ActiveRecord::Reflection::MacroReflection)
108
- reflection_klass.should_receive(:new) do |name, scope, options, parent|
109
- options[:foreign_key].should == 'qux_id'
108
+ expect(reflection_klass).to receive(:new) do |name, scope, options, parent|
109
+ expect(options[:foreign_key]).to eq('qux_id')
110
110
  end
111
111
  else
112
- reflection_klass.should_receive(:new) do |macro, name, options, parent|
113
- options[:foreign_key].should == 'qux_id'
112
+ expect(reflection_klass).to receive(:new) do |macro, name, options, parent|
113
+ expect(options[:foreign_key]).to eq('qux_id')
114
114
  end
115
115
  end
116
116
 
@@ -120,8 +120,8 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
120
120
  end
121
121
 
122
122
  it "sets conditions if there are none" do
123
- reflection_klass.should_receive(:new) do |macro, name, options, parent|
124
- options[:conditions].should == "::ts_join_alias::.\"foo_type\" = 'Bar'"
123
+ expect(reflection_klass).to receive(:new) do |macro, name, options, parent|
124
+ expect(options[:conditions]).to eq("::ts_join_alias::.\"foo_type\" = 'Bar'")
125
125
  end
126
126
 
127
127
  ThinkingSphinx::ActiveRecord::FilterReflection.call(
@@ -132,8 +132,8 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
132
132
  it "appends to the conditions array" do
133
133
  options[:conditions] = ['existing']
134
134
 
135
- reflection_klass.should_receive(:new) do |macro, name, options, parent|
136
- options[:conditions].should == ['existing', "::ts_join_alias::.\"foo_type\" = 'Bar'"]
135
+ expect(reflection_klass).to receive(:new) do |macro, name, options, parent|
136
+ expect(options[:conditions]).to eq(['existing', "::ts_join_alias::.\"foo_type\" = 'Bar'"])
137
137
  end
138
138
 
139
139
  ThinkingSphinx::ActiveRecord::FilterReflection.call(
@@ -144,8 +144,8 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
144
144
  it "extends the conditions hash" do
145
145
  options[:conditions] = {:x => :y}
146
146
 
147
- reflection_klass.should_receive(:new) do |macro, name, options, parent|
148
- options[:conditions].should == {:x => :y, :foo_type => 'Bar'}
147
+ expect(reflection_klass).to receive(:new) do |macro, name, options, parent|
148
+ expect(options[:conditions]).to eq({:x => :y, :foo_type => 'Bar'})
149
149
  end
150
150
 
151
151
  ThinkingSphinx::ActiveRecord::FilterReflection.call(
@@ -156,8 +156,8 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
156
156
  it "appends to the conditions string" do
157
157
  options[:conditions] = 'existing'
158
158
 
159
- reflection_klass.should_receive(:new) do |macro, name, options, parent|
160
- options[:conditions].should == "existing AND ::ts_join_alias::.\"foo_type\" = 'Bar'"
159
+ expect(reflection_klass).to receive(:new) do |macro, name, options, parent|
160
+ expect(options[:conditions]).to eq("existing AND ::ts_join_alias::.\"foo_type\" = 'Bar'")
161
161
  end
162
162
 
163
163
  ThinkingSphinx::ActiveRecord::FilterReflection.call(
@@ -166,9 +166,9 @@ describe ThinkingSphinx::ActiveRecord::FilterReflection do
166
166
  end unless defined?(ActiveRecord::Reflection::MacroReflection)
167
167
 
168
168
  it "returns the new reflection" do
169
- ThinkingSphinx::ActiveRecord::FilterReflection.call(
169
+ expect(ThinkingSphinx::ActiveRecord::FilterReflection.call(
170
170
  reflection, 'foo_bar', 'Bar'
171
- ).should == filtered_reflection
171
+ )).to eq(filtered_reflection)
172
172
  end
173
173
  end
174
174
  end
@@ -2,12 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe ThinkingSphinx::ActiveRecord::Index do
4
4
  let(:index) { ThinkingSphinx::ActiveRecord::Index.new :user }
5
- let(:indices_path) { double('indices path', :join => '') }
6
5
  let(:config) { double('config', :settings => {},
7
- :indices_location => indices_path, :next_offset => 8) }
6
+ :indices_location => 'location', :next_offset => 8) }
8
7
 
9
8
  before :each do
10
- ThinkingSphinx::Configuration.stub :instance => config
9
+ allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
11
10
  end
12
11
 
13
12
  describe '#append_source' do
@@ -15,32 +14,32 @@ describe ThinkingSphinx::ActiveRecord::Index do
15
14
  let(:source) { double('source') }
16
15
 
17
16
  before :each do
18
- ActiveSupport::Inflector.stub(:constantize => model)
19
- ThinkingSphinx::ActiveRecord::SQLSource.stub :new => source
20
- config.stub :next_offset => 17
17
+ allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
18
+ allow(ThinkingSphinx::ActiveRecord::SQLSource).to receive_messages :new => source
19
+ allow(config).to receive_messages :next_offset => 17
21
20
  end
22
21
 
23
22
  it "adds a source to the index" do
24
- index.sources.should_receive(:<<).with(source)
23
+ expect(index.sources).to receive(:<<).with(source)
25
24
 
26
25
  index.append_source
27
26
  end
28
27
 
29
28
  it "creates the source with the index's offset" do
30
- ThinkingSphinx::ActiveRecord::SQLSource.should_receive(:new).
29
+ expect(ThinkingSphinx::ActiveRecord::SQLSource).to receive(:new).
31
30
  with(model, hash_including(:offset => 17)).and_return(source)
32
31
 
33
32
  index.append_source
34
33
  end
35
34
 
36
35
  it "returns the new source" do
37
- index.append_source.should == source
36
+ expect(index.append_source).to eq(source)
38
37
  end
39
38
 
40
39
  it "defaults to the model's primary key" do
41
- model.stub :primary_key => :sphinx_id
40
+ allow(model).to receive_messages :primary_key => :sphinx_id
42
41
 
43
- ThinkingSphinx::ActiveRecord::SQLSource.should_receive(:new).
42
+ expect(ThinkingSphinx::ActiveRecord::SQLSource).to receive(:new).
44
43
  with(model, hash_including(:primary_key => :sphinx_id)).
45
44
  and_return(source)
46
45
 
@@ -48,9 +47,9 @@ describe ThinkingSphinx::ActiveRecord::Index do
48
47
  end
49
48
 
50
49
  it "uses a custom column when set" do
51
- model.stub :primary_key => :sphinx_id
50
+ allow(model).to receive_messages :primary_key => :sphinx_id
52
51
 
53
- ThinkingSphinx::ActiveRecord::SQLSource.should_receive(:new).
52
+ expect(ThinkingSphinx::ActiveRecord::SQLSource).to receive(:new).
54
53
  with(model, hash_including(:primary_key => :custom_sphinx_id)).
55
54
  and_return(source)
56
55
 
@@ -60,9 +59,9 @@ describe ThinkingSphinx::ActiveRecord::Index do
60
59
  end
61
60
 
62
61
  it "defaults to id if no primary key is set" do
63
- model.stub :primary_key => nil
62
+ allow(model).to receive_messages :primary_key => nil
64
63
 
65
- ThinkingSphinx::ActiveRecord::SQLSource.should_receive(:new).
64
+ expect(ThinkingSphinx::ActiveRecord::SQLSource).to receive(:new).
66
65
  with(model, hash_including(:primary_key => :id)).
67
66
  and_return(source)
68
67
 
@@ -72,12 +71,12 @@ describe ThinkingSphinx::ActiveRecord::Index do
72
71
 
73
72
  describe '#delta?' do
74
73
  it "defaults to false" do
75
- index.should_not be_delta
74
+ expect(index).not_to be_delta
76
75
  end
77
76
 
78
77
  it "reflects the delta? option" do
79
78
  index = ThinkingSphinx::ActiveRecord::Index.new :user, :delta? => true
80
- index.should be_delta
79
+ expect(index).to be_delta
81
80
  end
82
81
  end
83
82
 
@@ -88,16 +87,16 @@ describe ThinkingSphinx::ActiveRecord::Index do
88
87
  index = ThinkingSphinx::ActiveRecord::Index.new :user,
89
88
  :delta_processor => processor_class
90
89
 
91
- index.delta_processor.should == processor
90
+ expect(index.delta_processor).to eq(processor)
92
91
  end
93
92
  end
94
93
 
95
94
  describe '#document_id_for_key' do
96
95
  it "calculates the document id based on offset and number of indices" do
97
- config.stub_chain(:indices, :count).and_return(5)
98
- config.stub :next_offset => 7
96
+ allow(config).to receive_message_chain(:indices, :count).and_return(5)
97
+ allow(config).to receive_messages :next_offset => 7
99
98
 
100
- index.document_id_for_key(123).should == 622
99
+ expect(index.document_id_for_key(123)).to eq(622)
101
100
  end
102
101
  end
103
102
 
@@ -109,14 +108,14 @@ describe ThinkingSphinx::ActiveRecord::Index do
109
108
  end
110
109
 
111
110
  it "interprets the definition block" do
112
- ThinkingSphinx::ActiveRecord::Interpreter.should_receive(:translate!).
111
+ expect(ThinkingSphinx::ActiveRecord::Interpreter).to receive(:translate!).
113
112
  with(index, block)
114
113
 
115
114
  index.interpret_definition!
116
115
  end
117
116
 
118
117
  it "only interprets the definition block once" do
119
- ThinkingSphinx::ActiveRecord::Interpreter.should_receive(:translate!).
118
+ expect(ThinkingSphinx::ActiveRecord::Interpreter).to receive(:translate!).
120
119
  once
121
120
 
122
121
  index.interpret_definition!
@@ -128,13 +127,13 @@ describe ThinkingSphinx::ActiveRecord::Index do
128
127
  let(:model) { double('model') }
129
128
 
130
129
  it "translates symbol references to model class" do
131
- ActiveSupport::Inflector.stub(:constantize => model)
130
+ allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
132
131
 
133
- index.model.should == model
132
+ expect(index.model).to eq(model)
134
133
  end
135
134
 
136
135
  it "memoizes the result" do
137
- ActiveSupport::Inflector.should_receive(:constantize).with('User').once.
136
+ expect(ActiveSupport::Inflector).to receive(:constantize).with('User').once.
138
137
  and_return(model)
139
138
 
140
139
  index.model
@@ -145,7 +144,7 @@ describe ThinkingSphinx::ActiveRecord::Index do
145
144
  describe '#morphology' do
146
145
  context 'with a render' do
147
146
  before :each do
148
- FileUtils.stub :mkdir_p => true
147
+ allow(FileUtils).to receive_messages :mkdir_p => true
149
148
  end
150
149
 
151
150
  it "defaults to nil" do
@@ -154,7 +153,7 @@ describe ThinkingSphinx::ActiveRecord::Index do
154
153
  rescue Riddle::Configuration::ConfigurationError
155
154
  end
156
155
 
157
- index.morphology.should be_nil
156
+ expect(index.morphology).to be_nil
158
157
  end
159
158
 
160
159
  it "reads from the settings file if provided" do
@@ -165,7 +164,7 @@ describe ThinkingSphinx::ActiveRecord::Index do
165
164
  rescue Riddle::Configuration::ConfigurationError
166
165
  end
167
166
 
168
- index.morphology.should == 'stem_en'
167
+ expect(index.morphology).to eq('stem_en')
169
168
  end
170
169
  end
171
170
  end
@@ -173,26 +172,26 @@ describe ThinkingSphinx::ActiveRecord::Index do
173
172
  describe '#name' do
174
173
  it "uses the core suffix by default" do
175
174
  index = ThinkingSphinx::ActiveRecord::Index.new :user
176
- index.name.should == 'user_core'
175
+ expect(index.name).to eq('user_core')
177
176
  end
178
177
 
179
178
  it "uses the delta suffix when delta? is true" do
180
179
  index = ThinkingSphinx::ActiveRecord::Index.new :user, :delta? => true
181
- index.name.should == 'user_delta'
180
+ expect(index.name).to eq('user_delta')
182
181
  end
183
182
  end
184
183
 
185
184
  describe '#offset' do
186
185
  before :each do
187
- config.stub :next_offset => 4
186
+ allow(config).to receive_messages :next_offset => 4
188
187
  end
189
188
 
190
189
  it "uses the next offset value from the configuration" do
191
- index.offset.should == 4
190
+ expect(index.offset).to eq(4)
192
191
  end
193
192
 
194
193
  it "uses the reference to get a unique offset" do
195
- config.should_receive(:next_offset).with(:user).and_return(2)
194
+ expect(config).to receive(:next_offset).with(:user).and_return(2)
196
195
 
197
196
  index.offset
198
197
  end
@@ -200,11 +199,11 @@ describe ThinkingSphinx::ActiveRecord::Index do
200
199
 
201
200
  describe '#render' do
202
201
  before :each do
203
- FileUtils.stub :mkdir_p => true
202
+ allow(FileUtils).to receive_messages :mkdir_p => true
204
203
  end
205
204
 
206
205
  it "interprets the provided definition" do
207
- index.should_receive(:interpret_definition!).at_least(:once)
206
+ expect(index).to receive(:interpret_definition!).at_least(:once)
208
207
 
209
208
  begin
210
209
  index.render