Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/renderers/hyrax/renderers/domain_subject_attribute_renderer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true
module Hyrax
module Renderers
# This is used by PresentsAttributes to show domain subjects
class DomainSubjectAttributeRenderer < FacetedAttributeRenderer
private
def li_value(value)
link_to(ERB::Util.h(DomainSubjectService.new.label(value)), search_path(value))
end
end
end
end

10 changes: 10 additions & 0 deletions app/services/hyrax/domain_subject_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true
module Hyrax
# Provide select options for the domain subject field
class DomainSubjectService < QaSelectService
def initialize(_authority_name = nil)
super('domain_subjects')
end
end
end

11 changes: 11 additions & 0 deletions app/views/records/edit_fields/_domain_subject.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% domain_subject_service = Hyrax::DomainSubjectService.new %>
<%= f.input :domain_subject, as: :check_boxes,
collection: domain_subject_service.select_active_options,
include_blank: true,
item_helper: domain_subject_service.method(:include_current_value),
collection_wrapper_tag: :div,
item_wrapper_tag: :div,
hint: hint_with_links(key),
input_html: { class: 'form-control' } %>


31 changes: 31 additions & 0 deletions config/authorities/domain_subjects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
terms:
- id: Health & Medicine
term: Health & Medicine
active: true
- id: Education
term: Education
active: true
- id: Business
term: Business
active: true
- id: Media
term: Media
active: true
- id: Music
term: Music
active: true
- id: Arts & Humanities
term: Arts & Humanities
active: true
- id: Natural & Mathematical Sciences
term: Natural & Mathematical Sciences
active: true
- id: Social & Historical Sciences
term: Social & Historical Sciences
active: true
- id: Public Policy & Public Affairs
term: Public Policy & Public Affairs
active: true
- id: Informatics, Computing, & Engineering
term: Informatics, Computing, & Engineering
active: true
26 changes: 26 additions & 0 deletions spec/renderers/hyrax/campus_attribute_renderer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Hyrax::Renderers::CampusAttributeRenderer do

subject { described_class.new("field", "values", "options") }

describe "#li_value" do
before {
service_double = instance_double(Hyrax::CampusService)
allow(Hyrax::CampusService).to receive(:new).and_return(service_double)
allow(service_double).to receive(:label).with("B-Town").and_return "IUB"
allow(subject).to receive(:search_path).with("B-Town").and_return "Bloomington"
allow(ERB::Util).to receive(:h).with("IUB").and_return "Bton"
}
it "calls link_to" do
expect(ERB::Util).to receive(:h).with("IUB")
expect(subject).to receive(:search_path).with("B-Town")
expect(subject).to receive(:link_to).with("Bton", "Bloomington")

subject.send(:li_value, "B-Town")
end
end


end
26 changes: 26 additions & 0 deletions spec/renderers/hyrax/domain_subject_attribute_renderer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Hyrax::Renderers::DomainSubjectAttributeRenderer do

subject { described_class.new("field", "values", "options") }

describe "#li_value" do
before {
service_double = instance_double(Hyrax::DomainSubjectService)
allow(Hyrax::DomainSubjectService).to receive(:new).and_return(service_double)
allow(service_double).to receive(:label).with("informatics").and_return "engineering"
allow(subject).to receive(:search_path).with("informatics").and_return "computing"
allow(ERB::Util).to receive(:h).with("engineering").and_return "programming"
}
it "calls link_to" do
expect(ERB::Util).to receive(:h).with("engineering")
expect(subject).to receive(:search_path).with("informatics")
expect(subject).to receive(:link_to).with("programming", "computing")

subject.send(:li_value, "informatics")
end
end


end
16 changes: 16 additions & 0 deletions spec/services/hyrax/campus_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Hyrax::CampusService do

describe "#initialize" do
before {
allow(Hyrax::QaSelectService).to receive(:new)
}
it "calls parent class with super" do
expect(Hyrax::QaSelectService).to receive(:new)

Hyrax::CampusService.new(authority_name: nil)
end
end
end
16 changes: 16 additions & 0 deletions spec/services/hyrax/domain_subject_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Hyrax::DomainSubjectService do

describe "#initialize" do
before {
allow(Hyrax::QaSelectService).to receive(:new)
}
it "calls parent class with super" do
expect(Hyrax::QaSelectService).to receive(:new)

Hyrax::DomainSubjectService.new(authority_name: nil)
end
end
end