diff options
author | Nick Thomas <nick@gitlab.com> | 2019-02-04 12:52:22 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-02-04 12:52:22 +0000 |
commit | 3dadb1f870d6fb04375a9b0cd8bd1dd53b4cca25 (patch) | |
tree | 5eb587deca2955406c1a6ecd0d0ac68ec42b4f60 | |
parent | 2b0f4df0217b4a4aee53f964610d66ceedb68dca (diff) | |
download | gitlab-ce-3dadb1f870d6fb04375a9b0cd8bd1dd53b4cca25.tar.gz |
Allow SshHostKey.find_by to accept string keys
-rw-r--r-- | app/models/ssh_host_key.rb | 1 | ||||
-rw-r--r-- | spec/models/ssh_host_key_spec.rb | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/app/models/ssh_host_key.rb b/app/models/ssh_host_key.rb index f318d32c71c..fd23cc9ac87 100644 --- a/app/models/ssh_host_key.rb +++ b/app/models/ssh_host_key.rb @@ -26,6 +26,7 @@ class SshHostKey self.reactive_cache_lifetime = 10.minutes def self.find_by(opts = {}) + opts = HashWithIndifferentAccess.new(opts) return nil unless opts.key?(:id) project_id, url = opts[:id].split(':', 2) diff --git a/spec/models/ssh_host_key_spec.rb b/spec/models/ssh_host_key_spec.rb index 23a94334172..4c677569561 100644 --- a/spec/models/ssh_host_key_spec.rb +++ b/spec/models/ssh_host_key_spec.rb @@ -56,6 +56,29 @@ describe SshHostKey do end end + describe '.find_by' do + let(:project) { create(:project) } + let(:url) { 'ssh://invalid.invalid:2222' } + + let(:finding_id) { [project.id, url].join(':') } + + it 'accepts a string key' do + result = described_class.find_by('id' => finding_id) + + expect(result).to be_a(described_class) + expect(result.project).to eq(project) + expect(result.url.to_s).to eq(url) + end + + it 'accepts a symbol key' do + result = described_class.find_by(id: finding_id) + + expect(result).to be_a(described_class) + expect(result.project).to eq(project) + expect(result.url.to_s).to eq(url) + end + end + describe '#fingerprints', :use_clean_rails_memory_store_caching do it 'returns an array of indexed fingerprints when the cache is filled' do stub_reactive_cache(ssh_host_key, known_hosts: known_hosts) |