Commit 25018e09d903cb9a6cb064ea447888fe2e1c1d39

Authored by Rodrigo Souto
1 parent 6cb08f2f

macro: fix attributes after nokogiri change and write some tests

lib/noosfero/plugin/macro.rb
... ... @@ -33,9 +33,9 @@ class Noosfero::Plugin::Macro
33 33 end
34 34  
35 35 def attributes(macro)
36   - macro.attributes.to_hash.
  36 + macro.attributes.
37 37 select {|key, value| key[0..10] == 'data-macro-'}.
38   - inject({}){|result, a| result.merge({a[0][11..-1] => a[1]})}.
  38 + inject({}){|result, a| result.merge({a[0][11..-1] => a[1].value})}.
39 39 with_indifferent_access
40 40 end
41 41  
... ...
test/unit/macro_test.rb 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class MacroTest < ActiveSupport::TestCase
  4 +
  5 + class Plugin1 < Noosfero::Plugin
  6 + end
  7 +
  8 + class Plugin1::Macro < Noosfero::Plugin::Macro
  9 + def parse(params, inner_html, source)
  10 + "Testing: #{inner_html}"
  11 + end
  12 + end
  13 +
  14 + MACRO = "<div class='macro nonEdit' data-macro='#{Plugin1::Macro.identifier}' data-macro-attr1='1' data-macro-attr2='2' data-macro-attr3='3'>It works!</div>"
  15 +
  16 + def setup
  17 + @macro = Plugin1::Macro.new
  18 + @macro_element = Nokogiri::HTML(MACRO).css('.macro').first
  19 + end
  20 +
  21 + attr_reader :macro, :macro_element
  22 +
  23 + should 'access plugin' do
  24 + assert_equal Plugin1, Plugin1::Macro.plugin
  25 + end
  26 +
  27 + should 'parse attributes' do
  28 + attributes = macro.attributes(macro_element)
  29 + assert_equal '1', attributes['attr1']
  30 + assert_equal '2', attributes['attr2']
  31 + assert_equal '3', attributes['attr3']
  32 + end
  33 +
  34 + should 'convert macro' do
  35 + assert_equal 'Testing: It works!', macro.convert(macro_element, nil)
  36 + end
  37 +end
... ...