在我的rails app中,will_paginate gem用于分页帖子。每页显示10个帖子。所以,我写的是检查分页是否显示每页10个帖子。
最初我创建了12个帖子。我检查了第2页。是否显示所有帖子或2个帖子。它只显示了2个帖子
it 'does paginate records' do
12.times {FactoryBot.create(:post, topic_id: topic.id, user: controller.current_user)}
get :index, params: {topic_id: topic.id, start_date: Time.now - 5.days, end_date: Time.now + 5.day, page: 2}
p (assigns(:posts))
end
我需要在第2页显示2个帖子吗?如果有任何解决方案要检查第2页有2个帖子?
it 'does paginate records for second page' do
12.times {FactoryBot.create(:post, :post4, topic_id: topic.id, user: controller.current_user)}
get :index, params: {topic_id: topic.id, start_date: Time.now - 5.days, end_date: Time.now + 5.day, page: 2}
expect(assigns(:posts).map(&:id).count).to eq 2
expect(Post.count).to eq(12)
end
it 'does paginate records' do
first_two = create_list(:post, 2, topic_id: topic.id, user, controller.current_user }
create_list(:post, 10, topic_id: topic.id, user: controller.current_user }
get :index, params: {topic_id: topic.id, start_date: Time.now - 5.days, end_date: Time.now + 5.day, page: 2}
expect(assigns(:posts)).to eq first_two
end