ruby-on-rails – 日期时间值不正确; Ruby on Rails

ruby-on-rails – 日期时间值不正确; Ruby on Rails,第1张

概述我正在使用 Ruby on Rails中的邮件程序运行测试,我收到以下错误: *********-C02MGBVJFD57:myapp ************$bundle exec rake test:mailers# Running:EEFinished in 0.110500s, 18.0995 runs/s, 0.0000 assertions/s. 1) Error: 我正在使用 Ruby on Rails中的邮件程序运行测试,我收到以下错误:

*********-C02MGBVJFD57:myapp ************$bundle exec rake test:mailers# Running:EEFinished in 0.110500s,18.0995 runs/s,0.0000 assertions/s.  1) Error:UserMailerTest#test_account_activation:ActiveRecord::StatementInvalID: MysqL2::Error: Incorrect datetime value: '2014-12-18 01:07:49 UTC' for column 'activated_at' at row 1: INSERT INTO `users` (`name`,`email`,`password_digest`,`admin`,`activated`,`activated_at`,`created_at`,`updated_at`,`ID`) VALUES ('Michael Example','michael@example.com','a$hz6pvZctID6gZEuv0.qAe.0mEfbEjxso9GrXwC3yHRhIThIJ7Vx5m',1,'2014-12-18 01:07:49 UTC','2014-12-18 01:07:49',762146111)  2) Error:UserMailerTest#test_password_reset:ActiveRecord::StatementInvalID: MysqL2::Error: Incorrect datetime value: '2014-12-18 01:07:49 UTC' for column 'activated_at' at row 1: INSERT INTO `users` (`name`,'a$XTAWn5P9kikgOXqxQgiJqOjP027p4HnucHZ6pth2aaLwolaFcehsm',762146111)2 runs,0 assertions,0 failures,2 errors,0 skips

当我检查我的fixtures users.yml文件时,我看到我正在使用时区ruby戳:

michael:  name: Michael Example  email: michael@example.com  password_digest: <%= User.digest('password') %>  admin: true  activated: true  activated_at: <%= Time.zone.Now %>archer:  name: Sterling Archer  email: duchess@example.gov  password_digest: <%= User.digest('password') %>  activated: true  activated_at: <%= Time.zone.Now %>lana:  name: Lana Kane  email: hands@example.gov  password_digest: <%= User.digest('password') %>  activated: true  activated_at: <%= Time.zone.Now %>mallory:  name: Mallory Archer  email: boss@example.gov  password_digest: <%= User.digest('password') %>  activated: true  activated_at: <%= Time.zone.Now %><% 30.times do |n| %>user_<%= n %>:  name:  <%= "User #{n}" %>  email: <%= "user-#{n}@example.com" %>  password_digest: <%= User.digest('password') %>  activated: true  activated_at: <%= Time.zone.Now %><% end %>

我的db / seeds.rb文件如下所示:

User.create!(name:  "Example User",email: "example@railstutorial.org",password:              "foobar",password_confirmation: "foobar",admin: true,activated: true,activated_at: Time.zone.Now)99.times do |n|  name  = Faker::name.name  email = "example-#{n+1}@railstutorial.org"  password = "password"  User.create!(name:  name,email: email,password:              password,password_confirmation: password,activated_at: Time.zone.Now)end

编辑:这是测试

测试/邮寄者/ user_mailer_test.rb:

require 'test_helper'class UserMailerTest < ActionMailer::TestCase  test "account_activation" do    mail = UserMailer.account_activation    assert_equal "Account activation",mail.subject    assert_equal ["to@example.org"],mail.to    assert_equal ["from@example.com"],mail.from    assert_match "Hi",mail.body.encoded  end  test "password_reset" do    mail = UserMailer.password_reset    assert_equal "Password reset",mail.body.encoded  endend

有什么我做错了吗?谢谢您的帮助.

解决方法 activate_at是否在迁移文件中键入为datetime?您可能想尝试Time.zone.Now.to_datetime. 总结

以上是内存溢出为你收集整理的ruby-on-rails – 日期时间值不正确; Ruby on Rails全部内容,希望文章能够帮你解决ruby-on-rails – 日期时间值不正确; Ruby on Rails所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1238949.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存