1
類
這是我spec/factories/nodes.rb
RSpec的順序錯誤:未定義的方法`primary_key」絃樂:
FactoryGirl.define do
factory :node do
sequence(:name) { |n| "Node#{n}" }
family_tree nil
user nil
media ""
end
end
這是我node_spec.rb
require 'rails_helper'
describe Node do
it "is valid with a name" do
# node = Node.new(generate(:name))
expect(build(:node)).to be_valid
end
end
這是我收到的錯誤:
Failures:
1) Node is valid with a name
Failure/Error: expect(build(:node)).to be_valid
NoMethodError:
undefined method `primary_key' for String:Class
這是我的Node.rb
型號的架構:
# == Schema Information
#
# Table name: nodes
#
# id :integer not null, primary key
# name :string(255)
# family_tree_id :integer
# user_id :integer
# media_id :integer
# media_type :string(255)
# created_at :datetime
# updated_at :datetime
# circa :datetime
# is_comment :boolean
validates :name, presence: true
想法?
編輯1
所以我剛剛刪除整個文件,並用這個代替它,它現在的作品:
FactoryGirl.define do
factory :node do
sequence(:name) { |n| "Node#{n}" }
end
end
我不知道是什麼,雖然工作。
啊......對。這就說得通了。 – marcamillion