There is a column in my table that stores the active and inactive value in the STATUS column. I want to validate if when searching for the ACTIVE status if there are no INACTIVE records. How do I scan this column and use expect to validate that no INACTIVE value has appeared? And if it doesn't appear, I present a message like: puts 'no inactive record found in the list". i tried this: page.all('.tvGrid tr').each do |tr| next unless tr.has_css?('td.Status', text: "ATIVO")
<div style="display:table-cell;">
<table width="100%" >
<tbody>
<tr>
<th colspan="1" >Id</th>
<th colspan="1" >Código</th>
<th colspan="1" >Descrição</th>
<th colspan="1" >Centro Operacional</th>
<th colspan="1" >Status</th>
</tr>
<tr style="cursor:pointer;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'stvSetorAbastecimentos','1cfd','Modify',0,'','','');" >
<td align="right" valign="center" nowrap="">21</td>
<td valign="center" align="left" >02</td>
<td valign="center" align="left" >BARRETO PIRES</td>
<td align="left" valign="center" nowrap="">Águas de Niterói/GSO</td>
<td valign="center" align="left" >ATIVO</td>
</tr>
<tr style="cursor:pointer;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'stvSetorAbastecimentos','1cfd','Modify',1,'','','');" >
<td align="right" valign="center" nowrap="">41</td>
<td valign="center" align="left" >03</td>
<td valign="center" align="left" >CAFUBÁ PIRATININGA</td>
<td align="left" valign="center" nowrap="">Águas de Niterói/GSO</td>
<td valign="center" align="left" >ATIVO</td>
</tr>
<tr style="cursor:pointer;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'stvSetorAbastecimentos','1cfd','Modify',2,'','','');" >
<td align="right" valign="center" nowrap="">42</td>
<td valign="center" align="left" >04</td>
<td valign="center" align="left" >CAVALÃO</td>
<td align="left" valign="center" nowrap="">Águas de Niterói/GSO</td>
<td valign="center" align="left" >ATIVO</td>
</tr>
</tr>
</tbody>
</table>
</div>
CodePudding user response:
I want to validate if when searching for the ACTIVE status if there are no INACTIVE records.
Since you want to test the data, not how it is formatted, this is better done as a controller test.
You can use rails-controller-testing
to test what is passed to your views. assigns
gives you access to instance variables which have been passed to your views.
test "should show only active records" do
# Call the appropriate URL with the appropriate parameters
get search_url, params: { active: true }
# Check the right template is rendered
assert_template 'records/index'
# Check the correct data is passed to the view.
assert_equal Record.active, assigns(:records)
end