From ef6874c8557bd5d1bc12ff1cf9f3045ee8815738 Mon Sep 17 00:00:00 2001 From: Damian Janowski Date: Mon, 12 Apr 2010 17:35:12 -0300 Subject: [PATCH] Allow submitting forms by CSS selectors too. Priority is given to selecting by ID for backwards compatibility. Also add pending `submit_form` specs. --- lib/webrat/core/locators/form_locator.rb | 2 +- spec/public/submit_form_spec.rb | 53 +++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/webrat/core/locators/form_locator.rb b/lib/webrat/core/locators/form_locator.rb index 43707d2..5c655e7 100644 --- a/lib/webrat/core/locators/form_locator.rb +++ b/lib/webrat/core/locators/form_locator.rb @@ -10,7 +10,7 @@ module Webrat end def form_element - @dom.css("#" + @value).first + @dom.css("#" + @value).first || @dom.css(@value).first end end diff --git a/spec/public/submit_form_spec.rb b/spec/public/submit_form_spec.rb index 5b508eb..8270310 100644 --- a/spec/public/submit_form_spec.rb +++ b/spec/public/submit_form_spec.rb @@ -1,5 +1,56 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "submit_form" do - it "needs specs" + it "should submit forms by ID" do + with_html <<-HTML + +
+ + +
+ + HTML + + webrat_session.should_receive(:get).with("/form1", "email" => "test@example.com") + + fill_in "Email", :with => "test@example.com" + submit_form "form1" + end + + it "should submit forms by CSS" do + with_html <<-HTML + +
+ + +
+ + HTML + + webrat_session.should_receive(:get).with("/form1", "email" => "test@example.com") + + fill_in "Email", :with => "test@example.com" + submit_form "form[action='/form1']" + end + + it "should give priority to selecting forms by ID" do + with_html <<-HTML + +
+ + +
+ +
+ + +
+ + HTML + + webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com") + + fill_in "Another email", :with => "test@example.com" + submit_form "form" + end end