Skip to content

Commit

Permalink
Merge fffd5b4 into 4ec1a0c
Browse files Browse the repository at this point in the history
  • Loading branch information
alexBLR committed May 31, 2017
2 parents 4ec1a0c + fffd5b4 commit b98cdfb
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def self.modified_field
config.add_index_field solr_name("department", :stored_searchable), label: "Department"
config.add_index_field solr_name("school", :stored_searchable), label: "School"
config.add_index_field solr_name("partnering_agency", :stored_searchable), label: "Partnering Agency"
config.add_index_field solr_name("submitting_type", :stored_searchable), label: "I am submitting"

# solr fields to be displayed in the show (single result) view
# The ordering of the field names is the order of the display
config.add_show_field solr_name("title", :stored_searchable), label: "Title"
Expand All @@ -107,6 +109,7 @@ def self.modified_field
config.add_show_field solr_name("resource_type", :stored_searchable), label: "Resource Type"
config.add_show_field solr_name("format", :stored_searchable), label: "File Format"
config.add_show_field solr_name("identifier", :stored_searchable), label: "Identifier"
config.add_show_field solr_name("submitting_type", :stored_searchable), label: "I am submitting"
config.add_show_field solr_name("degree", :stored_searchable), label: "Degree"
config.add_show_field solr_name("department", :stored_searchable), label: "Department"
config.add_show_field solr_name("school", :stored_searchable), label: "School"
Expand Down
3 changes: 2 additions & 1 deletion 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.single_valued_fields = [:title, :creator]
self.terms += [:submitting_type]
self.single_valued_fields = [:title, :creator, :submitting_type]
end
end
3 changes: 3 additions & 0 deletions app/models/etd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ def set_defaults
property :partnering_agency, predicate: "http://id.loc.gov/vocabulary/relators/ctb" do |index|
index.as :stored_searchable
end
property :submitting_type, predicate: "http://www.europeana.eu/schemas/edm/hasType" do |index|
index.as :stored_searchable
end
end
4 changes: 4 additions & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ def partnering_agency
def primary
self[Solrizer.solr_name('primary')]
end

def submitting_type
self[Solrizer.solr_name('submitting_type')]
end
end
2 changes: 1 addition & 1 deletion app/presenters/etd_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class EtdPresenter < Hyrax::WorkShowPresenter
delegate :degree, :department, :school, :partnering_agency, to: :solr_document
delegate :degree, :department, :school, :partnering_agency, :submitting_type, to: :solr_document
end
16 changes: 16 additions & 0 deletions app/services/hyrax/submitting_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# services/submitting_service.rb
module Hyrax
class SubmittingService < Hyrax::QaSelectService
def initialize
super('submitting_type')
end

