2
Я пытаюсь сделать RSpec тест модели на проверке с объемом, но не понимаю, почему у меня есть ошибкарельсы тестовая модель validate_uniqueness область действия
моя модель
class EcrPortMapping < ActiveRecord::Base
belongs_to :ecr
validates :ecr_id,presence: true
validates :ecr_id, :uniqueness => {:scope => [:port_source, :port_target]}
validates :ecr_id, :uniqueness => {:scope => :port_source}
validates :ecr_id, :uniqueness => {:scope => :port_target}
end
мой RSpec тест
require 'rails_helper'
RSpec.describe EcrPortMapping, type: :model do
describe 'uniqueness of ecr_id for port & target' do
it 'should validate uniqueness of ecr_id scoped to port_target & port_source' do
ecr = FactoryGirl.create(:ecr)
FactoryGirl.create(:ecr_port_mapping, ecr_id: ecr.id)
should validate_uniqueness_of(:ecr_id).scoped_to([:port_source, :port_target])
should validate_uniqueness_of(:ecr_id).scoped_to(:port_source)
should validate_uniqueness_of(:ecr_id).scoped_to(:port_target)
end
end
i ошибка
Failure/Error: should validate_uniqueness_of(:ecr_id).scoped_to([:port_source, :port_target])
Did not expect errors to include "already exists" when ecr_id is set to 4,
got errors:
* "already exists" (attribute: ecr_id, value: 4) (with different value of port_source)
Мне нужен этот вид валидации
Где я совершил ошибку?