Skip to content

Commit f1ccbec

Browse files
committed
spec app/controllers/concerns/iiif/authz/v2/bytestreams_spec.rb (DLC-1171)
1 parent 35699a2 commit f1ccbec

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
require 'rails_helper'
2+
3+
describe Iiif::Authz::V2::Bytestreams, type: :unit do
4+
let(:test_class) do
5+
Class.new(ApplicationController) do
6+
include Iiif::Authz::V2::Bytestreams
7+
end
8+
end
9+
subject(:controller) do
10+
test_class.new
11+
end
12+
describe '#has_probeable_resource?' do
13+
let(:bytestream_id) { 'content' }
14+
let(:params) { { bytestream_id: bytestream_id } }
15+
16+
before do
17+
allow(controller).to receive(:params).and_return(params)
18+
end
19+
20+
it 'returns false when passed nil' do
21+
expect(controller.has_probeable_resource?(nil)).to be false
22+
end
23+
24+
context 'has a SolrDocument' do
25+
let(:solr_doc) { instance_double(SolrDocument) }
26+
let(:resource_doc) { { id: "fedora/pid/#{bytestream_id}" } }
27+
28+
context 'with resources' do
29+
before do
30+
allow(controller).to receive(:resources_for_document).with(solr_doc, false).and_return([resource_doc])
31+
end
32+
33+
it 'works when #resources_for_document returns a present value' do
34+
expect(controller.has_probeable_resource?(solr_doc)).to be true
35+
end
36+
end
37+
38+
context 'without resources' do
39+
let(:dc_type) { 'Software' }
40+
41+
before do
42+
allow(solr_doc).to receive(:fetch).with('dc_type_ssm', []).and_return([dc_type])
43+
allow(controller).to receive(:resources_for_document).with(solr_doc, false).and_return([])
44+
end
45+
46+
it 'returns false' do
47+
expect(controller.has_probeable_resource?(solr_doc)).to be false
48+
end
49+
50+
context 'but an image dc type' do
51+
let(:dc_type) { 'StillImage' }
52+
53+
it 'returns true' do
54+
expect(controller.has_probeable_resource?(solr_doc)).to be true
55+
end
56+
end
57+
end
58+
end
59+
end
60+
end

0 commit comments

Comments
 (0)