sunspot 2.2.7 → 2.5.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 (117) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/Appraisals +7 -0
  5. data/Gemfile +0 -8
  6. data/lib/sunspot/adapters.rb +4 -1
  7. data/lib/sunspot/configuration.rb +1 -0
  8. data/lib/sunspot/data_extractor.rb +36 -6
  9. data/lib/sunspot/dsl/field_query.rb +11 -0
  10. data/lib/sunspot/dsl/field_stats.rb +7 -0
  11. data/lib/sunspot/dsl/fields.rb +16 -0
  12. data/lib/sunspot/dsl/group.rb +10 -0
  13. data/lib/sunspot/dsl/scope.rb +23 -18
  14. data/lib/sunspot/field.rb +11 -0
  15. data/lib/sunspot/field_factory.rb +6 -2
  16. data/lib/sunspot/query/abstract_json_field_facet.rb +70 -0
  17. data/lib/sunspot/query/bbox.rb +5 -1
  18. data/lib/sunspot/query/date_field_json_facet.rb +25 -0
  19. data/lib/sunspot/query/field_json_facet.rb +19 -0
  20. data/lib/sunspot/query/field_stats.rb +35 -2
  21. data/lib/sunspot/query/group.rb +4 -5
  22. data/lib/sunspot/query/join.rb +2 -4
  23. data/lib/sunspot/query/range_json_facet.rb +28 -0
  24. data/lib/sunspot/query/restriction.rb +19 -4
  25. data/lib/sunspot/query.rb +3 -3
  26. data/lib/sunspot/schema.rb +10 -2
  27. data/lib/sunspot/search/abstract_search.rb +14 -1
  28. data/lib/sunspot/search/field_json_facet.rb +33 -0
  29. data/lib/sunspot/search/hit.rb +6 -1
  30. data/lib/sunspot/search/hit_enumerable.rb +4 -1
  31. data/lib/sunspot/search/json_facet_row.rb +40 -0
  32. data/lib/sunspot/search/json_facet_stats.rb +23 -0
  33. data/lib/sunspot/search/standard_search.rb +2 -3
  34. data/lib/sunspot/search/stats_json_row.rb +82 -0
  35. data/lib/sunspot/search/stats_row.rb +3 -1
  36. data/lib/sunspot/search.rb +4 -3
  37. data/lib/sunspot/session.rb +13 -5
  38. data/lib/sunspot/setup.rb +31 -0
  39. data/lib/sunspot/util.rb +23 -0
  40. data/lib/sunspot/version.rb +1 -1
  41. data/spec/api/adapters_spec.rb +32 -19
  42. data/spec/api/batcher_spec.rb +15 -15
  43. data/spec/api/binding_spec.rb +3 -3
  44. data/spec/api/class_set_spec.rb +3 -3
  45. data/spec/api/data_extractor_spec.rb +39 -0
  46. data/spec/api/hit_enumerable_spec.rb +32 -9
  47. data/spec/api/indexer/attributes_spec.rb +31 -31
  48. data/spec/api/indexer/batch_spec.rb +8 -7
  49. data/spec/api/indexer/dynamic_fields_spec.rb +8 -8
  50. data/spec/api/indexer/fixed_fields_spec.rb +12 -12
  51. data/spec/api/indexer/fulltext_spec.rb +8 -8
  52. data/spec/api/indexer/removal_spec.rb +14 -14
  53. data/spec/api/indexer_spec.rb +2 -2
  54. data/spec/api/query/advanced_manipulation_examples.rb +3 -3
  55. data/spec/api/query/connectives_examples.rb +26 -14
  56. data/spec/api/query/dsl_spec.rb +17 -9
  57. data/spec/api/query/dynamic_fields_examples.rb +18 -18
  58. data/spec/api/query/faceting_examples.rb +62 -62
  59. data/spec/api/query/fulltext_examples.rb +63 -58
  60. data/spec/api/query/function_spec.rb +26 -26
  61. data/spec/api/query/geo_examples.rb +6 -6
  62. data/spec/api/query/group_spec.rb +6 -6
  63. data/spec/api/query/highlighting_examples.rb +26 -26
  64. data/spec/api/query/join_spec.rb +2 -2
  65. data/spec/api/query/more_like_this_spec.rb +29 -29
  66. data/spec/api/query/ordering_pagination_examples.rb +25 -25
  67. data/spec/api/query/scope_examples.rb +39 -39
  68. data/spec/api/query/spatial_examples.rb +3 -3
  69. data/spec/api/query/spellcheck_examples.rb +3 -3
  70. data/spec/api/query/standard_spec.rb +1 -1
  71. data/spec/api/query/stats_examples.rb +8 -8
  72. data/spec/api/query/text_field_scoping_examples.rb +5 -5
  73. data/spec/api/query/types_spec.rb +4 -4
  74. data/spec/api/search/cursor_paginated_collection_spec.rb +12 -12
  75. data/spec/api/search/dynamic_fields_spec.rb +4 -4
  76. data/spec/api/search/faceting_spec.rb +55 -52
  77. data/spec/api/search/highlighting_spec.rb +7 -7
  78. data/spec/api/search/hits_spec.rb +43 -29
  79. data/spec/api/search/paginated_collection_spec.rb +18 -18
  80. data/spec/api/search/results_spec.rb +13 -13
  81. data/spec/api/search/search_spec.rb +3 -3
  82. data/spec/api/search/stats_spec.rb +10 -10
  83. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +19 -18
  84. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +9 -9
  85. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
  86. data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +10 -10
  87. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +14 -13
  88. data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +2 -2
  89. data/spec/api/session_proxy/spec_helper.rb +1 -1
  90. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +9 -5
  91. data/spec/api/session_spec.rb +42 -42
  92. data/spec/api/sunspot_spec.rb +7 -4
  93. data/spec/helpers/integration_helper.rb +1 -0
  94. data/spec/integration/atomic_updates_spec.rb +25 -11
  95. data/spec/integration/dynamic_fields_spec.rb +10 -10
  96. data/spec/integration/faceting_spec.rb +252 -39
  97. data/spec/integration/field_grouping_spec.rb +35 -16
  98. data/spec/integration/field_lists_spec.rb +57 -0
  99. data/spec/integration/geospatial_spec.rb +34 -8
  100. data/spec/integration/highlighting_spec.rb +5 -5
  101. data/spec/integration/indexing_spec.rb +5 -5
  102. data/spec/integration/join_spec.rb +45 -0
  103. data/spec/integration/keyword_search_spec.rb +47 -45
  104. data/spec/integration/local_search_spec.rb +4 -4
  105. data/spec/integration/more_like_this_spec.rb +7 -7
  106. data/spec/integration/scoped_search_spec.rb +108 -108
  107. data/spec/integration/spellcheck_spec.rb +52 -7
  108. data/spec/integration/stats_spec.rb +54 -13
  109. data/spec/integration/stored_fields_spec.rb +1 -1
  110. data/spec/integration/test_pagination.rb +4 -4
  111. data/spec/integration/unicode_spec.rb +1 -1
  112. data/spec/mocks/adapters.rb +33 -0
  113. data/spec/mocks/photo.rb +14 -4
  114. data/spec/mocks/post.rb +9 -1
  115. data/spec/spec_helper.rb +11 -10
  116. data/sunspot.gemspec +3 -1
  117. metadata +49 -6
