Permalink
Browse files

cleaned up StatefulWidget (lot of superseded methods). added some tes…

…ts. removed implemented TODOs and added new. yes, that's progress.
  • Loading branch information...
1 parent 1964eba commit df9f8e2d5c4c75e81dfb67fbf373bb4cea8f011b @apotonick committed Oct 9, 2008
View
@@ -16,9 +16,10 @@ desc 'Generate documentation for Apotomo.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Apotomo API'
- rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.options << '--line-numbers' << '--inline-source' << '-m README'
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_files.include('app/**/*.rb')
+ rdoc.rdoc_files.include('test/*.rb')
rdoc.rdoc_files.include('README')
end
View
@@ -1,7 +1,5 @@
Testing
-------
-- something like #assert_event, so we can check if a certain event was triggered
-- announce #last_state as stable test method
- provide something like #assert_transition to test if FSM goes where we want
- assert_update/assert_execute, to assert which components are updated (e.g. after
event chain)
@@ -19,11 +17,20 @@ Parameter
Persistence
-----------
- only save id of ActiveRecords, to avoid big sessions (discuss whether this is necessary)
-- make WidgetTree persistent, so it can be modified dynamically
-- provide a way to attach observers within widgets, not globally in the WidgetTree
+- provide session storage alternatives, like encoding in url or hidden field
+- introduce a rake task to clear the frozen tree
Events
------
-- calls to *_to_event should attach a persistent event-handler instead of doing this
- on the fly. This fixes a security hole where users can trigger arbitrary events
- through /apotomo/event.
+- only send back the newer EventHandler content when more than one event was triggered
+ and the content of an earlier EventHandler is overridden.
+- provide scrambling of the event url, so users can not trigger events out of scope
+- check if an EventHandler is executed in scope, meaning the triggering event was valid.
+
+Apotobug
+--------
+- return exception reports as text, not HTML, for better reading in Firebug.
+
+StatefulWidget
+--------------
+- provide an ordered list of rendered child views.
@@ -74,32 +74,6 @@ def initialize(controller, id, start_states=:widget_content, opts={})
def widget_content
end
-
- # Freezes the widget's instance variables, so it can reconstruct the state in the
- # next request.
- def freeze
- raise "deprecated"
- session[name.to_s] = freezer = {}
-
- (self.instance_variables - ivars_to_forget).each do |var|
- freezer[var.to_s] = instance_variable_get(var)
- end
-
- end
-
- def thaw
- raise "deprecated"
- return unless widget_session
-
- widget_session.each do |var, val|
- ### DISCUSS: what about some "generic" special treatment?
- if val.kind_of?(ActiveRecord::Base) and not val.new_record?
- val.reload
- end
- self.instance_variable_set(var, val)
- end
- end
-
# Defines the instance vars that should <em>not</em> survive between requests,
# which means they're not frozen in Apotomo::StatefulWidget#freeze.
@@ -113,30 +87,10 @@ def ivars_to_ignore
'@is_f5_fixme'
]
end
-
- def thaw_last_state
- raise "deprecated"
- return unless widget_session
- #puts "session is here: #{session[name.to_s].inspect}"
- return widget_session['@last_state']
- end
- #--
- ### DISCUSS: this is state_data:
- #--
- ### FIXME: we have to #reload the AR instances here!
- def thaw_child_params ### FIXME: is this good?
- raise "deprecated"
- return unless widget_session
- return widget_session['@child_params']
- end
-
- def widget_session
- raise "deprecated"
- session[name.to_s]
- end
-
+
# Returns true if the widget is currently rendering itself or its children.
+ ### DISCUSS: 2BRM.
def hot?
@content
end
@@ -107,6 +107,7 @@ def process_event_request(action)
### NOTE: this will be removed when the WidgetTree is fully dynamic.
if evt.type == :invoke
+ raise "deprecated"
evt.data={:state => params[:state].to_sym}
### FIXME: this is InvokeEvent specific and
### currently is only needed for explicit invoke(:some_state).
@@ -28,7 +28,8 @@ def monitor(evt_type, observed_widget_id, target_widget_id, target_state)
# Get EventHandlers for the specified +evt_type+ and the source widget +source_id+.
# Note that sourceless handlers for +evt_type+ are returned, too.
def event_handlers_for(evt_type, source_id)
- raise "no source_id given for #event_handlers_for!" unless source_id
+ ### DISCUSS: why did i check source_id?
+ #raise "no source_id given for #event_handlers_for!" unless source_id
### DISCUSS: handlers with explicit source first.
handlers_for_type_and_source(evt_type, source_id) + handlers_for_type(evt_type)
@@ -21,16 +21,16 @@ class ApplicationWidgetTree < Apotomo::WidgetTree
def draw(root)
root.watch(:onWidget, :widget_one, :widget_two, :some_state)
- root << widget('test_widget', :test_widget_id)
- root << widget('test_widget', :target_widget_id)
- root << widget('test_widget', :target2_widget_id)
- root << widget('test_widget', :widget_one)
- root << widget('test_widget', :widget_two)
- root << widget('test_widget', :widget_three)
+ root << widget('test_widget', :widget_content, :test_widget_id)
+ root << widget('test_widget', :widget_content, :target_widget_id)
+ root << widget('test_widget', :widget_content, :target2_widget_id)
+ root << widget('test_widget', :widget_content, :widget_one)
+ root << widget('test_widget', :widget_content, :widget_two)
+ root << widget('test_widget', :widget_content, :widget_three)
root
- root << widget('test_widget', :fireing, :fireing_state)
- root << widget('test_widget', :fireman, :fireman_state)
+ root << widget('test_widget', :fireing_state, :fireing)
+ root << widget('test_widget', :fireman_state, :fireman)
root.watch(:click, :fireman, :fireman_state, :fireing)
end
end
@@ -88,6 +88,24 @@ def test_widget_session_encapsulation
assert_equal session['apotomo_widget_content'].size, 4
end
+ # test if removed widgets are removed from the session container:
+ def test_widget_session_cleanup
+ r = cell(:my_test, :some, 'root')
+ r << a= cell(:my_test, :some, 'a')
+ r << b1= cell(:my_test, :some, 'b')
+ a << b2= cell(:my_test, :some, 'b')
+
+
+ freeze_tree_for(r, session)
+
+ r = thaw_tree_for(session, controller)
+ r.find_by_id('b').removeFromParent!
+
+ freeze_tree_for(r, session)
+ assert_equal session['apotomo_widget_content'].size, 3
+ #assert session['apotomo_widget_content'].reject?('b')
+ end
+
end
@@ -170,6 +170,6 @@ def test_address_to_event
def test_address_to_event_with_implicit_invoke_handler
-
+ # test if handler is attached to correct target!
end
end

0 comments on commit df9f8e2

Please sign in to comment.