-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check database and table's existence before getting the metadata. (
#8) * chore: no need to rescue * chore: add a bit comments * chore: fix rubocop issue
- Loading branch information
Showing
2 changed files
with
31 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'rails_helper' | ||
|
||
describe 'Database active check' do | ||
let(:model_class) { Blog } | ||
let(:model_decorator) { Wallaby::ActiveRecord::ModelDecorator.new model_class } | ||
|
||
context 'when database does not exist' do | ||
it 'returns empty hash' do | ||
expect(::ActiveRecord::Base).to receive(:connected?).and_return(false) | ||
expect(model_decorator.fields).to eq({}) | ||
end | ||
end | ||
|
||
context 'when table does not exist' do | ||
let(:model_class) { stub_const 'NotFoundTable', Class.new(ActiveRecord::Base) } | ||
|
||
it 'returns empty hash' do | ||
expect(::ActiveRecord::Base).to be_connected | ||
expect(model_class).not_to be_table_exists | ||
expect(model_decorator.fields).to eq({}) | ||
end | ||
end | ||
end |