Skip to content

Instantly share code, notes, and snippets.

@ogredude
Created March 8, 2012 20:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ogredude/2003109 to your computer and use it in GitHub Desktop.
Save ogredude/2003109 to your computer and use it in GitHub Desktop.
module Helpers
def sign_in(user)
@user_session = UserSession.create user
end
def fill_in_autocomplete(selector, value)
page.execute_script %Q{$('#{selector}').val('#{value}').keydown()}
end
def choose_autocomplete(text)
find('ul.ui-autocomplete').should have_content(text)
page.execute_script("$('.ui-menu-item:contains(\"#{text}\")').find('a').trigger('mouseenter').click()")
end
def wait_for_animation
wait_until do
page.evaluate_script('$(":animated").length') == 0
end
end
end
# Here's how to use the autocomplete, and how to avoid triggering the autocomplete.
context "User chooses new company" do
before(:each) do
visit new_user_path
fill_in_autocomplete "#user_dealership_attributes_company_attributes_name", "New company"
choose_autocomplete "New Company"
wait_for_animation
end
it "should expose new company and dealership fields" do
page.find(".company_info_fields").should be_visible
page.find("#new_dealership_fields").should be_visible
end
end
context "User does not use autocomplete" do
it "should expose new company and dealership fields" do
visit new_user_path
page.execute_script %Q{$("#user_dealership_attributes_company_attributes_name").val("New company").change()}
wait_for_animation
page.find(".company_info_fields").should be_visible
page.find("#new_dealership_fields").should be_visible
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment