umlaut 4.0.3 → 4.1.0.pre.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.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +6 -0
  3. data/app/assets/javascripts/umlaut/update_html.js +81 -23
  4. data/app/assets/stylesheets/umlaut/_misc.scss +1 -2
  5. data/app/assets/stylesheets/umlaut/_resolve.scss +44 -10
  6. data/app/controllers/export_email_controller.rb +2 -2
  7. data/app/controllers/feedback_controller.rb +1 -1
  8. data/app/controllers/umlaut/controller_behavior.rb +14 -0
  9. data/app/controllers/umlaut_configurable.rb +52 -21
  10. data/app/helpers/open_search_helper.rb +1 -1
  11. data/app/helpers/resolve_helper.rb +36 -35
  12. data/app/helpers/umlaut/section_highlights.rb +85 -0
  13. data/app/mixin_logic/metadata_helper.rb +11 -5
  14. data/app/models/collection.rb +129 -96
  15. data/app/models/dispatched_service.rb +4 -0
  16. data/app/models/referent.rb +7 -1
  17. data/app/models/request.rb +21 -0
  18. data/app/models/service_store.rb +16 -3
  19. data/app/presentation/section_renderer.rb +16 -17
  20. data/app/service_adaptors/blacklight.rb +11 -4
  21. data/app/service_adaptors/internet_archive.rb +58 -25
  22. data/app/service_adaptors/isi.rb +14 -4
  23. data/app/service_adaptors/jcr.rb +13 -4
  24. data/app/views/resolve/_fulltext.html.erb +1 -1
  25. data/app/views/resolve/_section_display.html.erb +1 -1
  26. data/app/views/resolve/_service_errors.html.erb +3 -3
  27. data/app/views/search/books.html.erb +1 -1
  28. data/app/views/search/journal_search.html.erb +2 -1
  29. data/app/views/search/journals.html.erb +2 -1
  30. data/db/orig_fixed_data/service_type_values.yml +15 -37
  31. data/lib/aws_product_sign.rb +1 -1
  32. data/lib/generators/templates/umlaut_services.yml +5 -2
  33. data/lib/generators/umlaut/install_generator.rb +1 -0
  34. data/{app/models → lib}/service_type_value.rb +36 -22
  35. data/lib/umlaut/routes.rb +34 -5
  36. data/lib/umlaut/test_help.rb +159 -0
  37. data/lib/umlaut/version.rb +2 -2
  38. data/lib/umlaut.rb +44 -9
  39. metadata +10 -8
