Skip to content

Commit

Permalink
Merge pull request #2570 from projecthydra/license_service
Browse files Browse the repository at this point in the history
Use the new CurationConcerns::LicenseService
  • Loading branch information
cbeer committed Aug 29, 2016
2 parents 6a5d807 + 07d2bfa commit 9e883b3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
12 changes: 11 additions & 1 deletion app/helpers/sufia/sufia_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Sufia
module SufiaHelperBehavior
include Sufia::CitationsBehavior
include ERB::Util # provides html_escape
extend Deprecation

def application_name
t('sufia.product_name', default: super)
Expand Down Expand Up @@ -162,7 +163,16 @@ def link_to_profile(args)
# @param [Hash] options from blacklight helper_method invocation. Maps rights URIs to links with labels.
# @return [ActiveSupport::SafeBuffer] rights statement links, html_safe
def rights_statement_links(options)
options[:value].map { |right| link_to RightsService.label(right), right }.to_sentence.html_safe
license_links(options)
end
deprecation_deprecate rights_statement_links: "use licence_links instead"

# A Blacklight helper_method
# @param [Hash] options from blacklight helper_method invocation. Maps rights URIs to links with labels.
# @return [ActiveSupport::SafeBuffer] rights statement links, html_safe
def license_links(options)
service = CurationConcerns::LicenseService.new
options[:value].map { |right| link_to service.label(right), right }.to_sentence.html_safe
end

def link_to_telephone(user)
Expand Down
2 changes: 1 addition & 1 deletion app/views/records/edit_fields/_rights.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= f.input :rights, as: :multi_value_select,
collection: RightsService.select_active_options,
collection: CurationConcerns::LicenseService.new.select_active_options,
include_blank: true,
item_helper: method(:include_current_value),
input_html: { class: 'form-control' } %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/records/show_fields/_rights.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<% record.rights.each do |r| %>
<%= link_to_field('rights', r, RightsService.label(r)) %> <%= iconify_auto_link(r, false) %><br />
<%= link_to_field('rights', r, CurationConcerns::RightsService.label(r)) %> <%= iconify_auto_link(r, false) %><br />
<% end %>
2 changes: 1 addition & 1 deletion lib/generators/sufia/templates/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def self.modified_field
config.add_index_field solr_name("date_uploaded", :stored_sortable, type: :date), label: "Date Uploaded", itemprop: 'datePublished', helper_method: :human_readable_date
config.add_index_field solr_name("date_modified", :stored_sortable, type: :date), label: "Date Modified", itemprop: 'dateModified', helper_method: :human_readable_date
config.add_index_field solr_name("date_created", :stored_searchable), label: "Date Created", itemprop: 'dateCreated'
config.add_index_field solr_name("rights", :stored_searchable), label: "Rights", helper_method: :rights_statement_links
config.add_index_field solr_name("rights", :stored_searchable), label: "Rights", helper_method: :license_links
config.add_index_field solr_name("resource_type", :stored_searchable), label: "Resource Type", link_to_search: solr_name("resource_type", :facetable)
config.add_index_field solr_name("file_format", :stored_searchable), label: "File Format", link_to_search: solr_name("file_format", :facetable)
config.add_index_field solr_name("identifier", :stored_searchable), label: "Identifier", helper_method: :index_field_link, field_name: 'identifier'
Expand Down
13 changes: 11 additions & 2 deletions spec/helpers/sufia_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,23 @@ def new_state
end

describe "#rights_statement_links" do
let(:options) { instance_double(Hash) }
it "calls license_links" do
expect(Deprecation).to receive(:warn)
expect(helper).to receive(:license_links).with(options)
helper.rights_statement_links(options)
end
end

describe "#license_links" do
it "maps the url to a link with a label" do
expect(helper.rights_statement_links(
expect(helper.license_links(
value: ["http://creativecommons.org/publicdomain/zero/1.0/"]
)).to eq("<a href=\"http://creativecommons.org/publicdomain/zero/1.0/\">CC0 1.0 Universal</a>")
end

it "converts multiple rights statements to a sentence" do
expect(helper.rights_statement_links(
expect(helper.license_links(
value: ["http://creativecommons.org/publicdomain/zero/1.0/",
"http://creativecommons.org/publicdomain/mark/1.0/",
"http://www.europeana.eu/portal/rights/rr-r.html"]
Expand Down

0 comments on commit 9e883b3

Please sign in to comment.