Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validations only work for current locale, not for translations added using set_translations #29

Open
khelben opened this issue Apr 26, 2010 · 0 comments

Comments

@khelben
Copy link

khelben commented Apr 26, 2010

when you define a 'validates_presence_of :something' on a model, this is only checked for translations in the current locale but not for any other translations you set using 'set_translations':

test "validates_presence_of using set_translations" do
Validatee.class_eval { validates_presence_of :string }
assert !Validatee.new.valid?
assert Validatee.new(:string => 'foo').valid?
### The following fails
assert_nothing_raised do
Validatee.new(:string => 'bar').set_translations(:fr => { :string => '' })
end
end

One solution is to set the validations on the translation class itself:

test "" do
Validatee.translation_class.class_eval do
validates_presence_of :string
end

I18n.locale = :en
validatee = Validatee.new(:string => "a string")
assert validatee.valid?
validatee.set_translations(:nl => {:string => ''}) rescue nil # we need to recsue as set_translations uses update_attributes!
assert !validatee.valid? ### this works

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant