Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Fixed bug where Scope was creating a new DOM rather than re-using the…
Browse files Browse the repository at this point in the history
… existing DOM. [#105 state:resolved]
  • Loading branch information
zdennis committed Jan 17, 2009
1 parent ebd9d8e commit cdf9908
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
2 changes: 2 additions & 0 deletions History.txt
Expand Up @@ -68,6 +68,8 @@

* Bug fixes

* Fixed bug where Scope was creating a new DOM rather than re-using the existing DOM.
[#105] (Zach Dennis)
* Support Rails > v2.2 by using ActionController::RequestParser for param parsing [#107]
(Marcello Nuccio)
* Raise a Webrat::NotFoundError if the scope passed to #within doesn't exist [#90]
Expand Down
14 changes: 2 additions & 12 deletions lib/webrat/core/scope.rb
Expand Up @@ -31,7 +31,7 @@ def initialize(session, &block) #:nodoc:
@session = session
instance_eval(&block) if block_given?

if @selector && scoped_element.nil?
if @selector && scoped_dom.nil?
raise Webrat::NotFoundError.new("The scope was not found on the page: #{@selector.inspect}")
end
end
Expand Down Expand Up @@ -316,17 +316,7 @@ def page_dom #:nodoc:
return dom
end

def scoped_dom #:nodoc:
source = Webrat::XML.to_html(scoped_element)

if @session.xml_content_type?
Webrat::XML.xml_document(source)
else
Webrat::XML.html_document(source)
end
end

def scoped_element
def scoped_dom
Webrat::XML.css_at(@scope.dom, @selector)
end

Expand Down
46 changes: 45 additions & 1 deletion spec/public/within_spec.rb
Expand Up @@ -59,7 +59,6 @@
end

it "should work when the scope is inside the form" do
pending "needs bug fix" do
with_html <<-HTML
<html>
<form id="form2" action="/form2">
Expand All @@ -77,6 +76,51 @@
end

submit_form "form2"
end

it "should work when the form submission occurs inside a scope" do
with_html <<-HTML
<html>
<body>
<div>
<form id="form2" action="/form2">
<label for="email">Email</label><input id="email" type="text" class="email2" name="email" />
<input type="submit" value="Add" />
</form>
</div>
</body>
</html>
HTML

webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com")
within "form[@action='/form2']" do
fill_in "Email", :with => "test@example.com"
click_button "Add"
end
end

it "should work when there are multiple forms with the same label text" do
with_html <<-HTML
<html>
<body>
<div>
<form id="form1" action="/form1">
<label for="email1">Email</label><input id="email1" type="text" class="email1" name="email1" />
<input type="submit" value="Add" />
</form>
<form id="form2" action="/form2">
<label for="email2">Email</label><input id="email2" type="text" class="email2" name="email2" />
<input type="submit" value="Add" />
</form>
</div>
</body>
</html>
HTML

webrat_session.should_receive(:get).with("/form2", "email2" => "test@example.com")
within "form[@action='/form2']" do
fill_in "Email", :with => "test@example.com"
click_button "Add"
end
end

Expand Down

0 comments on commit cdf9908

Please sign in to comment.