How can I write a capybara integration test with a form using jquery.selectize?
I\'d like to test a user entering a couple of values.
I created a helper that I mix in to my capybara feature specs:
module PageSteps
def fill_in_selectized(key, *values)
values.flatten.each do |value|
page.execute_script(%{
$('.#{key} .selectize-input input').val('#{value}');
$('##{key}').selectize()[0].selectize.createItem();
})
end
end
end
And here's an example of how it is used:
# Single value
fill_in_selectized('candidate_offices', 'Santa Monica')
# Multiple values
fill_in_selectized('candidate_offices', ['San Francisco', 'Santa Monica'])
The first parameter is a "key" and works in our application given our markup. Depending on your markup, you might need a little tweak. This requires a Javascript enabled capybara driver (we use poltergeist).