Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Add Geographic Origin as a dropdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed May 4, 2017
1 parent d082463 commit 71c5157
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/services/authority_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def self.for(property:, model:)
case property
when :language
Qa::Authorities::Local.subauthority_for('languages')
when :geographic_origin
Qa::Authorities::Local.subauthority_for('Geographic Origin')
end
rescue Qa::InvalidSubAuthority
Rails.logger.debug("Non-existent sub-authority requested for property #{property}")
Expand Down
10 changes: 10 additions & 0 deletions app/views/records/edit_fields/_controlled_field.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% authority = AuthorityFinder.for(property: key, model: f.object) %>
<% if authority %>
<% options = Hyrax::QaSelectService.new(authority.subauthority_name) %>
<%= f.input key,
collection: options.select_active_options,
include_blank: true,
input_html: { class: 'form-control', multiple: f.object.multiple?(key) } %>
<% else %>
<%= render "records/edit_fields/default", f: f, key: key%>
<% end %>
1 change: 1 addition & 0 deletions app/views/records/edit_fields/_geographic_origin.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render "controlled_field", key: key, f: f %>
11 changes: 1 addition & 10 deletions app/views/records/edit_fields/_language.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
<% authority = AuthorityFinder.for(property: key, model: f.object) %>
<% if authority %>
<% languages = Hyrax::QaSelectService.new(authority.subauthority_name) %>
<%= f.input :language,
collection: languages.select_active_options,
include_blank: true,
input_html: { class: 'form-control', multiple: f.object.multiple?(key) } %>
<% else %>
<%= render "records/edit_fields/default", f: f, key: key%>
<% end %>
<%= render "controlled_field", key: key, f: f %>
37 changes: 37 additions & 0 deletions spec/views/records/edit_fields/_geographic_origin.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'rails_helper'
include SimpleForm::ActionViewExtensions::FormHelper

RSpec.describe 'records/edit_fields/_geographic_origin.html.erb' do
let(:vocabulary) { nil }
let(:vocabulary_label) { "Geographic Origin" }
before do
Qa::Authorities::Local.registry.instance_variable_get(:@hash).delete(vocabulary_label)
allow(view).to receive(:f).and_return(simple_form_for(form))
allow(view).to receive(:key).and_return(:geographic_origin)
vocabulary
render
end
after do
Qa::Authorities::Local.registry.instance_variable_get(:@hash).delete(vocabulary_label)
end

context 'with an ephemera folder' do
let(:form) { Hyrax::EphemeraFolderForm.new(EphemeraFolder.new, nil, nil) }
context "when there is no language vocabulary" do
it "doesn't create a select box" do
expect(rendered).not_to have_selector "select"
end
end
context "when there is a language vocabulary" do
let(:vocabulary) do
Vocabulary.create!(label: vocabulary_label).tap do |vocab|
VocabularyTerm.create!(vocabulary: vocab, label: "Ireland")
VocabularyTerm.create!(vocabulary: vocab, label: "Japan")
end
end
it "creates a select box" do
expect(rendered).to have_select("Geographic origin", options: ['', 'Ireland', 'Japan'])
end
end
end
end
2 changes: 1 addition & 1 deletion spec/views/records/edit_fields/_language.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
end

context 'with an ephemera folder' do
let(:form) { Hyrax::EphemeraBoxForm.new(EphemeraFolder.new, nil, nil) }
let(:form) { Hyrax::EphemeraFolderForm.new(EphemeraFolder.new, nil, nil) }
context "when there is no language vocabulary" do
it "doesn't create a select box" do
expect(rendered).not_to have_selector "select"
Expand Down

0 comments on commit 71c5157

Please sign in to comment.