Ruby on Rails Monday, November 15, 2010

On Nov 14, 9:48 pm, 24z <r...@grandcentrix.com> wrote:
> In Agile Web Development with Rails, the following statement is given:
>
> assert_equal "has already been taken", product.errors[:title].join(';
> ')
>
> My question is: Why is the join(...) needed and what exactly does it
> do here?
>
> If it does what I assume, join an array of strings and use "; " as the
> separator, then I wonder how the assert_equal statement could ever
> evaluate to true as the first parameter is a static string without ";
> "
>
> Can you shed some light for me?

If there is only supposed to be one error on title (ie the
errors[:title] contains a single string) then join will just return
that string. Hard to say without knowing the wider context, but this
seems a fairly succinct way of saying that there should only be one
error for the title attribute and that it should be the one that comes
from the uniqueness validation.

Fred

--
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