testing - Integration test for the order for a query in Rails 5 -
rails 5 will deprecat assigns
, handy when testing order of ar query.
test "admin sorts members date joined" memberships_path(sort: :by_date_joined) memberships = assigns(:memberships) assert_equal [@bart, @lisa, @homer], memberships.to_a end
integration tests in rails 5 encourage simulate user experience as possible. means should search rendered html right links.
[@bart, @lisa, @homer].each |member| assert_select "#member_#{member.id}" end
assert_select
useful if want ensure members being rendered correctly, not guarantee order.
so can test order?
one way accomplish compare indexes of elements in dom:
assert response.body.index('member_1') < response.body.index('member_2')
depending on case, can use assert_select
nth-child
expect specific order.
Comments
Post a Comment