Created
March 31, 2009 03:48
-
-
Save dwaynemac/88038 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validates_uniqueness_of :dni, :allow_nil => true, :allow_blank=>true, :message=>I18n.t('persona.dni_already_exists') | |
validates_uniqueness_of :dni, :scope=>[:nombres, :apellidos], :allow_nil => true, :message=>I18n.t('persona.person_already_exists') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
should "demand DNI to be unique" do | |
Persona.make(:dni => "1") | |
assert_raise(ActiveRecord::RecordInvalid) { Persona.make(:dni => "1") } | |
assert_nothing_raised(ActiveRecord::RecordInvalid) { Persona.make(:dni => "2") } | |
end | |
# this helper won't work with :allow_nil | |
# should_require_unique_attributes :dni | |
should "allow no repetition of nombres, apellidos unless DNI is specified" do | |
Persona.make(:nombres => "Juan", :apellidos => "Topo") | |
assert_raise(ActiveRecord::RecordInvalid) do | |
p = Persona.make_unsaved(:nombres => "Juan", :apellidos => "Topo") | |
p.save! | |
end | |
assert_nothing_raise(ActiveRecord::RecordInvalid) do | |
p = Persona.make_unsaved(:dni => "5", :nombres => "Juan", :apellidos => "Topo") | |
p.save! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment