require File.dirname(__FILE__) + '/test_helper'
class ContentTagWithJavascriptEventsTest < Test::Unit::TestCase
include ActionView::Helpers::TagHelper
def setup
@controller = UnobtrusiveJavascriptControllerStub.new
@output = content_tag('div', 'my test div', {
:id => 'my_test_div', :class => 'some_class',
:onclick => 'alert("foo")',
:onmouseup => 'alert("foo")',
:onmousedown => 'alert("foo")',
:ondblclick => 'alert("foo")',
:onmouseover => 'alert("foo")',
:onmouseout => 'alert("foo")',
:onload => 'alert("foo")',
:onmousemove => 'alert("foo")'
})
end
def test_result_should_not_contain_any_inline_javascript_events
assert_equal '
my test div
', @output
end
def test_should_have_javascript_events_registered_as_unobtrusive
assert_equal 8, @controller.js_behaviours.size
assert @controller.js_behaviours.include?(:selector => '#my_test_div:click', :behaviour => 'alert("foo")')
assert @controller.js_behaviours.include?(:selector => '#my_test_div:mouseup', :behaviour => 'alert("foo")')
assert @controller.js_behaviours.include?(:selector => '#my_test_div:mousedown', :behaviour => 'alert("foo")')
assert @controller.js_behaviours.include?(:selector => '#my_test_div:dblclick', :behaviour => 'alert("foo")')
assert @controller.js_behaviours.include?(:selector => '#my_test_div:mouseover', :behaviour => 'alert("foo")')
assert @controller.js_behaviours.include?(:selector => '#my_test_div:mouseout', :behaviour => 'alert("foo")')
assert @controller.js_behaviours.include?(:selector => '#my_test_div:load', :behaviour => 'alert("foo")')
assert @controller.js_behaviours.include?(:selector => '#my_test_div:mousemove', :behaviour => 'alert("foo")')
end
end