Rails 5.1测试更改属性弃用警告

时间:2017-05-04 06:17:30

标签: ruby-on-rails unit-testing rspec ruby-on-rails-5

我刚刚将我的5.0.1应用升级到5.1,并且每当我运行我的rspec测试时,我都会收到巨大的数量的警告。

DEPRECATION WARNING: ActiveSupport.halt_callback_chains_on_return_false= is deprecated and will be removed in Rails 5.2. (called from <top (required)> at /home/doomy/Documents/rsm/config/initializers/new_framework_defaults.rb:23)
...DEPRECATION WARNING: The behavior of `changed_attributes` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_changes.transform_values(&:first)` instead. (called from block (3 levels) in <top (required)> at /home/doomy/Documents/rsm/spec/controllers/products_spec.rb:48)
DEPRECATION WARNING: The behavior of `changes` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_changes` instead. (called from block (3 levels) in <top (required)> at /home/doomy/Documents/rsm/spec/controllers/products_spec.rb:48)
DEPRECATION WARNING: The behavior of `changed` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_changes.keys` instead. (called from block (3 levels) in <top (required)> at /home/doomy/Documents/rsm/spec/controllers/products_spec.rb:48)
DEPRECATION WARNING: The behavior of `attribute_change` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute` instead. (called from block (3 levels) in <top (required)> at /home/doomy/Documents/rsm/spec/controllers/products_spec.rb:48)

对于我所进行的每项测试都会继续这样做,并且由于它在控制台上写了这么多东西,因此最终会花费更长的时间。

我对我应该改变的内容感到困惑,因为有问题的代码看起来并不寻常。

这里有关于第48行的products_spec.rb

describe "GET show" do

before(:each) do
  @product = create(:product, user: create(:product_admin))
end

context "anonymously" do
  it "renders" do
    get :show, params: { id: @product.id }
    expect(response).to render_template("show")
  end
end

context "as regular user" do
  it "renders" do
    get :show, params: { id: @product.id }
    login(create(:user))
    expect(response).to render_template("show")
  end
end
...

我认为它必须对之前的过滤器做一些事情,但我无法弄清楚是什么。搜索警告没有任何用处。

感谢。

0 个答案:

没有答案