@@ -4,15 +4,15 @@ describe 'search results', :type => :search do
4
4
  it 'loads single result' do
5
5
  post = Post.new
6
6
  stub_results(post)
7
- session.search(Post).results.should == [post]
7
+ expect(session.search(Post).results).to eq([post])
8
8
  end
9
9
 
10
10
  it 'loads multiple results in order' do
11
11
  post_1, post_2 = Post.new, Post.new
12
12
  stub_results(post_1, post_2)
13
- session.search(Post).results.should == [post_1, post_2]
13
+ expect(session.search(Post).results).to eq([post_1, post_2])
14
14
  stub_results(post_2, post_1)
15
- session.search(Post).results.should == [post_2, post_1]
15
+ expect(session.search(Post).results).to eq([post_2, post_1])
16
16
  end
17
17
 
18
18
  # This is a reduction of a crazy bug I found in production where some hits
@@ -22,42 +22,42 @@ describe 'search results', :type => :search do
22
22
  Namespaced::Comment.reset!
23
23
  results = [Post.new, Namespaced::Comment.new]
24
24
  stub_results(*results)
25
- session.search(Post, Namespaced::Comment).results.should == results
25
+ expect(session.search(Post, Namespaced::Comment).results).to eq(results)
26
26
  end
27
27
 
