I do not understand how to test with rspec and internationalization. For example, in query tests, I do
I18n.available_locales.each do |locale| visit users_path(locale: locale)
and it works fine: every locale test is correct.
But in email programs this trick does not work.
user_mailer_spec.rb
require "spec_helper" describe UserMailer do I18n.available_locales.each do |locale| let(:user) { FactoryGirl.build(:user, locale: locale.to_s) } let(:mail_registration) { UserMailer.registration_confirmation(user) } it "should send registration confirmation" do puts locale.to_yaml mail_registration.body.encoded.should include("test")
It works several times (as many locales as I have), but each time it generates html only for the default locale.
When I call UserMailer.registration_confirmation(@user).deliver from the controller, it works fine.
user_mailer.rb
... def registration_confirmation(user) @user = user mail(to: user.email, subject: t('user_mailer.registration_confirmation.subject')) do |format| format.html { render :layout => 'mailer'} format.text end end ...
view / user _mailer / registration_confirmation.text.erb
<%=t '.thx' %>, <%= @user.name %>. <%=t '.site_description' %> <%=t '.credentials' %>: <%=t '.email' %>: <%= @user.email %> <%=t '.password' %>: <%= @user.password %> <%=t '.sign_in_text' %>: <%= signin_url %> --- <%=t 'unsubscribe' %>
I repeat - it works great for all locales. My question is only about rspec tests for this.
alex
source share