more cool stuff

This commit is contained in:
John Bintz 2012-11-30 21:44:02 -05:00
parent 40b24799af
commit e05a88d340
2 changed files with 39 additions and 2 deletions

View File

@ -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

View File

@ -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