28
28
  it 'gracefully returns empty results when response is nil' do
29
29
  stub_nil_results
30
- session.search(Post).results.should == []
30
+ expect(session.search(Post).results).to eq([])
31
31
  end
32
32
 
33
33
  it 'returns search total as attribute of results' do
34
34
  stub_results(Post.new, 4)
35
- session.search(Post) do
35
+ expect(session.search(Post) do
36
36
  paginate(:page => 1)
37
- end.results.total_entries.should == 4
37
+ end.results.total_entries).to eq(4)
38
38
  end
39
39
 
40
40
  it 'returns total' do
41
41
  stub_results(Post.new, Post.new, 4)
42
- session.search(Post) { paginate(:page => 1) }.total.should == 4
42
+ expect(session.search(Post) { paginate(:page => 1) }.total).to eq(4)
43
43
  end
44
44
 
45
45
  it 'returns query time' do
46
46
  stub_nil_results
47
47
  connection.response['responseHeader'] = { 'QTime' => 42 }
48
- session.search(Post) { paginate(:page => 1) }.query_time.should == 42
48
+ expect(session.search(Post) { paginate(:page => 1) }.query_time).to eq(42)
49
49
  end
50
50
 
51
51
  it 'returns total for nil search' do
52
52
  stub_nil_results
53
- session.search(Post).total.should == 0
53
+ expect(session.search(Post).total).to eq(0)
54
54
  end
55
55
 
56
56
  it 'returns available results if some results are not available from data store' do
57
57
  posts = [Post.new, Post.new]
58
58
  posts.last.destroy
59
59
  stub_results(*posts)
60
- session.search(Post).results.should == posts[0..0]
60
+ expect(session.search(Post).results).to eq(posts[0..0])
61
61
  end
62
62
 
63
63
  it 'does not attempt to query the data store more than once when results are unavailable' do
@@ -65,8 +65,8 @@ describe 'search results', :type => :search do
65
65
  posts.each { |post| post.destroy }
66
66
  stub_results(*posts)
67
67
  search = session.search(Post) do
68
- data_accessor_for(Post).should_receive(:load_all).once.and_return([])
68
+ expect(data_accessor_for(Post)).to receive(:load_all).once.and_return([])
69
69
  end
70
- search.results.should == []
70
+ expect(search.results).to eq([])
71
71
  end
72
72
  end
@@ -6,7 +6,7 @@ describe Sunspot::Search do
6
6
  search = session.search Post do
7
7
  data_accessor_for(Post).custom_title = 'custom title'
8
8
  end
9
- search.results.first.title.should == 'custom title'
9
+ expect(search.results.first.title).to eq('custom title')
10
10
  end
11
11
 
12
12
  it 'should re-execute search' do
@@ -14,10 +14,10 @@ describe Sunspot::Search do
14
14
 
15
15
  stub_results(post_1)
16
16
  search = session.search Post
17
- search.results.should == [post_1]
17
+ expect(search.results).to eq([post_1])
18
18
 
19
19
  stub_results(post_2)
20
20
  search.execute!
21
- search.results.should == [post_2]
21
+ expect(search.results).to eq([post_2])
22
22
  end
23
23
  end
@@ -6,7 +6,7 @@ describe 'stats', :type => :search do
6
6
  result = session.search Post do
7
7
  stats :average_rating
8
8
  end
9
- result.stats(:average_rating).field_name.should == :average_rating
9
+ expect(result.stats(:average_rating).field_name).to eq(:average_rating)
10
10
  end
11
11
 
12
12
  it 'returns min for stats field' do
@@ -14,7 +14,7 @@ describe 'stats', :type => :search do
14
14
  result = session.search Post do
15
15
  stats :average_rating
16
16
  end
17
- result.stats(:average_rating).min.should == 1.0
17
+ expect(result.stats(:average_rating).min).to eq(1.0)
18
18
  end
19
19
 
20
20
  it 'returns max for stats field' do
@@ -22,7 +22,7 @@ describe 'stats', :type => :search do
22
22
  result = session.search Post do
23
23
  stats :average_rating
24
24
  end
25
- result.stats(:average_rating).max.should == 5.0
25
+ expect(result.stats(:average_rating).max).to eq(5.0)
26
26
  end
27
27
 
