Skip to content

Commit

Permalink
update some more specs like whats in #6127.
Browse files Browse the repository at this point in the history
  • Loading branch information
alishaevn committed Aug 4, 2023
1 parent e5a3357 commit 6cd8798
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
9 changes: 5 additions & 4 deletions spec/actors/hyrax/actors/embargo_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
end

it 'removes the embargo' do
expect { actor.destroy }
.to change { embargo_manager.under_embargo? }
.from(true)
.to false
actor.destroy

expect(work.embargo.embargo_release_date).to eq nil
expect(work.embargo.visibility_after_embargo).to eq nil
expect(work.embargo.visibility_during_embargo).to eq nil
end

it 'releases the embargo' do
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/hyrax_embargo.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
FactoryBot.define do
factory :hyrax_embargo, class: "Hyrax::Embargo" do
embargo_release_date { (Time.zone.today + 10).to_s }
embargo_release_date { (Time.zone.today + 10).to_datetime }
visibility_after_embargo { 'open' }
visibility_during_embargo { 'authenticated' }

Expand All @@ -12,7 +12,7 @@
end

trait :expired do
embargo_release_date { (Time.zone.today - 1).to_s }
embargo_release_date { (Time.zone.today - 1).to_datetime }
end
end
end
10 changes: 5 additions & 5 deletions spec/features/embargo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
sign_in user
end
describe 'creating an embargoed object' do
let(:future_date) { 5.days.from_now }
let(:later_future_date) { 10.days.from_now }
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'
Expand All @@ -20,19 +20,19 @@

# chosen embargo date is on the show page
skip 'embargogeddon' do
expect(page).to have_content(future_date.to_date.to_formatted_s(:standard))
expect(page).to have_content(future_date.to_formatted_s(:standard))
end

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.to_datetime.iso8601}']") # current embargo date is pre-populated in edit field
expect(page).to have_xpath("//input[@name='generic_work[embargo_release_date]' and @value='#{future_date.iso8601}']") # current embargo date is pre-populated in edit field

fill_in 'until', with: later_future_date.to_s

click_button 'Update Embargo'
expect(page).to have_content(later_future_date.to_date.to_formatted_s(:standard))
expect(page).to have_content(later_future_date.to_formatted_s(:standard))

click_link 'Edit'
fill_in 'Title', with: 'Embargo test CHANGED'
Expand Down
26 changes: 26 additions & 0 deletions spec/indexers/hyrax/valkyrie_file_set_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,32 @@
expect(subject['original_file_id_ssi']).to eq "#{file_set.id}/files/#{file_set.original_file_id}"
end
end

context 'with a valid embargo' do
let(:embargo) { FactoryBot.create(:hyrax_embargo) }

before { allow(file_set).to receive(:embargo_id).and_return(embargo.id) }

it 'sets the embargo expiration date and visibility settings' do
expect(subject['embargo_release_date_dtsi']).to eq embargo.embargo_release_date
expect(subject['visibility_after_embargo_ssim']).to eq embargo.visibility_after_embargo
expect(subject['visibility_during_embargo_ssim']).to eq embargo.visibility_during_embargo
expect(subject['embargo_history_ssim']).to be nil
end
end

context 'with an expired embargo' do
let(:embargo) { FactoryBot.create(:hyrax_embargo, :expired) }

before { allow(file_set).to receive(:embargo_id).and_return(embargo.id) }

it 'sets the embargo expiration date and visibility settings' do
expect(subject['embargo_release_date_dtsi']).to be nil
expect(subject['visibility_after_embargo_ssim']).to be nil
expect(subject['visibility_during_embargo_ssim']).to be nil
expect(subject['embargo_history_ssim']).to eq embargo.embargo_history
end
end
end

describe '#file_format' do
Expand Down

0 comments on commit 6cd8798

Please sign in to comment.