apotomo 0.1.4 → 1.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/Gemfile +5 -2
  2. data/Gemfile.lock +70 -21
  3. data/Rakefile +7 -7
  4. data/config/routes.rb +3 -3
  5. data/lib/apotomo/persistence.rb +21 -48
  6. data/lib/apotomo/rails/view_helper.rb +3 -11
  7. data/lib/apotomo/request_processor.rb +7 -10
  8. data/lib/apotomo/transition.rb +2 -2
  9. data/lib/apotomo/version.rb +1 -1
  10. data/lib/apotomo/widget.rb +12 -25
  11. data/lib/apotomo/widget_shortcuts.rb +1 -1
  12. data/lib/apotomo.rb +6 -0
  13. data/{generators/widget → lib/generators/apotomo}/USAGE +0 -0
  14. data/lib/generators/apotomo/templates/view.erb +7 -0
  15. data/lib/generators/apotomo/templates/view.haml +4 -0
  16. data/{generators/widget → lib/generators/apotomo}/templates/widget.rb +2 -1
  17. data/lib/generators/apotomo/templates/widget_test.rb +11 -0
  18. data/lib/generators/apotomo/widget_generator.rb +19 -0
  19. data/test/dummy/app/controllers/application_controller.rb +3 -0
  20. data/test/dummy/app/helpers/application_helper.rb +2 -0
  21. data/test/dummy/config/application.rb +45 -0
  22. data/test/dummy/config/boot.rb +10 -0
  23. data/test/dummy/config/environment.rb +5 -0
  24. data/test/dummy/config/environments/development.rb +26 -0
  25. data/test/dummy/config/environments/production.rb +49 -0
  26. data/test/dummy/config/environments/test.rb +35 -0
  27. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/test/dummy/config/initializers/inflections.rb +10 -0
  29. data/test/dummy/config/initializers/mime_types.rb +5 -0
  30. data/test/dummy/config/initializers/secret_token.rb +7 -0
  31. data/test/dummy/config/initializers/session_store.rb +8 -0
  32. data/test/dummy/config/routes.rb +59 -0
  33. data/test/dummy/tmp/app/cells/mouse_widget.rb +11 -0
  34. data/test/dummy/tmp/test/widgets/mouse_widget_test.rb +15 -0
  35. data/test/rails/controller_methods_test.rb +11 -14
  36. data/test/rails/rails_integration_test.rb +12 -11
  37. data/test/rails/view_helper_test.rb +4 -27
  38. data/test/rails/view_methods_test.rb +4 -6
  39. data/test/rails/widget_generator_test.rb +40 -37
  40. data/test/support/test_case_methods.rb +34 -7
  41. data/test/test_helper.rb +12 -24
  42. data/test/unit/container_test.rb +2 -1
  43. data/test/unit/event_handler_test.rb +2 -0
  44. data/test/unit/event_methods_test.rb +4 -3
  45. data/test/unit/invoke_test.rb +27 -22
  46. data/test/unit/onfire_integration_test.rb +2 -0
  47. data/test/unit/persistence_test.rb +51 -90
  48. data/test/unit/render_test.rb +6 -4
  49. data/test/unit/request_processor_test.rb +70 -48
  50. data/test/unit/stateful_widget_test.rb +3 -1
  51. data/test/unit/transition_test.rb +1 -0
  52. data/test/unit/widget_shortcuts_test.rb +3 -2
  53. data/test/unit/widget_test.rb +69 -56
  54. metadata +57 -34
  55. data/app/.jeweler_doesnt_like_empty_directories +0 -0
  56. data/generators/widget/templates/functional_test.rb +0 -8
  57. data/generators/widget/templates/view.html.erb +0 -2
  58. data/generators/widget/templates/view.html.haml +0 -3
  59. data/generators/widget/widget_generator.rb +0 -34
  60. data/lib/apotomo/test_methods.rb +0 -8
  61. data/test/support/assertions_helper.rb +0 -13
  62. data/test/unit/test_methods_test.rb +0 -11
data/test/test_helper.rb CHANGED
@@ -10,36 +10,28 @@ require 'mocha/integration'
10
10
 
11
11
 
12
12
  require 'cells'
