ruby on rails - Integration test: `assert_select 'a[href=?]'` fails for paginated pages -


i have many integration tests like:

first_page_of_users = user.page(1)                    # using kaminari pagination. first_page_of_users.each |user|   assert_select 'a[href=?]', user_path(user) end 

these tests fail error message such as:

expected @ least 1 element matching "a[href="/users/1"]", found 0.. 

i added puts @response.body tests see code responded with.

for users included in response body has correct hrefs, such href="/users/75938613". however, numbers behind /users/ higher, , "users1" indeed not present (not url not present entire record isn't on page). if ensure there few fixtures no pagination applies, tests pass. makes me feel if pagination order first_page_of_users = user.page(1) applies differs order in records first_page_of_users.each |user| assert_select 'a[href=?]', user_path(user) expects...

what causing error? applies different pages , models of app.


update: model when try

organization.all.each |org|   puts @response.body   assert_select 'a[href=?]', organization_path(org) end 

i error:

expected @ least 1 element matching "a[href="/organizations/fix0"]", 

the organization name "fix0" not present @ in body reponds with. (shortened) fixtures below , confirm there should not organization name. idea what's going on?

one:   name: abcd   activated: true   activated_at: 2015-04-16 11:38:53  two:   name: efgh   activated: true   activated_at: 2015-04-16 11:38:53  <% 35.times |n| %> organization_<%= n %>:   name: <%="fix#{n}" %>   activated: true   activated_at: <%= time.zone.now %> <% end %> 

when integration testing, it's important keep track of should show , test that. because have many records first page in case, land on later pages cause failing test. suspect, should verify first page of results present:

organization.order('organizations.name','desc').page(1).each |organization|      assert_select 'a[href=?]', organization_path(organization) end 

i recommend keeping smaller data set testing, because in case should 'get' page 2 in test , assertions above 'page(2)' well. means integration test has issue 2 requests (plus setup may need) , check results, , making habit of can slow down suite.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -