bento_search 1.5.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +27 -24
  3. data/Rakefile +30 -11
  4. data/app/assets/javascripts/bento_search/ajax_load.js +54 -22
  5. data/app/controllers/bento_search/search_controller.rb +31 -30
  6. data/app/helpers/bento_search_helper.rb +72 -74
  7. data/app/models/bento_search/concurrent_searcher.rb +136 -0
  8. data/app/models/bento_search/result_item.rb +15 -12
  9. data/app/models/bento_search/results/serialization.rb +22 -13
  10. data/app/models/bento_search/search_engine.rb +170 -140
  11. data/app/search_engines/bento_search/doaj_articles_engine.rb +20 -20
  12. data/app/search_engines/bento_search/ebsco_host_engine.rb +3 -3
  13. data/app/search_engines/bento_search/eds_engine.rb +326 -206
  14. data/app/search_engines/bento_search/google_books_engine.rb +2 -2
  15. data/app/search_engines/bento_search/scopus_engine.rb +87 -87
  16. data/app/search_engines/bento_search/summon_engine.rb +1 -1
  17. data/app/views/bento_search/_ajax_loading.html.erb +17 -0
  18. data/app/views/bento_search/_item_title.html.erb +2 -4
  19. data/app/views/bento_search/_link.html.erb +3 -3
  20. data/lib/bento_search.rb +24 -9
  21. data/lib/bento_search/engine.rb +2 -0
  22. data/lib/bento_search/version.rb +1 -1
  23. data/lib/generators/bento_search/install/ajax_load_js_generator.rb +15 -0
  24. data/test/decorator/standard_decorator_test.rb +30 -30
  25. data/test/dummy/app/assets/config/manifest.js +4 -0
  26. data/test/dummy/config/application.rb +7 -0
  27. data/test/dummy/config/boot.rb +4 -9
  28. data/test/dummy/config/environments/development.rb +2 -0
  29. data/test/dummy/config/environments/production.rb +7 -1
  30. data/test/dummy/config/environments/test.rb +10 -3
  31. data/test/functional/bento_search/search_controller_test.rb +68 -58
  32. data/test/helper/bento_search_helper_test.rb +103 -103
  33. data/test/search_engines/doaj_articles_engine_test.rb +9 -9
  34. data/test/search_engines/eds_engine_test.rb +91 -59
  35. data/test/search_engines/google_site_search_test.rb +48 -48
  36. data/test/search_engines/scopus_engine_test.rb +51 -51
  37. data/test/search_engines/search_engine_base_test.rb +108 -86
  38. data/test/search_engines/search_engine_test.rb +68 -56
  39. data/test/support/atom.xsd.xml +3 -3
  40. data/test/support/xml.xsd +117 -0
  41. data/test/test_helper.rb +23 -12
  42. data/test/unit/concurrent_searcher_test.rb +75 -0
  43. data/test/unit/pagination_test.rb +12 -12
  44. data/test/vcr_cassettes/eds/FullText_CustomLink.yml +198 -0
  45. data/test/vcr_cassettes/eds/basic_search_smoke_test.yml +1036 -1729
  46. data/test/vcr_cassettes/eds/catalog_ebook_query.yml +218 -0
  47. data/test/vcr_cassettes/eds/catalog_query.yml +255 -0
  48. data/test/vcr_cassettes/eds/get_auth_token.yml +11 -44
  49. data/test/vcr_cassettes/eds/get_auth_token_failure.yml +10 -7
  50. data/test/vcr_cassettes/eds/get_with_auth.yml +144 -153
  51. data/test/vcr_cassettes/eds/get_with_auth_recovers_from_bad_auth.yml +167 -223
  52. data/test/view/atom_results_test.rb +94 -94
  53. metadata +36 -46
  54. data/app/assets/javascripts/bento_search.js +0 -3
  55. data/app/item_decorators/bento_search/ebscohost/conditional_openurl_main_link.rb +0 -36
  56. data/app/item_decorators/bento_search/only_premade_openurl.rb +0 -20
  57. data/app/item_decorators/bento_search/openurl_add_other_link.rb +0 -39
  58. data/app/item_decorators/bento_search/openurl_main_link.rb +0 -34
  59. data/app/models/bento_search/multi_searcher.rb +0 -131
  60. data/test/dummy/config/initializers/secret_token.rb +0 -8
  61. data/test/unit/multi_searcher_test.rb +0 -49
