test/rails/controller_methods_test.rb in apotomo-0.1.4 vs test/rails/controller_methods_test.rb in apotomo-1.0.0.beta1

- old
+ new

@@ -1,13 +1,11 @@ require 'test_helper' class ControllerMethodsTest < ActionController::TestCase + include Apotomo::TestCaseMethods::TestController + context "A Rails controller" do - setup do - barn_controller! - end - context "responding to #apotomo_root" do should "initially return a root widget" do assert_equal 1, @controller.apotomo_root.size end @@ -25,11 +23,11 @@ end context "invoking #has_widgets" do setup do @controller.class.has_widgets do |root| - root << mouse_mock('mum') + root << widget(:mouse_cell, 'mum') end end should "add the widgets to apotomo_root" do assert_equal 'mum', @controller.apotomo_root['mum'].name @@ -40,32 +38,31 @@ assert @controller.apotomo_root['mum'] end should "allow multiple calls to has_widgets" do @controller.class.has_widgets do |root| - root << mouse_mock('kid') + root << widget(:mouse_cell, 'kid') end assert @controller.apotomo_root['mum'] assert @controller.apotomo_root['kid'] end should "inherit has_widgets blocks to sub-controllers" do - berry = mouse_mock('berry') + berry = widget(:mouse_cell, 'berry') @sub_controller = Class.new(@controller.class) do has_widgets { |root| root << berry } end.new @sub_controller.params = {} - @sub_controller.session = {} assert @sub_controller.apotomo_root['mum'] assert @sub_controller.apotomo_root['berry'] end should "be aliased to has_widgets" do @controller.class.has_widgets do |root| - root << mouse_mock('kid') + root << widget(:mouse_cell, 'kid') end assert @controller.apotomo_root['mum'] assert @controller.apotomo_root['kid'] end @@ -77,19 +74,19 @@ assert_equal 1, @controller.apotomo_root.size end should "extend the widget family and remember the block with one #use_widgets call" do @controller.use_widgets do |root| - root << mouse_mock + root << widget(:mouse_cell, 'mum') end assert_equal 1, @controller.bound_use_widgets_blocks.size assert_equal 2, @controller.apotomo_root.size end should "add blocks only once" do - block = Proc.new {|root| root << mouse_mock} + block = Proc.new {|root| root << widget(:mouse_cell, 'mum')} @controller.use_widgets &block @controller.use_widgets &block assert_equal 1, @controller.bound_use_widgets_blocks.size @@ -100,21 +97,21 @@ mum_and_kid! @controller.use_widgets do |root| root << @mum end @controller.use_widgets do |root| - root << mouse_mock('pet') + root << widget(:mouse_cell, 'pet') end assert_equal 2, @controller.bound_use_widgets_blocks.size assert_equal 4, @controller.apotomo_root.size end end context "invoking #url_for_event" do should "compute an url for any widget" do - assert_equal "/barn/render_event_response?source=mouse&type=footsteps&volume=9", @controller.url_for_event(:footsteps, :source => :mouse, :volume => 9) + assert_equal "/barn/render_event_response?source=mouse&volume=9&type=footsteps", @controller.url_for_event(:footsteps, :source => :mouse, :volume => 9) end end should "flush its bound_use_widgets_blocks with, guess, #flush_bound_use_widgets_blocks" do @controller.bound_use_widgets_blocks << Proc.new {} @@ -129,10 +126,10 @@ @mum = mouse_mock('mum', 'snuggle') {def snuggle; render; end} end should "render the widget" do @controller.apotomo_root << @mum - assert_equal '<div id="mum"><snuggle></snuggle></div>', @controller.render_widget('mum') + assert_equal "<div id=\"mum\"><snuggle></snuggle></div>\n", @controller.render_widget('mum') end end