Melalui tutorial Rails dan terjebak pada bab 9 untuk kesalahan terakhir ini.

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>'

Ini blok pengujian saya dari 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
0
Aniruddha 18 Mei 2015, 03:48

1 menjawab

Jawaban Terbaik

Ada kesalahan ketik di app/views/users/_users.html.erb saya, memperbaikinya membantu saya lulus ujian.

Kode yang benar adalah sebagai -

<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>
0
Aniruddha 24 Mei 2015, 22:35