end module FactoryBotSingleFactory def self.extended(obj) obj.to_create do |instance| attributes = instance.class.find_or_create_by(instance.attributes.compact).attributes instance.attributes = attributes.except('id') instance.id = attributes['id'] # id can't be mass-assigned instance.instance_variable_set('@new_record', false) # marks record as persisted end end end 2 https://gist.github.com/ReganRyanNZ/71e4128d34459d5b00dcb27d2ba1757e Λࢀߟʹͨ͠ɻ 13
:prefectures, :tokyo, :boolean up_only do execute 'UPDATE prefectures SET tokyo = 1 WHERE id == 13;' end change_column_null :prefectures, :tokyo, false end end 15