28
28
  it 'returns count for stats field' do
@@ -30,7 +30,7 @@ describe 'stats', :type => :search do
30
30
  result = session.search Post do
31
31
  stats :average_rating
32
32
  end
33
- result.stats(:average_rating).count.should == 120
33
+ expect(result.stats(:average_rating).count).to eq(120)
34
34
  end
35
35
 
36
36
  it 'returns sum for stats field' do
@@ -38,7 +38,7 @@ describe 'stats', :type => :search do
38
38
  result = session.search Post do
39
39
  stats :average_rating
40
40
  end
41
- result.stats(:average_rating).sum.should == 2200.0
41
+ expect(result.stats(:average_rating).sum).to eq(2200.0)
42
42
  end
43
43
 
44
44
  it 'returns facet rows for stats field' do
@@ -51,7 +51,7 @@ describe 'stats', :type => :search do
51
51
  facet :featured
52
52
  end
53
53
  end
54
- stats_facet_values(result, :average_rating, :featured).should == [false, true]
54
+ expect(stats_facet_values(result, :average_rating, :featured)).to eq([false, true])
55
55
  end
56
56
 
57
57
  it 'returns facet stats for stats field' do
@@ -63,8 +63,8 @@ describe 'stats', :type => :search do
63
63
  facet :featured
64
64
  end
65
65
  end
66
- stats_facet_stats(result, :average_rating, :featured, true).min.should == 2.0
67
- stats_facet_stats(result, :average_rating, :featured, true).max.should == 4.0
66
+ expect(stats_facet_stats(result, :average_rating, :featured, true).min).to eq(2.0)
67
+ expect(stats_facet_stats(result, :average_rating, :featured, true).max).to eq(4.0)
68
68
  end
69
69
 
70
70
  it 'returns instantiated stats facet values' do
@@ -76,7 +76,7 @@ describe 'stats', :type => :search do
76
76
  facet :blog_id
77
77
  end
78
78
  end
79
- search.stats(:average_rating).facet(:blog_id).rows.map { |row| row.instance }.should == blogs
79
+ expect(search.stats(:average_rating).facet(:blog_id).rows.map { |row| row.instance }).to eq(blogs)
80
80
  end
81
81
 
82
82
  it 'only returns verified instances when requested' do
@@ -89,6 +89,6 @@ describe 'stats', :type => :search do
89
89
  facet :blog_id
90
90
  end
91
91
  end
92
- search.stats(:average_rating).facet(:blog_id).rows(:verified => true).map { |row| row.instance }.should == [blog]
92
+ expect(search.stats(:average_rating).facet(:blog_id).rows(:verified => true).map { |row| row.instance }).to eq([blog])
93
93
  end
94
94
  end
@@ -9,8 +9,8 @@ describe Sunspot::SessionProxy::ClassShardingSessionProxy do
9
9
  it "should delegate #{method} to appropriate shard" do
10
10
  post = Post.new
11
11
  photo = Photo.new
12
- @proxy.post_session.should_receive(method).with([post])
13
- @proxy.photo_session.should_receive(method).with([photo])
12
+ expect(@proxy.post_session).to receive(method).with([post])
13
+ expect(@proxy.photo_session).to receive(method).with([photo])
14
14
  @proxy.send(method, post)
15
15
  @proxy.send(method, photo)
16
16
  end
@@ -18,14 +18,14 @@ describe Sunspot::SessionProxy::ClassShardingSessionProxy do
18
18
 
19
19
  [:remove_by_id, :remove_by_id!].each do |method|
20
20
  it "should delegate #{method} to appropriate shard" do
21
- @proxy.post_session.should_receive(method).with(Post, [1])
22
- @proxy.photo_session.should_receive(method).with(Photo, [1])
21
+ expect(@proxy.post_session).to receive(method).with(Post, [1])
22
+ expect(@proxy.photo_session).to receive(method).with(Photo, [1])
23
23
  @proxy.send(method, Post, 1)
24
24
  @proxy.send(method, Photo, 1)
25
25
  end
26
26
  it "should delegate #{method} to appropriate shard given ids" do
27
- @proxy.post_session.should_receive(method).with(Post, [1, 2])
28
- @proxy.photo_session.should_receive(method).with(Photo, [1, 2])
27
+ expect(@proxy.post_session).to receive(method).with(Post, [1, 2])
28
+ expect(@proxy.photo_session).to receive(method).with(Photo, [1, 2])
29
29
  @proxy.send(method, Post, 1, 2)
