Skip to content

Commit

Permalink
replaced samples with two sops forced to reference same policy
Browse files Browse the repository at this point in the history
  • Loading branch information
fherreazcue committed Oct 4, 2023
1 parent b907b0a commit 7bac631
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions test/unit/policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,39 +194,33 @@ class PolicyTest < ActiveSupport::TestCase
end
end

# Samples no longer reference the policy, they make a copy of it.
#
# test 'policy not destroyed if still referenced by assets' do
# policy = FactoryBot.create(:public_policy)
# sample_type = FactoryBot.create(:strain_sample_type)
# data_file = FactoryBot.create(:strain_sample_data_file, policy: policy)
# samples = data_file.extract_samples(sample_type, true).select(&:persisted?)
# sample = samples.first
#
# assert_equal sample.policy, data_file.policy
#
# assert_no_difference('Policy.count') do
# disable_authorization_checks { data_file.destroy }
# end
#
# assert_not_nil sample.reload.policy
# assert_not_nil Policy.find_by_id(policy.id)
# end
#
# test 'policy destroyed when no longer referenced' do
# policy = FactoryBot.create(:public_policy)
# sample_type = FactoryBot.create(:strain_sample_type)
# data_file = FactoryBot.create(:strain_sample_data_file, policy: policy)
# samples = data_file.extract_samples(sample_type, true).select(&:persisted?)
#
# disable_authorization_checks { data_file.destroy }
#
# assert_difference('Policy.count', -1) do
# disable_authorization_checks { samples.each(&:destroy) }
# end
#
# assert_nil Policy.find_by_id(policy.id)
# end
test 'policy not destroyed if still referenced by assets' do
policy = FactoryBot.create(:public_policy)
sop1 = FactoryBot.create(:sop, policy: policy)
sop2 = FactoryBot.create(:sop, policy: policy)

assert_equal sop1.policy, sop2.policy

assert_no_difference('Policy.count') do
disable_authorization_checks { sop1.destroy }
end

assert_not_nil sop2.reload.policy
assert_not_nil Policy.find_by_id(policy.id)
end

test 'policy destroyed when no longer referenced' do
policy = FactoryBot.create(:public_policy)
sop1 = FactoryBot.create(:sop, policy: policy)
sop2 = FactoryBot.create(:sop, policy: policy)
sops = [sop1, sop2]

assert_difference('Policy.count', -1) do
disable_authorization_checks { sops.each(&:destroy) }
end

assert_nil Policy.find_by_id(policy.id)
end

test 'public? false if sharing scope ALL::USERS' do
policy = FactoryBot.create(:public_policy,sharing_scope:Policy::ALL_USERS, access_type:Policy::ACCESSIBLE)
Expand Down

0 comments on commit 7bac631

Please sign in to comment.