@@ -4,50 +4,50 @@ require 'test_helper'
4
4
 
5
5
  class SearchEngineTest < ActiveSupport::TestCase
6
6
  MockEngine = BentoSearch::MockEngine
7
-
7
+
8
8
  test "takes configuration" do
9
9
  conf = Confstruct::Configuration.new( :foo => "foo", :bar => "bar", :top => {:next => "required key"} )
10
10
  engine = MockEngine.new(conf)
11
-
11
+
12
12
  assert_not_nil engine.configuration
13
13
  assert_equal "foo", engine.configuration.foo
14
14
  assert_equal "bar", engine.configuration.bar
15
15
  assert_equal "required key", engine.configuration.top.next
16
16
  end
17
-
17
+
18
18
  test "nested configuration with hash" do
19
19
  # possible bug in Confstruct make sure we're working around
20
- # if needed.
20
+ # if needed.
21
21
  # https://github.com/mbklein/confstruct/issues/14
22
22
  engine = MockEngine.new("top" => {"one" => "two"})
23
-
24
- assert_equal "two", engine.configuration.top.one
23
+
24
+ assert_equal "two", engine.configuration.top.one
25
25
  end
26
-
26
+
27
27
  test "nested required config key" do
28
28
  requires_class = Class.new(MockEngine) do
29
29
  def self.required_configuration
30
30
  ["required.mykey"]
31
31
  end
32
32
  end
33
-
33
+
34
34
  assert_raise ArgumentError do
35
35
  requires_class.new
36
- end
37
-
36
+ end
37
+
38
38
  assert_raise ArgumentError do
39
39
  requires_class.new(:requires => {})
40
40
  end
41
-
41
+
42
42
  assert_raise ArgumentError do
43
43
  requires_class.new(:required => {:mykey => nil})
44
44
  end
45
-
45
+
46
46
  assert_nothing_raised do
47
47
  requires_class.new(:required => {:mykey => "foo"})
48
48
  end
49
49
  end
50
-
50
+
51
51
  test "merges default configuration" do
52
52
  @dummy_class = Class.new do
53
53
  include BentoSearch::SearchEngine
@@ -59,120 +59,132 @@ class SearchEngineTest < ActiveSupport::TestCase
59
59
  }
60
60
  end
61
61
  end
62
-
62
+
63
63
  engine = @dummy_class.new( :two => "new", :array => ["one", "two"], :nested => {:two => "new"}, :required => {:mykey => "required key"} )
64
-
64
+
65
65
  assert_kind_of Confstruct::Configuration, engine.configuration
66
66
  assert_equal "default" , engine.configuration.one
67
67
  assert_equal "new" , engine.configuration.two
68
68
  assert_equal "default" , engine.configuration.nested.one
69
69
  assert_equal "new" , engine.configuration.nested.two
70
- assert_equal ["one", "two"] , engine.configuration.array
70
+ assert_equal ["one", "two"] , engine.configuration.array
71
71
  end
72
-
72
+
73
73
  test "no default configuration" do
74
74
  @dummy_class = Class.new do
75
75
  include BentoSearch::SearchEngine
76
76
  end
77
-
77
+
78
78
  engine = @dummy_class.new( :one => "one" )
79
-
79
+
80
80
  assert_kind_of Confstruct::Configuration, engine.configuration
81
81
  assert_equal "one", engine.configuration.one
82
82
  end
83
-
83
+
84
84
  test "sets metadata on results" do
85
85
  engine = MockEngine.new(:id => "foo")
86
-
86
+
87
87
  results = engine.search(:query => "cancer", :per_page => 20)
88
-
88
+
89
89
  assert_present results.search_args
90
90
  assert_equal "foo", results.engine_id
91
-
91
+
92
92
  pagination = results.pagination
93
93
  assert_present pagination
94
-
94
+
95
95
  assert_equal 20, pagination.per_page
96
96
  assert_equal 1, pagination.current_page
97
97
  assert_equal 1, pagination.start_record
98
98
  assert_equal 20, pagination.end_record
99
99
  assert pagination.first_page?
100
-
100
+
101
101
  assert_present pagination.total_pages
102
102
  assert_present pagination.count_records
103
-
103
+
104
104
  end
