Skip to content

Instantly share code, notes, and snippets.

@bryanchriswhite
Last active June 19, 2017 10:22
Show Gist options
  • Save bryanchriswhite/5062454 to your computer and use it in GitHub Desktop.
Save bryanchriswhite/5062454 to your computer and use it in GitHub Desktop.
<!--app/views/bills/index.html.erb-->
<table class="bills-table">
<thead>
<tr>
<th>Bill Number</th>
<th>Name 1</th>
<th>Name 2</th>
<th>Map Number</th>
</tr>
</thead>
<tbody>
<%- @bills.each do |bill| %>
<tr data-link=<%= bill_path bill %>>
<td><%= bill.bill_number %></td>
<td><%= bill.name_1 %></td>
<td><%= bill.name_2 %></td>
<td><%= bill.map_number %></td>
</tr>
<%- end %>
</tbody>
</table>
/Users/bwhite/.rvm/rubies/ruby-1.9.3-p286/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/bwhite/.rvm/gems/ruby-1.9.3-p286@taxes/bin/rspec /Users/bwhite/Projects/Taxes/spec/features/selecting_a_bill_spec.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter
Testing started at 11:09 PM ...
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
Rack::File headers parameter replaces cache_control after Rack 1.5.
expected there to be text /amount due:.*\$1234\.56/i in "Bill Number Name 1 Name 2 Map Number 1 smith 1 1 jones 11-11-111-11 2 smith 2 2 jones 11-11-111-12 3 smith 3 3 jones 11-11-111-13 4 smith 4 4 jones 11-11-111-14 5 smith 5 5 jones 11-11-111-15 6 smith 6 6 jones 11-11-111-16 7 smith 7 7 jones 11-11-111-17 8 smith 8 8 jones 11-11-111-18 9 smith 9 9 jones 11-11-111-19 10 smith 10 10 jones 11-11-111-110 121212 smithie 11 jones 11-11-111-111"
./spec/features/selecting_a_bill_spec.rb:28:in `block (4 levels) in <top (required)>'
expected there to be text /amount paid:.*\$9876.54/i in "Bill Number Name 1 Name 2 Map Number 21 smith 21 23 jones 11-11-111-123 22 smith 22 24 jones 11-11-111-124 23 smith 23 25 jones 11-11-111-125 24 smith 24 26 jones 11-11-111-126 25 smith 25 27 jones 11-11-111-127 26 smith 26 28 jones 11-11-111-128 27 smith 27 29 jones 11-11-111-129 28 smith 28 30 jones 11-11-111-130 29 smith 29 31 jones 11-11-111-131 30 smith 30 32 jones 11-11-111-132 121212 smithie 33 jones 11-11-111-133"
./spec/features/selecting_a_bill_spec.rb:42:in `block (4 levels) in <top (required)>'
4 examples, 2 failures, 2 passed
Finished in 12.815969 seconds
#spec/support/features/search_helper.rb
module Features
module SearchHelpers
def search_for_bill query, search_filter = :automatic
search_for_bill_by_radio(query, search_filter) || search_for_bill_by_select(query, search_filter)
end
def search_for_bill_by_radio query, search_filter
visit search_path
begin
choose "search_filter_#{search_filter}"
rescue
puts "WARNING rescuing: #{$!}"
false
else
fill_in :q, with: query
click_button 'Search'
true
end
end
def search_for_bill_by_select query, option
visit search_path
select option.to_s.humanize.titleize, from: :others
fill_in :q, with: query
click_button 'Search'
true
end
#TODO: create bills that should NOT match
shared_examples_for 'searches with no results' do |filter|
it 'shows the search page with a message' do
search_for_bill 'nonexistant', filter
page.should have_text(/no.*bills.*found/)
end
end
def create_default_filters
names = [:bill_number, :map_number, :name_1, :name_1_or_2]
descriptions = ['Bill Number matches exactly', 'Map Number begins with', 'Name 1 begins with', 'Name 1 or Name 2 contains']
queries = ['{bill_number: :q}', 'map_number ilike :q%', 'name_1 ilike :q%', 'to_tsvector(name_1) @@ to_tsquery(:q) OR to_tsvector(name_2) @@ to_tsquery(:q)']
ordinals = [1, 2, 3, 4]
primarys, enableds, hashes = [], [], []
4.times { primarys << true && enableds << true }
keys = [:names, :descriptions, :queries, :ordinals, :primarys]
4.times { |i| hashes << Hash[keys.map { |k| k.to_s.singularize.to_sym }.zip(keys.map { |k| eval(k.to_s)[i] })] }
hashes.each { |h| FactoryGirl.create :filter, h }
end
end
end
#spec/features/selecting_a_bill_spec.rb
require 'spec_helper.rb'
describe 'Selecting an individual bill', js: true do
context 'from a list of bills' do
before :each do
create_default_filters
FactoryGirl.create_list :bill, 10
end
shared_examples_for 'individual bills' do
it 'shows the individual bills information' do
page.find('td', text: 'smithie').click
#save_and_open_page
page.should have_content(/bill number.*121212/i)
page.should have_content(/name 1.*smithie/i)
end
end
context 'if the bill is due' do
before :each do
FactoryGirl.create :bill, name_1: 'smithie', bill_number: 121212, status: 'due'
search_for_bill 'smith', :name_1
page.all('td').any? { |e| e.text.match /.*smith.*/ }.should be true
end
it 'should show the current amount due' do
page.should have_content(/amount due:.*\$1234\.56/i)
end
it_behaves_like 'individual bills'
end
context 'if the bill is paid' do
before :each do
FactoryGirl.create :bill, name_1: 'smithie', bill_number: 121212, status: 'paid'
search_for_bill 'smith', :name_1
page.all('td').any? { |e| e.text.match /.*smith.*/ }.should be true
end
it 'should show the amount that was paid' do
page.should have_content(/amount paid:.*\$9876.54/i)
end
it_behaves_like 'individual bills'
end
end
end
<!--app/views/bills/show.html.erb-->
<table>
<tbody>
<tr>
<td>Bill Number:</td>
<td><%= @bill.bill_number %></td>
</tr>
<tr>
<td>Map Number:</td>
<td><%= @bill.map_number %></td>
</tr>
<tr>
<td>Name 1:</td>
<td><%= @bill.name_1 %></td>
</tr>
<tr>
<td>Name 2:</td>
<td><%= @bill.name_2 %></td>
</tr>
<tr>
<td>Address:</td>
<td><%= @bill.address %></td>
</tr>
<tr>
<td>Location:</td>
<td><%= @bill.location %></td>
</tr>
<tr>
<td>City, State Zip:</td>
<td><%= @bill.city_st_zip %></td>
</tr>
<tr>
<td>Comment:</td>
<td><%= @bill.comment %></td>
</tr>
<tr>
<td>PVA Account Number:</td>
<td><%= @bill.pva_account_number %></td>
</tr>
<tr>
<td>District:</td>
<td><%= @bill.district %></td>
</tr>
<tr>
<td>Bill Date:</td>
<td><%= @bill.date %></td>
</tr>
<tr>
<td>Bill Value:</td>
<td><%= @bill.face_value %></td>
</tr>
<tr>
<td>Description:</td>
<td><%= @bill.description %></td>
</tr>
<tr>
<td>PVA Account Suffix</td>
<td><%= @bill.pva_suffix %></td>
</tr>
</tbody>
</table>
<div>
<h2>If Paid By:</h2>
<table>
<tr>
<td>date</td>
<td>value</td>
</tr>
<tr>
<td>date</td>
<td>value</td>
</tr>
<tr>
<td>date</td>
<td>value</td>
</tr>
<tr>
<td>date</td>
<td>value</td>
</tr>
</table>
</div>
<div>
<h1>Status: <%= @bill.status.titleize %></h1>
<%- if @bill.is_paid? %>
<table>
<tr>
<td>Amount Paid:</td>
<td></td>
</tr>
<tr>
<td>Date Paid:</td>
<td></td>
</tr>
<tr>
<td>Pay Period:</td>
<td></td>
</tr>
</table>
<%- else %>
<h2>Amount Due: $<%= @bill.amount_due_today %></h2>
<%- end %>
</div>
@monsteronfire
Copy link

This is from a few years ago, but just wanted to ask if you ever managed to solve this? (Found this gist on thoughtbot/capybara-webkit#207)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment