Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


using validate_presence_of and validate_uniqueness_of with i18n raise error #53

anujaware opened this Issue · 14 comments

It gives error
Failure/Error: it { should validate_uniqueness_of(:scheme_id).scoped_to(:designation_id) }
Expected errors to include "%{model} is already exist" when scheme_id is set to 1732, got errors: ["scheme_id Designations scheme is already exist (1732)", "scheme_id Sale Scheme Designations scheme is already exist (1732)", "scheme_type Designations scheme is already exist (3)"]


Can you provide more example code to help us recreate this?


+1 on getting errors with "validate_presence_of" and i18n.

Will provide code and/or failing test_case later on.



Options are not interpolated into I18n by Shoulda::Matchers::ActiveModel::Helpers.default_error_messages:

In this file:
There is the information:
"# The values :model, :attribute and :value are always available for interpolation"

So, for example, I could place this in my application's en.yml file:

      blank: "%{attribute} can't be blank"

And when I run the test I will get this:
Expected errors to include "%{attribute} can't be blank" when carousel_id is set to nil, got errors: carousel_id Carousel can't be blank (nil)title Title can't be blank (nil)

attribute has not been interpolated.

This might help resolve the issue:



I get same error message when using ensure_length_of using interpolation with attribute. The only interpolation being passed in the hash is the count.


same here : Expected errors to include "doit être rempli(e)" when course is set to nil, got errors: ["course does not exist (nil)", "course_id does not exist (nil)"]



class CaseType < ActiveRecord::Base
  validates :name, presence: true, uniqueness: true


require 'spec_helper'

describe CaseType do
  it { should validate_presence_of(:name) }

It works normally when default locale is english.
But when default locale is another (russian, for example), it raise error:

Failure/Error: it { should validate_presence_of(:name) }
       Expected errors to include "translation missing: ru.activerecord.errors.messages.blank" when name is set to nil, got errors: ["name translation missing: (nil)"]

@kanfet this is a separate issue to the one described in here. The issue described here is about i18n interpolation.


@danhart look at error text again, please. It about i18n interpolation. There is no locale files. But error is the same.



I am also facing the same issue


#206 might fix this, since it passes in :attribute.


I have the same issue as @kanfet

I'm using matchers in Test/Unit and have some error messages overridden in locales/en but I am using the default message for uniqueness.

When I call should validate_uniqueness_of(:property_name)

I get:

Expected errors to include "translation missing: en.activerecord.errors.models.eligibility_question.attributes.property_name.taken" when property_name is set to "name", got errors: ["input_type is not a valid input type (nil)", "question_type is not a valid question type (nil)", "property_name is already taken (\"name\")"]

This seems to also be an i18n problem but not this interpolation issue. Should I open a new ticket?




#206 fixed this for me.


@andyw8 - Thanks for checking!

With the changes from #206 and possibly other ones along the way, I believe this issue has been resolved. Closing.

@mxie mxie closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.