【问题标题】:gettig deprecation warning for after create call back in rspec在 rspec 中创建回调后收到弃用警告
【发布时间】:2018-06-28 20:17:46
【问题描述】:

我在运行 RSpec 测试时收到如下警告

弃用警告:attribute_changed? 内部的行为 after 回调将在下一版本的 Rails 中更改。新的 返回值将反映调用该方法后的行为 save 返回(例如,与现在返回的相反)。至 保持当前行为,使用saved_change_to_attribute? 反而。 (在 (pry):12 从 set_about_page_title 调用)

class User < ApplicationRecord

  after_create :create_defaults

  def create_defaults
    set_about_page_title
    set_contact_page_title
    self.save
  end

  def set_about_page_title
    self.about_page_title = self.full_name
  end

  def set_contact_page_title
    self.contact_page_title = User::GET_IN_TOUCH
  end

end

【问题讨论】:

    标签: ruby-on-rails ruby rspec


    【解决方案1】:

    正如警告所说,attribute_changed? 已弃用,新名称为 saved_change_to_attribute?

    有很多方法被弃用了,你可以在这里找到它们https://github.com/rails/rails/pull/25337#issuecomment-225166796

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      相关资源
      最近更新 更多