对于使用定义的模型
belongs_to :municipal
validates :name, presence: true
has_one :gdstore, dependent: :destroy在控制台中
Neighbourhood.new(name: 'red distrikt').valid?
=> false
Neighbourhood.new(municipal_id: 3272, name: 'red distrikt').valid?
=> true但是运行这个测试
test "valid if name and municipal id defined" do
neighbourhood = Neighbourhood.new(municipal_id: 3272, name: 'red distrikt')
assert neighbourhood.valid?
end返回
Failure:
NeighbourhoodTest#test_valid_if_name_and_municipal_id_defined [/Volumes/SJT/r/gd /test/models/neighbourhood_test.rb:20]:
Expected false to be truthy.db模式确认:
create_table "neighbourhoods", force: :cascade do |t|
t.bigint "municipal_id", null: false那么这是怎么回事呢?注意:反向断言也会生成错误。我不期望has-one创建无效,因为它可能没有gdstore……
发布于 2020-11-14 02:12:31
好吧..。带有id: 3272的municipal没有夹具,因此测试错误。
https://stackoverflow.com/questions/64824711
复制相似问题