apotomo 1.0.5 → 1.1.0.rc1
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.
- data/.gitignore +5 -0
- data/CHANGES.textile +35 -7
- data/Gemfile +0 -2
- data/README.rdoc +9 -9
- data/apotomo.gemspec +3 -3
- data/lib/apotomo.rb +4 -47
- data/lib/apotomo/event.rb +2 -0
- data/lib/apotomo/event_handler.rb +0 -3
- data/lib/apotomo/event_methods.rb +6 -2
- data/lib/apotomo/invoke_event_handler.rb +5 -3
- data/lib/apotomo/javascript_generator.rb +19 -16
- data/lib/apotomo/rails/controller_methods.rb +84 -131
- data/lib/apotomo/rails/view_helper.rb +15 -31
- data/lib/apotomo/railtie.rb +24 -0
- data/lib/apotomo/request_processor.rb +17 -48
- data/lib/apotomo/test_case.rb +5 -5
- data/lib/apotomo/tree_node.rb +52 -61
- data/lib/apotomo/version.rb +1 -1
- data/lib/apotomo/widget.rb +70 -146
- data/lib/apotomo/widget/javascript_methods.rb +39 -0
- data/lib/apotomo/widget_shortcuts.rb +14 -40
- data/lib/generators/apotomo/widget_generator.rb +8 -9
- data/lib/generators/erb/widget_generator.rb +17 -0
- data/lib/generators/haml/widget_generator.rb +20 -0
- data/lib/generators/{apotomo/templates → templates}/view.erb +1 -1
- data/lib/generators/templates/view.haml +4 -0
- data/lib/generators/{apotomo/templates → templates}/widget.rb +1 -1
- data/lib/generators/{apotomo/templates → templates}/widget_test.rb +1 -1
- data/lib/generators/test_unit/widget_generator.rb +14 -0
- data/test/rails/caching_test.rb +10 -17
- data/test/rails/controller_methods_test.rb +9 -81
- data/test/rails/rails_integration_test.rb +76 -60
- data/test/rails/view_helper_test.rb +17 -28
- data/test/rails/widget_generator_test.rb +19 -31
- data/test/support/test_case_methods.rb +6 -20
- data/test/test_helper.rb +15 -25
- data/test/unit/event_handler_test.rb +1 -0
- data/test/unit/event_methods_test.rb +20 -8
- data/test/unit/event_test.rb +5 -0
- data/test/unit/javascript_generator_test.rb +19 -19
- data/test/unit/render_test.rb +17 -112
- data/test/unit/request_processor_test.rb +73 -111
- data/test/unit/test_case_test.rb +13 -7
- data/test/unit/widget_shortcuts_test.rb +24 -53
- data/test/unit/widget_test.rb +76 -36
- data/test/widgets/mouse/eat.erb +1 -0
- data/test/{fixtures → widgets}/mouse/eating.html.erb +0 -0
- data/test/{fixtures → widgets}/mouse/educate.html.erb +0 -0
- data/test/{fixtures → widgets}/mouse/feed.html.erb +0 -0
- data/test/{fixtures → widgets}/mouse/make_me_squeak.html.erb +0 -0
- data/test/{fixtures → widgets}/mouse/posing.html.erb +0 -0
- data/test/widgets/mouse/snuggle.html.erb +1 -0
- metadata +32 -50
- data/lib/apotomo/container_widget.rb +0 -10
- data/lib/apotomo/persistence.rb +0 -112
- data/lib/apotomo/rails/view_methods.rb +0 -7
- data/lib/apotomo/stateful_widget.rb +0 -29
- data/lib/apotomo/transition.rb +0 -46
- data/lib/generators/apotomo/templates/view.haml +0 -4
- data/test/dummy/log/production.log +0 -0
- data/test/dummy/log/server.log +0 -0
- data/test/dummy/public/javascripts/application.js +0 -2
- data/test/dummy/public/javascripts/controls.js +0 -965
- data/test/dummy/public/javascripts/dragdrop.js +0 -974
- data/test/dummy/public/javascripts/effects.js +0 -1123
- data/test/dummy/public/javascripts/prototype.js +0 -6001
- data/test/dummy/public/javascripts/rails.js +0 -175
- data/test/dummy/script/rails +0 -6
- data/test/dummy/tmp/app/cells/mouse_widget.rb +0 -11
- data/test/dummy/tmp/app/cells/mouse_widget/snuggle.html.erb +0 -7
- data/test/dummy/tmp/app/cells/mouse_widget/squeak.html.erb +0 -7
- data/test/dummy/tmp/test/widgets/mouse_widget_test.rb +0 -12
- data/test/fixtures/application_widget_tree.rb +0 -2
- data/test/fixtures/mouse/snuggle.html.erb +0 -1
- data/test/rails/view_methods_test.rb +0 -38
- data/test/unit/container_test.rb +0 -21
- data/test/unit/invoke_test.rb +0 -126
- data/test/unit/persistence_test.rb +0 -201
- data/test/unit/stateful_widget_test.rb +0 -58
- data/test/unit/test_addressing.rb +0 -110
- data/test/unit/test_jump_to_state.rb +0 -89
- data/test/unit/test_tab_panel.rb +0 -71
- data/test/unit/transition_test.rb +0 -34
@@ -4,42 +4,40 @@ class RequestProcessorTest < ActiveSupport::TestCase
|
|
4
4
|
include Apotomo::TestCaseMethods::TestController
|
5
5
|
|
6
6
|
def root_mum_and_kid!
|
7
|
+
mum_and_kid!
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
@root = Apotomo::Widget.new(parent_controller, 'root', :display)
|
11
|
-
@root << @mum
|
12
|
-
|
13
|
-
|
14
|
-
@session = {}
|
15
|
-
#freeze!
|
16
|
-
end
|
17
|
-
|
18
|
-
# Call SW.freeze_for on @session, "freezing" stateful widgets below @root there.
|
19
|
-
def freeze!
|
20
|
-
Apotomo::StatefulWidget.freeze_for(@session, @root)
|
9
|
+
@root = Apotomo::Widget.new(parent_controller, 'root', :display)
|
10
|
+
@root << @mum
|
21
11
|
end
|
22
12
|
|
23
13
|
|
24
|
-
context "
|
25
|
-
|
26
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller
|
14
|
+
context "RequestProcessor" do
|
15
|
+
setup do
|
16
|
+
@processor = Apotomo::RequestProcessor.new(parent_controller)
|
27
17
|
root = @processor.root
|
28
18
|
root << mouse_mock
|
19
|
+
end
|
20
|
+
|
21
|
+
should "allow external modification of the tree" do
|
22
|
+
root = @processor.root
|
29
23
|
assert_equal 2, @processor.root.size
|
30
24
|
end
|
25
|
+
|
26
|
+
should "delegate #render_widget_for to #root" do
|
27
|
+
assert_equal 'squeak!', @processor.render_widget_for('mouse', :squeak)
|
28
|
+
end
|
31
29
|
end
|
32
30
|
|
33
31
|
context "#attach_stateless_blocks_for" do
|
34
32
|
setup do
|
35
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller
|
33
|
+
@processor = Apotomo::RequestProcessor.new(parent_controller)
|
36
34
|
@root = @processor.root
|
37
35
|
assert_equal @root.size, 1
|
38
36
|
end
|
39
37
|
|
40
38
|
should "allow has_widgets blocks with root parameter" do
|
41
39
|
@processor.send(:attach_stateless_blocks_for, [Proc.new{ |root|
|
42
|
-
root
|
40
|
+
root << widget(:mouse, 'mouse')
|
43
41
|
}], @root, parent_controller)
|
44
42
|
|
45
43
|
assert_equal 'mouse', @processor.root['mouse'].name
|
@@ -47,13 +45,9 @@ class RequestProcessorTest < ActiveSupport::TestCase
|
|
47
45
|
end
|
48
46
|
|
49
47
|
context "option processing at construction time" do
|
50
|
-
context "with empty
|
48
|
+
context "with empty options" do
|
51
49
|
setup do
|
52
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller
|
53
|
-
end
|
54
|
-
|
55
|
-
should "mark the tree as flushed" do
|
56
|
-
assert @processor.widgets_flushed?
|
50
|
+
@processor = Apotomo::RequestProcessor.new(parent_controller)
|
57
51
|
end
|
58
52
|
|
59
53
|
should "provide a single root-node for #root" do
|
@@ -63,60 +57,15 @@ class RequestProcessorTest < ActiveSupport::TestCase
|
|
63
57
|
|
64
58
|
context "with controller" do
|
65
59
|
should "attach the passed parent_controller to root" do
|
66
|
-
assert_equal parent_controller, Apotomo::RequestProcessor.new(parent_controller, {},
|
60
|
+
assert_equal parent_controller, Apotomo::RequestProcessor.new(parent_controller, {}, []).root.parent_controller
|
67
61
|
end
|
68
62
|
end
|
69
|
-
|
70
|
-
context "with session" do
|
71
|
-
setup do
|
72
|
-
root_mum_and_kid!
|
73
|
-
@mum.version = 1
|
74
|
-
freeze!
|
75
|
-
|
76
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller, @session)
|
77
|
-
end
|
78
|
-
|
79
|
-
should "provide a widget family for #root" do
|
80
|
-
assert_equal 3, @processor.root.size
|
81
|
-
assert_equal 1, @processor.root['mum'].version
|
82
|
-
assert_not @processor.widgets_flushed?
|
83
|
-
end
|
84
|
-
|
85
|
-
context "having a flush flag set" do
|
86
|
-
setup do
|
87
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller, @session, :flush_widgets => true)
|
88
|
-
end
|
89
|
-
|
90
|
-
should "provide a single root for #root when :flush_widgets is set" do
|
91
|
-
assert_equal 1, @processor.root.size
|
92
|
-
assert @processor.widgets_flushed?
|
93
|
-
end
|
94
|
-
|
95
|
-
should "wipe-out our session variables" do
|
96
|
-
assert_nil @session[:apotomo_stateful_branches]
|
97
|
-
assert_nil @session[:apotomo_widget_ivars]
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
context "and with stateless widgets" do
|
103
|
-
setup do
|
104
|
-
root_mum_and_kid!
|
105
|
-
freeze!
|
106
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller, @session, {}, [Proc.new { |root| root << Apotomo::Widget.new(parent_controller, 'grandma', :eating) }])
|
107
|
-
end
|
108
|
-
|
109
|
-
should "first attach passed stateless, then stateful widgets to root" do
|
110
|
-
assert_equal 4, @processor.root.size
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
63
|
end
|
116
64
|
|
65
|
+
|
117
66
|
context "#process_for" do
|
118
67
|
setup do
|
119
|
-
class
|
68
|
+
class KidWidget < Apotomo::Widget
|
120
69
|
responds_to_event :doorSlam, :with => :flight
|
121
70
|
responds_to_event :doorSlam, :with => :squeak
|
122
71
|
def flight; render :text => "away from here!"; end
|
@@ -124,10 +73,10 @@ class RequestProcessorTest < ActiveSupport::TestCase
|
|
124
73
|
end
|
125
74
|
|
126
75
|
procs = [Proc.new{ |root,controller|
|
127
|
-
root <<
|
76
|
+
root << widget(:mouse, 'mum') << KidWidget.new(parent_controller, 'kid', :squeak)
|
128
77
|
}]
|
129
78
|
|
130
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller, {
|
79
|
+
@processor = Apotomo::RequestProcessor.new(parent_controller, {:js_framework => :prototype}, procs)
|
131
80
|
end
|
132
81
|
|
133
82
|
should "return an empty array if nothing was triggered" do
|
@@ -138,6 +87,14 @@ class RequestProcessorTest < ActiveSupport::TestCase
|
|
138
87
|
assert_equal ["away from here!", "squeak!"], @processor.process_for({:type => :doorSlam, :source => 'kid'})
|
139
88
|
end
|
140
89
|
|
90
|
+
should "append the params hash to the triggered event" do
|
91
|
+
KidWidget.class_eval do
|
92
|
+
def squeak(evt); render :text => evt.data.inspect; end
|
93
|
+
end
|
94
|
+
|
95
|
+
assert_equal ["away from here!", "{:type=>:doorSlam, :source=>\"kid\"}"], @processor.process_for({:type => :doorSlam, :source => 'kid'})
|
96
|
+
end
|
97
|
+
|
141
98
|
should "raise an exception when :source is unknown" do
|
142
99
|
assert_raises RuntimeError do
|
143
100
|
@processor.process_for({:type => :squeak, :source => 'tom'})
|
@@ -146,47 +103,11 @@ class RequestProcessorTest < ActiveSupport::TestCase
|
|
146
103
|
end
|
147
104
|
|
148
105
|
|
149
|
-
|
150
|
-
context "#freeze!" do
|
151
|
-
should "serialize stateful branches to @session" do
|
152
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller, {})
|
153
|
-
@processor.root << mum_and_kid!
|
154
|
-
assert_equal 3, @processor.root.size
|
155
|
-
@processor.freeze!
|
156
|
-
|
157
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller, @processor.session)
|
158
|
-
assert_equal 3, @processor.root.size
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "#render_widget_for" do
|
163
|
-
setup do
|
164
|
-
class MouseCell < Apotomo::Widget
|
165
|
-
def squeak; render :text => "squeak!"; end
|
166
|
-
end
|
167
|
-
|
168
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller, {}, {},
|
169
|
-
[Proc.new { |root| root << MouseCell.new(parent_controller, 'mum', :squeak) }])
|
170
|
-
end
|
171
|
-
|
172
|
-
should "render the widget when passing an existing widget id" do
|
173
|
-
assert_equal 'squeak!', @processor.render_widget_for('mum', {})
|
174
|
-
end
|
175
|
-
|
176
|
-
should "render the widget when passing an existing widget instance" do
|
177
|
-
assert_equal 'squeak!', @processor.render_widget_for(@processor.root['mum'], {})
|
178
|
-
end
|
179
106
|
|
180
|
-
should "raise an exception when a non-existent widget id id passed" do
|
181
|
-
assert_raises RuntimeError do
|
182
|
-
@processor.render_widget_for('mummy', {})
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
107
|
|
187
108
|
context "invoking #address_for" do
|
188
109
|
setup do
|
189
|
-
@processor = Apotomo::RequestProcessor.new(parent_controller
|
110
|
+
@processor = Apotomo::RequestProcessor.new(parent_controller)
|
190
111
|
end
|
191
112
|
|
192
113
|
should "accept an event :type" do
|
@@ -210,3 +131,44 @@ class RequestProcessorTest < ActiveSupport::TestCase
|
|
210
131
|
end
|
211
132
|
end
|
212
133
|
end
|
134
|
+
|
135
|
+
class RequestProcessorHooksTest < ActiveSupport::TestCase
|
136
|
+
include Apotomo::TestCaseMethods::TestController
|
137
|
+
include Apotomo::TestCaseMethods
|
138
|
+
|
139
|
+
context "Hooks in RequestProcessor" do
|
140
|
+
setup do
|
141
|
+
@class = Class.new(Apotomo::RequestProcessor)
|
142
|
+
end
|
143
|
+
|
144
|
+
context ":after_initialize hook" do
|
145
|
+
should "be called after the has_widgets blocks invokation" do
|
146
|
+
@k = mouse_mock("kid")
|
147
|
+
@class.after_initialize do |r|
|
148
|
+
r.root["mum"] << @k
|
149
|
+
end
|
150
|
+
|
151
|
+
@r = @class.new(parent_controller, {},
|
152
|
+
[Proc.new { |root| root << widget(:mouse, 'mum') }])
|
153
|
+
|
154
|
+
assert_equal @r.root["mum"]["kid"], @k
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context ":after_fire hook" do
|
159
|
+
should "be called in #process_for after fire" do
|
160
|
+
@k = mouse_mock("kid")
|
161
|
+
@class.after_fire do |r|
|
162
|
+
r.root["mum"] << @k = mouse_mock("kid")
|
163
|
+
end
|
164
|
+
|
165
|
+
# DISCUSS: maybe add a trigger test here?
|
166
|
+
@r = @class.new(parent_controller, {},
|
167
|
+
[Proc.new { |root| root << widget(:mouse, 'mum') }])
|
168
|
+
@r.process_for(:source => "root", :type => :noop) # calls ~after_fire.
|
169
|
+
|
170
|
+
assert_equal @k, @r.root["mum"]["kid"]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
data/test/unit/test_case_test.rb
CHANGED
@@ -18,7 +18,7 @@ class TestCaseTest < Test::Unit::TestCase
|
|
18
18
|
setup do
|
19
19
|
@klass = MouseWidgetTest
|
20
20
|
@test = @klass.new(:widget).tap{ |t| t.setup }
|
21
|
-
@klass.has_widgets { |r| r << widget(
|
21
|
+
@klass.has_widgets { |r| r << widget(:mouse, 'mum', :eating) }
|
22
22
|
end
|
23
23
|
|
24
24
|
should "respond to #root" do
|
@@ -40,12 +40,12 @@ class TestCaseTest < Test::Unit::TestCase
|
|
40
40
|
end
|
41
41
|
|
42
42
|
should "respond to #render_widget" do
|
43
|
-
assert_equal "<div id=\"mum\">burp!</div
|
44
|
-
assert_equal "<div id=\"mum\">burp!</div
|
43
|
+
assert_equal "<div id=\"mum\">burp!</div>\n", @test.render_widget('mum', :eat)
|
44
|
+
assert_equal "<div id=\"mum\">burp!</div>\n", @test.last_invoke
|
45
45
|
end
|
46
46
|
|
47
47
|
should "respond to #assert_select" do
|
48
|
-
@test.render_widget('mum')
|
48
|
+
@test.render_widget('mum', :eat)
|
49
49
|
|
50
50
|
assert_nothing_raised { @test.assert_select("div#mum", "burp!") }
|
51
51
|
|
@@ -68,9 +68,15 @@ class TestCaseTest < Test::Unit::TestCase
|
|
68
68
|
|
69
69
|
should "provide options from #trigger to the widget" do
|
70
70
|
@test.trigger(:footsteps, :source => 'mum', :direction => :kitchen)
|
71
|
-
assert_equal :kitchen, @mum.
|
71
|
+
assert_equal :kitchen, @mum.options[:direction]
|
72
72
|
end
|
73
73
|
|
74
|
+
#should "merge options from #trigger and constructor" do
|
75
|
+
# @test.root << @test.widget("mouse_cell", 'kid', :location => :hallway)
|
76
|
+
# @test.trigger(:footsteps, :source => 'kid', :direction => :kitchen)
|
77
|
+
# assert_equal({:direction => :kitchen, :location => :hallway}, @mum.param(:direction))
|
78
|
+
#end
|
79
|
+
|
74
80
|
should "respond to #assert_response" do
|
75
81
|
@test.trigger(:footsteps, :source => 'mum')
|
76
82
|
assert @test.assert_response("squeak!")
|
@@ -87,8 +93,8 @@ class TestCaseTest < Test::Unit::TestCase
|
|
87
93
|
assert_kind_of ActionController::Base, @test.parent_controller
|
88
94
|
end
|
89
95
|
|
90
|
-
should "respond to #
|
91
|
-
assert_equal "barn", @test.parent_controller.
|
96
|
+
should "respond to #controller_path" do
|
97
|
+
assert_equal "barn", @test.parent_controller.controller_path
|
92
98
|
end
|
93
99
|
end
|
94
100
|
end
|
@@ -1,105 +1,76 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class MumWidget <
|
4
|
-
class
|
3
|
+
class MumWidget < MouseWidget; end
|
4
|
+
class MouseTabsWidget;end
|
5
5
|
|
6
6
|
class WidgetShortcutsTest < Test::Unit::TestCase
|
7
7
|
include Apotomo::TestCaseMethods::TestController
|
8
8
|
|
9
9
|
context "#constant_for" do
|
10
10
|
should "constantize symbols" do
|
11
|
-
assert_equal MumWidget, constant_for(:
|
11
|
+
assert_equal MumWidget, constant_for(:mum)
|
12
12
|
end
|
13
13
|
|
14
14
|
should "not try to singularize the widget class" do
|
15
|
-
assert_equal
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "#cell" do
|
20
|
-
should "create a MouseCell instance for backward-compatibility" do
|
21
|
-
assert_kind_of MouseCell, cell(:mouse, :eating, 'mum')
|
15
|
+
assert_equal MouseTabsWidget, constant_for(:mouse_tabs)
|
22
16
|
end
|
23
17
|
end
|
24
18
|
|
25
19
|
context "#widget" do
|
26
20
|
context "with all arguments" do
|
27
21
|
setup do
|
28
|
-
@mum = widget(:
|
22
|
+
@mum = widget(:mum, 'mum', :eating, :color => 'grey', :type => :hungry)
|
29
23
|
end
|
30
24
|
|
31
25
|
should "create a MumWidget instance" do
|
32
26
|
assert_kind_of MumWidget, @mum
|
33
|
-
assert_equal :eating, @mum.instance_variable_get(:@start_state)
|
34
27
|
assert_equal 'mum', @mum.name
|
35
28
|
end
|
36
29
|
|
37
30
|
should "accept options" do
|
38
|
-
assert_equal({:color => "grey", :type => :hungry}, @mum.
|
31
|
+
assert_equal({:color => "grey", :type => :hungry}, @mum.options)
|
39
32
|
end
|
40
33
|
end
|
41
34
|
|
42
|
-
context "with 3 arguments and no
|
43
|
-
should "set
|
44
|
-
@mum = widget(:
|
35
|
+
context "with 3 arguments and no options" do
|
36
|
+
should "not set options" do
|
37
|
+
@mum = widget(:mum, 'mum', :squeak)
|
45
38
|
assert_kind_of MumWidget, @mum
|
46
|
-
assert_equal :display, @mum.instance_variable_get(:@start_state)
|
47
39
|
assert_equal 'mum', @mum.name
|
48
|
-
assert_equal({
|
40
|
+
assert_equal({}, @mum.options)
|
49
41
|
end
|
50
42
|
end
|
51
43
|
|
52
|
-
context "with
|
53
|
-
|
54
|
-
@mum = widget(:
|
44
|
+
context "with class and id" do
|
45
|
+
setup do
|
46
|
+
@mum = widget(:mum, 'mummy')
|
47
|
+
end
|
48
|
+
|
49
|
+
should "create a MumWidget instance" do
|
55
50
|
assert_kind_of MumWidget, @mum
|
56
|
-
assert_equal
|
57
|
-
assert_equal 'mum', @mum.name
|
58
|
-
assert_equal({}, @mum.opts)
|
51
|
+
assert_equal 'mummy', @mum.name
|
59
52
|
end
|
60
53
|
end
|
61
54
|
|
62
|
-
context "with
|
55
|
+
context "with class, only" do
|
63
56
|
setup do
|
64
|
-
@mum = widget(:
|
57
|
+
@mum = widget(:mum)
|
65
58
|
end
|
66
59
|
|
67
|
-
should "create a MumWidget instance
|
60
|
+
should "create a MumWidget instance named :mum" do
|
68
61
|
assert_kind_of MumWidget, @mum
|
69
|
-
assert_equal :
|
70
|
-
assert_equal 'mum', @mum.name
|
62
|
+
assert_equal :mum, @mum.name
|
71
63
|
end
|
72
64
|
end
|
73
65
|
|
66
|
+
|
74
67
|
should "yield itself" do
|
75
|
-
@mum = widget(:
|
68
|
+
@mum = widget(:mum, 'mum') do |mum|
|
76
69
|
assert_kind_of MumWidget, mum
|
77
|
-
mum << widget(:
|
70
|
+
mum << widget(:mum, 'kid')
|
78
71
|
end
|
79
72
|
assert_equal 2, @mum.size
|
80
73
|
assert_kind_of MumWidget, @mum['kid']
|
81
74
|
end
|
82
75
|
end
|
83
|
-
|
84
|
-
context "#container" do
|
85
|
-
setup do
|
86
|
-
@family = container('family')
|
87
|
-
end
|
88
|
-
|
89
|
-
should "create a ContainerWidget instance" do
|
90
|
-
assert_kind_of ::Apotomo::ContainerWidget, @family
|
91
|
-
assert_equal 'family', @family.name
|
92
|
-
end
|
93
|
-
|
94
|
-
should "yield itself" do
|
95
|
-
@container = container(:family) do |family|
|
96
|
-
family << widget(:mum_widget, 'mum')
|
97
|
-
end
|
98
|
-
assert_equal 2, @container.size
|
99
|
-
end
|
100
|
-
|
101
|
-
should "be aliased to #section for backward-compatibility" do
|
102
|
-
assert_kind_of ::Apotomo::ContainerWidget, section('family')
|
103
|
-
end
|
104
|
-
end
|
105
76
|
end
|
data/test/unit/widget_test.rb
CHANGED
@@ -9,34 +9,34 @@ class WidgetTest < ActiveSupport::TestCase
|
|
9
9
|
@mum = Apotomo::Widget.new(@controller, 'mum', :squeak)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
context "Widget.has_widgets" do
|
14
14
|
setup do
|
15
|
-
@mum = Class.new(
|
15
|
+
@mum = Class.new(MouseWidget) do
|
16
16
|
has_widgets do |me|
|
17
|
-
me << widget(
|
17
|
+
me << widget(:mouse, 'baby')
|
18
18
|
end
|
19
|
-
end.new(@controller, 'mum'
|
19
|
+
end.new(@controller, 'mum')
|
20
20
|
|
21
21
|
@kid = Class.new(@mum.class).new(@controller, 'mum', :squeak)
|
22
22
|
end
|
23
23
|
|
24
24
|
should "setup the widget family at creation time" do
|
25
25
|
assert_equal 1, @mum.children.size
|
26
|
-
assert_kind_of Apotomo::
|
26
|
+
assert_kind_of Apotomo::Widget, @mum['baby']
|
27
27
|
end
|
28
28
|
|
29
29
|
should "inherit trees for now" do
|
30
30
|
assert_equal 1, @mum.children.size
|
31
|
-
assert_kind_of Apotomo::
|
31
|
+
assert_kind_of Apotomo::Widget, @mum['baby']
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
context "Widget.after_add" do
|
36
36
|
setup do
|
37
|
-
@mum = Class.new(
|
37
|
+
@mum = Class.new(MouseWidget) do
|
38
38
|
after_add do |me, parent|
|
39
|
-
parent << widget(
|
39
|
+
parent << widget(:mouse, 'kid', :squeak)
|
40
40
|
end
|
41
41
|
end.new(@controller, 'mum', :squeak)
|
42
42
|
|
@@ -57,7 +57,7 @@ class WidgetTest < ActiveSupport::TestCase
|
|
57
57
|
assert_equal ['berry', 'kid'], @root.children.collect { |w| w.name }
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
context "A stateless widget" do
|
62
62
|
setup do
|
63
63
|
@mum = Apotomo::Widget.new(@controller, 'mum', :squeak)
|
@@ -91,23 +91,6 @@ class WidgetTest < ActiveSupport::TestCase
|
|
91
91
|
@mum.visible = false
|
92
92
|
assert_not @mum.visible?
|
93
93
|
end
|
94
|
-
|
95
|
-
context "in a widget family" do
|
96
|
-
setup do
|
97
|
-
@mum << @jerry = mouse_mock('jerry')
|
98
|
-
@mum << @berry = mouse_mock('berry')
|
99
|
-
end
|
100
|
-
|
101
|
-
should "per default return all #visible_children" do
|
102
|
-
assert_equal [@jerry, @berry], @mum.visible_children
|
103
|
-
assert_equal [], @jerry.visible_children
|
104
|
-
end
|
105
|
-
|
106
|
-
should "hide berry in #visible_children if he's invisible" do
|
107
|
-
@berry.visible = false
|
108
|
-
assert_equal [@jerry], @mum.visible_children
|
109
|
-
end
|
110
|
-
end
|
111
94
|
end
|
112
95
|
|
113
96
|
should "respond to #find_widget" do
|
@@ -128,16 +111,23 @@ class WidgetTest < ActiveSupport::TestCase
|
|
128
111
|
assert_equal @mum.name, @mum.widget_id
|
129
112
|
end
|
130
113
|
|
131
|
-
should "
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
assert_equal 'grey', @mum.param(:color)
|
136
|
-
assert_equal 'grey', @mum.param('color')
|
137
|
-
assert_equal 'shrew', @mum.param(:type)
|
138
|
-
assert_equal 'Logitech', @mum.param(:brand)
|
114
|
+
should "mark #param as deprecated" do
|
115
|
+
assert_raises RuntimeError do
|
116
|
+
@mum.param(:volume)
|
117
|
+
end
|
139
118
|
end
|
140
119
|
|
120
|
+
should "respond to DEFAULT_VIEW_PATHS" do
|
121
|
+
assert_equal ["app/widgets", "app/widgets/layouts"], Apotomo::Widget::DEFAULT_VIEW_PATHS
|
122
|
+
end
|
123
|
+
|
124
|
+
should "respond to .view_paths" do
|
125
|
+
assert_equal ActionView::PathSet.new(Apotomo::Widget::DEFAULT_VIEW_PATHS + ["test/widgets"]), Apotomo::Widget.view_paths
|
126
|
+
end
|
127
|
+
|
128
|
+
should "respond to .controller_path" do
|
129
|
+
assert_equal "mouse", MouseWidget.controller_path
|
130
|
+
end
|
141
131
|
|
142
132
|
# internal_methods:
|
143
133
|
should "not list internal methods in action_methods" do
|
@@ -145,8 +135,8 @@ class WidgetTest < ActiveSupport::TestCase
|
|
145
135
|
end
|
146
136
|
|
147
137
|
should "list both local and inherited states in Widget.action_methods" do
|
148
|
-
assert
|
149
|
-
assert Class.new(
|
138
|
+
assert MouseWidget.action_methods.collect{ |m| m.to_s }.include?("squeak")
|
139
|
+
assert Class.new(MouseWidget).action_methods.collect{ |m| m.to_s }.include?("squeak")
|
150
140
|
end
|
151
141
|
|
152
142
|
should "not list #display in internal_methods although it's defined in Object" do
|
@@ -154,3 +144,53 @@ class WidgetTest < ActiveSupport::TestCase
|
|
154
144
|
end
|
155
145
|
end
|
156
146
|
end
|
147
|
+
|
148
|
+
|
149
|
+
class RenderWidgetTest < ActiveSupport::TestCase
|
150
|
+
include Apotomo::TestCaseMethods::TestController
|
151
|
+
|
152
|
+
context "#render_widget" do
|
153
|
+
should "allow passing widget id" do
|
154
|
+
assert_equal "squeak!", mouse_mock.render_widget('mouse', :squeak)
|
155
|
+
end
|
156
|
+
|
157
|
+
should "allow passing widget instance" do
|
158
|
+
assert_equal 'squeak!', mouse_mock.render_widget(mouse_mock('mum'), :squeak)
|
159
|
+
end
|
160
|
+
|
161
|
+
should "use :display as standard state" do
|
162
|
+
mum = mouse_mock('Mum') do
|
163
|
+
def display
|
164
|
+
render :text => "#{widget_id}, that's me!"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
assert_equal "Mum, that's me!", mouse_mock.render_widget(mum)
|
169
|
+
end
|
170
|
+
|
171
|
+
should "raise an exception when a non-existent widget id is passed" do
|
172
|
+
e = assert_raises RuntimeError do
|
173
|
+
mouse_mock.render_widget('mummy')
|
174
|
+
end
|
175
|
+
|
176
|
+
assert_equal "Couldn't render non-existent widget `mummy`", e.message
|
177
|
+
end
|
178
|
+
|
179
|
+
should "pass options as state-args" do
|
180
|
+
mum = mouse_mock do
|
181
|
+
def display(color="grey")
|
182
|
+
render :text => "I'm #{color}"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
assert_equal("I'm grey", mouse_mock.render_widget(mum), "default value in state-arg didn't work")
|
187
|
+
assert_equal("I'm black", mouse_mock.render_widget(mum, :display, "black"))
|
188
|
+
end
|
189
|
+
|
190
|
+
should "use #find_widget from self to find the passed widget id" do
|
191
|
+
mum = mouse_mock('mum') << mouse_mock(:kid)
|
192
|
+
|
193
|
+
assert_equal "<div id=\"kid\">burp!</div>\n", mum.render_widget(:kid, :eat)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|