30
30
  @proxy.send(method, Photo, [1, 2])
31
31
  end
@@ -33,15 +33,15 @@ describe Sunspot::SessionProxy::ClassShardingSessionProxy do
33
33
 
34
34
  [:remove_all, :remove_all!].each do |method|
35
35
  it "should delegate #{method} with argument to appropriate shard" do
36
- @proxy.post_session.should_receive(method).with(Post)
37
- @proxy.photo_session.should_receive(method).with(Photo)
36
+ expect(@proxy.post_session).to receive(method).with(Post)
37
+ expect(@proxy.photo_session).to receive(method).with(Photo)
38
38
  @proxy.send(method, Post)
39
39
  @proxy.send(method, Photo)
40
40
  end
41
41
 
42
42
  it "should delegate #{method} without argument to all shards" do
43
- @proxy.post_session.should_receive(method)
44
- @proxy.photo_session.should_receive(method)
43
+ expect(@proxy.post_session).to receive(method)
44
+ expect(@proxy.photo_session).to receive(method)
45
45
  @proxy.send(method)
46
46
  end
47
47
  end
@@ -49,42 +49,43 @@ describe Sunspot::SessionProxy::ClassShardingSessionProxy do
49
49
  [:commit, :commit_if_dirty, :commit_if_delete_dirty, :optimize].each do |method|
50
50
  it "should delegate #{method} to all sessions" do
51
51
  [@proxy.post_session, @proxy.photo_session].each do |session|
52
- session.should_receive(method)
52
+ expect(session).to receive(method)
53
53
  end
54
54
  @proxy.send(method)
55
55
  end
56
56
  end
57
57
 
58
58
  it "should not support the :batch method" do
59
- lambda { @proxy.batch }.should raise_error(Sunspot::SessionProxy::NotSupportedError)
59
+ expect { @proxy.batch }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
60
60
  end
61
61
 
62
62
  it "should delegate new_search to search session, adding in shards parameter" do
63
63
  search = @proxy.new_search(Post)
64
- search.query[:shards].should ==
64
+ expect(search.query[:shards]).to eq(
65
65
  'http://photos.solr.local/solr,http://posts.solr.local/solr'
66
+ )
66
67
  end
67
68
 
68
69
  it "should delegate search to search session, adding in shards parameter" do
69
70
  @proxy.search(Post)
