Skip to content

Commit dc4f416

Browse files
fidelpjurewicz
andcommitted
Don't allow instantiation of DatabaseAdapter directly
Maybe it would make sense, but verification of data type would require a lot of gymnastics and we see no value in it. Co-authored-by: Piotr Jurewicz <[email protected]>
1 parent a990bc5 commit dc4f416

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/database_adapter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def initialize(data_type = NOT_SET)
3333
end
3434

3535
def initialize(adapter_name, data_type)
36+
raise UnsupportedAdapter if instance_of?(DatabaseAdapter)
37+
3638
validate_data_type!(data_type)
3739

3840
@adapter_name = adapter_name
@@ -57,6 +59,7 @@ def hash
5759

5860
def self.from_string(adapter_name, data_type = NOT_SET)
5961
raise NoMethodError unless eql?(DatabaseAdapter)
62+
6063
case adapter_name.to_s.downcase
6164
when "postgresql", "postgis"
6265
PostgreSQL.new(data_type)

ruby_event_store-active_record/spec/database_adapter_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ module ActiveRecord
5050
expect { DatabaseAdapter::SQLite.from_string("sqlite") }.to raise_error(NoMethodError)
5151
end
5252

53+
specify "don't allow instance of parent class directly" do
54+
expect { DatabaseAdapter.new("postgresql", "jsonb") }.to raise_error(UnsupportedAdapter)
55+
end
56+
5357
context "data type verification" do
5458
specify "MySQL supports binary" do
5559
expect(DatabaseAdapter::MySQL2.new("binary").data_type).to eq("binary")

0 commit comments

Comments
 (0)