Skip to content

Commit

Permalink
Commented tests that assumed policy reference instead of copy
Browse files Browse the repository at this point in the history
  • Loading branch information
fherreazcue committed Sep 29, 2023
1 parent 1409f1b commit b907b0a
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions test/unit/policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,37 +194,39 @@ class PolicyTest < ActiveSupport::TestCase
end
end

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
# 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 '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 b907b0a

Please sign in to comment.