70
- connection.should have_last_search_with(
71
+ expect(connection).to have_last_search_with(
71
72
  :shards => 'http://photos.solr.local/solr,http://posts.solr.local/solr'
72
73
  )
73
74
  end
74
75
 
75
76
  [:dirty, :delete_dirty].each do |method|
76
77
  it "should be dirty if any of the sessions are dirty" do
77
- @proxy.post_session.stub(:"#{method}?").and_return(true)
78
- @proxy.should send("be_#{method}")
78
+ allow(@proxy.post_session).to receive(:"#{method}?").and_return(true)
79
+ expect(@proxy).to send("be_#{method}")
79
80
  end
80
81
 
81
82
  it "should not be dirty if none of the sessions are dirty" do
82
- @proxy.should_not send("be_#{method}")
83
+ expect(@proxy).not_to send("be_#{method}")
83
84
  end
84
85
  end
85
86
 
86
87
  it "should raise a NotSupportedError when :config is called" do
87
- lambda { @proxy.config }.should raise_error(Sunspot::SessionProxy::NotSupportedError)
88
+ expect { @proxy.config }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
88
89
  end
89
90
 
90
91
  it_should_behave_like 'session proxy'
@@ -10,8 +10,8 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
10
10
  [:index, :index!, :remove, :remove!].each do |method|
11
11
  it "should delegate #{method} to appropriate shard" do
12
12
  posts = [Post.new(:id => 2), Post.new(:id => 1)]
13
- @proxy.sessions[0].should_receive(method).with([posts[0]])
14
- @proxy.sessions[1].should_receive(method).with([posts[1]])
13
+ expect(@proxy.sessions[0]).to receive(method).with([posts[0]])
14
+ expect(@proxy.sessions[1]).to receive(method).with([posts[1]])
15
15
  @proxy.send(method, posts[0])
16
16
  @proxy.send(method, posts[1])
17
17
  end
@@ -19,21 +19,21 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
19
19
 
20
20
  [:remove_by_id, :remove_by_id!].each do |method|
21
21
  it "should delegate #{method} to appropriate session" do
22
- @proxy.sessions[1].should_receive(method).with(Post, [3])
23
- @proxy.sessions[0].should_receive(method).with(Post, [2])
24
- @proxy.sessions[1].should_receive(method).with(Post, [1])
22
+ expect(@proxy.sessions[1]).to receive(method).with(Post, [3])
23
+ expect(@proxy.sessions[0]).to receive(method).with(Post, [2])
24
+ expect(@proxy.sessions[1]).to receive(method).with(Post, [1])
25
25
  @proxy.send(method, Post, 1)
26
26
  @proxy.send(method, Post, 2)
27
27
  @proxy.send(method, Post, 3)
28
28
  end
29
29
  it "should delegate #{method} to appropriate session given splatted index ids" do
30
- @proxy.sessions[0].should_receive(method).with(Post, [2])
31
- @proxy.sessions[1].should_receive(method).with(Post, [1, 3])
30
+ expect(@proxy.sessions[0]).to receive(method).with(Post, [2])
31
+ expect(@proxy.sessions[1]).to receive(method).with(Post, [1, 3])
32
32
  @proxy.send(method, Post, 1, 2, 3)
33
33
  end
34
34
  it "should delegate #{method} to appropriate session given array of index ids" do
35
- @proxy.sessions[0].should_receive(method).with(Post, [2])
36
- @proxy.sessions[1].should_receive(method).with(Post, [1, 3])
35
+ expect(@proxy.sessions[0]).to receive(method).with(Post, [2])
36
+ expect(@proxy.sessions[1]).to receive(method).with(Post, [1, 3])
37
37
  @proxy.send(method, Post, [1, 2, 3])
38
38
  end
39
39
  end
@@ -13,28 +13,32 @@ describe Sunspot::SessionProxy::MasterSlaveSessionProxy do
13
13
  methods.each do |method|
14
14
  it "should delegate #{method} to #{delegate}" do
15
15
  args = Array.new(Sunspot::Session.instance_method(method).arity.abs) do
16
- stub('arg')
16
+ double('arg')
17
+ end
18
+ if args.empty?
19
+ expect(instance_variable_get(:"@#{delegate}")).to receive(method).with(no_args)
20
+ else
21
+ expect(instance_variable_get(:"@#{delegate}")).to receive(method).with(*args)
17
22
  end
18
- instance_variable_get(:"@#{delegate}").should_receive(method).with(*args)
19
23
  @proxy.send(method, *args)
20
24
  end
21
25
  end
22
26
  end
23
27
 
24
28
  it 'should return master session config by default' do
25
- @proxy.config.should eql(@master_session.config)
29
+ expect(@proxy.config).to eql(@master_session.config)
26
30
  end
27
31
 
28
32
  it 'should return master session config when specified' do
29
- @proxy.config(:master).should eql(@master_session.config)
33
+ expect(@proxy.config(:master)).to eql(@master_session.config)
30
34
  end
31
35
 
32
36
  it 'should return slave session config when specified' do
33
- @proxy.config(:slave).should eql(@slave_session.config)
37
+ expect(@proxy.config(:slave)).to eql(@slave_session.config)
34
38
  end
35
39
 
36
40
  it 'should raise ArgumentError when bogus config specified' do
37
- lambda { @proxy.config(:bogus) }.should raise_error
41
+ expect { @proxy.config(:bogus) }.to raise_error
38
42
  end
39
43
 
40
44
  it_should_behave_like 'session proxy'
@@ -33,14 +33,14 @@ describe Sunspot::SessionProxy::Retry5xxSessionProxy do
33
33
  end
34
34
 
35
35
  it "should behave normally without a stubbed exception" do
36
- @sunspot_session.should_receive(:index).and_return(double)
36
+ expect(@sunspot_session).to receive(:index).and_return(double)
37
37
  Sunspot.index(post)
38
38
  end
39
39
 
40
40
  it "should be successful with a single exception followed by a sucess" do
41
41
  e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_rsolr_response(503))
