Hi all,

I have two locales FR and EN.

So, to test EN locale, I make volontary mistakes in my
alert_collaborator EN YML File translation to test if the EN locale is
set.

First of all, in my /config/environnement.rb I have
Rails::Initializer.run do |config|
[...]
  config.i18n.load_path += Dir[Rails.root.join('config', 'locales',
'**', '*.{rb,yml}')]
  config.i18n.default_locale = :fr
end

If i'm starting my prospects_controller_test.rb with no mistakes in my
FR YML File, there are no problem.
Started
.................................
Finished in 6.043841 seconds.
33 tests, 50 assertions, 0 failures, 0 errors

So, if a specify "I18n.locale = :en" in my setup functional test, like
this.

    setup do
      UserSession.create(Factory(:user))
      Factory(:agency)
      Factory(:feedback)
      @alert_collaborator = Factory.stub(:alert_collaborator)
      @alert_collaborator.id = 1001

      AlertCollaborator.stubs(:find).returns(@alert_collaborator)
      AlertCollaborator.stubs(:find).with(:all,
anything).returns([...@alert_collaborator])

      I18n.locale = :en

    end

There are no problem even if EN YML File translation contain an error.
It's strange.


But, if I remplace "I18n.locale = :en" by "I18n.default_locale = :en",
like this.

    setup do
      UserSession.create(Factory(:user))
      Factory(:agency)
      Factory(:feedback)
      @alert_collaborator = Factory.stub(:alert_collaborator)
      @alert_collaborator.id = 1001

      AlertCollaborator.stubs(:find).returns(@alert_collaborator)
      AlertCollaborator.stubs(:find).with(:all,
anything).returns([...@alert_collaborator])

      I18n.default_locale = :en

    end

Mistakes appears.

Loaded suite functional/hr/alert_collaborators_controller_test
Started
...EEEE....................EEE...
Finished in 5.872202 seconds.

So my conclusion is :

Functional test take default_locale variable while is running his
tests.
If we specify a locale changement in functional test with #locale
method from I18n module, it mustn't be take care of it.

On 18 juil, 21:20, Henrik N <[email protected]> wrote:
> On Jul 18, 5:16 pm, Christian Lescuyer <[email protected]> wrote:
>
> > Same here. This works:
>
> >   I18n.locale = :test
> >   assert_equal :test, I18n.locale
> >   assert_equal ',', I18n.translate('number.format.separator')
>
> > But this doesn't:
>
> >   @product = Factory.create(:product, :price => 49.95)
> >   I18n.locale = :test
> >   get :edit, :id => @product.permalink
> >   assert_select "#product_price[value='49,95']"
>
> > We're testing the view (@response.body), here, not the controller. But I
> > can't find where the view is rendered, and why I18n.locale is not used.
>
> As a sanity check... If these are controller tests, did you call
> integrate_views? Otherwise they do not actually render the view.

-- 
You received this message because you are subscribed to the Google Groups 
"rails-i18n" 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/rails-i18n?hl=en.

Reply via email to