-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
97 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
RSpec.describe "Setting up a database in a target gem", :with_gem do | ||
context "when no database adaptor is set" do | ||
before do | ||
gem.main_file.write(<<~RUBY) | ||
require "kangaru" | ||
module SomeGem | ||
extend Kangaru::Initialiser | ||
Kangaru.application.configure do |config| | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
it "does not raise any errors" do | ||
expect { gem.load! }.not_to raise_error | ||
end | ||
|
||
it "does not setup a database" do | ||
gem.load! | ||
expect(Kangaru.application.database).to be_nil | ||
end | ||
end | ||
|
||
context "when an invalid database adaptor is set" do | ||
before do | ||
gem.main_file.write(<<~RUBY) | ||
require "kangaru" | ||
module SomeGem | ||
extend Kangaru::Initialiser | ||
Kangaru.application.configure do |config| | ||
config.database.adaptor = :invalid | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
it "raises an error" do | ||
expect { gem.load! }.to raise_error( | ||
Kangaru::Database::AdaptorError, "invalid adaptor 'invalid'" | ||
) | ||
end | ||
end | ||
|
||
context "when adaptor is set to sqlite" do | ||
context "and database path is not set" do | ||
before do | ||
gem.main_file.write(<<~RUBY) | ||
require "kangaru" | ||
module SomeGem | ||
extend Kangaru::Initialiser | ||
Kangaru.application.configure do |config| | ||
config.database.adaptor = :sqlite | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
it "raises an error" do | ||
expect { gem.load! }.to raise_error( | ||
Kangaru::Database::SQLiteError, "path can't be blank" | ||
) | ||
end | ||
end | ||
|
||
context "and database path is set" do | ||
before do | ||
gem.main_file.write(<<~RUBY) | ||
require "kangaru" | ||
module SomeGem | ||
extend Kangaru::Initialiser | ||
Kangaru.application.configure do |config| | ||
config.database.adaptor = :sqlite | ||
config.database.path = "#{gem.path.join('database.sqlite3')}" | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
it "does not raise any errors" do | ||
expect { gem.load! }.not_to raise_error | ||
end | ||
|
||
it "sets the database instance" do | ||
gem.load! | ||
expect(Kangaru.application.database).to be_a(Kangaru::Database) | ||
end | ||
end | ||
end | ||
end |