hydra-core 10.0.0 → 10.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f45efd1b20cb587da16107c9eeb2436585a995f9
4
- data.tar.gz: f1b62768dd6b99194fd25f93fec69133ef385105
3
+ metadata.gz: 450a93f7a813de8c1c95a0cbee13bf603532155b
4
+ data.tar.gz: f24ba34d77864a069f95356f16a28d9b08f16303
5
5
  SHA512:
6
- metadata.gz: 8f60542cd2c982d5f8ba893c32a9109db4ba9b260814e71f172737d64d876ee1b459d2de3c072e9c76a0e044243717f200b8d6e9452d8489d9396f3a752c7df3
7
- data.tar.gz: 48a8abfa67c87d042828a936d7948beea5b3d5f263516fc2da008a71a6e39ee874b35aadbcc558be35e8bfb2e91b7da4937b974a3b4caf9cf8a796bb54701763
6
+ metadata.gz: 43931f2320aaf1cdc7019514fd250c2873823dd5b9eddc49388f2d553b19eae93194a6098321cd96baab9dd321c0bf219134f350124655d81d89539a89a71e33
7
+ data.tar.gz: a5f574df3e697acd7a361229b077932d8377f393ec60fc86695cb70075c556435be34930947cb3d93ca1c60d2a6d19fc1f22b7def83cb4f1c01a3ab8d2c0a7e8
@@ -5,7 +5,7 @@ module Hydra
5
5
 
6
6
  included do
7
7
  include Hydra::Controller::ControllerBehavior
8
- before_filter :authorize_download!
8
+ before_action :authorize_download!
9
9
  end
10
10
 
11
11
  # Responds to http requests to show the file
@@ -87,8 +87,7 @@ module Hydra
87
87
  # render an HTTP HEAD response
88
88
  def content_head
89
89
  response.headers['Content-Length'] = file.size
90
- response.headers['Content-Type'] = file.mime_type
91
- head :ok
90
+ head :ok, content_type: file.mime_type
92
91
  end
93
92
 
94
93
  # render an HTTP Range response
@@ -10,12 +10,17 @@ module Hydra
10
10
  # @param [String, Array] display_type a value suggestive of a partial
11
11
  # @return [String] the name of the partial to render
12
12
  # @example
13
- # type_field_to_partial_name(["info:fedora/hull-cModel:genericContent"])
13
+ # type_field_to_partial_name(["GenericContent"])
14
14
  # => 'generic_content'
15
- # type_field_to_partial_name(["info:fedora/hull-cModel:text.pdf"])
15
+ # type_field_to_partial_name(["text.pdf"])
16
16
  # => 'text_pdf'
17
17
  def type_field_to_partial_name(document, display_type)
18
- Array(display_type).first.gsub(/^[^\/]+\/[^:]+:/,"").gsub("-","_").underscore.parameterize("_")
18
+ str = Array(display_type).join(' '.freeze).underscore
19
+ if Rails.version >= '5.0.0'
20
+ str.parameterize(separator: '_'.freeze)
21
+ else
22
+ str.parameterize('_'.freeze)
23
+ end
19
24
  end
20
25
  end
21
26
  end
@@ -2,14 +2,18 @@ module Hydra::ContentNegotiation
2
2
  # CleanGraphRepository has a #find interface which returns a graph for use
3
3
  # with content negotiation.
4
4
  class CleanGraphRepository
5
- attr_reader :connection
6
- def initialize(connection)
5
+ attr_reader :connection, :replacer
6
+ # @param [#get] connection the connection to fedora
7
+ # @param [#call] replacer a function that is called with id and graph and returns a string representation of the new uri.
8
+ def initialize(connection, replacer = Hydra.config.id_to_resource_uri)
7
9
  @connection = connection
10
+ @replacer = replacer
8
11
  end
9
12
 
10
13
  def find(id)
11
14
  ReplacingGraphFinder.new(
12
- GraphFinder.new(connection, id)
15
+ GraphFinder.new(connection, id),
16
+ replacer
13
17
  ).graph
