I have a model which has a field called category_paths
. It is JSONB
in postgres.
When I set the category_paths
from factory_girl, factory_girl is changing the value type to String
. Consider the following code, even though I am assigning a Hash
, it gets changed to String
.
FactoryGirl.define do
factory :product do
title "MyString"
after(:build) do |p|
p.category_paths = Hash.new
puts p.category_paths.class # This prints as String
end
end
end
This is weird and I am not able to figure out what is happening. This works fine when tried from Rails console. The problem happens only when used in factory. Is this how factory_girl works? Or is there a way to control this behavior?
Here is the product model
class Product < ActiveRecord::Base
acts_as_copy_target
searchkick autocomplete: ['brand'], callbacks: :async
scope :search_import, -> { includes(:product_offers) }
has_many :product_offers, autosave: true
validates :title, presence: true
validate :validate_category_paths
end
Any help would be appreciated