Permalink
Browse files

Fix support for passing in an ActiveRecord model to within (which use…

…s dom_id) LB/BH
  • Loading branch information...
1 parent 8624714 commit b51ba029db89ba8f1b479d31fc6cf14035503b45 @brynary brynary committed Sep 18, 2009
@@ -11,21 +11,6 @@ def initialize(session)
@integration_session = session
end
- # The Rails version of within supports passing in a model and Webrat
- # will apply a scope based on Rails' dom_id for that model.
- #
- # Example:
- # within User.last do
- # click_link "Delete"
- # end
- def within(selector_or_object, &block)
- if selector_or_object.is_a?(String)
- super
- else
- super('#' + dom_id(selector_or_object), &block)
- end
- end
-
def doc_root
File.expand_path(File.join(RAILS_ROOT, 'public'))
end
@@ -5,5 +5,21 @@ module ActionController #:nodoc:
IntegrationTest.class_eval do
include Webrat::Methods
include Webrat::Matchers
+
+ # The Rails version of within supports passing in a model and Webrat
+ # will apply a scope based on Rails' dom_id for that model.
+ #
+ # Example:
+ # within User.last do
+ # click_link "Delete"
+ # end
+ def within(selector_or_object, &block)
+ if selector_or_object.is_a?(String)
+ super
+ else
+ super('#' + RecordIdentifier.dom_id(selector_or_object), &block)
+ end
+ end
+
end
end
@@ -40,4 +40,7 @@ def show_params
render :text => params.to_json
end
+ def within
+ end
+
end
@@ -0,0 +1,3 @@
+<div id="new_object">
+ <a href="/">Edit Object</a>
+</div>
@@ -12,6 +12,7 @@
webrat.before_redirect_form "/before_redirect_form", :action => "before_redirect_form"
webrat.redirect_to_show_params "/redirect_to_show_params", :action => "redirect_to_show_params"
webrat.show_params "/show_params", :action => "show_params"
+ webrat.within "/within", :action => "within"
webrat.root :action => "form"
end
@@ -89,6 +89,23 @@ class WebratTest < ActionController::IntegrationTest
assert_have_selector "h1"
end
+ test "should accept an Object argument to #within and translate using dom_id" do
+ webrat.simulate do
+ visit within_path
+
+ object = Object.new
+ def object.id
+ nil
+ end
+
+ within(object) do
+ click_link "Edit Object"
+ end
+
+ assert_contain "Webrat Form"
+ end
+ end
+
# Firefox detects and prevents infinite redirects under Selenium
unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium'
test "should detect infinite redirects" do
@@ -83,28 +83,4 @@
it "should provide a doc_root" do
Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:doc_root)
end
-
- it "should accept an ActiveRecord argument to #within and translate to a selector using dom_id" do
- pending "Move this to spec/public/within_spec.rb"
-
- body = <<-HTML
- <a href="/page1">Edit</a>
- <div id="new_object">
- <a href="/page2">Edit</a>
- </div>
- HTML
-
- response = mock("response", :body => body, :headers => {}, :code => 200)
- @integration_session.stub!(:response => response)
- @integration_session.should_receive(:get).with("/page2", {}, nil)
-
- rails_session = Webrat::RailsAdapter.new(@integration_session)
-
- object = Object.new
- object.stub!(:id => nil)
-
- rails_session.within(object) do
- rails_session.click_link 'Edit'
- end
- end
end

0 comments on commit b51ba02

Please sign in to comment.