Skip to content

Commit

Permalink
Test coverage for specifying an alternate adapter
Browse files Browse the repository at this point in the history
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
alassek committed Jun 8, 2024
1 parent c463379 commit 23b0a77
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ group :development do
gem "rubocop"
end

gem "sqlite3"

group :docs do
gem "redcarpet", platforms: :mri
gem "yard"
Expand Down
42 changes: 39 additions & 3 deletions spec/unit/relation_spec.rb
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

0 comments on commit 23b0a77

Please # to comment.