Skip to content

Commit

Permalink
fixing failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexBLR committed May 31, 2017
1 parent bd3302f commit b1a71f3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/forms/hyrax/etd_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class EtdForm < Hyrax::Forms::WorkForm
self.terms += [:school]
self.terms += [:degree]
self.terms += [:partnering_agency]
self.terms += [:submitting_type]
self.single_valued_fields = [:title, :creator, :submitting_type]
end
end
2 changes: 1 addition & 1 deletion spec/forms/hyrax/etd_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
its(:terms) { is_expected.to include(:school) }
its(:terms) { is_expected.to include(:degree) }
its(:terms) { is_expected.to include(:partnering_agency) }
its(:terms) { is_expected.to include(:submitting_type) }
its(:single_valued_fields) { is_expected.to include(:submitting_type) }
end
end
43 changes: 43 additions & 0 deletions spec/forms/single_valued_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'rails_helper'

RSpec.describe SingleValuedForm do
subject(:etd) { TestForm.new(work, nil, nil) }
let(:work) { FactoryGirl.build :etd }

before do
class TestForm < Hyrax::Forms::WorkForm
include SingleValuedForm
end
TestForm.single_valued_fields = [:identifier]
TestForm.model_class = ::Etd
TestForm.terms = [:identifier, :title]
end

after do
Object.send(:remove_const, :TestForm)
end

context "an instance" do
it "reports single-valued fields" do
expect(etd.multiple?(:identifier)).to be false
expect(etd.multiple?(:title)).to be true
end
end

context "the class" do
it "reports single-valued fields" do
expect(TestForm.multiple?(:identifier)).to be false
expect(TestForm.multiple?(:title)).to be true
end
end

describe "model_attributes" do
let(:params) { ActionController::Parameters.new(identifier: '123', title: ['Box 1']) }
let(:attribs) { TestForm.model_attributes(params).to_h }

it "converts singular fields to arrays" do
expect(attribs[:identifier]).to eq(['123'])
expect(attribs[:title]).to eq(['Box 1'])
end
end
end

0 comments on commit b1a71f3

Please sign in to comment.