13
- Cell::Base.add_view_path File.expand_path(File.dirname(__FILE__) + "/fixtures")
13
+ Cell::Base.append_view_path File.expand_path(File.dirname(__FILE__) + "/fixtures")
14
14
 
15
- puts Cell::Base.view_paths
15
+ require 'rails/engine'
16
16
 
17
17
  require 'apotomo'
18
18
  require 'apotomo/widget_shortcuts'
19
19
  require 'apotomo/rails/controller_methods'
20
20
  require 'apotomo/rails/view_methods'
21
- #require 'apotomo/assertions_helper'
22
21
 
23
22
 
24
23
 
25
24
 
26
25
  # Load test support files.
27
- Dir[File.join(File.dirname(__FILE__), *%w[support ** *.rb]).to_s].each { |f| require f }
26
+ require File.join(File.dirname(__FILE__), "support/test_case_methods")
28
27
 
29
28
 
30
29
  Test::Unit::TestCase.class_eval do
31
30
  include Apotomo::WidgetShortcuts
32
31
  include Apotomo::TestCaseMethods
33
- include Apotomo::AssertionsHelper
34
32
 
35
- def setup
36
- @controller = ApotomoController.new
37
- @request = ActionController::TestRequest.new
38
- @response = ActionController::TestResponse.new
39
- @controller.request = @request
40
- @controller.response = @response
41
- @controller.params = {}
42
- @controller.session = @session = {}
33
+ def assert_not(assertion)
34
+ assert !assertion
43
35
  end
44
36
  end
45
37
 
@@ -63,16 +55,12 @@ class RenderingTestCell < Apotomo::StatefulWidget
63
55
  end
64
56
 
65
57
 
66
-
67
- # We need to setup a fake route for the controller tests.
68
- ActionController::Routing::Routes.draw do |map|
69
- map.connect 'apotomo/:action', :controller => 'apotomo'
70
- map.connect 'barn/:action', :controller => 'barn'
58
+ # Enable dynamic states so we can do Cell.class_eval { def ... } at runtime.
59
+ class Apotomo::Widget
60
+ def action_method?(*); true; end
71
61
  end
72
- require File.join(File.dirname(__FILE__), '..', 'config/routes.rb') ### TODO: let rails engine handle that.
73
-
74
-
75
62
 
76
- module ::Rails
77
- def logger(*args); end
78
- end
63
+ ENV['RAILS_ENV'] = 'test'
64
+ require "dummy/config/environment"
65
+ #require File.join(File.dirname(__FILE__), '..', 'config/routes.rb') ### TODO: let rails engine handle that.
66
+ require "rails/test_help" # sets up ActionController::TestCase's @routes
@@ -1,10 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ContainerTest < Test::Unit::TestCase
4
+ include Apotomo::TestCaseMethods::TestController
5
+
4
6
  context "Rendering a container" do
5
7
  setup do
6
8
  @family = container('family')
7
- @family.controller = @controller
8
9
  end
9
10
 
10
11
  should "return an empty view if childless" do
@@ -1,6 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class EventHandlerTest < Test::Unit::TestCase
4
+ include Apotomo::TestCaseMethods::TestController
5
+
4
6
  context "an abstract EventHandler" do
5
7
  should "push nil to root's ordered page_updates when #call'ed" do
6
8
  @mum = mouse_mock('mum')
@@ -1,7 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class EventMethodsTest < Test::Unit::TestCase
4
-
4
+ include Apotomo::TestCaseMethods::TestController
5
+
5
6
  context "#respond_to_event and #fire" do
6
7
  setup do
7
8
  mum_and_kid!
@@ -49,11 +50,11 @@ class EventMethodsTest < Test::Unit::TestCase
49
50
  end
50
51
 
51
52
  should "add the handlers at creation time" do
52
- assert_equal [Apotomo::InvokeEventHandler.new(:widget_id => 'mum', :state => :answer_squeak)], AdultMouseCell.new('mum', :show).event_table.all_handlers_for(:peep, 'mum')
53
+ assert_equal [Apotomo::InvokeEventHandler.new(:widget_id => 'mum', :state => :answer_squeak)], AdultMouseCell.new(parent_controller, 'mum', :show).event_table.all_handlers_for(:peep, 'mum')
53
54
  end
