Created
March 8, 2012 20:07
-
-
Save ogredude/2003109 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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