FactoryGirl :: InvalidFactoryError(factory_girl-4.4.0 / lib / factory_girl.rb:73:in`lint')

时间:2014-07-26 16:44:42

标签: ruby-on-rails ruby factory-bot


我无法理解为什么这个工厂无效( FactoryGirl :: InvalidFactoryError(factory_girl-4.4.0 / lib / factory_girl.rb:73:in lint')。 这是:

FactoryGirl.define do
  factory :building do
    sequence(:map_index)  { |n| "#{n}" }
    static_building_id 1
    finished_at Time.now + 1.hour #This row is the problem!
    user
  end
end

这是user工厂:

FactoryGirl.define do
  factory :user do
    sequence(:email)  { |n| "test_mail#{n}#@gmail.com" }
    sequence(:password)  { |n| "password-#{n}" }
    sequence(:username)  { |n| "username-#{n}" }
  end
end

这是我的schema.rb

ActiveRecord::Schema.define(version: 20140726162156) do
  create_table "buildings", force: true do |t|
    t.integer  "user_id"
    t.integer  "static_building_id"
    t.integer  "level"
    t.datetime "time_creation"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "map_index"
    t.datetime "finished_at"
  end

这是我的模特:

class Building  < ActiveRecord::Base
        belongs_to :user

        validates :map_index, length: { in: 0..10}
        validates :static_building_id, length: { in: 0..10}
        validates :map_index, :static_building_id, presence: true

        before_create :initialize_building

        private

        def initialize_building
            self.level = 1
        end

    end

请注意没有finished_at(在数据库和工厂中)一切正常......有什么想法吗?

0 个答案:

没有答案