Skip to content

Commit

Permalink
Gets the HydraEditor::Presenter test suite passing
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Jul 30, 2019
1 parent 8a965f1 commit 0f9b2ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
let(:orm_class) { ActiveFedora }

before do
# class ActiveFedora; end unless defined?(ActiveFedora)
class ActiveFedora; end
end

Expand Down
26 changes: 24 additions & 2 deletions spec/presenters/hydra_editor_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TestFedoraModel

def self.unique?(field); end
def self.reflect_on_association(field); end
def self.terms; end
def title; end
def creator; end
def new_record?; end
Expand All @@ -38,8 +39,6 @@ def model_name; end

class TestPresenter
include Hydra::Presenter
# TODO: This needs to be removed
# self.model_class = model_class
# Terms is the list of fields displayed by app/views/generic_files/_show_descriptions.html.erb
self.terms = [:title, :creator]

Expand All @@ -58,6 +57,7 @@ class TestPresenter
before do
TestPresenter.model_class = model_class
allow(model_class).to receive(:unique?).and_return(false)
allow(model_class).to receive(:terms).and_return([:title, :creator])
allow(object).to receive(:new_record?).and_return(false)
allow(object).to receive(:persisted?).and_return(true)
allow(object).to receive(:model_name).and_return('TestModel')
Expand All @@ -75,6 +75,8 @@ class TestPresenter

describe '#terms' do
subject { presenter.terms }
let(:model_class) { TestFedoraModel }

it { is_expected.to eq [:title, :creator] }
end

Expand Down Expand Up @@ -137,6 +139,8 @@ def count

context 'for a multivalue string' do
let(:model_class) { TestFedoraModel }
let(:object) { model_class.new }
let(:presenter) { TestPresenter.new(object) }
let(:reflection) { double }
before do
allow(reflection).to receive(:collection?).and_return(true)
Expand All @@ -153,6 +157,16 @@ def count

context 'for a multivalue association' do
let(:field) { :contributors }
let(:model_class) { TestFedoraModel }
let(:object) { model_class.new }
let(:presenter) { TestPresenter.new(object) }
let(:reflection) { double }
let(:field) { :title }
before do
allow(reflection).to receive(:collection?).and_return(true)
allow(model_class).to receive(:reflect_on_association).with(field).and_return(reflection)
end

it { is_expected.to be true }
end

Expand All @@ -172,7 +186,15 @@ def count
subject { TestPresenter.multiple?(field) }

context 'for a multivalue string' do
let(:model_class) { TestFedoraModel }
let(:object) { model_class.new }
let(:presenter) { TestPresenter.new(object) }
let(:reflection) { double }
let(:field) { :title }
before do
allow(reflection).to receive(:collection?).and_return(true)
allow(model_class).to receive(:reflect_on_association).with(field).and_return(reflection)
end
it { is_expected.to be true }
end

Expand Down

0 comments on commit 0f9b2ad

Please sign in to comment.