rails tutorial ページネーションのテストが通らなくなった

前提

railsのminitestで、ページネーションが画面に表示されているかどうかのテストをしています。
コントローラーでユーザーの検索をかける処理で、

@users = User.paginate(page: params[:page])

から

@users = User.where(activated: true).paginate(page: params[:page])

と、アカウントを有効化しているユーザーのみを表示させようとwhereを使ったら「Expected exactly 2 elements matching "div.pagination", found 0..」というエラーが出ました。
ブラウザではページネーションは表示されていて、div.paginationもありました。

実現したいこと

・原因はなんなのかを知りたい
・エラーを無くすにはどうすればいいのか

発生している問題・エラーメッセージ

Expected exactly 2 elements matching "div.pagination", found 0..

該当のソースコード

controller

def index @users = User.where(activated: true).paginate(page: params[:page]) #成功  @users = User.paginate(page: params[:page]) end

index.html.erb

<% provide(:title, 'All users') %> <h1>All users</h1> <%= will_paginate %> <ul class="users"> <%= render @users %> </ul> <%= will_paginate %>

test

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", count: 2 #ここがエラー 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

試したこと

・whereの有無で試し、whereを記述するとエラーが起こりました。
・index.html.erbの「<%= will_paginate %>」を「<div class='pagination'><%= will_paginate %></div>」とするとテストは通りました。

補足情報(FW/ツールのバージョンなど)

cloud9
Rails 6.0.4

コメントを投稿

0 コメント