Skip to content

Commit

Permalink
fix and tests for error where contributor is new and tries can_view? #…
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Nov 12, 2024
1 parent 9a4a671 commit 9b6a763
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/assays/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<%= @assay.assay_class.title -%>
</p>
<% end %>
<% if @assay.contributor.can_view? %>
<% if @assay.contributor&.can_view? %>
<p class="id">
<label>
<%= t('contributor').capitalize -%>:
Expand Down
12 changes: 12 additions & 0 deletions test/functional/assays_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2277,4 +2277,16 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
end
end

test 'can show and edit with deleted contributor' do
assay = FactoryBot.create(:assay, deleted_contributor:'Person:99', policy: FactoryBot.create(:public_policy))
assay.update_column(:contributor_id, nil)
assert assay.can_view?
assert assay.can_edit?
assert_nil assay.contributor
get :show, params: { id: assay.id }
assert_response :success
get :edit, params: { id: assay.id }
assert_response :success
end

end
12 changes: 12 additions & 0 deletions test/functional/investigations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,18 @@ def test_title
assert_equal 'test obs unit 1', ObservationUnit.by_external_identifier('seek-test-obs-unit-1', investigation.projects).title
end

test 'can show and edit with deleted contributor' do
investigation = FactoryBot.create(:investigation, deleted_contributor:'Person:99', policy: FactoryBot.create(:public_policy))
investigation.update_column(:contributor_id, nil)
assert investigation.can_view?
assert investigation.can_edit?
assert_nil investigation.contributor
get :show, params: { id: investigation.id }
assert_response :success
get :edit, params: { id: investigation.id }
assert_response :success
end

private

def setup_test_case_investigation
Expand Down
12 changes: 12 additions & 0 deletions test/functional/studies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2111,4 +2111,16 @@ def test_should_show_investigation_tab
assert_redirected_to edit_isa_study_path(study)
end
end

test 'can show and edit with deleted contributor' do
study = FactoryBot.create(:study, deleted_contributor:'Person:99', policy: FactoryBot.create(:public_policy))
study.update_column(:contributor_id, nil)
assert study.can_view?
assert study.can_edit?
assert_nil study.contributor
get :show, params: { id: study.id }
assert_response :success
get :edit, params: { id: study.id }
assert_response :success
end
end

0 comments on commit 9b6a763

Please sign in to comment.