RailsTutorial Ch 9 分页和删除测试失败 link

RailsTutorial Ch 9 Test fail on pagination and delete link

正在阅读 rails 教程并因最后一个错误停留在第 9 章。

FAIL["test_index_as_admin_including_pagination_and_delete_links", UsersIndexTest, 1.799453]
 test_index_as_admin_including_pagination_and_delete_links#UsersIndexTest (1.80s)
        <delete> expected but was
        <User 19>..
        Expected 0 to be >= 1.
        test/integration/users_index_test.rb:18:in `block (2 levels) in <class:UsersIndexTest>'
        test/integration/users_index_test.rb:15:in `block in <class:UsersIndexTest>'

这是我来自 users_index_test.rb

的测试块
test "index as admin including pagination and delete links" do
    log_in_as(@admin)
    get users_path
    assert_template 'users/index'
    assert_select 'div.pagination'
    first_page_of_users = User.paginate(page: 1)
    first_page_of_users.each do |user|
      assert_select 'a[href=?]', user_path(user), text: user.name
      unless user == @admin
        assert_select 'a[href=?]', user_path(user), text: 'delete'
      end
    end
    assert_difference 'User.count', -1 do
      delete user_path(@non_admin)
    end
  end

我的 app/views/users/_users.html.erb 中有错别字,修改后帮助我通过了考试。

正确的代码是-

<li>
  <%= gravatar_for user, size: 50 %>
  <%= link_to user.name, user %>
  <% if current_user.admin? && !current_user?(user) %>
    | <%= link_to "delete", user, method: :delete,
                                  data: { confirm: "You sure?" } %>
  <% end %>
</li>