Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splits testing for spec/features/embargo_spec.rb to highlight bug. #6520

Merged
merged 1 commit into from
Dec 8, 2023
Merged
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
106 changes: 79 additions & 27 deletions spec/features/embargo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,44 @@
RSpec.describe 'embargo' do
let(:user) { create(:user) }

before do
sign_in user
before { sign_in user }

def go_to_embargo_mgmt_valkyrie
click_link 'Edit'
click_link 'Embargo Management Page'

expect(page).to have_content('This Monograph is under embargo.')
expect(page).to have_xpath("//input[@name='monograph[embargo_release_date]' and @value='#{future_date}']") # current embargo date is pre-populated in edit field
end

def go_to_embargo_mgmt_active_fedora
click_link 'Edit'
click_link 'Embargo Management Page'

expect(page).to have_content('This Generic Work is under embargo.')
expect(page).to have_xpath("//input[@name='generic_work[embargo_release_date]' and @value='#{future_date}']") # current embargo date is pre-populated in edit field
end

describe 'creating an embargoed object' do
let(:future_date) { Time.zone.today + 5 }
let(:later_future_date) { Time.zone.today + 10 }

it 'can be created, displayed and updated', :clean_repo, :workflow do
visit '/concern/generic_works/new'
fill_in 'Title', with: 'Embargo test'
fill_in 'Creator', with: 'Doe, Jane'
select('In Copyright', from: 'Rights statement')
choose 'Embargo'
fill_in 'generic_work_embargo_release_date', with: future_date
select 'Private', from: 'Restricted to'
select 'Public', from: 'then open it up to'
check('agreement')
click_button 'Save'

# chosen embargo date is on the show page
expect(page).to have_content(future_date.to_formatted_s(:standard))

click_link 'Edit'
click_link 'Embargo Management Page'

expect(page).to have_content('This Generic Work is under embargo.')
expect(page).to have_xpath("//input[@name='generic_work[embargo_release_date]' and @value='#{future_date}']") # current embargo date is pre-populated in edit field

go_to_embargo_mgmt_active_fedora
fill_in 'until', with: later_future_date.to_s

click_button 'Update Embargo'
Expand All @@ -51,7 +64,62 @@
end
end

describe 'updating embargoed object' do
shared_context('with future dates and admin user') do
let(:future_date) { Time.zone.today + 5 }
let(:later_future_date) { Time.zone.today + 10 }
let(:invalid_future_date) { Time.zone.today + 185 } # More than 6 months
let(:admin) { create(:admin) }
end

describe 'updating embargoed object (Valkyrie)' do
include_context 'with future dates and admin user'
let(:my_admin_set) do
valkyrie_create(:hyrax_admin_set, with_permission_template: true, title: ['admin set with embargo range'])
end
let(:permission_template) do
create(:permission_template, :with_delayed_release, :with_active_workflow, source_id: admin_set.id.to_s)
end
let(:default_admin_set) do
valkyrie_create(:default_hyrax_admin_set)
end
let(:work) do
valkyrie_create(:monograph,
depositor: user.user_key,
embargo: embargo,
title: ['embargoed work1'],
admin_set_id: my_admin_set.id,
edit_users: [user])
end
let(:embargo) do
valkyrie_create(:hyrax_embargo,
embargo_release_date: future_date,
visibility_after_embargo: 'open',
visibility_during_embargo: 'restricted')
end

xit 'can be updated with a valid date', pending: 'FIXME: cannot replicate development environment behavior' do
visit "/concern/generic_works/#{work.id}"
go_to_embargo_mgmt_valkyrie
fill_in 'until', with: later_future_date.to_s

click_button 'Update Embargo'
expect(page).to have_content(later_future_date.to_formatted_s(:standard))
expect(page).to have_content(my_admin_set.title.first)
end

# NOTE: Attempted to produce behavior in development environment, but error doesn't occur and date is saved.
xit 'cannot be updated with an invalid date', pending: 'FIXME: the expected behavior does not occur' do
visit "/concern/generic_works/#{work.id}"
go_to_embargo_mgmt_valkyrie
fill_in 'until', with: invalid_future_date.to_s

click_button 'Update Embargo'
expect(page).to have_content('Release date specified does not match permission template release requirements for selected AdminSet.')
end
end

describe 'updating embargoed object (ActiveFedora)', :active_fedora do
include_context 'with future dates and admin user'
let(:my_admin_set) do
create(:admin_set,
title: ['admin set with embargo range'],
Expand All @@ -63,10 +131,6 @@
description: ["A description"],
with_permission_template: {})
end
let(:future_date) { Time.zone.today + 5 }
let(:later_future_date) { Time.zone.today + 10 }
let(:invalid_future_date) { Time.zone.today + 185 } # More than 6 months
let(:admin) { create(:admin) }
let(:work) do
create(:work, title: ['embargoed work1'],
embargo_release_date: future_date,
Expand All @@ -78,13 +142,7 @@

it 'can be updated with a valid date' do
visit "/concern/generic_works/#{work.id}"

click_link 'Edit'
click_link 'Embargo Management Page'

expect(page).to have_content('This Generic Work is under embargo.')
expect(page).to have_xpath("//input[@name='generic_work[embargo_release_date]' and @value='#{future_date}']") # current embargo date is pre-populated in edit field

go_to_embargo_mgmt_active_fedora
fill_in 'until', with: later_future_date.to_s

click_button 'Update Embargo'
Expand All @@ -94,13 +152,7 @@

it 'cannot be updated with an invalid date' do
visit "/concern/generic_works/#{work.id}"

click_link 'Edit'
click_link 'Embargo Management Page'

expect(page).to have_content('This Generic Work is under embargo.')
expect(page).to have_xpath("//input[@name='generic_work[embargo_release_date]' and @value='#{future_date}']") # current embargo date is pre-populated in edit field

go_to_embargo_mgmt_active_fedora
fill_in 'until', with: invalid_future_date.to_s

click_button 'Update Embargo'
Expand Down