def include_current_value(value, _index, render_options, html_options)
unless value.blank? || active?(value)
html_options[:class] << ' force-select'
render_options += [[label(value), value]]
end
[render_options, html_options]
end
end
end
1 change: 1 addition & 0 deletions app/views/hyrax/base/_attribute_rows.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
<%= presenter.attribute_to_html(:school) %>
<%= presenter.attribute_to_html(:department) %>
<%= presenter.attribute_to_html(:partnering_agency) %>
<%= presenter.attribute_to_html(:submitting_type) %>
7 changes: 7 additions & 0 deletions app/views/records/edit_fields/_submitting_type.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% submitting_service = Hyrax::SubmittingService.new %>
<%= f.input :submitting_type, as: :select,
collection: submitting_service.select_all_options,
include_blank: true,
item_helper: submitting_service.method(:include_current_value),
input_html: { class: 'form-control' },
label: "I am submitting" %>
6 changes: 6 additions & 0 deletions app/views/records/edit_fields/hyrax/_submitting_type.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% submitting_service = Hyrax::SubmittingService.new %>
<%= f.input :submitting_type, as: :select,
collection: submitting_service.select_all_options,
include_blank: true,
item_helper: submitting_service.method(:include_current_value),
input_html: { class: 'form-control' } %>
4 changes: 4 additions & 0 deletions config/authorities/submitting_type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
terms:
- Honors Thesis
- Dissertation
- Masters Thesis
1 change: 1 addition & 0 deletions spec/factories/etd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
department ['Department of Russian and East Asian Languages and Cultures']
school ['Emory College of Arts and Sciences']
partnering_agency ["Does not apply (no collaborating organization)"]
submitting_type ["Honors Thesis"]
visibility Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
end
end
1 change: 1 addition & 0 deletions spec/features/create_etd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
fill_in "Degree", with: "Bachelor of Arts with Honors"
select('All rights reserved', from: 'Rights')
select('CDC', from: 'Partnering agency')
select("Honors Thesis", from: "I am submitting")
choose('open')
check('agreement')
click_on('My PDF')
Expand Down
1 change: 1 addition & 0 deletions spec/features/search_etd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
expect(page).to have_content etd.department.first
expect(page).to have_content etd.school.first
expect(page).to have_content etd.partnering_agency.first
expect(page).to have_content etd.submitting_type.first
# Now look for degree in the facets on the left
expect(page).to have_xpath("//h3", text: "Creator")
expect(page).to have_link(etd.creator.first, class: "facet_select")
Expand Down
1 change: 1 addition & 0 deletions spec/features/show_etd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
expect(page).to have_content etd.department.first
expect(page).to have_content etd.school.first
expect(page).to have_content etd.partnering_agency.first
expect(page).to have_content etd.submitting_type.first
end
end
end
1 change: 1 addition & 0 deletions spec/forms/hyrax/etd_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +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(: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
18 changes: 17 additions & 1 deletion spec/models/etd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
context "with a new ETD" do
its(:partnering_agency) { is_expected.to be_empty }
end
context "with an existing ETD that has a degree defined" do
context "with an existing ETD that has a partnering agency defined" do
subject do
described_class.create.tap do |etd|
etd.partnering_agency = partnering_agency
Expand All @@ -35,6 +35,22 @@
end
end

describe "#submitting_type" do
subject { described_class.new }
let(:submitting_type) { ["Honors Thesis"] }
context "with a new ETD" do
its(:submitting_type) { is_expected.to be_empty }
end
context "with an existing ETD that has a submitting work defined" do
subject do
described_class.create.tap do |etd|
etd.submitting_type = submitting_type
end
end
its(:submitting_type) { is_expected.to eq(submitting_type) }
end
end

describe "#department" do
subject { described_class.new }
context "with a new ETD" do
Expand Down
5 changes: 4 additions & 1 deletion spec/presenters/etd_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
let(:department) { ['Department of Russian and East Asian Languages and Cultures'] }
let(:school) { ['Emory College of Arts and Sciences'] }
let(:partnering_agency) { ["Does not apply (no collaborating organization)"] }
let(:submitting_type) { ["Honors Thesis"] }
let(:visibility) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
let :etd do
Etd.new(title: title, creator: creator, keyword: keyword, degree: degree, department: department, school: school, partnering_agency: partnering_agency, visibility: visibility)
Etd.new(title: title, creator: creator, keyword: keyword, degree: degree, department: department,
school: school, partnering_agency: partnering_agency, submitting_type: submitting_type, visibility: visibility)
end

let(:ability) { Ability.new(user) }
Expand All @@ -28,4 +30,5 @@
it { is_expected.to delegate_method(:department).to(:solr_document) }
it { is_expected.to delegate_method(:school).to(:solr_document) }
it { is_expected.to delegate_method(:partnering_agency).to(:solr_document) }
it { is_expected.to delegate_method(:submitting_type).to(:solr_document) }
end
17 changes: 17 additions & 0 deletions spec/services/hyrax/submitting_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

RSpec.describe Hyrax::SubmittingService do
before do
# Configure QA to use fixtures
qa_fixtures = { local_path: File.expand_path('config/authorities') }
allow(Qa::Authorities::Local).to receive(:config).and_return(qa_fixtures)
end

let(:service) { described_class.new }

describe "#select_all_options" do
it "has a select list" do
expect(service.select_all_options).to include(["Honors Thesis", "Honors Thesis"])
end
end
end

0 comments on commit b98cdfb

Please sign in to comment.