ruby on rails - How to test ransack output? Rspec -


i`ve got little problem here , hope me. have list of hotels in table. here view:

<% provide(:title, 'list of hotels') %> <h1>list of hotels</h1>  <table>   <tr>     <th><%= sort_link @search, :name, "name" %></th>     <th><%= sort_link @search, :breakfast, "breakfast" %></th>     <th><%= sort_link @search, :price_for_room, "price room" %></th>     <th><%= sort_link @search, :star_rating, "star rating" %></th>     <th><%= sort_link @search, :average_rating, "average rating" %></th>     <th><%= sort_link @search, :aasm_state, "state" %></th>   </tr>   <% @hotels.each |hotel| %>   <tr>     <td><%= link_to ""+hotel.name, controller: "hotels", action: "show", id: hotel %></td>     <td><%= hotel.breakfast %></td>     <td><%= hotel.price_for_room %></td>     <td><%= hotel.star_rating %></td>     <td><%= hotel.average_rating %></td>     <td><%= hotel.aasm_state %></td>   </tr>   <% end %> </table> 

and added ability users sort them name, price etc. ransack gem. problem have no idea how test output. wrote tests have no idea next. spec file: require 'spec_helper'

describe "admin"      ...      { expect(page).to have_link("name") }     { expect(page).to have_link("breakfast") }     { expect(page).to have_link("price room") }     { expect(page).to have_link("star rating") }     { expect(page).to have_link("average rating") }     { expect(page).to have_link("state") }      ... 

how test sorting , possibly filtering results? thanks.

rails 4.0.8 ruby 1.9.3p551 gem ransack latest version on moment

a test has 3 phases: setup, execute, assert.

the setup phase create hotels, have different properties aspect testing.

the execute phase click on link sorts hotels.

the assert phase inspect elements on page verify they're in correct order.

so end this:

# setup (using factorygirl or similar) # note how these intentionally not sorted create(:hotel, name: "hotel c") create(:hotel, name: "hotel a") create(:hotel, name: "hotel b")  # execute visit hotels_path click_link "name"  # assert hotel_names = page.all("td.hotel-name").map(&:text) expect(hotel_names).to eq ["hotel a", "hotel b", "hotel c"] 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -