Merge branch 'master' of github.com:johnbintz/semantic_rails_view_helpers
This commit is contained in:
commit
d288d62f9e
|
@ -8,6 +8,18 @@ def find_attribute(name, value = nil)
|
||||||
attribute
|
attribute
|
||||||
end
|
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)
|
def find_input(name)
|
||||||
find("[name$='[#{name}]']")
|
find("[name$='[#{name}]']")
|
||||||
end
|
end
|
||||||
|
@ -22,7 +34,11 @@ def set_input(name, value)
|
||||||
|
|
||||||
case input.tag_name.downcase
|
case input.tag_name.downcase
|
||||||
when 'select'
|
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
|
else
|
||||||
input.set(value)
|
input.set(value)
|
||||||
end
|
end
|
||||||
|
@ -54,18 +70,62 @@ module Capybara
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def dont_find(search)
|
def dont_find_wrap(search)
|
||||||
find(search)
|
yield
|
||||||
|
|
||||||
raise Capybara::ElementFound.new(search)
|
raise Capybara::ElementFound.new(search)
|
||||||
rescue Capybara::ElementNotFound
|
rescue Capybara::ElementNotFound
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dont_find(search)
|
||||||
|
dont_find_wrap(search) do
|
||||||
|
find(search)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def dont_find_object(object)
|
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
|
end
|
||||||
|
|
||||||
def find_object(object)
|
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
|
end
|
||||||
|
|
|
@ -38,6 +38,10 @@ module SemanticRailsViewHelpers
|
||||||
action = nil
|
action = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if action == :show
|
||||||
|
action = nil
|
||||||
|
end
|
||||||
|
|
||||||
options = Hash[options.collect { |k, v| [ k, CGI.escapeHTML(v.to_s) ] }]
|
options = Hash[options.collect { |k, v| [ k, CGI.escapeHTML(v.to_s) ] }]
|
||||||
|
|
||||||
route = model
|
route = model
|
||||||
|
@ -47,7 +51,15 @@ module SemanticRailsViewHelpers
|
||||||
end
|
end
|
||||||
|
|
||||||
def li_for(object, options = {}, &block)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue