Skip to content

Commit

Permalink
Merge pull request #2301 from andynu/lazy-load-type-mappings-patch
Browse files Browse the repository at this point in the history
Lazy load type mappings
  • Loading branch information
yahonda authored Sep 15, 2022
2 parents 63f14a5 + b614547 commit 3ec3919
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ def reconnect! # :nodoc:
@logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}" if @logger
end

def clear_cache!(*args, **kwargs)
super
self.class.clear_type_map!
end

def reset!
clear_cache!
super
Expand Down Expand Up @@ -697,6 +702,15 @@ def check_version
end

class << self
def type_map
@type_map ||= Type::TypeMap.new.tap { |m| initialize_type_map(m) }
@type_map
end

def clear_type_map!
@type_map = nil
end

private
def initialize_type_map(m)
super
Expand Down Expand Up @@ -730,10 +744,8 @@ def initialize_type_map(m)
end
end

TYPE_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) }

def type_map
TYPE_MAP
self.class.type_map
end

def extract_value_from_default(default)
Expand Down
8 changes: 8 additions & 0 deletions spec/active_record/oracle_enhanced/type/integer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,13 @@ class ::Test2Employee < ActiveRecord::Base
create_employee2
expect(@employee2.is_manager).to be_a(Integer)
end

it "should return Integer value from NUMBER(1) column if emulate_booleans is set to false" do
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = false
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.clear_type_map!
ActiveRecord::Base.clear_cache!
create_employee2
expect(@employee2.is_manager).to be_a(Integer)
end
end
end

0 comments on commit 3ec3919

Please sign in to comment.