@@ -0,0 +1,159 @@
1
+ require 'vcr'
2
+
3
+ module Umlaut
4
+ # Some methods helpful in writing automated tests against Umlaut. Used in
5
+ # Umlaut, can also be used in your local app or Umlaut plugin.
6
+ #
7
+ # Add to your test_helper.rb:
8
+ #
9
+ # require 'umlaut/test_help'
10
+ # include Umlaut::TestHelp
11
+ module TestHelp
12
+ # Methods you can use to make a mocked up Rails Request and corersponding Umlaut Request
13
+ # Pass in a URL, absolute or partial, eg "/resolve?isbn=X"
14
+ def fake_rails_request(umlaut_url)
15
+ # hard to figure out how to mock a request, this seems to work
16
+ ActionController::TestRequest.new(Rack::MockRequest.env_for(umlaut_url))
17
+ end
18
+
19
+ def fake_umlaut_request(umlaut_url)
20
+ rails_request = fake_rails_request(umlaut_url)
21
+ Request.find_or_create(rails_request.params, {}, rails_request)
22
+ end
23
+
24
+ # The list of configured services is global state. Sometimes
25
+ # we want to test with a specific configuration list. An experimental
26
+ # hacky way to let you do that. Yes, this is a smell of a bad design,
27
+ # but we do what we can.
28
+ #
29
+ # This is in progress and still needs more api, this is still too hard.
30
+ def with_service_config(hash)
31
+ original = ServiceStore.config
32
+ ServiceStore.config = hash
33
+ yield
34
+ ensure
35
+ ServiceStore.config = original
36
+ end
37
+
38
+ # Assert that, for a given request, a service with a given id registered
39
+ # a DispatchedService with status DispatchedService::Succesful
40
+ # assert_dispatched(umalut_request, "service_id")
41
+ #
42
+ # Assert that a service with a given id registered a DispatchedService
43
+ # with another status.
44
+ # assert_dispatched(umlaut_request, "service_id", DispatchedService::FailedTemporary)
45
+ def assert_dispatched(request, service_id, status = DispatchedService::Successful)
46
+ dispatched = request.dispatched_services.to_a.find {|ds| ds.service_id == service_id}
47
+
48
+ assert dispatched.present?, "No DispatchedService record for service_id `#{service_id}`"
49
+
50
+ if status
51
+ assert_equal status, dispatched.status
52
+ end
53
+ end
54
+
55
+ # Assert that for a given umlaut request, a service with a given ID
56
+ # recorded at least one ServiceResponse of any type:
57
+ # assert_service_responses(umlaut_service, "service_id")
58
+ #
59
+ # Assert that it recorded exactly `number` of ServiceResponses
60
+ # assert_service_responses(umlaut_service, 'service_id', :number => 5)
61
+ #
62
+ # Assert that it recorded some ServiceResponses, and _at least one_ of those
63
+ # ServiceResponses was of each of the kind(s) specified. With or without
64
+ # :number.
65
+ # assert_service_resposnes(umlaut_service, 'service_id', :includes_type => :fulltext)
66
+ # assert_service_resposnes(umlaut_service, 'service_id', :number => 5, :includes_type => :fulltext)
67
+ # assert_service_resposnes(umlaut_service, 'service_id', :number => 5, :includes_type => [:fulltext, :highlighted_link])
68
+ #
69
+ # On assertion success, the method will return the array of ServiceResponse
70
+ # objects found, OR if :number => 1, the single ServiceResponse not in an array
71
+ # for convenience.
72
+ def assert_service_responses(request, service_id, options = {})
73
+ number = options[:number]
74
+ type_names = Array(options[:includes_type])
75
+
76
+ responses = request.service_responses.to_a.find_all {|r| r.service_id == service_id}
77
+
78
+ if number
79
+ assert_equal number, responses.length, "Found #{responses.length} ServiceResponses from service id `#{service_id}`, expected #{number}"
80
+ else
81
+ assert responses.length > 0, "No ServiceResponse found for service id `#{service_id}"
82
+ end
83
+
84
+ type_names.each do |kind|
85
+ assert responses.find {|sr| sr.service_type_value_name == kind.to_s}, "The generated ServiceResponses for service id `#{service_id}` must include type #{kind}" if number.to_i > 0
86
+ end
87
+
88
+ if number == 1
89
+ return responses.first
90
+ else
91
+ return responses
92
+ end
93
+
94
+ end
95
+
96
+ # Keep it in a seperate module so people can include just that if they want
97
+ # Umlaut::TestHelp::TestWithCassette. If you've already included Umlaut::TestHelp
98
+ # into your
99
+ module TestWithCassette
100
+ # Helper to create a Test::Unit style test that is wrapped in
101
+ # VCR.use_cassette for testing. If you supply a 'group' option,
102
+ # then the cassettes will be placed on the file system in a directory
103
+ # based on that group, and the VCR cassettes will also be tagged
104
+ # with that group name.
105
+ #
106
+ # Extract this whole thing to a gem for sharing?
107
+ #
108
+ # An alternative to this method is using rspec (but not in Umlaut,
109
+ # we don't use rspec) OR using minitest-rails or minitest-spec-rails
110
+ # with minitest/spec style and the minitest-vcr gem. I've had mixed
111
+ # success with minitest/spec in rails.
112
+ #
113
+ # extend TestWithCassette
114
+ # test_with_cassette("do something", :group) do
115
+ # assert_...
116
+ # end
117
+ def test_with_cassette(name, group = nil, vcr_options ={}, &block)
118
+ # cribbed from Rails and modified for VCR
119
+ # https://github.com/rails/rails/blob/b451de0d6de4df6bc66b274cec73b919f823d5ae/activesupport/lib/active_support/testing/declarative.rb#L25
120
+
121
+ test_name_safe = name.gsub(/\s+/,'_')
122
+
123
+ test_method_name = "test_#{test_name_safe}".to_sym
124
+
125
+ raise "#{test_method_name} is already defined in #{self}" if methods.include?(test_method_name)
126
+
127
+ cassette_name = vcr_options.delete(:cassette)
128
+ unless cassette_name
129
+ # calculate default cassette name from test name
130
+ cassette_name = test_name_safe
131
+ # put in group subdir if group
132
+ cassette_name = "#{group}/#{cassette_name}" if group
133
+ end
134
+
135
+ # default tag with groupname, can be over-ridden.
136
+ vcr_options = {:tag => group}.merge(vcr_options) if group
137
+
138
+ if block_given?
139
+ define_method(test_method_name) do
140
+ VCR.use_cassette(cassette_name , vcr_options) do
141
+ instance_eval &block
142
+ end
143
+ end
144
+ else
145
+ define_method(test_method_name) do
146
+ flunk "No implementation provided for #{name}"
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ end
153
+ end
154
+
155
+
156
+
157
+
158
+
159
+
@@ -1,8 +1,8 @@
1
1
  module Umlaut
