Fix support for passing in an ActiveRecord model to within (which uses dom_id) LB/BH
This commit is contained in:
parent
862471476f
commit
b51ba029db
@ -11,21 +11,6 @@ module Webrat
|
|||||||
@integration_session = session
|
@integration_session = session
|
||||||
end
|
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
|
def doc_root
|
||||||
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
||||||
end
|
end
|
||||||
|
@ -5,5 +5,21 @@ module ActionController #:nodoc:
|
|||||||
IntegrationTest.class_eval do
|
IntegrationTest.class_eval do
|
||||||
include Webrat::Methods
|
include Webrat::Methods
|
||||||
include Webrat::Matchers
|
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
|
||||||
end
|
end
|
||||||
|
@ -40,4 +40,7 @@ class WebratController < ApplicationController
|
|||||||
render :text => params.to_json
|
render :text => params.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def within
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
3
spec/integration/rails/app/views/webrat/within.html.erb
Normal file
3
spec/integration/rails/app/views/webrat/within.html.erb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<div id="new_object">
|
||||||
|
<a href="/">Edit Object</a>
|
||||||
|
</div>
|
@ -12,6 +12,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||||||
webrat.before_redirect_form "/before_redirect_form", :action => "before_redirect_form"
|
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.redirect_to_show_params "/redirect_to_show_params", :action => "redirect_to_show_params"
|
||||||
webrat.show_params "/show_params", :action => "show_params"
|
webrat.show_params "/show_params", :action => "show_params"
|
||||||
|
webrat.within "/within", :action => "within"
|
||||||
|
|
||||||
webrat.root :action => "form"
|
webrat.root :action => "form"
|
||||||
end
|
end
|
||||||
|
@ -89,6 +89,23 @@ class WebratTest < ActionController::IntegrationTest
|
|||||||
assert_have_selector "h1"
|
assert_have_selector "h1"
|
||||||
end
|
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
|
# Firefox detects and prevents infinite redirects under Selenium
|
||||||
unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium'
|
unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium'
|
||||||
test "should detect infinite redirects" do
|
test "should detect infinite redirects" do
|
||||||
|
@ -83,28 +83,4 @@ describe Webrat::RailsAdapter do
|
|||||||
it "should provide a doc_root" do
|
it "should provide a doc_root" do
|
||||||
Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:doc_root)
|
Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:doc_root)
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user