FactoryGirl model's id => nil

470 Views Asked by At

I have model:

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

and test:

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

In logs I see that @store.id equals nil. What's the problem?

1

There are 1 best solutions below

2
agmcleod On

It's probably not getting saved. With your logger, output if there are any errors on the model:

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

Look for messages at the end of the output.