rails 오류 대상의 기본 메시지 다시 쓰기
1315 단어 errorMessageRails
발리데이 테스트 코드를 썼는데 갑자기 어떻게 하면 원래 잘못된 정보를 바꿀 수 있을까 하는 생각이 들어서 조사를 많이 했는데 그 결과 아래의 작법으로 순조롭게 진행되어서 공유해 봤어요.
첫번째
원시 오류문을 전제로 한 테스트 코드
it "is invalid if not having uniqe email" do
user = create(:user)
user2 = build(:user)
user2.valid?
expect(user2.errors[:email]).to include("has already been taken")
end
it "is invalid without a password" do
user = build(:user, password: "", password_confirmation: "")
user.valid?
expect(user.errors[:password]).to include("can't be blank")
end
테스트 결과
en.다시 쓰기
en:
activerecord:
errors:
messages:
blank: "what the fuck!!! You need to fill it"
taken: "what the hell are you thinking? it already exists"
hello: "Hello world"
테스트 결과
이것뿐이다
Reference
이 문제에 관하여(rails 오류 대상의 기본 메시지 다시 쓰기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/NateRive/items/bbc382eca06f130b5333텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)