sunspot_matchers 1.3.0.1 → 1.3.0.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.
- data/Gemfile.lock +1 -1
- data/README.markdown +7 -1
- data/lib/sunspot_matchers/matchers.rb +27 -1
- data/lib/sunspot_matchers/version.rb +1 -1
- data/spec/sunspot_matchers_spec.rb +18 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -54,9 +54,15 @@ an explicit search specified, it will use the last one.
|
|
54
54
|
|
55
55
|
`Sunspot.session.searches.first.should be_a_search_for(Post)`
|
56
56
|
|
57
|
+
## have_searchable_field
|
58
|
+
|
59
|
+
If you want to verify that a model has a searchable field, you can use this matcher:
|
60
|
+
|
61
|
+
`Post.should have_searchable_field(:name)`
|
62
|
+
|
57
63
|
## have_search_params
|
58
64
|
|
59
|
-
This is where the bulk of the functionality lies. There are seven types of search matches you can perform: `keywords`,
|
65
|
+
This is where the bulk of the functionality lies. There are seven types of search matches you can perform: `keywords` or `fulltext`,
|
60
66
|
`with`, `without`, `paginate`, `order_by`, `facet`, and `boost`.
|
61
67
|
|
62
68
|
In all of the examples below, the expectation fully matches the search terms. This is not expected or required. You can
|
@@ -148,7 +148,7 @@ module SunspotMatchers
|
|
148
148
|
WithMatcher
|
149
149
|
when :without
|
150
150
|
WithoutMatcher
|
151
|
-
when :keywords
|
151
|
+
when :keywords, :fulltext
|
152
152
|
KeywordsMatcher
|
153
153
|
when :boost
|
154
154
|
BoostMatcher
|
@@ -305,6 +305,32 @@ module SunspotMatchers
|
|
305
305
|
def be_a_search_for(expected_class)
|
306
306
|
BeASearchFor.new(expected_class)
|
307
307
|
end
|
308
|
+
|
309
|
+
class HaveSearchableField
|
310
|
+
|
311
|
+
def initialize(field)
|
312
|
+
@field = field
|
313
|
+
end
|
314
|
+
|
315
|
+
def matches?(klass)
|
316
|
+
@klass = klass
|
317
|
+
Sunspot::Setup.for(@klass).text_field_factories.find do |field|
|
318
|
+
field.name == @field
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
def failure_message_for_should
|
323
|
+
"expected class: #{@klass} to have searchable field: #{@field}"
|
324
|
+
end
|
325
|
+
|
326
|
+
def failure_message_for_should_not
|
327
|
+
"expected class: #{@klass} NOT to have searchable field: #{@field}"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
def have_searchable_field(field)
|
332
|
+
HaveSearchableField.new(field)
|
333
|
+
end
|
308
334
|
end
|
309
335
|
|
310
336
|
def any_param
|
@@ -48,7 +48,7 @@ describe "Sunspot Matchers" do
|
|
48
48
|
Sunspot.session.searches.last.should have_search_params(:keywords, 'bad pizza')
|
49
49
|
end
|
50
50
|
|
51
|
-
describe "keyword matcher" do
|
51
|
+
describe "keyword/fulltext matcher" do
|
52
52
|
it "should match if search matches" do
|
53
53
|
Sunspot.search(Post) do
|
54
54
|
keywords 'great pizza'
|
@@ -56,6 +56,13 @@ describe "Sunspot Matchers" do
|
|
56
56
|
Sunspot.session.should have_search_params(:keywords, 'great pizza')
|
57
57
|
end
|
58
58
|
|
59
|
+
it "should work with fulltext also" do
|
60
|
+
Sunspot.search(Post) do
|
61
|
+
fulltext 'great pizza'
|
62
|
+
end
|
63
|
+
Sunspot.session.should have_search_params(:fulltext, 'great pizza')
|
64
|
+
end
|
65
|
+
|
59
66
|
it "should not match if search does not match" do
|
60
67
|
Sunspot.search(Post) do
|
61
68
|
keywords 'terrible pizza'
|
@@ -719,4 +726,14 @@ describe "Sunspot Matchers" do
|
|
719
726
|
end
|
720
727
|
end
|
721
728
|
end
|
729
|
+
|
730
|
+
describe "have_searchable_field" do
|
731
|
+
it "should succeed if the model has the given field" do
|
732
|
+
Post.should have_searchable_field(:body)
|
733
|
+
end
|
734
|
+
|
735
|
+
it "should fail if the model does not have the given field" do
|
736
|
+
Post.should_not have_searchable_field(:potato)
|
737
|
+
end
|
738
|
+
end
|
722
739
|
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
|
-
hash:
|
4
|
+
hash: 67
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.3.0.
|
10
|
+
- 2
|
11
|
+
version: 1.3.0.2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Joseph Palermo
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2012-06-25 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|