-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
229 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module ToCocina | ||
module Work | ||
# Maps WorkForm to Cocina access parameters | ||
class AccessMapper | ||
def self.call(...) | ||
new(...).call | ||
end | ||
|
||
# @param [WorkForm] work_form | ||
def initialize(work_form:) | ||
@work_form = work_form | ||
end | ||
|
||
# @return [Hash] the Cocina access parameters | ||
def call | ||
{ | ||
view: access, | ||
download: access, | ||
license: license.presence, | ||
useAndReproductionStatement: I18n.t('license.terms_of_use') | ||
}.compact | ||
end | ||
|
||
private | ||
|
||
attr_reader :work_form | ||
|
||
delegate :access, :license, to: :work_form | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
spec/components/works/edit/access_settings_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Works::Edit::AccessSettingsComponent, type: :component do | ||
let(:form) { ActionView::Helpers::FormBuilder.new(nil, work_form, vc_test_controller.view_context, {}) } | ||
let(:work_form) { WorkForm.new(access: 'stanford') } | ||
let(:collection) { instance_double(Collection, depositor_selects_access?: depositor_selects) } | ||
|
||
context 'when the depositor selects access' do | ||
let(:depositor_selects) { true } | ||
|
||
it 'renders the select' do | ||
render_inline(described_class.new(form:, collection:)) | ||
|
||
expect(page).to have_select('Who can download the files?', options: ['Stanford Community', 'Everyone']) | ||
end | ||
end | ||
|
||
context 'when the collection specifies access' do | ||
let(:depositor_selects) { false } | ||
|
||
it 'states the access and renders a hidden field' do | ||
render_inline(described_class.new(form:, collection:)) | ||
|
||
expect(page).to have_text('The files in your deposit will be downloadable by the Stanford Community.') | ||
expect(page).to have_field('access', type: 'hidden', with: 'stanford') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ToCocina::Work::AccessMapper do | ||
subject(:access) { described_class.call(work_form:) } | ||
|
||
context 'when stanford access' do | ||
let(:work_form) { WorkForm.new(access: 'stanford') } | ||
|
||
it 'maps to cocina' do | ||
expect(access).to match( | ||
view: 'stanford', | ||
download: 'stanford', | ||
useAndReproductionStatement: String | ||
) | ||
end | ||
end | ||
|
||
context 'when world access' do | ||
let(:work_form) { WorkForm.new } | ||
|
||
it 'maps to cocina' do | ||
expect(access).to match( | ||
view: 'world', | ||
download: 'world', | ||
useAndReproductionStatement: String | ||
) | ||
end | ||
end | ||
|
||
context 'when license' do | ||
let(:work_form) { WorkForm.new(license: 'http://creativecommons.org/licenses/by/3.0/us/') } | ||
|
||
it 'maps to cocina' do | ||
expect(access).to match( | ||
view: 'world', | ||
download: 'world', | ||
license: 'http://creativecommons.org/licenses/by/3.0/us/', | ||
useAndReproductionStatement: String | ||
) | ||
end | ||
end | ||
|
||
context 'when none license' do | ||
let(:work_form) { WorkForm.new(license: '') } | ||
|
||
it 'maps to cocina' do | ||
expect(access).to match( | ||
view: 'world', | ||
download: 'world', | ||
useAndReproductionStatement: String | ||
) | ||
end | ||
end | ||
end |
Oops, something went wrong.