Ruby on Rails Thursday, September 1, 2011

Turgs wrote in post #1019574:
>
> test "Password must be long enough" do
> user = User.new(:email => "adam@example.com",
> :name => "Adam",
> :security_question => "What's my name?",
> :security_answer => "Adam")
>
> user.password = "1234567"
> assert user.invalid?
> assert_equal "should be between 8 and 2000 characters",
> user.errors[:password].join('; ')
>
> user.password = "12345678"
> assert user.valid? # this assertion is failing


Is the mobile phone number between 8 and 30 characters?

You can write the length validations more succinctly:

validates :password, :presence => true,
:length => 8..2000

And to form the strings to test against, I hope you are not writing them
out by hand:

user.password = ("123456790" * 200).chop
assert user.valid? # this assertion is failing

user.password = "1234567890" * 200


user.password = ("1234567890" * 200) + '1'
assert user.invalid?
#assert_equal 'should be between 8

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment