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

Adds items in this collection section. #724

Closed
wants to merge 1 commit into from
Closed

Conversation

justinlittman
Copy link
Contributor

closes #714

image

@@ -45,4 +45,8 @@ def relations(predicate)
node.attribute('resource').text.split('/', 2).last.split(':', 2).last
end
end

def object_type
document.root.at_xpath('identityMetadata/objectType').try(:text)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why try here? There shouldn't be any nodes with out an objectType, right? That's pretty fundamental.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because every other call to .text in this class is .try(:text). I have no idea why that would be, but following existing conventions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's a very good reason. A lot of this code was written 12 years ago before the model was clear and before there was a safe navigation operator in Ruby.

@@ -0,0 +1,3 @@
<% if @purl.object_type == 'collection' && @purl.catalog_key %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make a method collection? here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have, except PurlResource already has a .collection method which provides the collection that the item is a part of. It seems that a .collection? method that indicates whether this item is a collection risks confusion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel that we should move as much logic from the views as possible. If we need to rename collection to is_member_of, I think that would be good to and help align with Cocina terminology.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name has been refactored, so please move this to the collection? method now.

@@ -0,0 +1,3 @@
<% if @purl.object_type == 'collection' && @purl.catalog_key %>
<%= link_to 'View items in this collection in SearchWorks', "#{Settings.searchworks.url}/catalog?f[collection][]=#{@purl.catalog_key}" %>
Copy link
Contributor

@jcoyne jcoyne Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible the collection is not released to searchworks?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, because it has a catalog key.

context 'when a published collection' do
let(:purl) { PurlResource.new(id: 'bb631ry3167') }

it 'displays a View items in this collection link' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this same scenario tested in the integration test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I wanted the test cases in this spec to be complete so that a dev could understand the expected behavior from the view from this alone.

The integration test is necessary because it tests that the view is actually called.


it 'does not display View items in this collection link' do
render
expect(rendered).not_to have_css 'a', text: 'View items in this collection in SearchWorks'
Copy link
Contributor

@jcoyne jcoyne Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two negative assertion tests are very fragile because a change to the text in the template that does not also change these tests completely makes these assertions useless. E.g we could show a link, but since the text has changed we won't catch it.

Can we just assert that nothing is rendered in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out how to assert nothing is rendered, so just removed the text assertion.

@@ -85,6 +86,18 @@
</div>
<% end %>

<% if collection_items.present? %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just move all of this into the partial? That is already wrapped in a conditional. Alternatively if you introduce a ViewComponent here, you can make this be the render? condition. I find that much easier to read and test rather than this approach here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, but I am following the existing pattern in this file. I'm not trying to refactor in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the existing pattern in #727 so please follow that pattern here.


describe '#object_type' do
it 'pulls the value from the identity metadata' do
allow(subject).to receive(:public_xml_body).and_return <<-EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this to a before as it's part of setting up the scenario and has no assertions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just following the pattern in this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This codebase is full of bad patterns and needs to be over hauled. Please use practices like https://www.betterspecs.org/#mock and not the existing patterns here.

end
end

context 'when an unpublished collection' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we know it's "unpublished"? Do you mean "doesn't have a catkey"? I'm concerned that we're overloading what "published" means.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, changed to when collection does not have a catalog record id.

@jcoyne
Copy link
Contributor

jcoyne commented Oct 24, 2023

There are now conflicts with the DOI feature.

@justinlittman
Copy link
Contributor Author

Superceded by #736

@justinlittman justinlittman deleted the t714-collection branch October 25, 2023 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collection PURL pages should support exploring the collection
2 participants