【发布时间】:2017-11-30 01:55:32
【问题描述】:
最初,我的代码有弃用警告:
Ruby on Rails: Deprecation Warnings
我已经在一定程度上更改了这段代码,但我仍然有一个警告。
请参阅下面的警告和代码。 如何修复它并确保所有测试都通过?提前致谢。
弃用警告:在集成测试中使用位置参数已被弃用,ETA:00:00:30 支持关键字参数,并将在 Rails 5.1 中删除。
不推荐使用的样式: 获取 "/profile", { id: 1 }, { "X-Extra-Header" => "123" }
新的关键字样式: 获取“/profile”,参数:{ id:1},标题:{“X-Extra-Header”=>“123”} (从 /home/ubuntu/workspace/origin/test/integration/following_test.rb:30 中的块(2 个级别)调用) 68/68:[============================================== ============] 100% 时间:00:00:04,时间:00:00:04
在 4.25284 秒内完成 68 次测试,336 次断言,0 次失败,0 次错误,0 次跳过
require 'test_helper'
class FollowingTest < ActionDispatch::IntegrationTest
def setup
@user = users(:michael)
@other = users(:archer)
log_in_as(@user)
end
test "following page" do
get following_user_path(@user)
assert_not @user.following.empty?
assert_match @user.following.count.to_s, response.body
@user.following.each do |user|
assert_select "a[href=?]", user_path(user)
end
end
test "followers page" do
get followers_user_path(@user)
assert_not @user.followers.empty?
assert_match @user.followers.count.to_s, response.body
@user.followers.each do |user|
assert_select "a[href=?]", user_path(user)
end
end
test "should follow a user the standard way" do
assert_difference '@user.following.count', 1 do
post relationships_path, followed_id: @other.id
end
end
test "should follow a user with Ajax" do
assert_difference '@user.following.count', 1 do
post relationships_path(followed_id: @other.id), xhr: true
end
end
test "should unfollow a user the standard way" do
@user.follow(@other)
relationship = @user.active_relationships.find_by(followed_id: @other.id)
assert_difference '@user.following.count', -1 do
delete relationship_path(relationship)
end
end
test "should unfollow a user with Ajax" do
@user.follow(@other)
relationship = @user.active_relationships.find_by(followed_id: @other.id)
assert_difference '@user.following.count', -1 do
delete relationship_path(relationship), xhr: true
end
end
end
【问题讨论】:
标签: ruby-on-rails