diff --git a/lib/semantic_rails_view_helpers/capybara.rb b/lib/semantic_rails_view_helpers/capybara.rb index e5f52c5..028457b 100644 --- a/lib/semantic_rails_view_helpers/capybara.rb +++ b/lib/semantic_rails_view_helpers/capybara.rb @@ -67,5 +67,34 @@ def dont_find_object(object) end def find_object(object) - find("[data-id='#{object.id}']") + find(object_matcher(object)) +end + +def within_object(object, &block) + within(object_matcher(object), &block) +end + +def object_matcher(object) + "[data-id='#{object.id}'][data-type='#{object.class}']" +end + +def within_object_of_type(klass, &block) + within("[data-type='#{klass}']", &block) +end + +def within_any(search, &block) + case search + when Class + search = "[data-type='#{search}']" + end + + all(search).each_with_index do |node, index| + begin + within("#{search}:eq(#{index + 1})", &block) + return true + rescue RSpec::Expectations::ExpectationNotMetError + end + end + + false end diff --git a/lib/semantic_rails_view_helpers/view_helpers.rb b/lib/semantic_rails_view_helpers/view_helpers.rb index 7c68702..cd860d9 100644 --- a/lib/semantic_rails_view_helpers/view_helpers.rb +++ b/lib/semantic_rails_view_helpers/view_helpers.rb @@ -42,7 +42,15 @@ module SemanticRailsViewHelpers end def li_for(object, options = {}, &block) - content_tag(:li, capture(&block), options.merge('data-id' => object.id)) + type = begin + if object.respond_to?(:model) + object.model.class + else + object.class + end + end + + content_tag(:li, capture(&block), options.merge('data-type' => type, 'data-id' => object.id)) end end end