42
- @sunspot_session.should_receive(:index).and_return do
43
- @sunspot_session.should_receive(:index).and_return(double)
42
+ expect(@sunspot_session).to receive(:index) do
43
+ expect(@sunspot_session).to receive(:index).and_return(double)
44
44
  raise e
45
45
  end
46
46
  Sunspot.index(post)
@@ -51,23 +51,23 @@ describe Sunspot::SessionProxy::Retry5xxSessionProxy do
51
51
  e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_response)
52
52
  fake_success = double('success')
53
53
 
54
- @sunspot_session.should_receive(:index).and_return do
55
- @sunspot_session.should_receive(:index).and_return do
56
- @sunspot_session.stub(:index).and_return(fake_success)
54
+ expect(@sunspot_session).to receive(:index) do
55
+ expect(@sunspot_session).to receive(:index) do
56
+ allow(@sunspot_session).to receive(:index).and_return(fake_success)
57
57
  raise e
58
58
  end
59
59
  raise e
60
60
  end
61
61
 
62
62
  response = Sunspot.index(post)
63
- response.should_not == fake_success
64
- response.should == fake_response
63
+ expect(response).not_to eq(fake_success)
64
+ expect(response).to eq(fake_response)
65
65
  end
66
66
 
67
67
  it "should not retry a 4xx" do
68
68
  e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_rsolr_response(400))
69
- @sunspot_session.should_receive(:index).and_raise(e)
70
- lambda { Sunspot.index(post) }.should raise_error
69
+ expect(@sunspot_session).to receive(:index).and_raise(e)
70
+ expect { Sunspot.index(post) }.to raise_error
71
71
  end
72
72
 
73
73
  # TODO: try against more than just Sunspot.index? but that's just testing the
@@ -8,8 +8,8 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
8
8
  [:index, :index!, :remove, :remove!].each do |method|
9
9
  it "should delegate #{method} to appropriate shard" do
10
10
  posts = [Post.new(:blog_id => 2), Post.new(:blog_id => 3)]
11
- @proxy.sessions[0].should_receive(method).with([posts[0]])
12
- @proxy.sessions[1].should_receive(method).with([posts[1]])
11
+ expect(@proxy.sessions[0]).to receive(method).with([posts[0]])
12
+ expect(@proxy.sessions[1]).to receive(method).with([posts[1]])
13
13
  @proxy.send(method, posts[0])
14
14
  @proxy.send(method, posts[1])
15
15
  end
@@ -17,17 +17,17 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
17
17
 
18
18
  [:remove_by_id, :remove_by_id!, :atomic_update, :atomic_update!].each do |method|
19
19
  it "should raise NotSupportedError when #{method} called" do
20
- lambda { @proxy.send(method, Post, 1) }.should raise_error(Sunspot::SessionProxy::NotSupportedError)
20
+ expect { @proxy.send(method, Post, 1) }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
21
21
  end
22
22
  end
23
23
 
24
24
  [:remove_all, :remove_all!].each do |method|
25
25
  it "should raise NotSupportedError when #{method} called with argument" do
26
- lambda { @proxy.send(method, Post) }.should raise_error(Sunspot::SessionProxy::NotSupportedError)
26
+ expect { @proxy.send(method, Post) }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
27
27
  end
28
28
 
29
29
  it "should delegate #{method} without argument to all shards" do
30
- @proxy.sessions.each { |session| session.should_receive(method) }
30
+ @proxy.sessions.each { |session| expect(session).to receive(method) }
31
31
  @proxy.send(method)
32
32
  end
33
33
  end
@@ -35,42 +35,43 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
35
35
  [:commit, :commit_if_dirty, :commit_if_delete_dirty, :optimize].each do |method|
36
36
  it "should delegate #{method} to all sessions" do
37
37
  @proxy.sessions.each do |session|
38
- session.should_receive(method)
38
+ expect(session).to receive(method)
39
39
  end
40
40
  @proxy.send(method)
41
41
  end
42
42
  end
43
43
 
44
44
  it "should not support the :batch method" do
45
- lambda { @proxy.batch }.should raise_error(Sunspot::SessionProxy::NotSupportedError)
45
+ expect { @proxy.batch }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
46
46
  end
47
47
 
48
48
  it "should delegate new_search to search session, adding in shards parameter" do
49
49
  search = @proxy.new_search(Post)
