1. Postgres jsonb type => Hash
Let's say I have a schema.rb
that declares a posts table thusly:
create_table 'vehicle', force: :cascade do |t|
# ...
t.jsonb "vehicle_info", default: {}
end
Here's the error I get when I try rake active_mocker:build
:
Database type 'jsonb' is not a registered type.
To register use ActiveRecordSchemaScrapper::Attributes.register_type(name: :jsonb, klass: <RubyClass>)
It's not clear to me where I'm supposed to put ActiveRecordSchemaScrapper::Attributes.register_type(name: :jsonb, klass: <RubyClass>)
. I think it's active_mocker's job to register these data types prior to trying to scrape schema.rb
.
2. Postgres inet type => IPAddr
I have in my schema.rb
a field t.inet "current_sign_in_ip"
.
Naturally, I wanted to map inet to IPAddr (see section 1.10).
I added the following
# active_mocker.rb
ActiveRecordSchemaScrapper::Attributes.register_type(name: :inet, klass: IPAddr)
The mock gets generated, but when I use it in my tests the generated code:
def types
@types ||= ActiveMocker::HashProcess.new({ id: Fixnum, email: String, encrypted_password: String, reset_password_token: String, reset_password_sent_at: DateTime, remember_created_at: DateTime, sign_in_count: Fixnum, current_sign_in_at: DateTime, last_sign_in_at: DateTime, current_sign_in_ip: IPAddr, last_sign_in_ip: IPAddr, created_at: DateTime, updated_at: DateTime, first_name: String, last_name: String, phone: String, address1: String, address2: String, postcode: String, state: String, approval_notes: String, role: String, image: String, public_page_id: String, county: String, gender: String, title: String, town: String, city_id: Fixnum, deposit_pence: Fixnum, referral_code: String, authentication_token: String, national_insurance: String, current_mode: String, dvla_points: Fixnum, accident_3_years: Axiom::Types::Boolean, motoring_5_years: Axiom::Types::Boolean, criminal_5_years: Axiom::Types::Boolean, refused_insurance: Axiom::Types::Boolean, special_conditions_notes: String, on_drover_fleet_policy: Axiom::Types::Boolean, uk_resident_since: Date, notes: String, date_of_birth: Date }, method(:build_type)).merge(super)
end
... gives me a
NameError: uninitialized constant Class::IPAddr
i.e. generated mock is missing a require 'ipaddr'