From 22aa73b3ee1491b5a1b4271b4f85b53c40f11ff3 Mon Sep 17 00:00:00 2001 From: Timm Date: Tue, 30 Jul 2013 14:45:12 +0200 Subject: Cleaned up SubstitutionContext class. --- .../lib/action_dispatch/testing/assertions/selector.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'actionpack/lib/action_dispatch/testing/assertions/selector.rb') diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 59bd6dc3b4..235934f5f1 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -427,25 +427,23 @@ module ActionDispatch @regexes = [] end - def add(regex) + def add_regex(regex) + return regex unless regex.is_a?(Regexp) @regexes.push(regex) - id_for(regex) + last_id.to_s # avoid implicit conversions of Fixnum to String end - def id_for(regex) - @regexes.index(regex).to_s # to_s to store it in selector string + def last_id + @regexes.count - 1 end def match(matches, attribute, id) - matches.find_all { |node| node[attribute] =~ @regexes[id.to_i] } + matches.find_all { |node| node[attribute] =~ @regexes[id] } end def substitute!(selector, values) - while selector.index(@substitute) - break if values.empty? - value = values.shift - value = add(value) if value.is_a?(Regexp) - selector.sub!(@substitute, value) + while !values.empty? && selector.index(@substitute) + selector.sub!(@substitute, add_regex(values.shift)) end selector end -- cgit v1.2.3