50
- search.query[:shards].should ==
50
+ expect(search.query[:shards]).to eq(
51
51
  'http://localhost:8980/solr,http://localhost:8981/solr'
52
+ )
52
53
  end
53
54
 
54
55
  it "should delegate search to search session, adding in shards parameter" do
55
56
  @proxy.search(Post)
56
- connection.should have_last_search_with(
57
+ expect(connection).to have_last_search_with(
57
58
  :shards => 'http://localhost:8980/solr,http://localhost:8981/solr'
58
59
  )
59
60
  end
60
61
 
61
62
  [:dirty, :delete_dirty].each do |method|
62
63
  it "should be dirty if any of the sessions are dirty" do
63
- @proxy.sessions[0].stub(:"#{method}?").and_return(true)
64
- @proxy.should send("be_#{method}")
64
+ allow(@proxy.sessions[0]).to receive(:"#{method}?").and_return(true)
65
+ expect(@proxy).to send("be_#{method}")
65
66
  end
66
67
 
67
68
  it "should not be dirty if none of the sessions are dirty" do
68
- @proxy.should_not send("be_#{method}")
69
+ expect(@proxy).not_to send("be_#{method}")
69
70
  end
70
71
  end
71
72
 
72
73
  it "should raise a NotSupportedError when :config is called" do
73
- lambda { @proxy.config }.should raise_error(Sunspot::SessionProxy::NotSupportedError)
74
+ expect { @proxy.config }.to raise_error(Sunspot::SessionProxy::NotSupportedError)
74
75
  end
75
76
 
76
77
  it_should_behave_like 'session proxy'
@@ -13,8 +13,8 @@ describe Sunspot::SessionProxy::ShardingSessionProxy do
13
13
  it "should call rescued_exception when an exception is caught" do
14
14
  SUPPORTED_METHODS.each do |method|
15
15
  e = FakeException.new(method)
16
- @search_session.stub(method).and_raise(e)
17
- @proxy.should_receive(:rescued_exception).with(method, e)
16
+ allow(@search_session).to receive(method).and_raise(e)
17
+ expect(@proxy).to receive(:rescued_exception).with(method, e)
18
18
  @proxy.send(method)
19
19
  end
20
20
  end
@@ -3,7 +3,7 @@ require File.expand_path('spec_helper', File.join(File.dirname(__FILE__), '..'))
3
3
  shared_examples_for 'session proxy' do
4
4
  Sunspot::Session.public_instance_methods(false).each do |method|
5
5
  it "should respond to #{method.inspect}" do
6
- @proxy.should respond_to(method)
6
+ expect(@proxy).to respond_to(method)
7
7
  end
8
8
  end
9
9
  end
@@ -17,7 +17,7 @@ describe Sunspot::SessionProxy::ThreadLocalSessionProxy do
17
17
  end
18
18
 
19
19
  it 'should have the same session for the same thread' do
20
- @proxy.session.should eql(@proxy.session)
20
+ expect(@proxy.session).to eql(@proxy.session)
21
21
  end
22
22
 
23
23
  it 'should not have the same session for different threads' do
@@ -26,20 +26,24 @@ describe Sunspot::SessionProxy::ThreadLocalSessionProxy do
26
26
  Thread.new do
27
27
  session2 = @proxy.session
28
28
  end.join
29
- session1.should_not eql(session2)
29
+ expect(session1).not_to eql(session2)
30
30
  end
31
31
 
32
32
  it 'should not have the same session for the same thread in different proxy instances' do
33
33
  proxy2 = Sunspot::SessionProxy::ThreadLocalSessionProxy.new(@config)
34
- @proxy.session.should_not eql(proxy2.session)
34
+ expect(@proxy.session).not_to eql(proxy2.session)
35
35
  end
36
36
 
37
37
  (Sunspot::Session.public_instance_methods(false) - ['config', :config]).each do |method|
38
38
  it "should delegate #{method.inspect} to its session" do
39
39
  args = Array.new(Sunspot::Session.instance_method(method).arity.abs) do
40
- stub('arg')
40
+ double('arg')
41
+ end
42
+ if args.empty?
43
+ expect(@proxy.session).to receive(method).with(no_args)
44
+ else
45
+ expect(@proxy.session).to receive(method).with(*args)
41
46
  end
42
- @proxy.session.should_receive(method).with(*args)
43
47
  @proxy.send(method, *args)
44
48
  end
45
49
  end