thoughtbot / factory_bot

A library for setting up Ruby objects as test data.

Home Page:https://thoughtbot.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build_stubbed does not fill id for uuid column type with SQLServer

vividmuimui opened this issue · comments

Description

When using SQLServer and 'uuid' as the primary key type, they 'build_stubbed' method does not automatically fill the id column. I would assume that this is filled independent of the column type.

def uuid_primary_key?(result_instance)
result_instance.respond_to?(:column_for_attribute) &&
(column = result_instance.column_for_attribute(result_instance.class.primary_key)) &&
column.respond_to?(:sql_type) &&
column.sql_type == "uuid"
end

I'm thinking the code here is the problem.

image

In SQLServer, the column.sql_type seems to be "uniqueidentifier".
I think it might work if I use column.type, but I don't know if this is a problem in other databases, so I've raised an issue.

Reproduction Steps

Sample code → https://github.com/vividmuimui/sqlserver-factorybot/commits/main/

Expected behavior

When you use build_stubbed, the primary key is always set. Also if you use the uuid type.

Actual behavior

The id of the generated instance is nil.

System configuration

factory_bot version: 6.4.5
rails version: 7.1.3
ruby version: v3.3.0