This repository has been archived by the owner on Jan 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding controlled vocabulary for creator to input field
Includes form for editing a creator
- Loading branch information
1 parent
b710ede
commit 9407fe2
Showing
10 changed files
with
138 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<%= form.fields_for :creator do |creator_form| %> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-md-12 col-lg-3"> | ||
<%= form.label :role %> | ||
<%= creator_form.text_field :role, field.options.merge!(list: "#{field.label}_role") %> | ||
<datalist id="<%= "#{field.label}_role" %>"> | ||
<% field.datalist(component: :roles).each do |item| %> | ||
<option value="<%= item %>"><%= item.label %></option> | ||
<% end %> | ||
</datalist> | ||
</div> | ||
|
||
<div class="col-md-12 col-lg-3"> | ||
<%= form.label :agent %> | ||
<%= creator_form.text_field :agent, field.options.merge!(list: "#{field.label}_agent") %> | ||
<datalist id="<%= "#{field.label}_agent" %>"> | ||
<% field.datalist(component: :agents).each do |item| %> | ||
<option value="<%= item.id %>"><%= item %></option> | ||
<% end %> | ||
</datalist> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
# @note Class used for mocking sets of RDF terms that are usually very large and can take a long time | ||
# to initially load. By mocking them, we can reduce testing time. | ||
class MockRDF | ||
def self.relators | ||
[ | ||
RDF::Vocabulary::Term.new('http://id.loc.gov/vocabulary/relators/bsl', attributes: { label: 'blasting' }), | ||
RDF::Vocabulary::Term.new('http://id.loc.gov/vocabulary/relators/cli', attributes: { label: 'climbing' }) | ||
] | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.before do | ||
allow(RDF::Vocab::MARCRelators).to receive(:to_a).and_return(MockRDF.relators) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples 'a creator form' do | ||
it 'renders the new form' do | ||
assert_select 'input[name=?]', "#{resource.model_name.param_key}[creator][agent]" | ||
assert_select 'input[name=?]', "#{resource.model_name.param_key}[creator][role]" | ||
|
||
assert_select 'datalist[id=?]', 'creator_role' | ||
assert_select 'option[value=?]', 'http://id.loc.gov/vocabulary/relators/bsl' | ||
assert_select 'option', 'blasting' | ||
assert_select 'option[value=?]', 'http://id.loc.gov/vocabulary/relators/cli' | ||
assert_select 'option', 'climbing' | ||
|
||
assert_select 'datalist[id=?]', 'creator_agent' | ||
assert_select 'option[value=?]', agent1.id.to_s | ||
assert_select 'option', 'Jane Doe' | ||
assert_select 'option[value=?]', agent2.id.to_s | ||
assert_select 'option', 'John Doe' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'shared/input_partials/creator', type: :view do | ||
let!(:agent1) { create :agent, given_name: 'Jane', surname: 'Doe' } | ||
let!(:agent2) { create :agent } | ||
let(:field) { instance_double Schema::InputField, options: {}, label: 'creator' } | ||
|
||
before do | ||
allow(field).to receive(:datalist).with(component: :roles).and_return(MockRDF.relators) | ||
allow(field).to receive(:datalist).with(component: :agents).and_return([agent1, agent2]) | ||
view.form_for(resource, url: 'blah') do |form| | ||
render 'shared/input_partials/creator', form: form, field: field | ||
end | ||
end | ||
|
||
context 'with a work' do | ||
let(:resource) { build :work } | ||
|
||
it_behaves_like 'a creator form' | ||
end | ||
|
||
context 'with an archival collection' do | ||
let(:resource) { build :archival_collection } | ||
|
||
it_behaves_like 'a creator form' | ||
end | ||
|
||
context 'with an library collection' do | ||
let(:resource) { build :library_collection } | ||
|
||
it_behaves_like 'a creator form' | ||
end | ||
|
||
context 'with an curated collection' do | ||
let(:resource) { build :curated_collection } | ||
|
||
it_behaves_like 'a creator form' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters