issues with rails i18n #37

Closed
benvds opened this Issue Jun 18, 2009 · 11 comments

8 participants

@benvds

I seem to have issues with shoulda (thoughtbot-shoulda (2.10.1)) when i'm using translations in rails 2.3.2. One method not working is: should_require_attributes.

@qrush

Could you provide some examples? Throw it in a gist, perhaps: http://gist.github.com

Thanks!

@benvds

Maybe the problem could be solved if for every attribute all the activerecord error messages are set. But with many models and attributes this is a hell of a lot of work. Instead i use generic activerecord error messages which are just fine.

The classes can be found here:
http://gist.github.com/132526

I get the following error message:

[
1) Failure:
test: Customer should require first_name to be set. (CustomerTest)
    [vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/assertions.rb:50:in `assert_accepts'
     vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/macros.rb:46:in `__bind_1245402819_887562'
     vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:in `call'
     vendor/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:in `test: Customer should require first_name to be set. ']:

Expected errors to include "translation missing: nl, activerecord, errors, messages, blank" when first_name is set to nil, got errors: comment translation missing: nl, activerecord, errors, models, customer, attributes, comment, too_long (nil)city translation missing: nl, activerecord, errors, models, customer, attributes, city, blank (nil)city translation missing: nl, activerecord, errors, models, customer, attributes, city, too_long (nil)postal_code translation missing: nl, activerecord, errors, models, customer, attributes, postal_code, blank (nil)postal_code translation missing: nl, activerecord, errors, models, customer, attributes, postal_code, too_long (nil)identification translation missing: nl, activerecord, errors, models, customer, attributes, identification, blank (nil)identification translation missing: nl, activerecord, errors, models, customer, attributes, identification, too_long (nil)street translation missing: nl, activerecord, errors, models, customer, attributes, street, blank (nil)street translation missing: nl, activerecord, errors, models, customer, attributes, street, too_long (nil)phone translation missing: nl, activerecord, errors, models, customer, attributes, phone, blank (nil)phone translation missing: nl, activerecord, errors, models, customer, attributes, phone, too_long (nil)last_name translation missing: nl, activerecord, errors, models, customer, attributes, last_name, blank (nil)last_name translation missing: nl, activerecord, errors, models, customer, attributes, last_name, too_long (nil)first_name translation missing: nl, activerecord, errors, models, customer, attributes, first_name, blank (nil)first_name translation missing: nl, activerecord, errors, models, customer, attributes, first_name, too_long (nil)]
@teambox

I'm having the same issue, did you find a way to fix it?

@taryneast

I've got a patch that's working for m (ie my own tests in my own rails project run fine now). but it'll take time for me to write shoulda-compatible tests.

I'll put the patch up somewhere so you can see.

Mostly it's a matter of adding the :attribute=> and :count => into the correct places.

@taryneast

ok, here's the patch.
http://pastie.org/662116

The problem: nothing was passing the actual attribute into the default_error_messages method, so the tests were all testing against:
"Please enter a value for {{attribute}}"

instead of, say:
"Please enter a value for Myfield"

@universal

i had the same problem in a rails3 project which was mainly due to that most error messages have been moved from activerecord.errors... to errors...

the fix is simple, but most likely breaks backwards compatability. couldn't run the shoulda tests using rails3 since the loading process seems to have been changed. but with my changes quite a bunch of tests fail because of not finding the correct default translation.

i've put the changes along with some changes to fix rails3 deprecation warnings in my fork in the rails3 branch:

http://github.com/universal/shoulda/tree/rails3

@jferris
thoughtbot, inc. member

Is this still an issue with shoulda 2.11?

@carlosramireziii

This is still an issue as of 2.11.3.

@gabebw
thoughtbot, inc. member

Is this still an issue with shoulda 3.0?

@taryneast

Dear "is this still an issue" people... build a test case for it... if your code passes, then it's not an issue anymore. :)

@gabebw
thoughtbot, inc. member

@taryneast - can you please file a pull request over at shoulda-matchers? (That's where all of the "real code" lives now. Shoulda has become just a meta-gem that depends on that code.)

Thanks,
Gabe

@gabebw gabebw closed this Mar 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment