-
Notifications
You must be signed in to change notification settings - Fork 118
/
presenter_factory_spec.rb
51 lines (45 loc) · 1.54 KB
/
presenter_factory_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'spec_helper'
RSpec.describe Hyrax::PresenterFactory do
describe "#build_for" do
let(:presenter_class) { Hyrax::FileSetPresenter }
before do
allow(ActiveFedora::SolrService.instance.conn).to receive(:post)
.with('select', data: { q: "{!terms f=id}12,13", rows: 1000, qt: 'standard' })
.and_return('response' => { 'docs' => results })
end
subject { described_class.build_for(ids: ['12', '13'], presenter_class: presenter_class) }
context "when some ids are found in solr" do
let(:results) { [{ "id" => "12" }, { "id" => "13" }] }
it "has two results" do
expect(subject.size).to eq 2
end
end
context "when some ids are not found in solr" do
let(:results) { [{ "id" => "13" }] }
it "has one result" do
expect(subject.size).to eq 1
end
end
context "with more arguments" do
let(:presenter_class) do
Class.new(Hyrax::FileSetPresenter) do
attr_reader :two, :three
def initialize(_one, two, three)
@two = two
@three = three
end
end
end
let(:results) { [{ "id" => "12" }, { "id" => "13" }] }
subject do
described_class.build_for(ids: ['12', '13'],
presenter_class: presenter_class,
args: ['more', 'and more'])
end
it 'passes all the arguments' do
expect(subject.first.two).to eq 'more'
expect(subject.first.three).to eq 'and more'
end
end
end
end