Search code examples
ruby-on-railsrubytestingfactory-botrspec-rails

FactoryBot end as a table fiel


I'm having problems creating some factories, when the database was created someone called a field of a table like "end" now when I try to build the factory when i I type end and then try to assign a value it takes that en as the end of the factory not as an atribute of the table.

Any Idea of how can I fix it?


Solution

  • I think you are trying to use a reserved word as an attribute name in your factory definitions. This is how you can do it:

    factory :enrique_table do
      add_attribute(:end) { 'just the beginning' }
    end
    

    add_attribute method let's you define attributes with reserved words. If you like to learn more about FactoryBot, head over to their Getting Started guide.

    Hope it helps.