14
18
  end
15
19
  end
@@ -1,9 +1,13 @@
1
1
  module Hydra::ContentNegotiation
2
2
  # Replaces Fedora URIs in a graph with a Hydra-configured alternative.
3
3
  class FedoraUriReplacer
4
- def initialize(fedora_base_uri, graph)
4
+ # @param [String] fedora_base_uri the internal Fedora base uri
5
+ # @param [RDF::Graph] graph the original graph that needs URIs replaced
6
+ # @param [#call] replacer a function that is called with id and graph and returns a string representation of the new uri.
7
+ def initialize(fedora_base_uri, graph, replacer)
5
8
  @fedora_base_uri = fedora_base_uri
6
9
  @graph = graph
10
+ @replacer = replacer
7
11
  end
8
12
 
9
13
  def run
@@ -12,11 +16,11 @@ module Hydra::ContentNegotiation
12
16
 
13
17
  private
14
18
 
15
- attr_reader :fedora_base_uri, :graph
19
+ attr_reader :fedora_base_uri, :graph, :replacer
16
20
 
17
21
  def replace_uri(uri)
18
22
  id = ActiveFedora::Base.uri_to_id(uri)
19
- RDF::URI(Hydra.config.id_to_resource_uri.call(id, graph))
23
+ RDF::URI(replacer.call(id, graph))
20
24
  end
21
25
 
22
26
  def replaced_objects
@@ -2,6 +2,13 @@ module Hydra::ContentNegotiation
2
2
  # Decorator for Finder which replaces Fedora subjects in the graph with a
3
3
  # configured URI
4
4
  class ReplacingGraphFinder < SimpleDelegator
5
+
6
+ attr_reader :replacer
7
+ def initialize(graph_finder, replacer)
8
+ super(graph_finder)
9
+ @replacer = replacer
10
+ end
11
+
5
12
  def graph
6
13
  graph_replacer.run
7
14
  end
@@ -9,11 +16,13 @@ module Hydra::ContentNegotiation
9
16
  private
10
17
 
11
18
  def graph_replacer
12
- ::Hydra::ContentNegotiation::FedoraUriReplacer.new(base_uri, __getobj__.graph)
19
+ ::Hydra::ContentNegotiation::FedoraUriReplacer.new(base_uri,
20
+ __getobj__.graph,
21
+ replacer)
13
22
  end
14
23
 
15
24
  def base_uri
