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

Implements delete for direct containers. #832

Merged
merged 1 commit into from
Jun 30, 2015
Merged

Implements delete for direct containers. #832

merged 1 commit into from
Jun 30, 2015

Conversation

hectorcorrea
Copy link
Member

Fixes #794

@flyingzumwalt
Copy link
Member

Could you also add a test for this behavior in direct_container_spec.rb?

@hectorcorrea
Copy link
Member Author

@flyingzumwalt I added a couple of tests for direct_container and that uncovered a few bugs.

I still need to (1) make sure the new tests that I added are correct and exercising the right functionality, and (2) figure out why 4 of the integration tests are now failing.


it "deletes the contained resource directly" do
expect(history.files).to eq [file1, file2]
file1.delete
Copy link
Member Author

Choose a reason for hiding this comment

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

@jcoyne could you confirm is this how we want to test the delete in direct containers? (1/2)

Copy link
Member

Choose a reason for hiding this comment

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

Not quite. This is just deleting the file, but not through the association.

@@ -63,7 +63,15 @@ def ldp_connection
# If this file has a parent with ldp#contains, we know it is not new.
# By tracking exists we prevent an unnecessary HEAD request.
def new_record?
!@exists && ldp_source.new?
!@exists && ldp_new_record?
Copy link
Member Author

Choose a reason for hiding this comment

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

@jcoyne this is what I needed to do to get the delete for direct_container to work. The call to target.delete(record) in collection_association.rb internally calls new_record? after the actual record has been deleted. I believe when Ruby processes target.delete(record) it's using the == operator defined in file.rb which in turns calls new_record.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should be tracking @destroyed like core does? (https://github.com/projecthydra/active_fedora/blob/7ed4ca1cb4443b6b39dccea4dba18442809cb028/lib/active_fedora/persistence.rb#L49) Can you show me where target.delete(record) is calling ==?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tracking @destroyed might be another way to do it.

There is no explicit place in the code where we call == but when I step into the target.delete(record) line it takes me directly to the == so I suspect Ruby is internally calling == when deleting an element in an array.

Copy link
Member

Choose a reason for hiding this comment

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

So, where is target.delete()? in CollectionAssociation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we need == to use new_record?. I'm working up a new PR to remove that. Please stand by.

Copy link
Member

Choose a reason for hiding this comment

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

@hectorcorrea try rebasing against #840. Then would you be able to revert your change to new_record?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jcoyne that did it!

@hectorcorrea
Copy link
Member Author

@jcoyne @flyingzumwalt I think this PR is good to go (despite coverall's meaningless warning)

Eventually I would like to add another test in direct_container_spec.rb to test directly_contains without the use of files but I won't have time to get to this for a while. So I would suggest merging this PR as-is.

@@ -221,6 +221,10 @@ def update_record(options = {})
refresh
end

def build_ldp_resource(id)
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove this? I don't see it used anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, now I recall that we did have some reason to add it. Never mind.

jcoyne added a commit that referenced this pull request Jun 30, 2015
Implements delete for direct containers.
@jcoyne jcoyne merged commit bd71b7f into master Jun 30, 2015
@jcoyne jcoyne deleted the issue_794 branch June 30, 2015 13:30
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.

4 participants