sunspot_matchers 2.1.1.1 → 2.1.1.2
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.
- checksums.yaml +4 -4
- data/README.markdown +13 -1
- data/lib/sunspot_matchers/matchers.rb +33 -2
- data/lib/sunspot_matchers/version.rb +1 -1
- data/spec/have_dynamic_field_matcher_spec.rb +30 -0
- data/spec/sunspot_matchers_spec.rb +29 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f9638b2e0405f2318ea981cbc3f943391b3c245
|
4
|
+
data.tar.gz: 3393b79ea2608a515e1eabb9f10ecf7e314d0ead
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3ab73b9fdc51ad5ac5f339a0550a67d4130853946bbe3b0f56711f430bc942194bae261cb6f84d0ddeb421aed7865e6176df3e23c97012f1fcc9b108eee0f39
|
7
|
+
data.tar.gz: b14ea7b125f77710509c675eab598add202af4a07667c0fbdf9bdbe6560ebe6ade8768f29107ce5953511cf306c4f8ea9949dfee37f02d14660905916ce4186a
|
data/README.markdown
CHANGED
@@ -66,6 +66,18 @@ You can also use the shorthand syntax:
|
|
66
66
|
it { should have_searchable_field(:name) }
|
67
67
|
end
|
68
68
|
|
69
|
+
## have_dynamic_field
|
70
|
+
|
71
|
+
If you want to verify that a model has a dynamic searchable field, you can use this matcher:
|
72
|
+
|
73
|
+
`Post.should have_dynamic_field(:commenter_read)`
|
74
|
+
|
75
|
+
You can also use the shorthand syntax:
|
76
|
+
|
77
|
+
describe User do
|
78
|
+
it { should have_dynamic_field(:commenter_read) }
|
79
|
+
end
|
80
|
+
|
69
81
|
## have_search_params
|
70
82
|
|
71
83
|
This is where the bulk of the functionality lies. There are seven types of search matches you can perform: `keywords` or `fulltext`,
|
@@ -293,4 +305,4 @@ These are used like:
|
|
293
305
|
assert_is_search_for Sunspot.session, Blog
|
294
306
|
assert_is_not_search_for Sunspot.session, Person
|
295
307
|
|
296
|
-
Check out the test/sunspot_matchers_test.rb for more examples
|
308
|
+
Check out the test/sunspot_matchers_test.rb for more examples
|
@@ -331,8 +331,7 @@ module SunspotMatchers
|
|
331
331
|
|
332
332
|
def matches?(klass_or_object)
|
333
333
|
@klass = klass_or_object.class.name == 'Class' ? klass_or_object : klass_or_object.class
|
334
|
-
|
335
|
-
@sunspot && (@sunspot.all_text_fields + @sunspot.fields).collect(&:name).include?(@field)
|
334
|
+
sunspot && fields_to_match.include?(@field)
|
336
335
|
end
|
337
336
|
|
338
337
|
def description
|
@@ -347,11 +346,43 @@ module SunspotMatchers
|
|
347
346
|
def failure_message_when_negated
|
348
347
|
"expected class: #{@klass} NOT to have searchable field: #{@field}"
|
349
348
|
end
|
349
|
+
|
350
|
+
def sunspot
|
351
|
+
@sunspot ||= Sunspot::Setup.for(@klass)
|
352
|
+
end
|
353
|
+
|
354
|
+
def fields_to_match
|
355
|
+
(sunspot.all_text_fields + sunspot.fields).collect(&:name)
|
356
|
+
end
|
350
357
|
end
|
351
358
|
|
352
359
|
def have_searchable_field(field)
|
353
360
|
HaveSearchableField.new(field)
|
354
361
|
end
|
362
|
+
|
363
|
+
class HaveDynamicField < HaveSearchableField
|
364
|
+
def description
|
365
|
+
"have dynamic searchable field '#{@field}'"
|
366
|
+
end
|
367
|
+
|
368
|
+
def failure_message
|
369
|
+
message = "expected class: #{@klass} to have dynamic searchable field: #{@field}"
|
370
|
+
message << ", but Sunspot was not configured on #{@klass}" unless @sunspot
|
371
|
+
end
|
372
|
+
|
373
|
+
def failure_message_when_negated
|
374
|
+
"expected class: #{@klass} NOT to have dynamic searchable field: #{@field}"
|
375
|
+
end
|
376
|
+
|
377
|
+
def fields_to_match
|
378
|
+
sunspot.dynamic_field_factories.collect(&:name)
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
def have_dynamic_field(field)
|
383
|
+
HaveDynamicField.new(field)
|
384
|
+
end
|
385
|
+
|
355
386
|
end
|
356
387
|
|
357
388
|
class AnyParam < String
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'sunspot'
|
2
|
+
require 'sunspot_matchers'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
describe SunspotMatchers::HaveDynamicField do
|
6
|
+
let(:matcher) do
|
7
|
+
described_class.new(:field).tap do |matcher|
|
8
|
+
matcher.matches? klass
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when a class has no searchable fields" do
|
13
|
+
let(:klass) { NotALotGoingOn = Class.new }
|
14
|
+
|
15
|
+
it "gives Sunspot configuration error" do
|
16
|
+
expect(matcher.failure_message).to match(/Sunspot was not configured/)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when a class has an unexpected searchable field" do
|
21
|
+
let(:klass) { IndexedWithWrongThings = Class.new }
|
22
|
+
before do
|
23
|
+
Sunspot.setup(klass) { text :parachute }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "does not have an error" do
|
27
|
+
expect(matcher.failure_message).to be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -18,6 +18,7 @@ Sunspot.setup(Post) do
|
|
18
18
|
integer :popularity
|
19
19
|
time :published_at
|
20
20
|
float :average_rating
|
21
|
+
dynamic_boolean(:commenter_read)
|
21
22
|
end
|
22
23
|
|
23
24
|
Sunspot.setup(Blog) do
|
@@ -815,8 +816,9 @@ describe "Sunspot Matchers" do
|
|
815
816
|
expect(have_searchable_field(field_name).description).to eq description
|
816
817
|
end
|
817
818
|
|
818
|
-
|
819
|
-
|
819
|
+
context "when given an instance" do
|
820
|
+
subject {Post.new}
|
821
|
+
it { is_expected.to have_searchable_field(:body) }
|
820
822
|
end
|
821
823
|
|
822
824
|
it "succeeds if the model has the given field" do
|
@@ -833,4 +835,29 @@ describe "Sunspot Matchers" do
|
|
833
835
|
expect(Person).to_not have_searchable_field(:name)
|
834
836
|
end
|
835
837
|
end
|
838
|
+
|
839
|
+
describe "have_dynamic_field" do
|
840
|
+
it "provides a description" do
|
841
|
+
field_name = :commenter_read
|
842
|
+
description = "have dynamic searchable field '#{field_name}'"
|
843
|
+
expect(have_dynamic_field(field_name).description).to eq description
|
844
|
+
end
|
845
|
+
|
846
|
+
context "when given an instance" do
|
847
|
+
subject {Post.new}
|
848
|
+
it { is_expected.to have_dynamic_field(:commenter_read) }
|
849
|
+
end
|
850
|
+
|
851
|
+
it "succeeds if the model has the given field" do
|
852
|
+
expect(Post).to have_dynamic_field(:commenter_read)
|
853
|
+
end
|
854
|
+
|
855
|
+
it "fails if the model does not have the given field" do
|
856
|
+
expect(Post).to_not have_dynamic_field(:potato)
|
857
|
+
end
|
858
|
+
|
859
|
+
it "fails if the model does not have any dynamic fields" do
|
860
|
+
expect(Person).to_not have_dynamic_field(:name)
|
861
|
+
end
|
862
|
+
end
|
836
863
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.1.
|
4
|
+
version: 2.1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Palermo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/sunspot_matchers/sunspot_session_spy.rb
|
85
85
|
- lib/sunspot_matchers/test_helper.rb
|
86
86
|
- lib/sunspot_matchers/version.rb
|
87
|
+
- spec/have_dynamic_field_matcher_spec.rb
|
87
88
|
- spec/have_searchable_field_matcher_spec.rb
|
88
89
|
- spec/sunspot_matchers_spec.rb
|
89
90
|
- sunspot_matchers.gemspec
|