Skip to content

Commit

Permalink
line_graph_tag and test
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmeissl committed Apr 27, 2010
1 parent b892f20 commit 1914ec3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/grafico/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ def graph_tag(graph_type, element, data, options = {})
args << options.to_json unless options.empty?
javascript_tag "var #{options[:variable_name] || (element + graph_type)} = new Grafico.#{graph_type}($('#{element}'), #{args.join});"
end

def line_graph_tag(element, data, options = {})
graph_tag 'LineGraph', element, data, options
end
end
end
3 changes: 3 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
require 'action_controller'

class Test::Unit::TestCase
def wrap_as_javascript(javascript)
"<script type=\"text/javascript\">\n//<![CDATA[\n#{javascript}\n//]]>\n</script>"
end
end

class TestHelper
Expand Down
6 changes: 5 additions & 1 deletion test/test_grafico.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def test_setup
end

def test_graph_tag
assert_equal @helper.graph_tag('FooGraph', 'my_element', [1, 2, 3]), "<script type=\"text/javascript\">\n//<![CDATA[\nvar my_elementFooGraph = new Grafico.FooGraph($('my_element'), [1,2,3]);\n//]]>\n</script>"
assert_equal @helper.graph_tag('FooGraph', 'my_element', [1, 2, 3]), wrap_as_javascript("var my_elementFooGraph = new Grafico.FooGraph($('my_element'), [1,2,3]);")
end

def test_line_graph_tag
assert_equal @helper.line_graph_tag('my_element', [1, 2, 3]), wrap_as_javascript("var my_elementLineGraph = new Grafico.LineGraph($('my_element'), [1,2,3]);")
end
end

0 comments on commit 1914ec3

Please sign in to comment.