105
-
105
+
106
106
  test "sets metadata on items" do
107
- engine = MockEngine.new(:id => "foo", :for_display => {:mykey => "value", :decorator => "Foo"})
107
+ engine = MockEngine.new(:id => "foo", :for_display => {:mykey => "value", :decorator => "Foo"})
108
108
  results = engine.search(:query => "cancer")
109
109
  record = results.first
110
-
110
+
111
111
  assert_present record.engine_id
112
112
  assert_present record.display_configuration
113
- assert_present record.decorator
113
+ assert_present record.decorator
114
114
  end
115
-
115
+
116
116
  test "failed sets metadata on results" do
117
117
  engine = MockEngine.new(:id => "fail_engine", :error => {:message => "failed"}, :for_display => {:foo => "foo"})
118
-
118
+
119
119
  results = engine.search(:query => "cancer", :per_page => 20)
120
-
120
+
121
121
  assert results.failed?
122
122
  assert_present results.error
123
123
  assert_equal "fail_engine", results.engine_id
124
124
  assert_present results.search_args
125
- assert_equal( {:foo => "foo"}, results.display_configuration )
125
+ assert_equal( {:foo => "foo"}, results.display_configuration )
126
126
  end
127
-
127
+
128
128
  test "auto rescued exception, with proper metadata" do
129
- engine = MockEngine.new(:id => "raises", :raise_exception_class => 'TimeoutError', :for_display => {:foo => "foo"})
130
-
129
+ engine = MockEngine.new(:id => "raises", :raise_exception_class => BentoSearch::RubyTimeoutClass.name, :for_display => {:foo => "foo"})
130
+
131
131
  results = engine.search("foo", :per_page => 20)
132
-
132
+
133
133
  assert results.failed?, "marked failed"
134
- assert_present results.error
134
+ assert_present results.error
135
+ assert_present results.error[:exception]
135
136
  assert_equal "raises", results.engine_id
136
137
  assert_present results.search_args
137
138
  assert_equal "foo", results.search_args[:query]
138
-
139
+
139
140
  assert_equal( {:foo => "foo"}, results.display_configuration )
140
141
  end
141
-
142
-
142
+
143
+ test "can set auto rescued exceptions on instance" do
144
+ engine = MockEngine.new(:id => "raises", :raise_exception_class => "StandardError", :for_display => {:foo => "foo"})
145
+ engine.auto_rescued_exceptions = [StandardError]
146
+
147
+ results = engine.search("foo", :per_page => 20)
148
+
149
+ assert results.failed?, "marked failed"
150
+ assert_present results.error
151
+ assert_present results.error[:exception]
152
+ end
153
+
154
+
143
155
  test "has empty :for_display config" do
144
156
  engine = MockEngine.new
145
-
157
+
146
158
  assert_not_nil engine.configuration.for_display
147
159
  end
148
-
160
+
149
161
  test "error results still filled out okay" do
150
162
  engine = MockEngine.new(:error => {:msg => "forced error"}, :id => "test")
151
-
163
+
152
164
  results = engine.search("foo")
153
-
165
+
154
166
  assert_present results.search_args
155
167
  assert_equal "test", results.engine_id
156
-
168
+
157
169
  pagination = nil
158
170
  assert_nothing_raised { pagination = results.pagination }
159
-
171
+
160
172
  assert_present pagination
161
173
  assert_equal 0, pagination.count_records
162
-
174
+
163
175
  end
164
-
165
-
176
+
177
+
166
178
  test "carries display configuration over to results" do
