Skip to content

Commit

Permalink
Endpoint: override #to_s with better implementation, since PreservedO…
Browse files Browse the repository at this point in the history
…bjectHandler now logs endpoint info, since it no longer assumes an online endpoint that it can look up using a storage_dir
  • Loading branch information
jmartin-sul committed Nov 8, 2017
1 parent 1a84aa8 commit 973df36
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/models/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@ def self.seed_storage_root_endpoints_from_config(endpoint_type, preservation_pol
def self.default_storage_root_endpoint_type
EndpointType.find_by!(type_name: Settings.endpoints.storage_root_defaults.endpoint_type_name)
end

def to_h
{
endpoint_name: endpoint_name,
endpoint_type_name: endpoint_type.type_name,
endpoint_type_class: endpoint_type.endpoint_class,
endpoint_node: endpoint_node,
storage_location: storage_location,
recovery_cost: recovery_cost
}
end

def to_s
"<Endpoint: #{to_h}>"
end
end
19 changes: 19 additions & 0 deletions spec/models/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,23 @@
expect { Endpoint.default_storage_root_endpoint_type }.to raise_error(ActiveRecord::RecordNotFound)
end
end

describe '#to_h' do
it 'has the expected values' do
expect(endpoint.to_h).to eq(
endpoint_name: 'aws-us-east-2',
endpoint_type_name: 'aws',
endpoint_type_class: 'archive',
endpoint_node: 's3.us-east-2.amazonaws.com',
storage_location: 'sdr-bucket-01',
recovery_cost: 5
)
end
end

describe '#to_s' do
it 'just dumps the result of #to_h as a string, prefixed with the class name' do
expect(endpoint.to_s).to match(/Endpoint.*#{Regexp.escape(endpoint.to_h.to_s)}/)
end
end
end

0 comments on commit 973df36

Please sign in to comment.