apotomo 1.0.5 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,39 @@
|
|
1
|
+
module Apotomo
|
2
|
+
module JavascriptMethods
|
3
|
+
# Wraps the rendered content in a replace statement targeted at your +Apotomo.js_framework+ setting.
|
4
|
+
# Use +:selector+ to change the selector.
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# Assuming you set
|
9
|
+
# Apotomo.js_framework = :jquery
|
10
|
+
#
|
11
|
+
# and call replace in a state
|
12
|
+
#
|
13
|
+
# replace :view => :squeak, :selector => "div#mouse"
|
14
|
+
# #=> "$(\"div#mouse\").replaceWith(\"<div id=\\\"mum\\\">squeak!<\\/div>\")"
|
15
|
+
def replace(*args)
|
16
|
+
wrap_in_javascript_for(:replace, *args)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Same as replace except that the content is wrapped in an update statement.
|
20
|
+
#
|
21
|
+
# Example for +:jquery+:
|
22
|
+
#
|
23
|
+
# update :view => :squeak
|
24
|
+
# #=> "$(\"mum\").html(\"<div id=\\\"mum\\\">squeak!<\\/div>\")"
|
25
|
+
def update(*args)
|
26
|
+
wrap_in_javascript_for(:update, *args)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def wrap_in_javascript_for(mode, *args)
|
31
|
+
content = render(*args)
|
32
|
+
options = args.first.is_a?(::Hash) ? args.shift : {}
|
33
|
+
|
34
|
+
options[:selector] ?
|
35
|
+
Apotomo.js_generator.send(mode, options[:selector], content) : # replace(:twitter)
|
36
|
+
Apotomo.js_generator.send("#{mode}_id", name, content) # replace_id(:twitter)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,59 +1,33 @@
|
|
1
1
|
module Apotomo
|
2
2
|
# Shortcut methods for creating widget trees.
|
3
3
|
module WidgetShortcuts
|
4
|
-
# Shortcut for creating an instance of
|
5
|
-
# If +start_state+ is omited, :display is default. Yields self.
|
4
|
+
# Shortcut for creating an instance of <tt>class_name+"_widget"</tt> named +id+. Yields self.
|
6
5
|
#
|
7
6
|
# Example:
|
8
7
|
#
|
9
|
-
# widget(:
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# Start state is <tt>:display</tt>, whereas the latter also populates @opts.
|
8
|
+
# widget(:comments)
|
9
|
+
#
|
10
|
+
# will create a +CommentsWidget+ with id :comments.
|
13
11
|
#
|
14
|
-
# widget(:
|
15
|
-
# widget(:comments_widget, 'post-comments', :reload, :user => @current_user)
|
12
|
+
# widget(:comments, 'post-comments', :user => current_user)
|
16
13
|
#
|
17
|
-
#
|
14
|
+
# sets id to 'posts_comments' and #options to the hash.
|
18
15
|
#
|
19
16
|
# You can also use namespaces.
|
20
17
|
#
|
21
18
|
# widget('jquery/tabs', 'panel')
|
22
|
-
def widget(
|
23
|
-
|
24
|
-
|
25
|
-
state = :display
|
26
|
-
end
|
19
|
+
def widget(prefix, *args)
|
20
|
+
options = args.extract_options!
|
21
|
+
id = args.shift || prefix
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def container(id, *args, &block)
|
34
|
-
widget('apotomo/container_widget', id, *args, &block)
|
35
|
-
end
|
36
|
-
|
37
|
-
def section(*args)
|
38
|
-
container(*args)
|
39
|
-
end
|
40
|
-
|
41
|
-
# TODO: deprecate.
|
42
|
-
def cell(base_name, states, id, *args)
|
43
|
-
widget(base_name.to_s + '_cell', states, id, *args)
|
44
|
-
end
|
45
|
-
|
46
|
-
def tab_panel(id, *args)
|
47
|
-
widget('apotomo/tab_panel_widget', :display, id, *args)
|
48
|
-
end
|
49
|
-
|
50
|
-
def tab(id, *args)
|
51
|
-
widget('apotomo/tab_widget', :display, id, *args)
|
23
|
+
constant_for(prefix).new(parent_controller, id, options).tap do |object|
|
24
|
+
yield object if block_given?
|
25
|
+
end
|
52
26
|
end
|
53
27
|
|
54
28
|
private
|
55
|
-
def constant_for(class_name)
|
56
|
-
class_name.
|
29
|
+
def constant_for(class_name) # TODO: use Cell.class_from_cell_name.
|
30
|
+
"#{class_name}_widget".classify.constantize
|
57
31
|
end
|
58
32
|
end
|
59
33
|
end
|
@@ -1,19 +1,18 @@
|
|
1
|
-
require 'generators/cells/
|
1
|
+
require 'generators/cells/base'
|
2
2
|
|
3
3
|
module Apotomo
|
4
4
|
module Generators
|
5
|
-
class WidgetGenerator < Cells::Generators::
|
6
|
-
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
5
|
+
class WidgetGenerator < ::Cells::Generators::Base
|
6
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), '../templates'))
|
7
7
|
|
8
8
|
def create_cell_file
|
9
|
-
|
10
|
-
template 'widget.rb', File.join('app/cells', class_path, "#{file_name}.rb")
|
9
|
+
template 'widget.rb', File.join('app/widgets', class_path, "#{file_name}_widget.rb")
|
11
10
|
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
check_class_collision :suffix => "Widget"
|
13
|
+
|
14
|
+
hook_for(:template_engine)
|
15
|
+
hook_for(:test_framework) # TODO: implement rspec-apotomo.
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'generators/cells/base'
|
2
|
+
|
3
|
+
module Erb
|
4
|
+
module Generators
|
5
|
+
class WidgetGenerator < ::Cells::Generators::Base
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_views
|
9
|
+
for state in actions do
|
10
|
+
@state = state
|
11
|
+
@path = File.join('app/widgets', file_name, "#{state}.html.erb")
|
12
|
+
template "view.erb", @path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'generators/cells/base'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
module Generators
|
5
|
+
class WidgetGenerator < ::Cells::Generators::Base
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_views
|
9
|
+
for state in actions do
|
10
|
+
@state = state
|
11
|
+
@path = File.join('app/widgets', file_name, "#{state}.html.haml")
|
12
|
+
|
13
|
+
template "view.haml", @path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'generators/cells/base'
|
2
|
+
|
3
|
+
module TestUnit
|
4
|
+
module Generators
|
5
|
+
class WidgetGenerator < ::Cells::Generators::Base
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_test
|
9
|
+
@states = actions
|
10
|
+
template 'widget_test.rb', File.join('test/widgets/', "#{file_name}_widget_test.rb")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/test/rails/caching_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
3
|
+
# TODO: assert that same-named cells and widgets don't overwrite their caches.
|
4
4
|
|
5
5
|
class CachingTest < ActiveSupport::TestCase
|
6
6
|
include Apotomo::TestCaseMethods::TestController
|
@@ -8,31 +8,24 @@ class CachingTest < ActiveSupport::TestCase
|
|
8
8
|
class CheeseWidget < Apotomo::Widget
|
9
9
|
cache :holes
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#def self.reset!
|
16
|
-
# @@counter = 0
|
17
|
-
#end
|
18
|
-
|
19
|
-
def increment!
|
20
|
-
self.class.holes += 1
|
21
|
-
end
|
22
|
-
|
23
|
-
def holes
|
24
|
-
render :text => increment!
|
11
|
+
def holes(count)
|
12
|
+
render :text => count
|
25
13
|
end
|
26
14
|
end
|
27
15
|
|
28
16
|
context "A caching widget" do
|
29
17
|
setup do
|
18
|
+
ActionController::Base.perform_caching = true
|
30
19
|
@cheese = CheeseWidget.new(parent_controller, 'cheese', :holes)
|
31
20
|
end
|
32
21
|
|
22
|
+
teardown do
|
23
|
+
ActionController::Base.perform_caching = false
|
24
|
+
end
|
25
|
+
|
33
26
|
should "invoke the cached state only once" do
|
34
|
-
assert_equal "1", @cheese.invoke
|
35
|
-
assert_equal "1", @cheese.invoke
|
27
|
+
assert_equal "1", @cheese.invoke(:holes, 1)
|
28
|
+
assert_equal "1", @cheese.invoke(:holes, 2)
|
36
29
|
end
|
37
30
|
end
|
38
31
|
end
|
@@ -16,7 +16,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context "responding to #apotomo_request_processor" do
|
19
|
-
should "initially return the processor which has
|
19
|
+
should "initially return the processor which has an empty root" do
|
20
20
|
assert_kind_of Apotomo::RequestProcessor, @controller.apotomo_request_processor
|
21
21
|
assert_equal 1, @controller.apotomo_request_processor.root.size
|
22
22
|
end
|
@@ -29,7 +29,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
29
29
|
context "invoking #has_widgets" do
|
30
30
|
setup do
|
31
31
|
@controller.class.has_widgets do |root|
|
32
|
-
root << widget(:
|
32
|
+
root << widget(:mouse, 'mum')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -44,7 +44,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
44
44
|
|
45
45
|
should "allow multiple calls to has_widgets" do
|
46
46
|
@controller.class.has_widgets do |root|
|
47
|
-
root << widget(:
|
47
|
+
root << widget(:mouse, 'kid')
|
48
48
|
end
|
49
49
|
|
50
50
|
assert @controller.apotomo_root['mum']
|
@@ -52,7 +52,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
52
52
|
end
|
53
53
|
|
54
54
|
should "inherit has_widgets blocks to sub-controllers" do
|
55
|
-
berry = widget(:
|
55
|
+
berry = widget(:mouse, 'berry')
|
56
56
|
@sub_controller = Class.new(@controller.class) do
|
57
57
|
has_widgets { |root| root << berry }
|
58
58
|
end.new
|
@@ -68,88 +68,34 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
68
68
|
end
|
69
69
|
|
70
70
|
@controller.class.has_widgets do |root|
|
71
|
-
root << widget(:
|
71
|
+
root << widget(:mouse, 'kid', :display, :roomies => roomies)
|
72
72
|
end
|
73
73
|
|
74
|
-
assert_equal ['mice', 'cows'], @controller.apotomo_root['kid'].
|
74
|
+
assert_equal ['mice', 'cows'], @controller.apotomo_root['kid'].options[:roomies]
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
|
79
|
-
should "have an empty apotomo_root if no call happened, yet" do
|
80
|
-
assert_equal [], @controller.bound_use_widgets_blocks
|
81
|
-
assert_equal 1, @controller.apotomo_root.size
|
82
|
-
end
|
83
|
-
|
84
|
-
should "extend the widget family and remember the block with one #use_widgets call" do
|
85
|
-
@controller.use_widgets do |root|
|
86
|
-
root << widget(:mouse_cell, 'mum')
|
87
|
-
end
|
88
|
-
|
89
|
-
assert_equal 1, @controller.bound_use_widgets_blocks.size
|
90
|
-
assert_equal 2, @controller.apotomo_root.size
|
91
|
-
end
|
92
|
-
|
93
|
-
should "add blocks only once" do
|
94
|
-
block = Proc.new {|root| root << widget(:mouse_cell, 'mum')}
|
95
|
-
|
96
|
-
@controller.use_widgets &block
|
97
|
-
@controller.use_widgets &block
|
98
|
-
|
99
|
-
assert_equal 1, @controller.bound_use_widgets_blocks.size
|
100
|
-
assert_equal 2, @controller.apotomo_root.size
|
101
|
-
end
|
102
|
-
|
103
|
-
should "allow multiple calls with different blocks" do
|
104
|
-
mum_and_kid!
|
105
|
-
@controller.use_widgets do |root|
|
106
|
-
root << @mum
|
107
|
-
end
|
108
|
-
@controller.use_widgets do |root|
|
109
|
-
root << widget(:mouse_cell, 'pet')
|
110
|
-
end
|
111
|
-
|
112
|
-
assert_equal 2, @controller.bound_use_widgets_blocks.size
|
113
|
-
assert_equal 4, @controller.apotomo_root.size
|
114
|
-
end
|
115
|
-
end
|
78
|
+
|
116
79
|
|
117
80
|
context "invoking #url_for_event" do
|
118
81
|
should "compute an url for any widget" do
|
119
82
|
assert_equal "/barn/render_event_response?source=mouse&type=footsteps&volume=9", @controller.url_for_event(:footsteps, :source => :mouse, :volume => 9)
|
120
83
|
end
|
121
84
|
end
|
122
|
-
|
123
|
-
should "flush its bound_use_widgets_blocks with, guess, #flush_bound_use_widgets_blocks" do
|
124
|
-
@controller.bound_use_widgets_blocks << Proc.new {}
|
125
|
-
assert_equal 1, @controller.bound_use_widgets_blocks.size
|
126
|
-
@controller.flush_bound_use_widgets_blocks
|
127
|
-
assert_equal 0, @controller.bound_use_widgets_blocks.size
|
128
|
-
end
|
129
85
|
end
|
130
86
|
|
131
87
|
context "invoking #render_widget" do
|
132
88
|
setup do
|
133
|
-
@mum = mouse_mock('mum', '
|
89
|
+
@mum = mouse_mock('mum', 'eating')
|
134
90
|
end
|
135
91
|
|
136
92
|
should "render the widget" do
|
137
93
|
@controller.apotomo_root << @mum
|
138
|
-
assert_equal "<div id=\"mum\"
|
94
|
+
assert_equal "<div id=\"mum\">burp!</div>\n", @controller.render_widget('mum', :eat)
|
139
95
|
end
|
140
96
|
end
|
141
97
|
|
142
98
|
|
143
|
-
|
144
|
-
context "invoking #apotomo_freeze" do
|
145
|
-
should "freeze the widget tree to session" do
|
146
|
-
assert_equal 0, @controller.session.size
|
147
|
-
@controller.send :apotomo_freeze
|
148
|
-
assert @controller.session[:apotomo_widget_ivars]
|
149
|
-
assert @controller.session[:apotomo_stateful_branches]
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
99
|
context "processing an event request" do
|
154
100
|
setup do
|
155
101
|
@mum = mouse_mock('mum', :eating)
|
@@ -180,24 +126,6 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
180
126
|
end
|
181
127
|
end
|
182
128
|
|
183
|
-
context "The ProcHash" do
|
184
|
-
setup do
|
185
|
-
@procs = Apotomo::Rails::ControllerMethods::ProcHash.new
|
186
|
-
@b = Proc.new{}; @d = Proc.new{}
|
187
|
-
@c = Proc.new{}
|
188
|
-
@procs << @b
|
189
|
-
end
|
190
|
-
|
191
|
-
should "return true for procs it includes" do
|
192
|
-
assert @procs.include?(@b)
|
193
|
-
assert @procs.include?(@d) ### DISCUSS: line nr is id, or do YOU got a better idea?!
|
194
|
-
end
|
195
|
-
|
196
|
-
should "reject unknown procs" do
|
197
|
-
assert ! @procs.include?(@c)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
129
|
### FIXME: could somebody get that working?
|
202
130
|
context "Routing" do
|
203
131
|
should_eventually "generate routes to the render_event_response action" do
|
@@ -1,90 +1,55 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class RailsIntegrationTest < ActionController::TestCase
|
4
|
+
include Apotomo::TestCaseMethods::TestController
|
5
|
+
|
4
6
|
def simulate_request!
|
5
7
|
@controller.instance_eval { @apotomo_request_processor = nil }
|
6
|
-
|
7
|
-
### FIXME: @controller.session = Marshal.load(Marshal.dump(@controller.session))
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
context "A Rails controller" do
|
10
|
+
context "ActionController" do
|
13
11
|
setup do
|
14
|
-
@mum =
|
15
|
-
@mum.
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
@mum = mum = MouseWidget.new(parent_controller, 'mum', :eating)
|
13
|
+
@mum.instance_eval do
|
14
|
+
def eating; render; end
|
15
|
+
end
|
16
|
+
|
17
|
+
@mum.respond_to_event :squeak
|
18
|
+
|
19
|
+
@controller.class.has_widgets do |root|
|
20
|
+
root << mum
|
19
21
|
end
|
20
22
|
|
21
|
-
@controller.instance_variable_set(:@mum, @mum)
|
22
23
|
@controller.instance_eval do
|
23
24
|
def widget
|
24
|
-
|
25
|
-
root << @mum
|
26
|
-
end
|
27
|
-
|
28
|
-
render :text => render_widget('mum')
|
25
|
+
render :text => render_widget('mum', :eat)
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|
32
29
|
|
33
|
-
should "freeze the widget tree once after each request" do
|
34
|
-
assert_equal 0, @controller.session.size
|
35
|
-
|
36
|
-
get 'widget'
|
37
|
-
assert_equal 1, @controller.session[:apotomo_stateful_branches].size
|
38
|
-
end
|
39
|
-
|
40
|
-
should "invoke a #use_widgets block only once per session" do
|
41
|
-
#assert_equal 1, @controller.apotomo_root.size
|
42
|
-
|
43
|
-
get 'widget'
|
44
|
-
assert_response :success
|
45
|
-
assert_equal 1, @controller.session[:apotomo_stateful_branches].size
|
46
|
-
|
47
|
-
simulate_request!
|
48
|
-
|
49
|
-
get 'widget'
|
50
|
-
assert_equal 1, @controller.session[:apotomo_stateful_branches].size
|
51
|
-
assert_response :success
|
52
|
-
|
53
|
-
simulate_request!
|
54
|
-
|
55
|
-
get 'widget'
|
56
|
-
assert_response :success
|
57
|
-
assert_equal 2, @controller.apotomo_root.size, "mum added multiple times"
|
58
|
-
end
|
59
|
-
|
60
30
|
should "provide the rails view helpers in state views" do
|
61
31
|
@mum.instance_eval do
|
62
|
-
def
|
32
|
+
def eat; render :view => :make_me_squeak; end
|
63
33
|
end
|
64
34
|
|
65
35
|
get 'widget'
|
66
36
|
assert_select "a", "mum"
|
67
37
|
end
|
68
38
|
|
69
|
-
should "
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
simulate_request!
|
75
|
-
|
76
|
-
get 'widget'
|
77
|
-
assert_response :success
|
78
|
-
assert_not @controller.apotomo_request_processor.widgets_flushed?
|
79
|
-
|
80
|
-
simulate_request!
|
39
|
+
should "pass the event with all params data as state-args" do
|
40
|
+
@mum.instance_eval do
|
41
|
+
def squeak(evt); render :text => evt.data; end
|
42
|
+
end
|
81
43
|
|
82
|
-
get '
|
83
|
-
|
84
|
-
assert @controller.apotomo_request_processor.widgets_flushed?
|
44
|
+
get 'render_event_response', :source => 'mum', :type => :squeak, :pitch => :high
|
45
|
+
assert_equal "{\"source\"=>\"mum\", \"type\"=>:squeak, \"pitch\"=>:high, \"controller\"=>\"barn\", \"action\"=>\"render_event_response\"}", @response.body
|
85
46
|
end
|
86
47
|
|
87
48
|
should "render updates to the parent window for an iframe request" do
|
49
|
+
@mum.instance_eval do
|
50
|
+
def squeak(evt); render :text => "<b>SQUEAK!</b>"; end
|
51
|
+
end
|
52
|
+
|
88
53
|
get 'widget'
|
89
54
|
assert_response :success
|
90
55
|
|
@@ -94,7 +59,58 @@ class RailsIntegrationTest < ActionController::TestCase
|
|
94
59
|
|
95
60
|
assert_response :success
|
96
61
|
assert_equal 'text/html', @response.content_type
|
97
|
-
assert_equal "<html><body><script type='text/javascript' charset='utf-8'>\nvar loc = document.location;\nwith(window.parent) { setTimeout(function() { window.eval('<
|
62
|
+
assert_equal "<html><body><script type='text/javascript' charset='utf-8'>\nvar loc = document.location;\nwith(window.parent) { setTimeout(function() { window.eval('<b>SQUEAK!<\\/b>'); window.loc && loc.replace('about:blank'); }, 1) }\n</script></body></html>", @response.body
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
context "ActionView" do
|
67
|
+
setup do
|
68
|
+
@controller.instance_eval do
|
69
|
+
def widget
|
70
|
+
render :inline => "<%= render_widget 'mum', :eat %>"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
should "respond to #render_widget" do
|
76
|
+
get :widget
|
77
|
+
assert_select "#mum", "burp!"
|
78
|
+
end
|
79
|
+
|
80
|
+
should "respond to #url_for_event" do
|
81
|
+
@controller.instance_eval do
|
82
|
+
def widget
|
83
|
+
render :inline => "<%= url_for_event :footsteps, :source => 'mum' %>"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
get :widget
|
88
|
+
assert_equal "/barn/render_event_response?source=mum&type=footsteps", @response.body
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
class IncludingApotomoSupportTest < ActiveSupport::TestCase
|
96
|
+
context "A controller not including ControllerMethods explicitely" do
|
97
|
+
setup do
|
98
|
+
@class = Class.new(ActionController::Base)
|
99
|
+
@controller = @class.new
|
100
|
+
@controller.request = ActionController::TestRequest.new
|
101
|
+
end
|
102
|
+
|
103
|
+
should "respond to .has_widgets only" do
|
104
|
+
assert_respond_to @class, :has_widgets
|
105
|
+
assert_not_respond_to @class, :apotomo_request_processor
|
106
|
+
end
|
107
|
+
|
108
|
+
should "mixin all methods after first use of .has_widgets" do
|
109
|
+
@class.has_widgets do |root|
|
110
|
+
end
|
111
|
+
|
112
|
+
assert_respond_to @class, :has_widgets
|
113
|
+
assert_respond_to @controller, :apotomo_request_processor
|
98
114
|
end
|
99
115
|
end
|
100
116
|
end
|