Skip to content

Commit

Permalink
Test Hyrax::WorkFormService
Browse files Browse the repository at this point in the history
These tests are being introduced to provide a baseline for a form service for
creating forms that work with valkyrie models.
  • Loading branch information
Tom Johnson committed Jan 14, 2020
1 parent ba8e906 commit 6f4a2b5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/services/hyrax/work_form_service.rb
@@ -1,4 +1,6 @@
module Hyrax
##
# A factory that builds work forms based on the `#model_name` of the work.
class WorkFormService
def self.build(curation_concern, current_ability, *extra)
form_class(curation_concern).new(curation_concern, current_ability, *extra)
Expand Down
30 changes: 30 additions & 0 deletions spec/services/hyrax/work_form_service_spec.rb
@@ -0,0 +1,30 @@
# frozen_string_literal: true

RSpec.describe Hyrax::WorkFormService do
subject(:form_service) { described_class }
let(:work) { GenericWork.new }

describe '.form_class' do
it 'returns a form class by constant name convention' do
expect(form_service.form_class(work)).to eq Hyrax::GenericWorkForm
end

context 'with a missing form class' do
let(:work) { Hyrax::Test::SimpleWorkLegacy.new }

it 'raises a NameError' do
expect { form_service.form_class(work) }.to raise_error NameError
end
end
end

describe '.build' do
let(:ability) { :FAKE_ABILITY }
let(:controller) { :FAKE_CONTROLLER }

it 'returns an instance of the form class' do
expect(form_service.build(work, ability, controller))
.to be_a Hyrax::GenericWorkForm
end
end
end

0 comments on commit 6f4a2b5

Please sign in to comment.