I have the following form
<%= form_for(@route, :html => {:class => "form-horizontal", :role => 'form'}) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="form-group">
<input type="text" name="route_origin_input" id="route_origin_input" placeholder="From" onFocus="geolocate(); autocompleteLocation(this,route_origin)" class="form-control" />
<%= f.hidden_field :origin, class: "form-control" %>
</div>
<div class="form-group">
<input type="text" name="route_destination_input" id="route_destination_input" placeholder="Destination" onFocus="geolocate(); autocompleteLocation(this,route_destination)" class="form-control" />
<%= f.hidden_field :destination, class: "form-control" %>
</div>
<div class="form-group">
<% options = options_from_collection_for_select(@vehicleList, 'vehicle', 'vehicle') %>
<%= f.select :vehicle, options, class: "form-control" %>
</div>
<div class="form-group">
<%= f.date_field :departure_date, class: "form-control" %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary", id: "route_post" %>
<% end %>
and the following test
require 'spec_helper'
describe "Route pages" do
subject { page }
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
describe "route creation" do
before {
visit terminal_path
}
describe "with invalid information" do
it "should not create a route" do
expect { click_button "route_post" }.not_to change(Route, :count)
end
describe "error messages" do
before { click_button "route_post" }
it { should have_danger_message('Not Submitted') }
end
end
describe "with valid information", :js => true do
before do
fill_in 'route_origin_input', with: "Kimmage, Dublin, Ireland"
fill_in 'route_destination_input', with: "Kimmage, Dublin, Ireland"
fill_in 'route_departure_date', with: Time.now
select 'Car', :from => "route_vehicle"
end
it "should create a route" do
expect { click_button "route_post" }.to change(Route, :count).by(1)
end
end
end
end
For some reason the two text fields that I have added with html cannot be found by capybara
The error I receive is
Failure/Error: fill_in 'route_origin_input', with: "Kimmage, Dublin, Ireland" Capybara::ElementNotFound: Unable to find field "route_origin_input" # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/node/finders.rb:41:in
block in find' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/node/base.rb:84:in
synchronize' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/node/finders.rb:30:infind' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/node/actions.rb:56:in
fill_in' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/session.rb:676:inblock (2 levels) in <class:Session>' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in
block (2 levels) in ' # ./spec/requests/route_pages_spec.rb:30:in `block (4 levels) in '
I've used fill_in in other tests and the only difference I can see is that I have used standard html code in the form. These fields are used to process the info the user enters and then add the result to a hidden field that is part of my model, basically getting the result from Google maps api.
EDIT: Here is the HTML
<div class="form-group">
<input type="text" name="route_origin_input" id="route_origin_input" placeholder="From" onFocus="geolocate(); autocompleteLocation(this,route_origin)" class="form-control" />
<input class="form-control" id="route_origin" name="route[origin]" type="hidden" />
</div>