2
- VERSION = "4.0.3"
2
+ VERSION = "4.1.0.pre.2"
3
3
 
4
4
  # This is used in Umlaut's .gemspec for generating the gem,
5
5
  # and is also used in the umlaut app generator to make sure
6
6
  # we're generating with a compatible Rails version.
7
- RAILS_COMPAT_SPEC = [">= 3.2.12", "< 4.2.0"]
7
+ RAILS_COMPAT_SPEC = [">= 3.2.12", "< 4.3.0"]
8
8
  end
data/lib/umlaut.rb CHANGED
@@ -2,6 +2,7 @@ require 'umlaut/version'
2
2
  require 'umlaut/routes'
3
3
  require 'umlaut/util'
4
4
 
5
+
5
6
  # not sure why including openurl gem doesn't do the require, but it
6
7
  # seems to need this.
7
8
  require 'openurl'
@@ -32,10 +33,41 @@ module Umlaut
32
33
  app.config.assets.precompile << "umlaut_ui.js"
33
34
  end
34
35
 
35
- initializer "#{engine_name}.backtrace_cleaner" do |app|
36
+ initializer "#{engine_name}.preload" do
37
+ require 'service_type_value' # stored in lib, load it ourselves, after Umlaut::Engine is loaded
38
+ end
39
+
40
+ config.whitelisted_backtrace = {}
41
+ config.whitelisted_backtrace[self.root] = self.engine_name
36
42
 
37
- engine_root_regex = Regexp.escape (self.root.to_s + File::SEPARATOR)
43
+ # The Rails backtrace cleaner strips some lines from exception backtraces,
44
+ # and prettifies the lines left.
45
+ #
46
+ # Umlaut uses the default backtrace cleaner for cleaning backtraces
47
+ # for outputting in error logs in various places.
48
+ #
49
+ # We want to make sure Umlaut lines stay in the backtrace and are prettified,
50
+ # so we customize the default backtrace cleaner. You can add additional
51
+ # gems (such as Umlaut plugins) to the whitelist of ones to keep in the
52
+ # backtrace, for instance a Rails engine gem might define an initializer
53
+ # in it's engine class, inserted to run BEFORE this one, that adds
54
+ # itself, like:
55
+ #
56
+ # initializer "#{engine_name}.backtrace_cleaner", :before => "umlaut.backtrace_cleaner" do
57
+ # Umlaut::Engine.config.whitelisted_backtrace[self.root] = self.engine_name
58
+ # end
59
+ initializer "#{engine_name}.backtrace_cleaner" do |app|
60
+ # config.whitelisted_backtrace is a hash from root file path t
61
+ # short name. We want to turn the filepaths into regexes left-anchored
62
+ # and with trailing separator.
63
+ whitelisted_path_regexes = config.whitelisted_backtrace.inject({}) do |h, (k, v)|
64
+ h[/^#{Regexp.escape(k.to_s + File::SEPARATOR)}/] = v.to_s
65
+ h
66
+ end
67
+ union_name_re = Regexp.union whitelisted_path_regexes.values.collect {|n| /^#{Regexp.escape n}/}
68
+ union_path_re = Regexp.union whitelisted_path_regexes.keys
38
69
 
70
+
39
71
  # Clean those ERB lines, we don't need the internal autogenerated
40
72
  # ERB method, what we do need (line number in ERB file) is already there
41
73
  Rails.backtrace_cleaner.add_filter do |line|
@@ -44,13 +76,12 @@ module Umlaut
44
76
 
45
77
  # Remove our own engine's path prefix, even if it's
46
78
  # being used from a local path rather than the gem directory.
47
- Rails.backtrace_cleaner.add_filter do |line|
48
- line.sub(/^#{engine_root_regex}/, "#{engine_name} ")
79
+ whitelisted_path_regexes.each_pair do |path_re, name|
80
+ Rails.backtrace_cleaner.add_filter do |line|
81
+ line.sub(path_re, "#{name} ")
82
+ end
49
83
  end
50
84
 
51
- # This actually seemed not to be neccesary, and wasn't behaving right? Let's
52
- # try without it...
53
- #
54
85
  # Keep Umlaut's own stacktrace in the backtrace -- we have to remove Rails
55
86
  # silencers and re-add them how we want.
56
87
  Rails.backtrace_cleaner.remove_silencers!
@@ -59,8 +90,8 @@ module Umlaut
59
90
  # it's from Umlaut engine
60
91
  Rails.backtrace_cleaner.add_silencer do |line|
61
92
  (line !~ Rails::BacktraceCleaner::APP_DIRS_PATTERN) &&
62
- (line !~ /^#{engine_root_regex}/ ) &&
63
- (line !~ /^#{engine_name} /)
93
+ (line !~ union_name_re ) &&
94
+ (line !~ union_path_re )
64
95
  end
65
96
  end
66
97
 
@@ -69,5 +100,9 @@ module Umlaut
69
100
  #initializer("#{engine_name}.patch_connection_pool", :before => "active_record.initialize_database") do |app|
70
101
  load File.join(self.root, "active_record_patch", "connection_pool.rb")
71
102
  #end
103
+
72
104
  end
73
105
  end
106
+
107
+
108
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umlaut
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.1.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind, et al
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 3.2.12
20
20
  - - <
21
21
  - !ruby/object:Gem::Version
22
- version: 4.2.0
22
+ version: 4.3.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 3.2.12
30
30
  - - <
31
31
  - !ruby/object:Gem::Version
32
- version: 4.2.0
32
+ version: 4.3.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: jquery-rails
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -361,6 +361,7 @@ files:
361
361
  - app/helpers/umlaut/footer_helper.rb
362
362
  - app/helpers/umlaut/helper.rb
363
363
  - app/helpers/umlaut/html_head_helper.rb
364
+ - app/helpers/umlaut/section_highlights.rb
364
365
  - app/helpers/umlaut/url_generation.rb
365
366
  - app/mailers/emailer.rb
366
367
  - app/mailers/feedback_mailer.rb
@@ -385,7 +386,6 @@ files:
385
386
  - app/models/request.rb
386
387
  - app/models/service_response.rb
387
388
  - app/models/service_store.rb
388
- - app/models/service_type_value.rb
389
389
  - app/models/service_wave.rb
390
390
  - app/models/sfx4/abstract/README.md
391
391
  - app/models/sfx4/abstract/az_extra_info.rb
@@ -502,6 +502,7 @@ files:
502
502
  - lib/generators/umlaut/install_generator.rb
503
503
  - lib/generators/umlaut/remove_turbolinks_generator.rb
504
504
  - lib/generators/umlaut_app_template.rb
505
+ - lib/service_type_value.rb
505
506
  - lib/tasks/umlaut.rake
506
507
  - lib/tasks/umlaut_asset_compile.rake
507
508
  - lib/tasks/umlaut_migrate_permalinks.rake
@@ -509,6 +510,7 @@ files:
509
510
  - lib/truncate_to_db_limit.rb
510
511
  - lib/umlaut.rb
511
512
  - lib/umlaut/routes.rb
513
+ - lib/umlaut/test_help.rb
512
514
  - lib/umlaut/util.rb
513
515
  - lib/umlaut/version.rb
514
516
  homepage: https://github.com/team-umlaut/umlaut
@@ -525,12 +527,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
525
527
  version: '0'
526
528
  required_rubygems_version: !ruby/object:Gem::Requirement
527
529
  requirements:
528
- - - ! '>='
530
+ - - ! '>'
529
531
  - !ruby/object:Gem::Version
530
- version: '0'
532
+ version: 1.3.1
531
533
  requirements: []
532
534
  rubyforge_project:
533
- rubygems_version: 2.4.1
535
+ rubygems_version: 2.4.4
534
536
  signing_key:
535
537
  specification_version: 4
536
538
  summary: For Libraries, a just-in-time last-mile service aggregator, taking OpenURL