[katello-devel] Breaking translation bug

Brad Buckingham bbuckingham at redhat.com
Wed Oct 3 14:03:37 UTC 2012


On 10/03/2012 09:43 AM, David Davis wrote:
> So there's a bug that's happening only in Jenkins where we're getting these failures:
>
> Changeset Changeset should adding content fail adding content from not promoted repository should fail on add package
>       Failure/Error: lambda { @changeset.add_package!("pack", @prod) }.
>         expected ActiveRecord::RecordInvalid with message matching /has not been promoted/, got #<ActiveRecord::RecordInvalid: translation missing: User_#<RSpec::Core::ExampleGroup::Nested_66::Nested_3::Nested_6:0x7f5b6bc44c08>.activerecord.errors.messages.record_invalid>
>       # ./spec/models/changeset_spec.rb:175
>
> The problem is that in the controller we're setting I18n.locale to current_user's default_locale and we're mocking current_user in a lot of cases so the locale just ends up being some mock-type data. Then when it runs the model specs, it fails in jenkins because the locale is not en (for English). It happens only on some systems because it depends on which order the specs are run (model then controller vs. controller then model).
>
> There's a few different way to fix this from happening, each with their faults:
>
> 1. Just set the default_locale to en for the user mocked models. Problem: if we ever end up testing non-English locales or if someone forgets to stub #default_locale, the changeset specs will break again.
>
> 2. Reset the locale before each rspec test. Problem: I am not aware of a good place to do this.
>
> 3. Reset the locale on an as-needed basis. Problem: This is kind of a hack but then again it's probably a bad idea for any spec to assume the locale is set to en.
>
> Any thoughts?
>
> Thanks.
>
> David
>
> _______________________________________________
> katello-devel mailing list
> katello-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/katello-devel
I'd probably lean towards #2.  (As you mention, the key is knowing 
'where' this can be specified.  Perhaps as part of the helper used to 
define the user (real or mock).)  At least then, we know the behavior 
should be expected to be the same for all tests.  In general, testing or 
verifying using different locales seems like it could be handled 
differently.  From an rspec point of view, not sure what we'd really be 
looking for.  With the exception of tests associated with an actual user 
where we want to make sure that changing the user's locale generates 
different results, it seems like for locale, we are really most 
interested in knowing whether all strings are translated and that those 
strings are correct (which doesn't seem like something for rspec).




More information about the katello-devel mailing list