Sha256: 7d4f51dd7607b44d5c3b6fd57711cb603a724b50315e50d972c864671420e47a

Contents?: true

Size: 659 Bytes

Versions: 3

Compression:

Stored size: 659 Bytes

Contents

module FactoryBotRails
  class FactoryValidator
    class ActiveRecordValidator
      def validate!(payload)
        attributes, for_class = payload.values_at(:attributes, :class)
        attributes.each do |attribute|
          if for_class < ActiveRecord::Base && for_class.primary_key == attribute.name.to_s
            raise FactoryBot::AttributeDefinitionError, <<~ERROR
              Attribute generates #{for_class.primary_key.inspect} primary key for #{for_class.name}"

              Do not define #{for_class.primary_key.inspect}. Instead, rely on the database to generate it.
            ERROR
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
factory_bot_rails-6.4.2 lib/factory_bot_rails/factory_validator/active_record_validator.rb
factory_bot_rails-6.4.0 lib/factory_bot_rails/factory_validator/active_record_validator.rb
factory_bot_rails-6.3.0 lib/factory_bot_rails/factory_validator/active_record_validator.rb