On Jan 9, 1:08 am, bearblu <[email protected]> wrote:
> The following code from the RailsSpace book:
>   def correct_error_message(boundary, length)
>     error_messages = ActiveRecord::Errors.default_error_messages
>     if boundary == :max
>       sprintf(error_messages[:too_long], length)
>     elsif boundary == :min
>       sprintf(error_messages[:too_short], length)
>     else
>       raise ArgumentError, "boundary must be :max or :min"
>     end
>   end
>
> resulted in the following error message.
> Loaded suite /home/rmartin/NetBeansProjects/TestForge/test/unit/
> user_test
> Started
> DEPRECATION WARNING: ActiveRecord::Errors.default_error_messages has
> been deprecated. Please use I18n.translate
> ('activerecord.errors.messages').. (called from default_error_messages
> at /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> validations.rb:24)
> ....F.....
> Finished in 0.201547 seconds.
>
>   1) Failure:
> test_screen_name_length_boundaries(UserTest)
>     [/home/rmartin/NetBeansProjects/TestForge/test/unit/../
> test_helper.rb:72:in `assert_length'
>      /home/rmartin/NetBeansProjects/TestForge/test/unit/user_test.rb:
> 39:in `test_screen_name_length_boundaries'
>      /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/
> active_support/testing/setup_and_teardown.rb:94:in `__send__'
>      /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/
> active_support/testing/setup_and_teardown.rb:94:in `run']:
> <"is too short (minimum is {{count}} characters)"> expected but was
> <"is too short (minimum is 4 characters)">.
>
> 10 tests, 31 assertions, 1 failures, 0 errors
>
> The deprecation warning I get but it doesn't appear as though the
> error message is being manipulated correctly; any help out there?

I am getting the same problem

The deprecation warning is easy

in your user_test.rb setup method replace the line:
    @error_messages = ActiveRecord::Errors.default_error_messages
with the line:
    @error_messages =  I18n.translate('activerecord.errors.messages')

This is part of the internationalization of rails.

I still haven't tracked down why sprintf wants a variable named count
instead of just taking the variable in min_length.
For now I have performed the hack of commenting out the original line
and adding a hand formatted line for the two min_length tests:

    #correct_error_message = sprintf(@error_messages[:too_short],
min_length)
    correct_error_message = "is too short (minimum is #{min_length}
characters)"

and replace the three max_length tests:

    #correct_error_message = sprintf(@error_messages[:too_long],
max_length)
    correct_error_message = "is too long (maximum is #{max_length}
characters)"

I would prefer to use the sprintf to format the message from
the :too_short symbol. It should change automatically if the
default :too_short message changes. I'll live with the hack for now
and chase down the change in sprintf in my spare time.

I'll try to remeber to post the sprintf answer when i find it.


Sean



--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to