54
55
 
55
56
  should "not inherit handlers for now" do
56
- assert_equal [], BabyMouseCell.new('kid', :show).event_table.all_handlers_for(:peep, 'kid')
57
+ assert_equal [], BabyMouseCell.new(parent_controller, 'kid', :show).event_table.all_handlers_for(:peep, 'kid')
57
58
  end
58
59
  end
59
60
 
@@ -1,6 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class InvokeTest < Test::Unit::TestCase
4
+ include Apotomo::TestCaseMethods::TestController
5
+
4
6
  class LocalMouse < MouseCell
5
7
  def snuggle; render; end
6
8
  def educate; render :view => :snuggle; end
@@ -8,26 +10,26 @@ class InvokeTest < Test::Unit::TestCase
8
10
 
9
11
  context "Invoking a single widget" do
10
12
  setup do
11
- @mum = LocalMouse.new('mum', :snuggle)
13
+ @mum = LocalMouse.new(parent_controller, 'mum', :snuggle)
12
14
  end
13
15
 
14
16
  context "implicitely" do
15
17
  should "always enter the given state" do
16
18
  @mum.invoke :snuggle
17
- assert_equal :snuggle, @mum.last_state
19
+ assert_equal 'snuggle', @mum.last_state
18
20
 
19
21
  @mum.invoke :educate
20
- assert_equal :educate, @mum.last_state
22
+ assert_equal 'educate', @mum.last_state
21
23
  end
22
24
  end
23
25
 
24
26
  context "explicitely" do
25
27
  should "per default enter the start state" do
26
28
  @mum.invoke
27
- assert_equal :snuggle, @mum.last_state
29
+ assert_equal 'snuggle', @mum.last_state
28
30
 
29
31
  @mum.invoke
30
- assert_equal :snuggle, @mum.last_state
32
+ assert_equal 'snuggle', @mum.last_state
31
33
  end
32
34
 
33
35
  context "with defined transitions" do
@@ -37,17 +39,20 @@ class InvokeTest < Test::Unit::TestCase
37
39
  end
38
40
 
39
41
  @mum.invoke
40
- assert_equal :snuggle, @mum.last_state
42
+ assert_equal 'snuggle', @mum.last_state
41
43
  end
42
44
 
43
45
  should "automatically follow the transitions if defined" do
46
+ assert_equal 'snuggle', @mum.last_state
47
+ puts "invoooooooooooooogue"
48
+ puts @mum.last_state.inspect
44
49
  @mum.invoke
45
- assert_equal :educate, @mum.last_state
50
+ assert_equal 'educate', @mum.last_state
46
51
  end
47
52
 
48
53
  should "nevertheless allow undefined implicit invokes" do
49
54
  @mum.invoke :snuggle
50
- assert_equal :snuggle, @mum.last_state
55
+ assert_equal 'snuggle', @mum.last_state
51
56
  end
52
57
  end
53
58
  end
@@ -55,10 +60,10 @@ class InvokeTest < Test::Unit::TestCase
55
60
 
56
61
  context "Invoking a widget family" do
57
62
  setup do
58
- @mum = LocalMouse.new('mum', :snuggle)
63
+ @mum = LocalMouse.new(parent_controller, 'mum', :snuggle)
59
64
 
60
65
  # create an anonym class for @kid so we don't pollute with #transition's.
61
- @mum << @kid = mouse_class_mock.new('kid', :snooze)
66
+ @mum << @kid = mouse_class_mock.new(parent_controller, 'kid', :snooze)
62
67
  @kid.instance_eval do
63
68
  def snooze; render :nothing => true; end
64
69
  def listen; render :nothing => true; end
@@ -68,12 +73,12 @@ class InvokeTest < Test::Unit::TestCase
68
73
  context "implicitely" do
69
74
  should "per default send kid to its start state" do
70
75
  @mum.invoke :snuggle
71
- assert_equal :snuggle, @mum.last_state
72
- assert_equal :snooze, @kid.last_state
76
+ assert_equal 'snuggle', @mum.last_state
77
+ assert_equal 'snooze', @kid.last_state
73
78
 