167
- engine = MockEngine.new(:id => "foo",
179
+ engine = MockEngine.new(:id => "foo",
168
180
  :for_display => {:foo => "bar", :nested => {"one" => "two"}}
169
181
  )
170
-
182
+
171
183
  results = engine.search("foo")
172
184
 
173
185
  assert_present results.display_configuration
174
- assert_present results.display_configuration.foo
175
- assert_present results.display_configuration.nested.one
186
+ assert_present results.display_configuration.foo
187
+ assert_present results.display_configuration.nested.one
176
188
  end
177
-
189
+
178
190
  end
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="utf-8" ?>
2
- <xs:schema targetNamespace="http://www.w3.org/2005/Atom" elementFormDefault="qualified"
2
+ <xs:schema targetNamespace="http://www.w3.org/2005/Atom" elementFormDefault="qualified"
3
3
  attributeFormDefault="unqualified"
4
4
  xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xs="http://www.w3.org/2001/XMLSchema">
5
5
  <xs:annotation>
@@ -8,7 +8,7 @@
8
8
  found here http://www.atomenabled.org/developers/syndication/atom-format-spec.php.
9
9
  </xs:documentation>
10
10
  </xs:annotation>
11
- <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd" />
11
+ <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="./xml.xsd" />
12
12
  <xs:annotation>
13
13
  <xs:documentation>
14
14
  An Atom document may have two root elements, feed and entry, as defined in section 2.
@@ -237,4 +237,4 @@
237
237
  <xs:attribute ref="xml:lang" />
238
238
  <xs:anyAttribute namespace="##other"/>
239
239
  </xs:attributeGroup>
240
- </xs:schema>
240
+ </xs:schema>
@@ -0,0 +1,117 @@
1
+ <?xml version='1.0'?>
2
+ <!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd" >
3
+ <xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="en">
4
+
5
+ <xs:annotation>
6
+ <xs:documentation>
7
+ See http://www.w3.org/XML/1998/namespace.html and
8
+ http://www.w3.org/TR/REC-xml for information about this namespace.
9
+
10
+ This schema document describes the XML namespace, in a form
11
+ suitable for import by other schema documents.
12
+
13
+ Note that local names in this namespace are intended to be defined
14
+ only by the World Wide Web Consortium or its subgroups. The
15
+ following names are currently defined in this namespace and should
16
+ not be used with conflicting semantics by any Working Group,
17
+ specification, or document instance:
18
+
19
+ base (as an attribute name): denotes an attribute whose value
20
+ provides a URI to be used as the base for interpreting any
21
+ relative URIs in the scope of the element on which it
22
+ appears; its value is inherited. This name is reserved
23
+ by virtue of its definition in the XML Base specification.
24
+
25
+ lang (as an attribute name): denotes an attribute whose value
26
+ is a language code for the natural language of the content of
27
+ any element; its value is inherited. This name is reserved
28
+ by virtue of its definition in the XML specification.
29
+
30
+ space (as an attribute name): denotes an attribute whose
31
+ value is a keyword indicating what whitespace processing
32
+ discipline is intended for the content of the element; its
33
+ value is inherited. This name is reserved by virtue of its
34
+ definition in the XML specification.
35
+
36
+ Father (in any context at all): denotes Jon Bosak, the chair of
37
+ the original XML Working Group. This name is reserved by
38
+ the following decision of the W3C XML Plenary and
39
+ XML Coordination groups:
40
+
41
+ In appreciation for his vision, leadership and dedication
42
+ the W3C XML Plenary on this 10th day of February, 2000
43
+ reserves for Jon Bosak in perpetuity the XML name
44
+ xml:Father
45
+ </xs:documentation>
46
+ </xs:annotation>
47
+
48
+ <xs:annotation>
49
+ <xs:documentation>This schema defines attributes and an attribute group
50
+ suitable for use by
51
+ schemas wishing to allow xml:base, xml:lang or xml:space attributes
52
+ on elements they define.
53
+
54
+ To enable this, such a schema must import this schema
55
+ for the XML namespace, e.g. as follows:
56
+ &lt;schema . . .>
57
+ . . .
58
+ &lt;import namespace="http://www.w3.org/XML/1998/namespace"
59
+ schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>
60
+
61
+ Subsequently, qualified reference to any of the attributes
62
+ or the group defined below will have the desired effect, e.g.
63
+
64
+ &lt;type . . .>
65
+ . . .
66
+ &lt;attributeGroup ref="xml:specialAttrs"/>
67
+
68
+ will define a type which will schema-validate an instance
69
+ element with any of those attributes</xs:documentation>
70
+ </xs:annotation>
71
+
72
+ <xs:annotation>
73
+ <xs:documentation>In keeping with the XML Schema WG's standard versioning
74
+ policy, this schema document will persist at
75
+ http://www.w3.org/2001/03/xml.xsd.
76
+ At the date of issue it can also be found at
77
+ http://www.w3.org/2001/xml.xsd.
78
+ The schema document at that URI may however change in the future,
79
+ in order to remain compatible with the latest version of XML Schema
80
+ itself. In other words, if the XML Schema namespace changes, the version
81
+ of this document at
82
+ http://www.w3.org/2001/xml.xsd will change
83
+ accordingly; the version at
84
+ http://www.w3.org/2001/03/xml.xsd will not change.
85
+ </xs:documentation>
86
+ </xs:annotation>
87
+
88
+ <xs:attribute name="lang" type="xs:language">
89
+ <xs:annotation>
90
+ <xs:documentation>In due course, we should install the relevant ISO 2- and 3-letter
91
+ codes as the enumerated possible values . . .</xs:documentation>
92
+ </xs:annotation>
93
+ </xs:attribute>
94
+
95
+ <xs:attribute name="space" default="preserve">
96
+ <xs:simpleType>
97
+ <xs:restriction base="xs:NCName">
98
+ <xs:enumeration value="default"/>
99
+ <xs:enumeration value="preserve"/>
100
+ </xs:restriction>
101
+ </xs:simpleType>
102
+ </xs:attribute>
103
+
104
+ <xs:attribute name="base" type="xs:anyURI">
105
+ <xs:annotation>
106
+ <xs:documentation>See http://www.w3.org/TR/xmlbase/ for
107
+ information about this attribute.</xs:documentation>
108
+ </xs:annotation>
109
+ </xs:attribute>
110
+
111
+ <xs:attributeGroup name="specialAttrs">
112
+ <xs:attribute ref="xml:base"/>
113
+ <xs:attribute ref="xml:lang"/>
114
+ <xs:attribute ref="xml:space"/>
115
+ </xs:attributeGroup>
116
+
117
+ </xs:schema>
data/test/test_helper.rb CHANGED
@@ -2,14 +2,25 @@
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
4
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
5
6
 
6
- # we insist on minitest, when only the best will do.
7
- # Rails will build on top of it if it's there.
8
- require 'minitest/autorun'
9
- require 'minitest/unit'
10
-
7
+ # we insist on minitest, when only the best will do.
8
+ # Rails will build on top of it if it's there.
9
+ require 'minitest/spec'
11
10
  require "rails/test_help"
12
11
 
12
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
13
+ # to be shown.
14
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
15
+
16
+ # We're not supposed to have to manually install rails-controller-testing, not
17
+ # sure why we do.
18
+ begin
19
+ require 'rails-controller-testing'
20
+ Rails::Controller::Testing.install
21
+ rescue LoadError
22
+ end
23
+
13
24
  Rails.backtrace_cleaner.remove_silencers!
14
25
 
15
26
  # Load support files
@@ -25,23 +36,23 @@ end
25
36
  # back. Useful for efficiency, also useful for
26
37
  # testing code against API's that not everyone
27
38
  # has access to -- the responses can be cached
28
- # and re-used.
39
+ # and re-used.
29
40
  require 'vcr'
30
41
  require 'webmock'
31
42
 
32
43
  # To allow us to do real HTTP requests in a VCR.turned_off, we
33
- # have to tell webmock to let us.
44
+ # have to tell webmock to let us.
34
45
  WebMock.allow_net_connect!
35
46
 
36
47
  VCR.configure do |c|
37
48
  c.cassette_library_dir = 'test/vcr_cassettes'
38
49
  # webmock needed for HTTPClient testing
39
- c.hook_into :webmock
50
+ c.hook_into :webmock
40
51
  end
41
52
 
42
53
  # Silly way to not have to rewrite all our tests if we
43
54
  # temporarily disable VCR, make VCR.use_cassette a no-op
44
- # instead of no-such-method.
55
+ # instead of no-such-method.
45
56
  if ! defined? VCR
46
57
  module VCR
47
58
  def self.use_cassette(*args)
@@ -50,9 +61,9 @@ if ! defined? VCR
50
61
  end
51
62
  end
52
63
 
53
- # re-open to add
64
+ # re-open to add
54
65
  # some custom assertions, that used to be in mini-test, or that
55
- # we wanted to add.
66
+ # we wanted to add.
56
67
  class ActiveSupport::TestCase
57
68
 
58
69
  def assert_present(object, msg = nil)
@@ -65,4 +76,4 @@ class ActiveSupport::TestCase
65
76
  assert object.blank?, msg
66
77
  end
67
78
 
68
- end
79
+ end