Ruby on rails 从Rails 3.2到4.1的转换和模型测试

Ruby on rails 从Rails 3.2到4.1的转换和模型测试,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,我正在将应用程序从Rails 3.2迁移到Rails 4.1。我有一个模型用户,写得像 class User < ActiveRecord::Base #some code def to_hash end def other_method end end 如果我测试其他方法,它也会失败(但属性工作正常) 在rails c中,一切正常。在Rails3.2上,它也可以正常工作。有什么问题吗?对不起,伙计们,我发现了一个错误。我在spec_helper中有这样的代码 cl

我正在将应用程序从Rails 3.2迁移到Rails 4.1。我有一个模型用户,写得像

class User < ActiveRecord::Base
  #some code
  def to_hash
  end

  def other_method
  end
end
如果我测试其他方法,它也会失败(但属性工作正常)


在rails c中,一切正常。在Rails3.2上,它也可以正常工作。有什么问题吗?

对不起,伙计们,我发现了一个错误。我在spec_helper中有这样的代码

class User < ActiveRecord::Base
  SOME_DATE = 1.day
end
class用户
在评论之后,一切都很好。我不知道为什么它会停止我的项目

它在3.2上工作,但在4.1上没有工作
我需要它来存根一个常量。

放置User.last.send(:to_hash).inspect;puts User.last.instance_eval{to_hash}正在rails c中工作,但不在rspec中。我不知道to_hash方法的内部是什么,但您可能希望使用
User.last.attributes
@MrYoshiji我需要\u hash,因为我使用的是tire,它使用的是这个方法。但没有一种方法是有效的。
class User < ActiveRecord::Base
  SOME_DATE = 1.day
end