74
79
  @mum.invoke :educate
75
- assert_equal :educate, @mum.last_state
76
- assert_equal :snooze, @kid.last_state
80
+ assert_equal 'educate', @mum.last_state
81
+ assert_equal 'snooze', @kid.last_state
77
82
  end
78
83
 
79
84
  should "follow the kid's transition if defined" do
@@ -83,8 +88,8 @@ class InvokeTest < Test::Unit::TestCase
83
88
 
84
89
  @mum.invoke :snuggle
85
90
  @mum.invoke :educate
86
- assert_equal :educate, @mum.last_state
87
- assert_equal :listen, @kid.last_state
91
+ assert_equal 'educate', @mum.last_state
92
+ assert_equal 'listen', @kid.last_state
88
93
  end
89
94
 
90
95
  should "send kid to the given state passed to #render" do
@@ -95,8 +100,8 @@ class InvokeTest < Test::Unit::TestCase
95
100
  end
96
101
 
97
102
  @mum.invoke :snuggle
98
- assert_equal :snuggle, @mum.last_state
99
- assert_equal :listen, @kid.last_state
103
+ assert_equal 'snuggle', @mum.last_state
104
+ assert_equal 'listen', @kid.last_state
100
105
  end
101
106
 
102
107
  should "send kid to the :invoke state as it overrides #transition" do
@@ -111,12 +116,12 @@ class InvokeTest < Test::Unit::TestCase
111
116
  end
112
117
 
113
118
  @mum.invoke :snuggle
114
- assert_equal :snuggle, @mum.last_state
115
- assert_equal :snooze, @kid.last_state
119
+ assert_equal 'snuggle', @mum.last_state
120
+ assert_equal 'snooze', @kid.last_state
116
121
 
117
122
  @mum.invoke :educate
118
- assert_equal :educate, @mum.last_state
119
- assert_equal :snooze, @kid.last_state
123
+ assert_equal 'educate', @mum.last_state
124
+ assert_equal 'snooze', @kid.last_state
120
125
  end
121
126
  end
122
127
  end
@@ -1,6 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class OnfireIntegrationTest < Test::Unit::TestCase
4
+ include Apotomo::TestCaseMethods::TestController
5
+
4
6
  context "including Onfire into the StatefulWidget it" do
5
7
  setup do
6
8
  @mum = mouse_mock('mum')
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class PersistenceTest < Test::Unit::TestCase
4
+ include Apotomo::TestCaseMethods::TestController
4
5
 
5
6
  class PersistentMouse < Apotomo::StatefulWidget # we need a named class for marshalling.
6
7
  attr_reader :who, :what
@@ -14,51 +15,27 @@ class PersistenceTest < Test::Unit::TestCase
14
15
  def recap; render :nothing => true; end
15
16
  end
16
17
 
18
+ def stateless(name)
19
+ Apotomo::Widget.new(parent_controller, name, :eat)
20
+ end
21
+
22
+ def stateful(name)
23
+ PersistentMouse.new(parent_controller, name, :educate)
24
+ end
25
+
17
26
  context "StatefulWidget" do
18
27
 
19
28
  context ".stateful_branches_for" do
20
29
  should "provide all stateful branch-roots seen from root" do
21
- @root = Apotomo::Widget.new('root', :eat)
30
+ @root = stateless('root')
22
31
  @root << mum_and_kid!
23
- @root << Apotomo::Widget.new('berry', :eat) << @jerry = mouse_mock('jerry', :eat)
32
+ @root << stateless('berry') << @jerry = mouse_mock('jerry', :eat)
24
33
 
25
34
  assert_equal ['mum', 'jerry'], Apotomo::StatefulWidget.stateful_branches_for(@root).collect {|n| n.name}
26
35
  end
27
36
  end
28
37
  end
29
38
 