16
- @base_uri ||= uri.gsub(/#{id}$/,'')
25
+ @base_uri ||= ActiveFedora.fedora.host + ActiveFedora.fedora.base_path
17
26
  end
18
27
  end
19
28
  end
data/hydra-core.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.required_ruby_version = '>= 1.9.3'
20
20
 
21
- gem.add_dependency "rails", '~> 4.0'
21
+ gem.add_dependency "railties", '>= 4.0.0', '< 6'
22
22
  gem.add_dependency 'hydra-access-controls', version
23
23
 
24
24
  gem.add_development_dependency 'sqlite3', '~> 1.3'
@@ -4,8 +4,8 @@ require 'blacklight/catalog'
4
4
  class CatalogController < ApplicationController
5
5
 
6
6
  include Hydra::Catalog
7
- # These before_filters apply the hydra access controls
8
- before_filter :enforce_show_permissions, only: :show
7
+ # This filter applies the hydra access controls
8
+ before_action :enforce_show_permissions, only: :show
9
9
 
10
10
  configure_blacklight do |config|
11
11
  ## Class for sending and receiving requests from a search index
@@ -1,3 +1,3 @@
1
1
  module HydraHead
2
- VERSION = "10.0.0"
2
+ VERSION = "10.2.0"
3
3
  end
@@ -96,8 +96,8 @@ describe CatalogController do
96
96
  end
97
97
  it "should convert it" do
98
98
  graph = RDF::Graph.new << RDF::Reader.for(:ntriples).new(response.body)
99
- title_statement = graph.query([nil, RDF::DC.title, nil]).first
100
- related_statement = graph.query([nil, RDF::DC.isReferencedBy, nil]).first
99
+ title_statement = graph.query([nil, RDF::Vocab::DC.title, nil]).first
100
+ related_statement = graph.query([nil, RDF::Vocab::DC.isReferencedBy, nil]).first
101
101
  expect(title_statement.subject).to eq RDF::URI("http://hydra.box/catalog/#{asset.id}")
102
102
  expect(related_statement.object).to eq RDF::URI("http://hydra.box/catalog/#{related.id}")
103
103
  end
@@ -74,7 +74,7 @@ describe DownloadsController do
74
74
  allow(ContentHolder).to receive(:default_file_path).and_return('buzz')
75
75
  get :show, id: obj
76
76
  expect(response).to be_successful
77
- expect(response.headers['Content-Type']).to eq "image/png"
77
+ expect(response.headers['Content-Type']).to start_with "image/png"
78
78
  expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"buzz.png\""
79
79
  expect(response.body).to eq 'fizz'
80
80
  end
@@ -83,7 +83,7 @@ describe DownloadsController do
83
83
  expect(DownloadsController.default_file_path).to eq "content"
84
84
  get :show, id: obj
85
85
  expect(response).to be_successful
86
- expect(response.headers['Content-Type']).to eq "image/png"
86
+ expect(response.headers['Content-Type']).to start_with "image/png"
87
87
  expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
88
88
  expect(response.body).to eq 'foobarfoobarfoobar'
89
89
  end
@@ -99,7 +99,7 @@ describe DownloadsController do
99
99
  it "should return it" do
100
100
  get :show, id: obj, file: "descMetadata"
101
101
  expect(response).to be_successful
102
- expect(response.headers['Content-Type']).to eq "text/plain"
102
+ expect(response.headers['Content-Type']).to start_with "text/plain"
103
103
  expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"metadata.xml\""
104
104
  expect(response.body).to eq "It's a stream"
105
105
  end
@@ -108,14 +108,14 @@ describe DownloadsController do
108
108
  it "should support setting disposition to inline" do
109
109
  get :show, id: obj, :disposition => "inline"
110
110
  expect(response).to be_successful
111
- expect(response.headers['Content-Type']).to eq "image/png"
111
+ expect(response.headers['Content-Type']).to start_with "image/png"
112
112
  expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
113
113
  expect(response.body).to eq 'foobarfoobarfoobar'
114
114
  end
115
115
  it "should allow you to specify filename for download" do
116
116
  get :show, id: obj, "filename" => "my%20dog.png"
117
117
  expect(response).to be_successful
118
- expect(response.headers['Content-Type']).to eq "image/png"
118
+ expect(response.headers['Content-Type']).to start_with "image/png"
119
119
  expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"my%20dog.png\""
120
120
  expect(response.body).to eq 'foobarfoobarfoobar'
121
121
  end
@@ -128,37 +128,42 @@ describe DownloadsController do
128
128
  parent.save!
129
129
  expect(controller).to receive(:authorize!).with(:download, instance_of(ActiveFedora::File)).and_return(true)
130
130
  end
131
+
131
132
  it "head request" do
132
133
  request.env["HTTP_RANGE"] = 'bytes=0-15'
133
134
  head :show, id: parent, file: 'webm'
134
135
  expect(response.headers['Content-Length']).to eq 16
135
136
  expect(response.headers['Accept-Ranges']).to eq 'bytes'
136
- expect(response.headers['Content-Type']).to eq 'video/webm'
137
+ expect(response.headers['Content-Type']).to start_with 'video/webm'
137
138
  end
138
- it "should send the whole thing" do
139
+
140
+ it "sends the whole thing" do
139
141
  request.env["HTTP_RANGE"] = 'bytes=0-15'
140
142
  get :show, id: '1234', file: 'webm'
141
143
  expect(response.body).to eq 'one1two2threfour'
142
144
  expect(response.headers["Content-Range"]).to eq 'bytes 0-15/16'
143
145
  expect(response.headers["Content-Length"]).to eq '16'
144
146
  expect(response.headers['Accept-Ranges']).to eq 'bytes'
145
- expect(response.headers['Content-Type']).to eq "video/webm"
147
+ expect(response.headers['Content-Type']).to start_with "video/webm"
146
148
  expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"MyVideo.webm\""
147
149
  expect(response.status).to eq 206
148
150
  end
149
- it "should send the whole thing when the range is open ended" do
151
+
152
+ it "sends the whole thing when the range is open ended" do
150
153
  request.env["HTTP_RANGE"] = 'bytes=0-'
151
154
  get :show, id: '1234', file: 'webm'
152
155
  expect(response.body).to eq 'one1two2threfour'
153
156
  end
154
- it "should get a range not starting at the beginning" do
157
+
158
+ it "gets a range not starting at the beginning" do
155
159
  request.env["HTTP_RANGE"] = 'bytes=3-15'
156
160
  get :show, id: '1234', file: 'webm'
157
161
  expect(response.body).to eq '1two2threfour'
158
162
  expect(response.headers["Content-Range"]).to eq 'bytes 3-15/16'
159
163
  expect(response.headers["Content-Length"]).to eq '13'
160
164
  end
161
- it "should get a range not ending at the end" do
165
+
166
+ it "gets a range not ending at the end" do
162
167
  request.env["HTTP_RANGE"] = 'bytes=4-11'
163
168
  get :show, id: '1234', file: 'webm'
164
169
  expect(response.body).to eq 'two2thre'
@@ -14,20 +14,20 @@ describe BlacklightHelper do
14
14
  allow(helper).to receive(:blacklight_config).and_return(config)
15
15
  end
16
16
 
17
- it "should lop off everything before the first colin after the slash" do
18
- expect(helper.document_partial_name('has_model_s' => ["info:fedora/afmodel:Presentation"])).to eq "presentation"
19
- expect(helper.document_partial_name('has_model_s' => ["info:fedora/hull-cModel:genericContent"])).to eq "generic_content"
17
+ it "changes camel case to underscored lowercase" do
18
+ expect(helper.document_partial_name('has_model_s' => ["Presentation"])).to eq "presentation"
19
+ expect(helper.document_partial_name('has_model_s' => ["GenericContent"])).to eq "generic_content"
20
20
  end
21
21
 
22
22
  context "with a single valued field" do
23
- let(:field_name) { 'active_fedora_model_ssi' }
23
+ let(:field_name) { 'has_model_s' }
24
24
  it "should support single valued fields" do
25
- expect(helper.document_partial_name('active_fedora_model_ssi' => "Chicken")).to eq "chicken"
25
+ expect(helper.document_partial_name('has_model_s' => "Chicken")).to eq "chicken"
26
26
  end
27
27
  end
28
28
 
29
- it "should handle periods" do
30
- expect(helper.document_partial_name('has_model_s' => ["info:fedora/afmodel:text.PDF"])).to eq "text_pdf"
29
+ it "handles periods" do
30
+ expect(helper.document_partial_name('has_model_s' => ["text.PDF"])).to eq "text_pdf"
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Hydra::ContentNegotiation::ReplacingGraphFinder do
4
+ let(:graph) { double }
5
+ let(:finder) { double(graph: graph,
6
+ uri: 'http://127.0.0.1:8986/rest/test/28/01/ph/00/2801ph009',
7
+ id: '2801ph009') }
8
+ let(:replacer) { double }
9
+ subject { described_class.new finder, replacer }
10
+
11
+ describe "graph" do
12
+ it "has the correct base url" do
13
+ expect(Hydra::ContentNegotiation::FedoraUriReplacer).to receive(:new)
14
+ .with(ending_with("/rest/test"), graph, replacer)
15
+ .and_return(double(run: nil))
16
+
17
+ subject.graph
18
+ end
19
+ end
20
+ end
data/spec/spec_helper.rb CHANGED
@@ -20,7 +20,7 @@ ActiveFedora::Base.logger = Logger.new(STDOUT)
20
20
 
21
21
  require 'active_fedora/cleaner'
22
22
  RSpec.configure do |config|
23
- config.include Devise::TestHelpers, type: :controller
23
+ config.include Devise::Test::ControllerHelpers, type: :controller
24
24
  config.use_transactional_fixtures = true
25
25
  config.infer_spec_type_from_file_location!
26
26
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0
4
+ version: 10.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt, Bess Sadler, Julie Meloni, Naomi Dushay, Jessie Keck, John Scofield,
@@ -9,36 +9,42 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-08 00:00:00.000000000 Z
12
+ date: 2016-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rails
15
+ name: railties
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 4.0.0
21
+ - - "<"
19
22
  - !ruby/object:Gem::Version
20
- version: '4.0'
23
+ version: '6'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: 4.0.0
31
+ - - "<"
26
32
  - !ruby/object:Gem::Version
27
- version: '4.0'
33
+ version: '6'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: hydra-access-controls
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
32
38
  - - '='
33
39
  - !ruby/object:Gem::Version
34
- version: 10.0.0
40
+ version: 10.2.0
35
41
  type: :runtime
36
42
  prerelease: false
37
43
  version_requirements: !ruby/object:Gem::Requirement
38
44
  requirements:
39
45
  - - '='
40
46
  - !ruby/object:Gem::Version
41
- version: 10.0.0
47
+ version: 10.2.0
42
48
  - !ruby/object:Gem::Dependency
43
49
  name: sqlite3
44
50
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +146,7 @@ files:
140
146
  - spec/controllers/ip_based_ability_spec.rb
141
147
  - spec/factories.rb
142
148
  - spec/helpers/blacklight_helper_spec.rb
149
+ - spec/models/content_negotiation/replacing_graph_finder_spec.rb
143
150
  - spec/models/solr_document_spec.rb
144
151
  - spec/models/user_spec.rb
145
152
  - spec/rcov.opts
@@ -151,7 +158,6 @@ files:
151
158
  - spec/support/db/migrate/20111101221803_create_searches.rb
152
159
  - spec/support/matchers/helper_matcher.rb
153
160
  - spec/support/matchers/solr_matchers.rb
154
- - spec/test_app_templates/Gemfile.extra
155
161
  - spec/unit/hydra-head-engine_spec.rb
156
162
  - spec/unit/hydra-head_spec.rb
157
163
  homepage: http://projecthydra.org
@@ -185,6 +191,7 @@ test_files:
185
191
  - spec/controllers/ip_based_ability_spec.rb
186
192
  - spec/factories.rb
187
193
  - spec/helpers/blacklight_helper_spec.rb
194
+ - spec/models/content_negotiation/replacing_graph_finder_spec.rb
188
195
  - spec/models/solr_document_spec.rb
189
196
  - spec/models/user_spec.rb
190
197
  - spec/rcov.opts
@@ -196,7 +203,5 @@ test_files:
196
203
  - spec/support/db/migrate/20111101221803_create_searches.rb
197
204
  - spec/support/matchers/helper_matcher.rb
198
205
  - spec/support/matchers/solr_matchers.rb
199
- - spec/test_app_templates/Gemfile.extra
200
206
  - spec/unit/hydra-head-engine_spec.rb
201
207
  - spec/unit/hydra-head_spec.rb
202
- has_rdoc:
@@ -1,6 +0,0 @@
1
- gem 'rspec-rails', '~> 3.1', group: :test
2
- gem 'rspec-its'
3
- gem 'byebug' unless ENV['CI']
4
-
5
- gem 'rails', ENV.fetch('RAILS_VERSION', '4.2.6')
6
- gem 'blacklight', ENV.fetch('BLACKLIGHT_VERSION', '6.0.0')