Merge branch 'master' of github.com:johnbintz/semantic_rails_view_helpers

This commit is contained in:
John Bintz 2012-12-06 11:03:50 -05:00
commit d288d62f9e
2 changed files with 78 additions and 6 deletions

View File

@ -8,6 +8,18 @@ def find_attribute(name, value = nil)
attribute
end
def dont_find_attribute(name, value = nil, &block)
dont_find_wrap("attribute #{name}") do
find_attribute(name, value, &block)
end
end
def has_attribute?(name, value)
attribute = find_attribute(name)
attribute.text == value
end
def find_input(name)
find("[name$='[#{name}]']")
end
@ -22,7 +34,11 @@ def set_input(name, value)
case input.tag_name.downcase
when 'select'
input.find("option[value='#{value}']").select_option
begin
input.find("option[value='#{value}']").select_option
rescue Capybara::ElementNotFound
input.find("option[text()='#{value}']").select_option
end
else
input.set(value)
end
@ -54,18 +70,62 @@ module Capybara
end
end
def dont_find(search)
find(search)
def dont_find_wrap(search)
yield
raise Capybara::ElementFound.new(search)
rescue Capybara::ElementNotFound
true
end
def dont_find(search)
dont_find_wrap(search) do
find(search)
end
end
def dont_find_object(object)
dont_find("[data-id='#{object.id}']")
case object
when Class
dont_find("[data-type='#{object}']")
else
dont_find("[data-id='#{object.id}']")
end
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
def refind_object(object)
object.class.find(object.id)
end

View File

@ -38,6 +38,10 @@ module SemanticRailsViewHelpers
action = nil
end
if action == :show
action = nil
end
options = Hash[options.collect { |k, v| [ k, CGI.escapeHTML(v.to_s) ] }]
route = model
@ -47,7 +51,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