-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 %> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}" %> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? %> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
e1cd970
to
38e43f3
Compare
There are now conflicts with the DOI feature. |
Superceded by #736 |
closes #714