30
- context "After #hibernate_widget (request) the widget" do
31
- should "still have the same ivars" do
32
- @mum = PersistentMouse.new('mum', :educate)
33
- @mum.controller = @controller ### FIXME: remove that dependency
34
-
35
- @mum.invoke(:educate)
36
-
37
- assert_equal @mum.last_state, :educate
38
- assert_equal @mum.who, "the cat"
39
- assert_equal @mum.what, "run away"
40
-
41
- @mum = hibernate_widget(@mum)
42
- @mum.controller = @controller ### FIXME: remove that dependency
43
-
44
- @mum.invoke(:recap)
45
-
46
- assert_equal @mum.last_state, :recap
47
- assert_equal @mum.who, "the cat"
48
- assert_equal @mum.what, "run away"
49
- end
50
-
51
- should "still have its event_table" do
52
- @mum = PersistentMouse.new('mum', :educate)
53
- @event = Apotomo::Event.new(:squeak, @mum)
54
- @mum.respond_to_event :squeak, :with => :educate
55
-
56
- assert_equal 1, @mum.send(:local_event_handlers, @event).size
57
- @mum = hibernate_widget(@mum)
58
- assert_equal 1, @mum.send(:local_event_handlers, @event).size
59
- end
60
- end
61
-
62
39
  context "freezing and thawing a widget family" do
63
40
  setup do
64
41
  mum_and_kid!
@@ -67,7 +44,7 @@ class PersistenceTest < Test::Unit::TestCase
67
44
 
68
45
  context "and calling #flush_storage" do
69
46
  should "clear the storage from frozen data" do
70
- @root = Apotomo::Widget.new('root', :eat)
47
+ @root = stateless('root')
71
48
  @root << @mum
72
49
 
73
50
  Apotomo::StatefulWidget.freeze_for(@storage, @root)
@@ -86,7 +63,7 @@ class PersistenceTest < Test::Unit::TestCase
86
63
  @mum.freeze_ivars_to(@storage)
87
64
 
88
65
  assert_equal 1, @storage.size
89
- assert_equal 5, @storage['mum'].size
66
+ assert_equal 6, @storage['mum'].size
90
67
  end
91
68
 
92
69
  should "push family's freezable ivars to the storage when calling #freeze_data_to" do
@@ -94,9 +71,9 @@ class PersistenceTest < Test::Unit::TestCase
94
71
  @mum.freeze_data_to(@storage)
95
72
 
96
73
  assert_equal 3, @storage.size
97
- assert_equal 5, @storage['mum'].size
98
- assert_equal 5, @storage['mum/kid'].size
99
- assert_equal 4, @storage['mum/kid/pet'].size
74
+ assert_equal 6, @storage['mum'].size
75
+ assert_equal 6, @storage['mum/kid'].size
76
+ assert_equal 5, @storage['mum/kid/pet'].size
100
77
  end
101
78
 
102
79
  should "push ivars and structure to the storage when calling #freeze_to" do
@@ -107,10 +84,10 @@ class PersistenceTest < Test::Unit::TestCase
107
84
 
108
85
  context "that has also stateless widgets" do
109
86
  setup do
110
- @root = Apotomo::Widget.new('root', :eat)
87
+ @root = stateless('root')
111
88
  @root << mum_and_kid!
112
- @root << Apotomo::Widget.new('berry', :eat) << @jerry = mouse_mock('jerry', :eat)
113
- @root << Apotomo::Widget.new('tom', :eating)
89
+ @root << stateless('berry') << @jerry = mouse_mock('jerry', :eat)
90
+ @root << stateless('tom')
114
91
 
115
92
  Apotomo::StatefulWidget.freeze_for(@storage, @root)
116
93
  end
@@ -120,18 +97,13 @@ class PersistenceTest < Test::Unit::TestCase
120
97
  end
121
98
 
122
99
  should "save stateful branches only" do
123
- #@mum.root!
124
- #@jerry.root! # disconnect stateful branches.
125
-
126
- assert_equal([[@mum, 'root'], [@jerry, 'berry']], @storage[:apotomo_stateful_branches])
127
- assert @storage[:apotomo_stateful_branches].first.first.root?, "mum not disconnected from root"
128
- assert @storage[:apotomo_stateful_branches].last.first.root?, "jerry not disconnected from berry"
100
+ assert_equal([[[MouseCell, 'mum', 'root'], [MouseCell, 'kid', 'mum']], [[MouseCell, 'jerry', 'berry']]], @storage[:apotomo_stateful_branches])
129
101
  end
130
102
 
