我是一名有用的助手,可以为您翻译文本。
我在avatar_parts_spec.rb中使用了一个shoulda匹配器,但无法通过测试:
测试:
移植:
什么可能是错误的原因?
编辑: Github仓库:https://github.com/preciz/avatar_parts
我在avatar_parts_spec.rb中使用了一个shoulda匹配器,但无法通过测试:
测试:
require 'rails_helper'
RSpec.describe AvatarPart, :type => :model do
it { should validate_presence_of(:name) }
it { should validate_presence_of(:type) }
it { should validate_uniqueness_of(:name).case_insensitive }
it { should belong_to(:avatar) }
end
模型:
class AvatarPart < ActiveRecord::Base
attr_accessible :name, :type, :avatar_id
belongs_to :avatar
validates_uniqueness_of :name, case_sensitive: false
validates :name, :type, presence: true, allow_blank: false
end
移植:
class CreateAvatarParts < ActiveRecord::Migration
def change
create_table :avatar_parts do |t|
t.string :name, null: false
t.string :type, null: false
t.integer :avatar_id
t.timestamps
end
end
end
错误:
1) AvatarPart should require unique value for name
Failure/Error: it { should validate_uniqueness_of(:name).case_insensitive }
ActiveRecord::StatementInvalid:
SQLite3::ConstraintException: NOT NULL constraint failed: avatar_parts.type: INSERT INTO "avatar_parts" ("avatar_id", "created_at", "name", "type", "updated_at") VALUES (?, ?, ?, ?, ?)
什么可能是错误的原因?
编辑: Github仓库:https://github.com/preciz/avatar_parts
case_insensitive
? - Vishal Vijay