FactoryGirl模型的id =>零

时间:2014-04-02 12:29:28

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

我有模特:

class CreateStores < ActiveRecord::Migration
  def change
    create_table :stores do |t|
      t.integer :admin_id
      t.string :name
      t.string :subdomain
      t.string :linked_domain

      t.timestamps
    end
  end
end

并测试:

require 'test_helper'

class Api::Be::UsersControllerTest < ActionController::TestCase

  setup do
    @admin = FactoryGirl.create :admin

    @store = FactoryGirl.create :store
    @store.ug_default = UgDefault.new
    @store.save

    Rails::logger.debug "HERE: #{@store.id}"

    @customer = FactoryGirl.create :customer
    @customer.userable_id = @store.id
    @customer.save
  end

在日志中,我看到@store.id等于零。有什么问题?

1 个答案:

答案 0 :(得分:0)

可能没有得救。使用记录器,如果模型上有任何错误,则输出:

Rails.logger.debug "#{@store.errors.inspect}"

在输出结尾处查找消息。