131
103
  should "attach stateful branches to the tree in thaw_for" do
132
- @new_root = Apotomo::Widget.new('root', :eat)
133
- @new_root << Apotomo::Widget.new('berry', :eat)
134
- assert_equal @new_root, Apotomo::StatefulWidget.thaw_for(@storage, @new_root)
104
+ @new_root = stateless('root')
105
+ @new_root << stateless('berry')
106
+ assert_equal @new_root, Apotomo::StatefulWidget.thaw_for(@controller, @storage, @new_root)
135
107
 
136
108
  assert_equal 5, @new_root.size # without tom.
137
109
  end
@@ -139,27 +111,27 @@ class PersistenceTest < Test::Unit::TestCase
139
111
  should "re-establish ivars recursivly when calling #thaw_for" do
140
112
  @storage[:apotomo_stateful_branches] = Marshal.load(Marshal.dump(@storage[:apotomo_stateful_branches]))
141
113
 
142
- @new_root = Apotomo::Widget.new('root', :eat)
143
- @new_root << Apotomo::Widget.new('berry', :eat)
144
- @new_root = Apotomo::StatefulWidget.thaw_for(@storage, @new_root)
114
+ @new_root = stateless('root')
115
+ @new_root << stateless('berry')
116
+ @new_root = Apotomo::StatefulWidget.thaw_for(@controller, @storage, @new_root)
145
117
 
146
118
  assert_equal :answer_squeak, @new_root['mum'].instance_variable_get(:@start_state)
147
119
  assert_equal :peek, @new_root['mum']['kid'].instance_variable_get(:@start_state)
148
120
  end
149
121
 
150
122
  should "raise an exception when thaw_for can't find the branch's parent" do
151
- @new_root = Apotomo::Widget.new('dad', :eat)
123
+ @new_root = stateless('dad')
152
124
 
153
125
  assert_raises RuntimeError do
154
- Apotomo::StatefulWidget.thaw_for(@storage, @new_root)
126
+ Apotomo::StatefulWidget.thaw_for(@controller, @storage, @new_root)
155
127
  end
156
128
  end
157
129
 
158
130
  should "clear the fields in the storage when fetching in #thaw_for" do
159
- @new_root = Apotomo::Widget.new('root', :eat)
160
- @new_root << Apotomo::Widget.new('berry', :eat)
131
+ @new_root = stateless('root')
132
+ @new_root << stateless('berry')
161
133
 
162
- Apotomo::StatefulWidget.thaw_for(@storage, @new_root)
134
+ Apotomo::StatefulWidget.thaw_for(@controller, @storage, @new_root)
163
135
 
164
136
  assert_nil @storage[:apotomo_stateful_branches]
165
137
  assert_nil @storage[:apotomo_widget_ivars]
@@ -189,46 +161,35 @@ class PersistenceTest < Test::Unit::TestCase
189
161
 
190
162
  end
191
163
 
192
- context "dumping and loading" do
164
+ context "#dump_tree" do
193
165
  setup do
194
- @mum = PersistentMouse.new('mum', :eating)
195
- @mum << @kid = PersistentMouse.new('kid', :eating)
166
+ @mum = stateful('mum')
167
+ @mum << @kid = stateful('kid')
168
+ @kid << @pet = stateful('pet')
169
+ @mum << @berry = stateful('berry')
170
+
196
171
  end
197
172
 
198
- context "a single stateful widget" do
199
- should "provide a serialized widget on #node_dump" do
200
- assert_equal "mum|PersistenceTest::PersistentMouse|mum", @mum.dump_node
201
- assert_equal "kid|PersistenceTest::PersistentMouse|mum", @kid.dump_node
202
- end
203
-
204
- should "recover the widget skeleton when invoking self.node_load" do
205
- @mum, parent = ::Apotomo::StatefulWidget.load_node(@mum.dump_node)
206
- assert_kind_of PersistentMouse, @mum
207
- assert_equal 'mum', @mum.name
208
- assert_equal 1, @mum.size
209
- assert_equal 'mum', parent
210
- end
173
+ should "return a list of widget metadata" do
174
+ assert_equal [[PersistentMouse, 'mum', nil], [PersistentMouse, 'kid', 'mum'], [PersistentMouse, 'pet', 'kid'], [PersistentMouse, 'berry', 'mum']], @mum.dump_tree
211
175
  end
