Ruby on rails 4 为什么datetime不是预期的以及如何修复?

Ruby on rails 4 为什么datetime不是预期的以及如何修复?,ruby-on-rails-4,rspec,Ruby On Rails 4,Rspec,我不明白为什么rails datetime不匹配。以下测试失败,因为我在日期创建的_不相同,但我不知道为什么 试验 输出 CoursesController GET #index - json renders the #index view (FAILED - 1) Failures: 1) CoursesController GET #index - json renders the #index view Failure/Error: expect(respon

我不明白为什么rails datetime不匹配。以下测试失败,因为我在日期创建的_不相同,但我不知道为什么

试验

输出

CoursesController
  GET #index - json
    renders the #index view (FAILED - 1)

Failures:

  1) CoursesController GET #index - json renders the #index view
     Failure/Error: expect(response.body).to eq [course].to_json

       expected: "[{\"id\":2,\"partner_id\":2,\"name\":\"MyCourse 1\",\"created_at\":\"2014-08-29T10:49:06.205+02:00\",\"updated_at\":\"2014-08-29T10:49:06.205+02:00\",\"status\":\"active\"}]"
            got: "[{\"id\":2,\"partner_id\":2,\"name\":\"MyCourse 1\",\"created_at\":\"2014-08-29T10:49:06.000+02:00\",\"updated_at\":\"2014-08-29T10:49:06.000+02:00\",\"status\":\"active\"}]"

       (compared using ==)
     # ./spec/controllers/courses_controller_spec.rb:59:in `block (3 levels) in <top (required)>'
课程控制器
获取#索引-json
呈现#索引视图(失败-1)
失败:
1) CoursesController获取#索引-json呈现#索引视图
失败/错误:expect(response.body).to eq[course].to_json
应为:“[{\'id\':2,\'partner\'id\':2,\'name\':\'MyCourse 1\',\'created\'s\':\'2014-08-29T10:49:06.205+02:00\',\'Update\'s\':\'2014-08-29T10:49:06.205+02:00\',\'status\':'active\'
获得:“[{\'id\':2,\'partner\'id\':2,\'name\':\'MyCourse 1\',\'created\'s\':\'2014-08-29T10:49:06.000+02:00\',\'Update\'s\':\'2014-08-29T10:49:06.000+02:00\',\'status\':'active\'
(使用==进行比较)
#./spec/controller/courses\u controller\u spec.rb:59:in'block(3级)in'
任何想法都将不胜感激


谢谢。

经过进一步调查,似乎在保存到MySQL时会丢失一些精度。要纠正这个问题,我所做的就是
航向。重新加载
,精度现在匹配

CoursesController
  GET #index - json
    renders the #index view (FAILED - 1)

Failures:

  1) CoursesController GET #index - json renders the #index view
     Failure/Error: expect(response.body).to eq [course].to_json

       expected: "[{\"id\":2,\"partner_id\":2,\"name\":\"MyCourse 1\",\"created_at\":\"2014-08-29T10:49:06.205+02:00\",\"updated_at\":\"2014-08-29T10:49:06.205+02:00\",\"status\":\"active\"}]"
            got: "[{\"id\":2,\"partner_id\":2,\"name\":\"MyCourse 1\",\"created_at\":\"2014-08-29T10:49:06.000+02:00\",\"updated_at\":\"2014-08-29T10:49:06.000+02:00\",\"status\":\"active\"}]"

       (compared using ==)
     # ./spec/controllers/courses_controller_spec.rb:59:in `block (3 levels) in <top (required)>'