Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

getting a start on some Flare plugin unit tests

Erik Hatcherbcf88974a928
diff --git a/client/ruby/flare/vendor/plugins/flare/lib/flare/context.rb b/client/ruby/flare/vendor/plugins/flare/lib/flare/context.rb
index ad2675f9031..879cc381a48 100644
--- a/client/ruby/flare/vendor/plugins/flare/lib/flare/context.rb
+++ b/client/ruby/flare/vendor/plugins/flare/lib/flare/context.rb
@@ -24,7 +24,7 @@ class Flare::Context
clear
@facet_queries = {} # name => {:queries => [], :filters => []}
- @index_info = @connection.send(Solr::Request::IndexInfo.new)
+ @index_info = index_info
excluded = @solr_config[:facets_exclude] ? @solr_config[:facets_exclude].collect {|e| e.to_s} : []
@facet_fields = @index_info.field_names.find_all {|v| v =~ /_facet$/} - excluded # TODO: is facets_excluded working? where are the tests?! :)
@@ -42,7 +42,7 @@ class Flare::Context
@page = 1
# this is cleared for development purposes - allowing flare to stay running but different Solr datasets swapping
- @index_info = @connection.send(Solr::Request::IndexInfo.new)
+ @index_info = index_info
excluded = @solr_config[:facets_exclude] ? @solr_config[:facets_exclude].collect {|e| e.to_s} : []
@facet_fields = @index_info.field_names.find_all {|v| v =~ /_facet$/} - excluded
@text_fields = @index_info.field_names.find_all {|v| v =~ /_text$/}
@@ -143,4 +143,8 @@ class Flare::Context
"#{filter[:negative] ? '-' : ''}#{filter[:field]}:#{value}"
end
end
+
+ def index_info
+ @connection.send(Solr::Request::IndexInfo.new)
+ end
end
diff --git a/client/ruby/flare/vendor/plugins/flare/test/flare_context_test.rb b/client/ruby/flare/vendor/plugins/flare/test/flare_context_test.rb
new file mode 100755
index 00000000000..28ee813509b
--- /dev/null
+++ b/client/ruby/flare/vendor/plugins/flare/test/flare_context_test.rb
@@ -0,0 +1,71 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+
+require 'test/unit'
+require 'flare'
+
+class Flare::Context
+ def index_info
+ Solr::Response::IndexInfo.new(<<RUBY_CODE
+ {
+ 'responseHeader'=>{
+ 'status'=>0,
+ 'QTime'=>7},
+ 'fields'=>{
+ 'body_zh_text'=>{'type'=>'text_zh'},
+ 'type_zh_facet'=>{'type'=>'string'},
+ 'subject_era_facet'=>{'type'=>'string'},
+ 'call_number_display'=>{'type'=>'text'},
+ 'id'=>{'type'=>'string'},
+ 'title_text'=>{'type'=>'text'},
+ 'isbn_text'=>{'type'=>'text'},
+ 'source_facet'=>{'type'=>'string'},
+ 'subject_geographic_facet'=>{'type'=>'string'},
+ 'author_text'=>{'type'=>'text'},
+ 'marc_text'=>{'type'=>'text'},
+ 'body_en_text'=>{'type'=>'text'},
+ 'author_zh_facet'=>{'type'=>'string'},
+ 'title_en_text'=>{'type'=>'text'},
+ 'subject_topic_facet'=>{'type'=>'string'},
+ 'library_facet'=>{'type'=>'string'},
+ 'subject_genre_facet'=>{'type'=>'string'},
+ 'external_url_display'=>{'type'=>'text'},
+ 'format_facet'=>{'type'=>'string'},
+ 'type_en_facet'=>{'type'=>'string'},
+ 'author_en_facet'=>{'type'=>'string'},
+ 'text'=>{'type'=>'text'},
+ 'call_number_facet'=>{'type'=>'string'},
+ 'year_facet'=>{'type'=>'string'},
+ 'location_facet'=>{'type'=>'string'},
+ 'title_zh_text'=>{'type'=>'text_zh'}},
+ 'index'=>{
+ 'maxDoc'=>1337165,
+ 'numDocs'=>1337159,
+ 'version'=>'1174965134952'}}
+RUBY_CODE
+)
+ end
+end
+
+class FlareContextTest < Test::Unit::TestCase
+ def setup
+ @flare_context = Flare::Context.new({:solr_url => 'http://localhost:8983/solr'})
+ end
+
+ def test_clear
+ @flare_context.page = 5
+ @flare_context.clear
+ assert_equal @flare_context.page, 1
+ end
+end
\ No newline at end of file