-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test coverage for specifying an alternate adapter
Hanami::DB::Relation will retain the ROM behavior of selecting an alternate adapter with Relation[adapter_name] syntax, so this needs to have test coverage. Closes #3
- Loading branch information
Showing
2 changed files
with
41 additions
and
3 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 |
---|---|---|
@@ -1,9 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Hanami::DB::Relation do | ||
subject(:relation) { Class.new(described_class) } | ||
let :adapters do | ||
{ | ||
default: [:sql, "sqlite::memory"], | ||
alternate: [:memory, "memory://test"] | ||
} | ||
end | ||
|
||
let!(:config) { ROM::Configuration.new(adapters) } | ||
|
||
before do | ||
module Test | ||
class User < Hanami::DB::Relation | ||
schema(:users) {} # rubocop:disable Lint/EmptyBlock | ||
end | ||
|
||
class APITokens < Hanami::DB::Relation[:memory] | ||
schema(:api_tokens) {} # rubocop:disable Lint/EmptyBlock | ||
end | ||
end | ||
|
||
config.register_relation Test::User | ||
config.register_relation Test::APITokens | ||
end | ||
|
||
subject(:rom) { ROM.container(config) } | ||
|
||
context "no adapter specified" do | ||
subject(:relation) { rom.relations[:users] } | ||
|
||
it "chooses the default" do | ||
expect(relation.adapter).to eq :sql | ||
end | ||
end | ||
|
||
context "adapter is specified" do | ||
subject(:relation) { rom.relations[:api_tokens] } | ||
|
||
it "defaults to the :sql adapter" do | ||
expect(relation.adapter).to eq :sql | ||
it "chooses the given adapter" do | ||
expect(relation.adapter).to eq :memory | ||
end | ||
end | ||
end |