sufia 6.0.0.beta1 → 6.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -2
- data/Gemfile +10 -1
- data/History.md +21 -0
- data/SUFIA_VERSION +1 -1
- data/app/assets/images/orcid.png +0 -0
- data/app/assets/javascripts/sufia.js +1 -1
- data/app/assets/javascripts/sufia/batch_edit.js +36 -54
- data/app/assets/javascripts/sufia/edit_metadata.js +10 -11
- data/app/assets/javascripts/sufia/permissions.js +2 -26
- data/app/assets/stylesheets/sufia.css.scss +10 -2
- data/app/assets/stylesheets/sufia/_batch-edit.scss +8 -6
- data/app/assets/stylesheets/sufia/_dashboard.scss +10 -0
- data/app/assets/stylesheets/sufia/_settings.scss +1 -0
- data/app/assets/stylesheets/sufia/_styles.scss +5 -3
- data/app/controllers/batch_controller.rb +9 -6
- data/app/controllers/batch_edits_controller.rb +2 -2
- data/app/controllers/collections_controller.rb +19 -3
- data/app/controllers/concerns/sufia/batch_edits_controller_behavior.rb +30 -29
- data/app/controllers/concerns/sufia/breadcrumbs.rb +8 -3
- data/app/controllers/concerns/sufia/files_controller_behavior.rb +19 -7
- data/app/controllers/concerns/sufia/users_controller_behavior.rb +14 -2
- data/app/controllers/single_use_links_viewer_controller.rb +5 -1
- data/app/forms/sufia/forms/batch_edit_form.rb +6 -0
- data/app/forms/sufia/forms/collection_edit_form.rb +17 -0
- data/app/forms/sufia/forms/generic_file_edit_form.rb +16 -0
- data/app/helpers/generic_file_helper.rb +3 -47
- data/app/helpers/sufia/permissions_helper.rb +29 -0
- data/app/helpers/sufia/sufia_helper_behavior.rb +11 -0
- data/app/inputs/multi_value_with_help_input.rb +8 -0
- data/app/inputs/select_with_help_input.rb +3 -0
- data/app/inputs/select_with_modal_help_input.rb +36 -0
- data/app/inputs/with_help_icon.rb +32 -0
- data/app/models/concerns/sufia/solr_document_behavior.rb +1 -1
- data/app/presenters/sufia/collection_presenter.rb +29 -0
- data/app/presenters/sufia/generic_file_presenter.rb +14 -0
- data/app/presenters/sufia/presenter_renderer.rb +53 -0
- data/app/views/batch/_metadata.html.erb +10 -44
- data/app/views/batch/_more_metadata.html.erb +3 -2
- data/app/views/batch/edit.html.erb +2 -2
- data/app/views/batch_edits/edit.html.erb +13 -17
- data/app/views/collections/_form.html.erb +5 -5
- data/app/views/collections/_show_descriptions.html.erb +8 -10
- data/app/views/collections/edit.html.erb +8 -9
- data/app/views/collections/edit_fields/_description.html.erb +1 -2
- data/app/views/dashboard/_index_partials/_stats.html.erb +3 -3
- data/app/views/generic_files/_descriptions.html.erb +5 -8
- data/app/views/generic_files/_permission_form.html.erb +8 -17
- data/app/views/generic_files/_show_descriptions.html.erb +3 -4
- data/app/views/generic_files/edit.html.erb +1 -2
- data/app/views/generic_files/jq_upload.json.jbuilder +8 -0
- data/app/views/records/edit_fields/_default.html.erb +5 -10
- data/app/views/records/edit_fields/_description.html.erb +5 -10
- data/app/views/records/edit_fields/_resource_type.html.erb +2 -5
- data/app/views/records/edit_fields/_rights.html.erb +3 -9
- data/app/views/single_use_links_viewer/show.html.erb +10 -16
- data/app/views/users/_profile.html.erb +1 -2
- data/app/views/users/_user_info.html.erb +20 -3
- data/app/views/users/edit.html.erb +11 -2
- data/app/views/users/show.html.erb +1 -1
- data/config/locales/sufia.en.yml +46 -26
- data/config/routes.rb +1 -1
- data/lib/generators/sufia/install_generator.rb +4 -0
- data/lib/sufia.rb +4 -0
- data/lib/sufia/form_builder.rb +16 -0
- data/lib/sufia/version.rb +1 -1
- data/spec/actors/generic_file/actor_spec.rb +1 -2
- data/spec/controllers/batch_controller_spec.rb +16 -48
- data/spec/controllers/batch_edits_controller_spec.rb +27 -16
- data/spec/controllers/collections_controller_spec.rb +81 -61
- data/spec/controllers/generic_files_controller_spec.rb +17 -2
- data/spec/controllers/users_controller_spec.rb +13 -3
- data/spec/features/collection_spec.rb +93 -88
- data/spec/features/users_spec.rb +1 -1
- data/spec/forms/collection_edit_form_spec.rb +20 -0
- data/spec/forms/generic_file_edit_form_spec.rb +26 -0
- data/spec/helpers/generic_file_helper_spec.rb +33 -7
- data/spec/helpers/permissions_helper_spec.rb +21 -0
- data/spec/inputs/multi_value_with_help_input_spec.rb +25 -0
- data/spec/inputs/select_with_modal_help_input_spec.rb +21 -0
- data/spec/jobs/batch_update_job_spec.rb +11 -14
- data/spec/lib/sufia/breadcrumbs_spec.rb +46 -8
- data/spec/models/generic_file_spec.rb +0 -13
- data/spec/models/user_spec.rb +23 -0
- data/spec/presenters/presenter_renderer_spec.rb +19 -0
- data/spec/presenters/sufia/generic_file_presenter_spec.rb +12 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/input_support.rb +12 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- data/spec/views/batch/edit.html.erb_spec.rb +13 -23
- data/spec/views/batch_edits/edit.html.erb_spec.rb +19 -0
- data/spec/views/collections/_form.html.erb_spec.rb +26 -28
- data/spec/views/collections/_show_descriptions.html.erb_spec.rb +15 -9
- data/spec/views/dashboard/index_spec.rb +2 -2
- data/spec/views/generic_file/_permission_form.html.erb_spec.rb +23 -0
- data/spec/views/generic_file/edit.html.erb_spec.rb +5 -0
- data/spec/views/generic_file/show.html.erb_spec.rb +5 -0
- data/sufia-models/app/actors/sufia/generic_file/actor.rb +1 -1
- data/sufia-models/app/jobs/batch_update_job.rb +5 -5
- data/sufia-models/app/models/batch.rb +7 -3
- data/sufia-models/app/models/concerns/sufia/collection.rb +7 -25
- data/sufia-models/app/models/concerns/sufia/generic_file.rb +0 -1
- data/sufia-models/app/models/concerns/sufia/generic_file/export.rb +2 -2
- data/sufia-models/app/models/concerns/sufia/generic_file/indexing.rb +4 -13
- data/sufia-models/app/models/concerns/sufia/generic_file/metadata.rb +1 -1
- data/sufia-models/app/models/concerns/sufia/user.rb +24 -17
- data/sufia-models/app/models/sufia/orcid_validator.rb +8 -0
- data/sufia-models/app/services/sufia/generic_file_indexing_service.rb +13 -0
- data/sufia-models/app/services/sufia/indexing_service.rb +15 -0
- data/sufia-models/lib/generators/sufia/models/abstract_migration_generator.rb +30 -0
- data/sufia-models/lib/generators/sufia/models/cached_stats_generator.rb +3 -47
- data/sufia-models/lib/generators/sufia/models/install_generator.rb +11 -31
- data/sufia-models/lib/generators/sufia/models/orcid_field_generator.rb +19 -0
- data/sufia-models/lib/generators/sufia/models/proxies_generator.rb +2 -31
- data/sufia-models/lib/generators/sufia/models/templates/config/redis.yml +3 -0
- data/sufia-models/lib/generators/sufia/models/templates/config/sufia.rb +3 -0
- data/sufia-models/lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb +5 -0
- data/sufia-models/lib/generators/sufia/models/upgrade400_generator.rb +2 -33
- data/sufia-models/lib/generators/sufia/models/user_stats_generator.rb +31 -0
- data/sufia-models/lib/sufia/models/engine.rb +1 -0
- data/sufia-models/lib/sufia/models/version.rb +1 -1
- data/sufia-models/sufia-models.gemspec +5 -5
- data/sufia.gemspec +2 -3
- metadata +49 -39
- data/app/assets/javascripts/sufia/multiForm.js +0 -67
- data/app/helpers/records_helper.rb +0 -4
- data/app/helpers/sufia/records_helper_behavior.rb +0 -68
- data/app/views/batch_edits/update_edit.js.erb +0 -5
- data/app/views/collections/_edit_descriptions.html.erb +0 -18
- data/app/views/collections/edit_fields/_title.html.erb +0 -3
- data/app/views/generic_files/_field_form.html.erb +0 -20
- data/app/views/records/_edit_field.html.erb +0 -22
- data/app/views/records/edit_fields/_suffix.html.erb +0 -10
- data/app/views/records/edit_fields/_type.html.erb +0 -8
- data/app/views/users/_social_media_info.html.erb +0 -20
- data/spec/helpers/records_helper_spec.rb +0 -102
- data/spec/models/generic_file/web_form_spec.rb +0 -35
- data/sufia-models/app/models/concerns/sufia/generic_file/accessible_attributes.rb +0 -87
- data/sufia-models/app/models/concerns/sufia/generic_file/web_form.rb +0 -62
@@ -1,67 +0,0 @@
|
|
1
|
-
(function( $ ){
|
2
|
-
|
3
|
-
$.fn.multiForm = function( options ) {
|
4
|
-
|
5
|
-
// Create some defaults, extending them with any options that were provided
|
6
|
-
var settings = $.extend( { }, options);
|
7
|
-
|
8
|
-
function addField() {
|
9
|
-
count = $(this).closest('.form-group').find('input').size();
|
10
|
-
var cloneId = this.id.replace("submit", "clone");
|
11
|
-
var newId = this.id.replace("submit", "elements");
|
12
|
-
var cloneElem = $('#'+cloneId).clone();
|
13
|
-
// change the add button to a remove button
|
14
|
-
var plusbttn = cloneElem.find('#'+this.id);
|
15
|
-
var sr_hidden = '<span aria-hidden="true"><i class="glyphicon glyphicon-remove"></i></span>';
|
16
|
-
var sr_only = '<span class="sr-only">remove this ' + this.name.replace("_", " ") + '</span>';
|
17
|
-
var remove_button = sr_hidden + sr_only;
|
18
|
-
plusbttn.html(remove_button);
|
19
|
-
plusbttn.on('click',removeField);
|
20
|
-
|
21
|
-
|
22
|
-
// remove the help tag on subsequent added fields
|
23
|
-
cloneElem.find('.formHelp').remove();
|
24
|
-
cloneElem.find('.modal-div').remove();
|
25
|
-
|
26
|
-
//clear out the value for the element being appended
|
27
|
-
//so the new element has a blank value
|
28
|
-
// Note: there may be more than one input field. Example:
|
29
|
-
// creator_name
|
30
|
-
// creator_role
|
31
|
-
textFields = cloneElem.find('input[type=text]')
|
32
|
-
$.each(textFields, function(n, tf) {
|
33
|
-
newName = $(tf).attr('name').replace('[0]', '['+count+']');
|
34
|
-
$(tf).attr('name', newName).val('').attr("required", false)
|
35
|
-
})
|
36
|
-
|
37
|
-
if (settings.afterAdd) {
|
38
|
-
settings.afterAdd(this, cloneElem)
|
39
|
-
}
|
40
|
-
|
41
|
-
$('#'+newId).append(cloneElem);
|
42
|
-
cloneElem.find('input[type=text]').focus();
|
43
|
-
return false;
|
44
|
-
}
|
45
|
-
|
46
|
-
function removeField () {
|
47
|
-
// get parent and remove it
|
48
|
-
$(this).closest('.input-group').remove();
|
49
|
-
return false;
|
50
|
-
}
|
51
|
-
|
52
|
-
return this.each(function() {
|
53
|
-
|
54
|
-
// Tooltip plugin code here
|
55
|
-
/*
|
56
|
-
* adds additional metadata elements
|
57
|
-
*/
|
58
|
-
$('.adder', this).click(addField);
|
59
|
-
|
60
|
-
$('.remover', this).click(removeField);
|
61
|
-
|
62
|
-
|
63
|
-
});
|
64
|
-
|
65
|
-
};
|
66
|
-
})( jQuery );
|
67
|
-
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module Sufia
|
2
|
-
module RecordsHelperBehavior
|
3
|
-
def add_field(key)
|
4
|
-
more_or_less_button(key, 'adder', '+')
|
5
|
-
end
|
6
|
-
|
7
|
-
def subtract_field(key)
|
8
|
-
more_or_less_button(key, 'remover', '-')
|
9
|
-
end
|
10
|
-
|
11
|
-
def help_icon(key, content = nil, title = nil)
|
12
|
-
content = content || metadata_help(key)
|
13
|
-
title = title || get_label(key)
|
14
|
-
link_to '#', id: "generic_file_#{key.to_s}_help", rel: 'popover',
|
15
|
-
'data-content' => content,
|
16
|
-
'data-original-title' => title,
|
17
|
-
'aria-label' => get_aria_label(key) do
|
18
|
-
content_tag 'i', '', "aria-hidden" => true, class: "help-icon"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def help_icon_modal(modal_id)
|
23
|
-
link_to '#' + modal_id, id: "generic_file_#{modal_id}_help_modal", rel: 'button',
|
24
|
-
data: { toggle: 'modal' }, 'aria-label' => get_aria_label(modal_id) do
|
25
|
-
content_tag 'i', '', "aria-hidden" => true, class: 'help-icon'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def metadata_help(key)
|
30
|
-
I18n.t("sufia.metadata_help.#{key}", default: key.to_s.humanize)
|
31
|
-
end
|
32
|
-
|
33
|
-
def get_label(key)
|
34
|
-
I18n.t("sufia.field_label.#{key}", default: key.to_s.humanize)
|
35
|
-
end
|
36
|
-
|
37
|
-
def get_aria_label(key)
|
38
|
-
I18n.t("sufia.aria_label.#{key}", default: default_aria_label(key.to_s.humanize))
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def more_or_less_button(key, html_class, symbol)
|
44
|
-
icon = (symbol == "-") ? "remove" : "plus"
|
45
|
-
content_tag 'span', class: 'input-group-btn field-controls' do
|
46
|
-
content_tag "button", class: "#{html_class} btn", id: "additional_#{key}_submit", name: "additional_#{key}" do
|
47
|
-
sr_hidden(icon) + sr_only(key.to_s)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def sr_hidden icon
|
53
|
-
content_tag "span", "aria-hidden" => true do
|
54
|
-
content_tag "i", "", class: "glyphicon glyphicon-#{icon}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def sr_only text
|
59
|
-
content_tag "span", class: "sr-only" do
|
60
|
-
"add another #{text}"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def default_aria_label text
|
65
|
-
I18n.t("sufia.aria_label.default", title: text)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
<%# This mimics the generic_files/descriptions partial & re-uses some of its sub-partials %>
|
2
|
-
<div id="descriptions_display" class="tab-pane active">
|
3
|
-
<%= form_for collection, url: collections.collection_path, html: {multipart: true, class: 'form-horizontal'} do |f| %>
|
4
|
-
<%= hidden_field_tag('redirect_tab', 'descriptions') %>
|
5
|
-
<h2 class="non lower">Descriptions <small class="pull-right"><span class="error">*</span> indicates required fields</small> </h2>
|
6
|
-
<div class="well">
|
7
|
-
|
8
|
-
<% (collection.terms_for_editing).each do |term| %>
|
9
|
-
<%= render partial: "records/edit_field", locals: { record: collection, f: f, render_req: true, key: term } %>
|
10
|
-
<% end %>
|
11
|
-
|
12
|
-
</div><!-- /well -->
|
13
|
-
<div class="action-button">
|
14
|
-
<%= f.button '<i class="glyphicon glyphicon-floppy-disk"></i> Save Descriptions'.html_safe, type: 'submit', class: 'btn btn-primary',
|
15
|
-
onclick: "confirmation_needed = false;", id: "upload_submit", name: "update_descriptions" %>
|
16
|
-
</div>
|
17
|
-
<% end %>
|
18
|
-
</div>
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<% render_req ||= true # render_req is true for single file edit, false for batch edit%>
|
2
|
-
<div class="batch-group">
|
3
|
-
<% vals = f.object[key] %>
|
4
|
-
<% if render_req && required?(key) %>
|
5
|
-
<%= f.label key do %>
|
6
|
-
<span class="required-field">*</span><%= get_label(key) %>
|
7
|
-
<% end %>
|
8
|
-
<% else %>
|
9
|
-
<%= f.label key, get_label(key) %>
|
10
|
-
<% end %>
|
11
|
-
<%= help_icon(key) %>
|
12
|
-
<% if key == :resource_type %>
|
13
|
-
<%# resource_type is a multiselect box, so don't render one row for each %>
|
14
|
-
<%= render_edit_field_partial(key, record: f.object, f: f, render_req: render_req) %>
|
15
|
-
<% else %>
|
16
|
-
<% vals.to_ary.each_with_index do |v, index| %>
|
17
|
-
<%= render_edit_field_partial(key, record: f.object, f: f, v: v, index: index, render_req: render_req) %>
|
18
|
-
<% end %>
|
19
|
-
<% end %>
|
20
|
-
</div><!-- /.batch-group -->
|
@@ -1,22 +0,0 @@
|
|
1
|
-
<%# Overriding hydra-editor so that we can replace the call to 'render_edit_field_partial'
|
2
|
-
# With render_edit_field_partial_with_action because there is also a
|
3
|
-
# 'render_edit_field_partial' in sufia that uses 'generic_file' as the action. %>
|
4
|
-
<% render_req ||= true # render_req is true for single file edit, false for batch edit%>
|
5
|
-
<div class="form-group">
|
6
|
-
<% vals = record[key] %>
|
7
|
-
<% if render_req && record.required?(key) %>
|
8
|
-
<% tmp = '<span class="required-field">*</span>' + get_label(key) %>
|
9
|
-
<%= f.label key, tmp.html_safe %>
|
10
|
-
<% else %>
|
11
|
-
<%= f.label key, get_label(key) %>
|
12
|
-
<% end %>
|
13
|
-
|
14
|
-
<% if key == :resource_type %>
|
15
|
-
<%# resource_type is a multiselect box, so don't render one row for each %>
|
16
|
-
<%= render_edit_field_partial(key, record: record, f: f, render_req: render_req) %>
|
17
|
-
<% else %>
|
18
|
-
<% Array(vals).each_with_index do |v, index| %>
|
19
|
-
<%= render_edit_field_partial(key, record: record, f: f, v: v, index: index, render_req: render_req) %>
|
20
|
-
<% end %>
|
21
|
-
<% end %>
|
22
|
-
</div><!-- /.form-group -->
|
@@ -1,8 +0,0 @@
|
|
1
|
-
<div class="form-group">
|
2
|
-
<%= f.label :resource_type, "Resource Types", for: "resource_type" %>
|
3
|
-
<p class="help-block">You may select multiple types to apply<p>
|
4
|
-
<%= f.select :resource_type, options_for_select(Sufia.config.resource_types.keys), {},
|
5
|
-
{multiple: true, size: 7} %>
|
6
|
-
<%= help_icon(:resource_type) %>
|
7
|
-
</div>
|
8
|
-
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<% if !user.facebook_handle.blank?() %>
|
2
|
-
<dt><i class="fa fa-facebook"></i> Facebook Handle</dt>
|
3
|
-
<dd><%= link_to "http://facebook.com/#{user.facebook_handle}", "http://facebook.com/#{user.facebook_handle}", {target:'_blank'} %></dd>
|
4
|
-
<% end %>
|
5
|
-
|
6
|
-
<% if !user.twitter_handle.blank?() %>
|
7
|
-
<dt><i class="fa fa-twitter"></i> Twitter Handle</dt>
|
8
|
-
<dd><%= link_to "http://twitter.com/#{user.twitter_handle}", "http://twitter.com/#{user.twitter_handle}", {target:'_blank'} %></dd>
|
9
|
-
<% end %>
|
10
|
-
|
11
|
-
<!--
|
12
|
-
|
13
|
-
<dt><i class="fa fa-google-plus"></i> Google+ Handle</dt>
|
14
|
-
<dd><%# link_to user.googleplus_handle, "http://google.com/+#{user.googleplus_handle}", {target:'_blank'} %></dd>
|
15
|
-
-->
|
16
|
-
|
17
|
-
<% if !user.linkedin_handle.blank?() %>
|
18
|
-
<dt><i class="fa fa-linkedin"></i> Linked In</dt>
|
19
|
-
<dd><%= link_to "#{@linkedInUrl}", "#{@linkedInUrl}", {target:'_blank'} %></dd>
|
20
|
-
<% end %>
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RecordsHelper do
|
4
|
-
|
5
|
-
describe "#add_field" do
|
6
|
-
let(:expected) {
|
7
|
-
"<span class=\"input-group-btn field-controls\"><button class=\"adder btn\" id=\"additional_test_submit\" name=\"additional_test\"><span aria-hidden=\"true\"><i class=\"glyphicon glyphicon-plus\"></i></span><span class=\"sr-only\">add another test</span></button></span>"
|
8
|
-
}
|
9
|
-
|
10
|
-
subject { helper.add_field(:test) }
|
11
|
-
it { is_expected.to eq expected }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#subtract_field" do
|
15
|
-
let(:expected) {
|
16
|
-
"<span class=\"input-group-btn field-controls\"><button class=\"remover btn\" id=\"additional_test_submit\" name=\"additional_test\"><span aria-hidden=\"true\"><i class=\"glyphicon glyphicon-remove\"></i></span><span class=\"sr-only\">add another test</span></button></span>"
|
17
|
-
}
|
18
|
-
|
19
|
-
subject { helper.subtract_field(:test) }
|
20
|
-
it { is_expected.to eq expected }
|
21
|
-
end
|
22
|
-
|
23
|
-
it "draws help_icon" do
|
24
|
-
str = String.new(helper.help_icon(:tag))
|
25
|
-
doc = Nokogiri::HTML(str)
|
26
|
-
a = doc.xpath('//a').first
|
27
|
-
expect(a.attr('data-content')).to eql("Words or phrases you select to describe what the file is about. These are used to search for content. <em>This is a required field</em>.")
|
28
|
-
expect(a.attr('data-original-title')).to eql("Keyword")
|
29
|
-
expect(a.attr('id')).to eql("generic_file_tag_help")
|
30
|
-
expect(a.children.first.attr('class')).to eql('help-icon')
|
31
|
-
end
|
32
|
-
|
33
|
-
specify "draws help_icon_modal" do
|
34
|
-
str = String.new(helper.help_icon_modal('myModal'))
|
35
|
-
doc = Nokogiri::HTML(str)
|
36
|
-
a = doc.xpath('//a').first
|
37
|
-
expect(a.attr('href')).to eq('#myModal')
|
38
|
-
expect(a.attr('data-toggle')).to eq('modal')
|
39
|
-
expect(a.attr('id')).to eq('generic_file_myModal_help_modal')
|
40
|
-
expect(a.children.first.attr('class')).to eq('help-icon')
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "download links" do
|
44
|
-
|
45
|
-
let(:file) { GenericFile.new(id: "fake-1") }
|
46
|
-
let(:link_text) { helper.render_download_link("Download Fake") }
|
47
|
-
let(:icon_text) { helper.render_download_icon("Download the full-sized Fake") }
|
48
|
-
|
49
|
-
before { assign :generic_file, file }
|
50
|
-
|
51
|
-
describe "#render_download_link" do
|
52
|
-
it "has default text" do
|
53
|
-
expect(helper.render_download_link).to have_selector("#file_download")
|
54
|
-
expect(helper.render_download_link).to have_content("Download")
|
55
|
-
end
|
56
|
-
|
57
|
-
it "includes user-supplied link text" do
|
58
|
-
expect(link_text).to have_selector("#file_download")
|
59
|
-
expect(link_text).to have_content("Download Fake")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#render_download_icon" do
|
64
|
-
it "has default text" do
|
65
|
-
expect(helper.render_download_icon).to have_selector("#file_download")
|
66
|
-
expect(helper.render_download_icon).to match("Download the document")
|
67
|
-
end
|
68
|
-
|
69
|
-
it "includes user-supplied icon text" do
|
70
|
-
expect(icon_text).to have_selector("#file_download")
|
71
|
-
expect(icon_text).to match("Download the full-sized Fake")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "#metadata_help" do
|
77
|
-
specify "default" do
|
78
|
-
expect(helper.metadata_help("foo")).to eql("Foo")
|
79
|
-
end
|
80
|
-
specify "using a key" do
|
81
|
-
expect(helper.metadata_help("language")).to eql("The language of the file content.")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#get_label" do
|
86
|
-
specify "default" do
|
87
|
-
expect(helper.get_label("foo")).to eql("Foo")
|
88
|
-
end
|
89
|
-
specify "using a key" do
|
90
|
-
expect(helper.get_label("tag")).to eql("Keyword")
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "#get_aria_label" do
|
95
|
-
specify "default" do
|
96
|
-
expect(helper.get_aria_label("foo")).to eql("Usage information for Foo")
|
97
|
-
end
|
98
|
-
specify "using a key" do
|
99
|
-
expect(helper.get_aria_label("tag")).to eql("Usage information for keyword")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GenericFile, :type => :model do
|
4
|
-
before do
|
5
|
-
subject.apply_depositor_metadata('jcoyne')
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "terms_for_editing" do
|
9
|
-
it "should return a list" do
|
10
|
-
expect(subject.terms_for_editing).to eq([:resource_type, :title, :creator, :contributor, :description, :tag,
|
11
|
-
:rights, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url])
|
12
|
-
end
|
13
|
-
end
|
14
|
-
describe "terms_for_display" do
|
15
|
-
it "should return a list" do
|
16
|
-
expect(subject.terms_for_display).to eq([:resource_type, :title,
|
17
|
-
:creator, :contributor, :description, :tag, :rights, :publisher,
|
18
|
-
:date_created, :subject, :language, :identifier, :based_near,
|
19
|
-
:related_url])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "accessible_attributes" do
|
24
|
-
it "should have a list" do
|
25
|
-
expect(subject.accessible_attributes).to include(:part_of, :resource_type, :title, :creator, :contributor, :description,
|
26
|
-
:tag, :rights, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url, :permissions_attributes)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should sanitize them" do
|
30
|
-
expect(subject.sanitize_attributes({'part_of' => 'A book', 'something_crazy' => "get's thrown out"})).to eq(
|
31
|
-
{'part_of' => 'A book'}
|
32
|
-
)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module Sufia
|
2
|
-
module GenericFile
|
3
|
-
module AccessibleAttributes
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
included do
|
6
|
-
class_attribute :_accessible_attributes
|
7
|
-
self._accessible_attributes = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
def accessible_attributes(role = :default)
|
11
|
-
self.class._accessible_attributes[role] || []
|
12
|
-
end
|
13
|
-
|
14
|
-
# Sanitize the provided attributes using only those that are specified
|
15
|
-
# as accessible by attr_accessor
|
16
|
-
# @param [Hash] attributes the raw parameters
|
17
|
-
# @param [Hash] args a hash of options
|
18
|
-
# @option args [Symbol] :as (:default) the role to use
|
19
|
-
# @return A sanitized hash of parameters
|
20
|
-
def sanitize_attributes(attributes = {}, args = {})
|
21
|
-
role = args[:as] || :default
|
22
|
-
attributes.select { |k,v| accessible_attributes.include?(k.to_sym)}
|
23
|
-
end
|
24
|
-
|
25
|
-
module ClassMethods
|
26
|
-
# Specifies a white list of model attributes that can be set via
|
27
|
-
# mass-assignment.
|
28
|
-
#
|
29
|
-
# Like +attr_protected+, a role for the attributes is optional,
|
30
|
-
# if no role is provided then :default is used. A role can be defined by
|
31
|
-
# using the :as option.
|
32
|
-
#
|
33
|
-
# Mass-assignment will only set attributes in this list, to assign to
|
34
|
-
# the rest of # attributes you can use direct writer methods. This is
|
35
|
-
# meant to protect sensitive attributes from being overwritten by
|
36
|
-
# malicious users # tampering with URLs or forms.
|
37
|
-
#
|
38
|
-
# class Customer
|
39
|
-
# include ActiveModel::MassAssignmentSecurity
|
40
|
-
#
|
41
|
-
# attr_accessor :name, :credit_rating
|
42
|
-
#
|
43
|
-
# attr_accessible :name
|
44
|
-
# attr_accessible :name, :credit_rating, as: :admin
|
45
|
-
#
|
46
|
-
# def assign_attributes(values, options = {})
|
47
|
-
# sanitize_for_mass_assignment(values, options[:as]).each do |k, v|
|
48
|
-
# send("#{k}=", v)
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# When using the :default role:
|
54
|
-
#
|
55
|
-
# customer = Customer.new
|
56
|
-
# customer.assign_attributes({ "name" => "David", "credit_rating" => "Excellent", last_login: 1.day.ago }, as: :default)
|
57
|
-
# customer.name # => "David"
|
58
|
-
# customer.credit_rating # => nil
|
59
|
-
#
|
60
|
-
# customer.credit_rating = "Average"
|
61
|
-
# customer.credit_rating # => "Average"
|
62
|
-
#
|
63
|
-
# And using the :admin role:
|
64
|
-
#
|
65
|
-
# customer = Customer.new
|
66
|
-
# customer.assign_attributes({ "name" => "David", "credit_rating" => "Excellent", last_login: 1.day.ago }, as: :admin)
|
67
|
-
# customer.name # => "David"
|
68
|
-
# customer.credit_rating # => "Excellent"
|
69
|
-
#
|
70
|
-
# Note that using <tt>Hash#except</tt> or <tt>Hash#slice</tt> in place of
|
71
|
-
# +attr_accessible+ to sanitize attributes provides basically the same
|
72
|
-
# functionality, but it makes a bit tricky to deal with nested attributes.
|
73
|
-
def attr_accessible(*args)
|
74
|
-
options = args.extract_options!
|
75
|
-
role = options[:as] || :default
|
76
|
-
|
77
|
-
self._accessible_attributes ||= {}
|
78
|
-
|
79
|
-
Array.wrap(role).each do |name|
|
80
|
-
self._accessible_attributes[name] = args.map &:to_sym
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|