From 9286cee4253cd147c4f1ad5c46787bd32c51fb60 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 15 Apr 2013 11:18:16 -0400 Subject: [PATCH] multi checkbox finder --- lib/semantic_rails_view_helpers/capybara.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/semantic_rails_view_helpers/capybara.rb b/lib/semantic_rails_view_helpers/capybara.rb index 6c11a42..db2297d 100644 --- a/lib/semantic_rails_view_helpers/capybara.rb +++ b/lib/semantic_rails_view_helpers/capybara.rb @@ -21,7 +21,12 @@ def has_attribute?(name, value) end def find_input(name, additional_search = '') - find("[name$='[#{name}]']#{additional_search}") + search = "[#{name}]" + if name[/\[\]$/] + search = "[#{name[0..-3]}][]" + end + + find("[name$='#{search}']#{additional_search}") end def set_input(name, value) @@ -34,7 +39,16 @@ def set_input(name, value) when true, false find_input(name, '[type=checkbox]') else - find_input(name) + begin + find_input(name) + rescue Capybara::ElementNotFound + search_value = value + search_value = value.id if value.respond_to?(:id) + + result = find_input("#{name}_ids[]", "[value='#{search_value}']") + value = true + result + end end case input.tag_name.downcase