代码之家  ›  专栏  ›  技术社区  ›  mechnicov

电子邮件正文包含西里尔字母符号时测试失败

  •  0
  • mechnicov  · 技术社区  · 6 年前

    在模板中,我用俄语添加了信息。

    Привет, <%= @user.name %>!
    Для завершения активации своего аккаунта необходимо пройти по этой ссылке:
    <%= edit_account_activation_url(@user.activation_token, email: @user.email) %>
    

    账户\激活.html.erb

    <p>Привет, <%= @user.name %>!</p>
    <p>Вы успешно зарегистрированы, но для завершения активации своего аккаунта необходимо пройти <%= link_to "по этой ссылке", edit_account_activation_url(@user.activation_token, email: @user.email) %>.</p>
    

    在开发环境(在浏览器中)的电子邮件预览看起来很完美,没有任何错误。

    我为他们写了测试。

    class UserMailerTest < ActionMailer::TestCase
        test "account_activation" do
            user = users(:test)
            user.activation_token = User.new_token
            mail = UserMailer.account_activation(user)
    
            assert_match user.name, mail.body.encoded
            assert_match user.activation_token, mail.body.encoded
            assert_match CGI.escape(user.email), mail.body.encoded
        end
    end
    

    FAIL["test_account_activation", Minitest::Result, 2018-11-05 15:04:41 +0300]
        test_account_activation#Minitest::Result (1541419481.77s)
        Expected /Edem\ Example/ to match # encoding: US-ASCII
        "\r\n----==_mimepart_5be06c46e2863_1afb2b1883b445bc35221\r\nContent-Type: text/plain;\r\n charset=UTF-8\r\nContent-Transfer-Encoding: base64\r\n\r\n0J/RgNC40LLQtdGCLCBFZGVtIEV4YW1wbGUhDQoNCtCU0L7QsdGA0L4g0L/Q\r\nvtC20LDQu9C+0LLQsNGC0Ywg0L3QsCBTYW1wbGVBcHAhDQrQktGLINGD0YHQ\r\nv9C10YjQvdC+INC30LDRgNC10LPQuNGB0YLRgNC40YDQvtCy0LDQvdGLLCDQ\r\nvdC+INC00LvRjyDQt9Cw0LLQtdGA0YjQtdC90LjRjyDQsNC60YLQuNCy0LDR\r\nhtC40Lgg0YHQstC+0LXQs9C+INCw0LrQutCw0YPQvdGC0LAg0L3QtdC+0LHR\r\nhdC+0LTQuNC80L4g0L/RgNC+0LnRgtC4INC/0L4g0Y3RgtC+0Lkg0YHRgdGL\r\n0LvQutC1Og0KaHR0cDovL2xvY2FsaG9zdDozMDAwL2FjY291bnRfYWN0aXZh\r\ndGlvbnMvaC1zdktRZnpsNTQ5aUNyaVFCV2c4dy9lZGl0P2VtYWlsPWVkZW0l\r\nNDBleGFtcGxlLmNvbQ0KDQrQldGB0LvQuCDQktGLINC90LUg0YDQtdCz0LjR\r\ngdGC0YDQuNGA0L7QstCw0LvQuNGB0Ywg0L3QsCBTYW1wbGVBcHAsINC/0YDQ\r\nvtGB0YLQviDQv9GA0L7QuNCz0L3QvtGA0LjRgNGD0LnRgtC1INGN0YLQviDQ\r\nv9C40YHRjNC80L4uDQoNCg==\r\n\r\n----==_mimepart_5be06c46e2863_1afb2b1883b445bc35221\r\nContent-Type: text/html;\r\n charset=UTF-8\r\nContent-Transfer-Encoding: base64\r\n\r\nPCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCiAgPGhlYWQ+DQogICAgPG1ldGEg\r\naHR0cC1lcXVpdj0iQ29udGVudC1UeXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7\r\nIGNoYXJzZXQ9dXRmLTgiIC8+DQogICAgPHN0eWxlPg0KICAgICAgLyogRW1h\r\naWwgc3R5bGVzIG5lZWQgdG8gYmUgaW5saW5lICovDQogICAgPC9zdHlsZT4N\r\nCiAgPC9oZWFkPg0KDQogIDxib2R5Pg0KICAgIDxoMT5TYW1wbGUgQXBwPC9o\r\nMT4NCg0KPHA+0J/RgNC40LLQtdGCLCBFZGVtIEV4YW1wbGUhPC9wPg0KPHA+\r\nJm5ic3A8L3A+DQo8cD7QlNC+0LHRgNC+INC/0L7QttCw0LvQvtCy0LDRgtGM\r\nINC90LAgU2FtcGxlQXBwITwvcD4NCjxwPtCS0Ysg0YPRgdC/0LXRiNC90L4g\r\n0LfQsNGA0LXQs9C40YHRgtGA0LjRgNC+0LLQsNC90YssINC90L4g0LTQu9GP\r\nINC30LDQstC10YDRiNC10L3QuNGPINCw0LrRgtC40LLQsNGG0LjQuCDRgdCy\r\n0L7QtdCz0L4g0LDQutC60LDRg9C90YLQsCDQvdC10L7QsdGF0L7QtNC40LzQ\r\nviDQv9GA0L7QudGC0LggPGEgaHJlZj0iaHR0cDovL2xvY2FsaG9zdDozMDAw\r\nL2FjY291bnRfYWN0aXZhdGlvbnMvaC1zdktRZnpsNTQ5aUNyaVFCV2c4dy9l\r\nZGl0P2VtYWlsPWVkZW0lNDBleGFtcGxlLmNvbSI+0L/QviDRjdGC0L7QuSDR\r\ngdGB0YvQu9C60LU8L2E+LjwvcD4NCjxwPiZuYnNwPC9wPg0KPHA+0JXRgdC7\r\n0Lgg0JLRiyDQvdC1INGA0LXQs9C40YHRgtGA0LjRgNC+0LLQsNC70LjRgdGM\r\nINC90LAgU2FtcGxlQXBwLCDQv9GA0L7RgdGC0L4g0L/RgNC+0LjQs9C90L7R\r\ngNC40YDRg9C50YLQtSDRjdGC0L4g0L/QuNGB0YzQvNC+LjwvcD4NCg0KICA8\r\nL2JvZHk+DQo8L2h0bWw+DQo=\r\n\r\n----==_mimepart_5be06c46e2863_1afb2b1883b445bc35221--\r\n".
        test/mailers/user_mailer_test.rb:12:in `block in <class:UserMailerTest>'
    

    在使用西里尔字母符号的情况下,如何更正这些测试以获得成功的结果?

    1 回复  |  直到 5 年前
        1
  •  0
  •   mechnicov    6 年前

    我曾经

    assert_match user.name, mail.text_part.decoded
    assert_match user.activation_token, mail.text_part.decoded
    assert_match CGI.escape(user.email), mail.text_part.decoded
    

    试验成功了