spec/integration/db/db_spec.rb in hanami-2.2.0.beta1 vs spec/integration/db/db_spec.rb in hanami-2.2.0.beta2
- old
+ new
@@ -37,10 +37,11 @@
Hanami.app.prepare :db
expect(Hanami.app["db.config"]).to be_an_instance_of ROM::Configuration
expect(Hanami.app["db.gateway"]).to be_an_instance_of ROM::SQL::Gateway
+ expect(Hanami.app["db.gateways.default"]).to be Hanami.app["db.gateway"]
# Manually run a migration and add a test record
gateway = Hanami.app["db.gateway"]
migration = gateway.migration do
change do
@@ -88,10 +89,11 @@
Hanami.app.prepare :db
expect(Hanami.app["db.config"]).to be_an_instance_of ROM::Configuration
expect(Hanami.app["db.gateway"]).to be_an_instance_of ROM::SQL::Gateway
+ expect(Hanami.app["db.gateways.default"]).to be Hanami.app["db.gateway"]
# Manually run a migration and add a test record
gateway = Hanami.app["db.gateway"]
migration = gateway.migration do
change do
@@ -115,12 +117,10 @@
write "config/app.rb", <<~RUBY
require "hanami"
module TestApp
class App < Hanami::App
- config.inflections do |inflections|
- end
end
end
RUBY
write "app/relations/.keep", ""
@@ -129,10 +129,36 @@
expect { Hanami.app.prepare :db }.to raise_error(Hanami::ComponentLoadError, /database_url/)
end
end
+ it "raises an error when the database driver gem is missing" do
+ allow(Hanami).to receive(:bundled?).and_call_original
+ expect(Hanami).to receive(:bundled?).with("pg").and_return false
+
+ with_tmp_directory(Dir.mktmpdir) do
+ write "config/app.rb", <<~RUBY
+ require "hanami"
+
+ module TestApp
+ class App < Hanami::App
+ end
+ end
+ RUBY
+
+ write "app/relations/.keep", ""
+
+ ENV["DATABASE_URL"] = "postgres://127.0.0.0"
+
+ require "hanami/prepare"
+
+ expect { Hanami.app.prepare :db }.to raise_error(Hanami::ComponentLoadError) { |error|
+ expect(error.message).to include %(The "pg" gem is required)
+ }
+ end
+ end
+
it "allows the user to configure the provider" do
with_tmp_directory(Dir.mktmpdir) do
write "config/app.rb", <<~RUBY
require "hanami"
@@ -152,14 +178,13 @@
end
RUBY
write "config/providers/db.rb", <<~RUBY
Hanami.app.configure_provider :db do
- configure do |config|
- # In this test, we're not setting an ENV["DATABASE_URL"], and instead configuring
- # it via the provider source config, to prove that this works
-
- config.database_url = "sqlite::memory"
+ # In this test, we're not setting an ENV["DATABASE_URL"], and instead configuring
+ # it via the provider source config, to prove that this works
+ config.gateway :default do |gw|
+ gw.database_url = "sqlite::memory"
end
end
RUBY
require "hanami/prepare"