require 'test_helper' require 'action_view/test_case' class ViewHelperTest < Apotomo::TestCase include ActionDispatch::Assertions::DomAssertions include Apotomo::TestCase::TestController # TODO: move to Apotomo::TestCase, refactor, test. class MouseWidget < Apotomo::Widget end def in_view(subject, &block) if subject.kind_of?(Apotomo::Widget) subject.opts[:block] = block else subject = subject.new(@controller, 'mum', :display, :block => block) end setup_test_states_in(subject) unless subject.respond_to?(:in_view)# add #in_view state to subject cell. subject.class.action_methods << "in_view" subject.invoke(:in_view) end def mouse_mock(id='mum', start_state=:eat, opts={}, &block) mouse = MouseWidget.new(parent_controller, id, start_state, opts) mouse.instance_eval &block if block_given? mouse end context "A widget state view" do teardown do Apotomo.js_framework = :prototype end should_eventually "respond to #multipart_form_to_event" do assert_dom_equal( "
", in_view(MouseWidget) do multipart_form_to_event(:footsteps) end) end should "respond to #url_for_event" do assert_equal("/barn/render_event_response?source=mum&type=footsteps", in_view(MouseWidget) do url_for_event(:footsteps) end) end should "respond to #url_for_event with a namespaced controller" do @controller = namespaced_controller assert_equal("/farm/barn/render_event_response?source=mum&type=footsteps", in_view(MouseWidget) do url_for_event(:footsteps) end) end should "respond to #widget_div" do assert_equal('
squeak!
', in_view(MouseWidget) do widget_div { "squeak!" } end) end should "respond to #widget_div with options" do assert_equal('
squeak!
', in_view(MouseWidget) do widget_div(:id => 'kid', :class => "mouse") { "squeak!" } end) end should "respond to #widget_id" do assert_equal('mum', in_view(MouseWidget){ widget_id }) end context "#widget_javascript" do should "usually render a javascript block" do assert_equal("", in_view(MouseWidget) do widget_javascript { 'alert("Beer!")' } end) end # FIXME: get the test running? should_eventually "be quiet if suppress_js is set" do @suppress_js = true ### TODO: use a local, not an instance variable. mum = mouse_mock do def in_view render :suppress_js => true end end assert_equal(nil, in_view(mum) do widget_javascript { 'alert("Beer!")' } end) end end end end