From c4387c9f43f7c0625e19a3f5d90377f012fdbb69 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 25 Jan 2013 08:43:49 -0500 Subject: [PATCH] refine some finders --- lib/semantic_rails_view_helpers/capybara.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/semantic_rails_view_helpers/capybara.rb b/lib/semantic_rails_view_helpers/capybara.rb index 2120cf4..3526179 100644 --- a/lib/semantic_rails_view_helpers/capybara.rb +++ b/lib/semantic_rails_view_helpers/capybara.rb @@ -106,11 +106,17 @@ def within_object(object, &block) end def object_matcher(object) - "[data-id='#{object.id}'][data-type='#{object.class}']" + if object.respond_to?(:id) + match = "[data-type='#{object.class}'][data-id='#{object.id}']" + elsif object.kind_of?(::Class) + match = "[data-type='#{object}']" + end + + match end def within_object_of_type(klass, &block) - within("[data-type='#{klass}']", &block) + within_object(klass, &block) end def within_any(search, &block)