test/support/test_case_methods.rb in apotomo-0.1.4 vs test/support/test_case_methods.rb in apotomo-1.0.0.beta1

- old
+ new

@@ -1,13 +1,11 @@ module Apotomo module TestCaseMethods # Provides a ready-to-use mouse widget instance. def mouse_mock(id='mouse', start_state=:eating, opts={}, &block) - #mouse = mouse_class_mock.new(id, start_state, opts) - mouse = MouseCell.new(id, start_state, opts) + mouse = MouseCell.new(parent_controller, id, start_state, opts) mouse.instance_eval &block if block_given? - mouse.controller = @controller mouse end def mouse_class_mock(&block) klass = Class.new(MouseCell) @@ -46,23 +44,52 @@ def self.default_url_options; {:controller => :barn}; end end.new @controller.class.instance_eval { include Apotomo::Rails::ControllerMethods } @controller.extend ActionController::UrlWriter @controller.params = {} - @controller.session = {} + ### FIXME: @controller.session = {} end def hibernate_widget(widget, session = {}) - widget.freeze_to(session) + Apotomo::StatefulWidget.freeze_for(session, widget) session = Marshal.load(Marshal.dump(session)) - Apotomo::StatefulWidget.thaw_from(session) + Apotomo::StatefulWidget.thaw_for(@controller, session, ) end def hibernate(widget, session = {}) Apotomo::StatefulWidget.freeze_for(session, widget) session = Marshal.load(Marshal.dump(session)) Apotomo::StatefulWidget.thaw_for(session, widget('apotomo/widget', 'root')) end + + module TestController + def setup + barn_controller! + end + + # Creates a mock controller instance. Currently, each widget needs a parent controller instance due to some + # sucky dependency in cells. + def barn_controller! + @controller = Class.new(ActionController::Base) do + def initialize + extend ActionController::UrlWriter + self.params = {} + self.request = ActionController::TestRequest.new + end + + def self.name; "BarnController"; end + + def self.default_url_options; {:controller => :barn}; end + include Apotomo::Rails::ControllerMethods + end.new + ### FIXME: @controller.session = {} + end + + def parent_controller + @controller + end + + end end -end \ No newline at end of file +end