mardi 27 octobre 2015

Integration test for the order for a query in Rails 5

Rails 5 will deprecat assigns, which is handy when testing the order of an AR query.

test "admin sorts members by date joined" do
  get memberships_path(sort: :by_date_joined)
  memberships = assigns(:memberships)
  assert_equal [@bart, @lisa, @homer], memberships.to_a
end

Integration tests in Rails 5 encourage you to simulate the user experience as much as possible. This means we should search the rendered HTML for the right links.

[@bart, @lisa, @homer].each do |member|
  assert_select "#member_#{member.id}"
end

assert_select is useful if we want to ensure that members are being rendered correctly, but it does not guarantee order.

So what can we do to test the order?

Aucun commentaire:

Enregistrer un commentaire