Commit 80fe1db0b1e2848fa36ab5be6084e3fb6c3f1876

Authored by Braulio Bhavamitra
1 parent 6e6793d8

rails4: simplify and fix find_tag_in_string

test/test_helper.rb
@@ -141,20 +141,8 @@ class ActiveSupport::TestCase @@ -141,20 +141,8 @@ class ActiveSupport::TestCase
141 141
142 def find_tag_in_string text, options 142 def find_tag_in_string text, options
143 doc = Nokogiri::HTML.fragment text 143 doc = Nokogiri::HTML.fragment text
144 - tag = doc.css(options[:tag]).first  
145 - return unless tag  
146 - content = tag.text.strip  
147 -  
148 - attributes = {}; tag.attributes.each do |a, v|  
149 - a = a.to_sym  
150 - next unless options[:attributes].has_key? a  
151 - attributes[a] = v.value  
152 - end if options[:attributes].present?  
153 -  
154 - ret = true  
155 - ret &&= options[:attributes].blank? || attributes == options[:attributes]  
156 - ret &&= options[:content].blank? || content == options[:content]  
157 - ret 144 + tag = doc.css("#{options[:tag]}#{options[:attributes].map{ |a, v| "[#{a}=\"#{v}\"]" }.join}").first
  145 + tag
158 end 146 end
159 147
160 def assert_tag_in_string(text, options) 148 def assert_tag_in_string(text, options)
test/unit/cms_helper_test.rb
@@ -10,9 +10,9 @@ class CmsHelperTest < ActionView::TestCase @@ -10,9 +10,9 @@ class CmsHelperTest < ActionView::TestCase
10 10
11 should 'show default options for article' do 11 should 'show default options for article' do
12 result = options_for_article(build(RssFeed, :profile => Profile.new)) 12 result = options_for_article(build(RssFeed, :profile => Profile.new))
13 - assert_match /id="article_published_true" name="article\[published\]" type="radio" value="true"/, result  
14 - assert_match /id="article_published_false" name="article\[published\]" type="radio" value="false"/, result  
15 - assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result 13 + assert_tag_in_string result, tag: 'input', attributes: {id: 'article_published_true', name:'article[published]', type: 'radio', value: 'true'}
  14 + assert_tag_in_string result, tag: 'input', attributes: {id: 'article_published_false', name:'article[published]', type: 'radio', value: 'false'}
  15 + assert_tag_in_string result, tag: 'input', attributes: {id: 'article_accept_comments', name:'article[accept_comments]', type: 'checkbox', value: '1'}
16 end 16 end
17 17
18 should 'show custom options for blog' do 18 should 'show custom options for blog' do