Skip to content

Commit

Permalink
Merge 70a01ce into efe042a
Browse files Browse the repository at this point in the history
  • Loading branch information
gburgett committed Jan 17, 2020
2 parents efe042a + 70a01ce commit 17c2cb8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions wcc-contentful/lib/wcc/contentful/store/postgres_store.rb
Expand Up @@ -34,6 +34,8 @@ def keys
arr = []
result.each { |r| arr << r['id'].strip }
arr
rescue PG::ConnectionBad
[]
end

def delete(key)
Expand All @@ -48,6 +50,8 @@ def find(key, **_options)
return if result.num_tuples == 0

JSON.parse(result.getvalue(0, 1))
rescue PG::ConnectionBad
nil
end

def find_all(content_type:, options: nil)
Expand Down Expand Up @@ -131,6 +135,8 @@ def resolve

statement = 'SELECT * FROM contentful_raw ' + @statement
@resolved = @connection_pool.with { |conn| conn.exec(statement, @params) }
rescue PG::ConnectionBad
[]
end

def push_param(param, params)
Expand Down
35 changes: 35 additions & 0 deletions wcc-contentful/spec/wcc/contentful/store/postgres_store_spec.rb
Expand Up @@ -49,4 +49,39 @@
# assert
expect(results).to eq([data, data, data])
end

context 'db does not exist' do
subject {
WCC::Contentful::Store::PostgresStore.new(double('Configuration'),
{ dbname: 'asdf' }, size: 5)
}

it '#set raises error' do
expect {
subject.set('foo', { 'key' => 'val' })
}.to raise_error(PG::ConnectionBad)
end

it '#delete raises error' do
expect {
subject.delete('foo')
}.to raise_error(PG::ConnectionBad)
end

# DB should not need to exist in order to run rake db:setup
it '#find returns nil' do
result = subject.find('foo')
expect(result).to be nil
end

it '#find_all returns empty' do
result = subject.find_all(content_type: 'foo').to_a
expect(result).to eq([])
end

it '#keys returns empty' do
result = subject.keys.to_a
expect(result).to eq([])
end
end
end

0 comments on commit 17c2cb8

Please sign in to comment.