Added failing test.
Fixed unwanted deletion of custom plugs on Reference nodes.

Previously plugs that were unrelated to the reference were being deleted when a reference was reloaded. This would include plugs added by the ui for keeping track of node position etc. Now plugs are only removed if they are considered part of the reference - if they have connections to the nodes within the reference.