212
176
 
213
- context "a stateful widget family" do
214
- should "provide the serialized tree on _dump" do
215
- assert_equal "mum|PersistenceTest::PersistentMouse|mum\nkid|PersistenceTest::PersistentMouse|mum\n", @mum._dump(10)
216
- end
217
-
218
- should "recover the widget tree on _load" do
219
- @mum = ::Apotomo::StatefulWidget._load(@mum._dump(10))
220
- assert_equal 2, @mum.size
221
- assert_equal @mum, @mum['kid'].parent
177
+ should "return a tree for #load_tree" do
178
+ cold_widgets = @mum.dump_tree
179
+ assert_equal ['mum', 'kid', 'pet', 'berry'], Apotomo::StatefulWidget.send(:load_tree, @controller, cold_widgets).collect { |n| n.name }
180
+ end
181
+
182
+ context "#frozen_widget_in?" do
183
+ should "return true if a valid widget is passed" do
184
+ @session = {}
185
+ assert_not Apotomo::StatefulWidget.frozen_widget_in?(@session)
186
+ Apotomo::StatefulWidget.freeze_for(@session, @berry)
187
+ assert Apotomo::StatefulWidget.frozen_widget_in?(@session)
222
188
  end
223
189
  end
224
190
  end
225
191
 
226
- context "#frozen_widget_in?" do
227
- should "return true if a valid widget is passed" do
228
- assert_not Apotomo::StatefulWidget.frozen_widget_in?({})
229
- assert Apotomo::StatefulWidget.frozen_widget_in?({:apotomo_stateful_branches => [[mouse_mock, 'root']]})
230
- end
231
- end
192
+
232
193
 
233
194
  context "#symbolized_instance_variables?" do
234
195
  should "return instance_variables as symbols" do
@@ -1,6 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class RenderTest < ActionView::TestCase
4
+ include Apotomo::TestCaseMethods::TestController
5
+
4
6
  context "Rendering a single widget" do
5
7
  setup do
6
8
  @mum = mouse_mock
@@ -133,13 +135,13 @@ class RenderTest < ActionView::TestCase
133
135
  end
134
136
 
135
137
  should "render the :view" do
136
- assert_equal "<div id=\"mouse\"><snuggle></snuggle></div>", @mum.invoke(:squeak)
138
+ assert_equal "<div id=\"mouse\"><snuggle></snuggle></div>\n", @mum.invoke(:squeak)
137
139
  end
138
140
 
139
141
  should "render the children" do
140
142
  @mum << @kid
141
143
 
142
- assert_equal "<div id=\"mouse\"><snuggle>squeeeeaaak</snuggle></div>", @mum.invoke(:squeak)
144
+ assert_equal "<div id=\"mouse\"><snuggle>squeeeeaaak</snuggle></div>\n", @mum.invoke(:squeak)
143
145
  assert @kid.rendered?
144
146
  end
145
147
  end
@@ -204,7 +206,7 @@ class RenderTest < ActionView::TestCase
204
206
  end
205
207
 
206
208
  should "per default render kid's content inside mums div with rendered_children" do
207
- assert_equal '<div id="mum"><snuggle><div id="kid">burp!</div></snuggle></div>', @mum.invoke(:snuggle)
209
+ assert_equal "<div id=\"mum\"><snuggle><div id=\"kid\">burp!</div></snuggle></div>\n", @mum.invoke(:snuggle)
208
210
  end
209
211
 
210
212
  should "skip kids if :render_children=>false but still provide a rendered_children hash" do
@@ -212,7 +214,7 @@ class RenderTest < ActionView::TestCase
212
214
  def snuggle; render :render_children => false; end
213
215
  end
214
216
 
215
- assert_equal '<div id="mum"><snuggle></snuggle></div>', @mum.invoke(:snuggle)
217
+ assert_equal "<div id=\"mum\"><snuggle></snuggle></div>\n", @mum.invoke(:snuggle)
216
218
  end
217
219
 
218
220
  should_eventually "provide an ordered rendered_children hash"