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.
Files changed (83) hide show
  1. data/.gitignore +5 -0
  2. data/CHANGES.textile +35 -7
  3. data/Gemfile +0 -2
  4. data/README.rdoc +9 -9
  5. data/apotomo.gemspec +3 -3
  6. data/lib/apotomo.rb +4 -47
  7. data/lib/apotomo/event.rb +2 -0
  8. data/lib/apotomo/event_handler.rb +0 -3
  9. data/lib/apotomo/event_methods.rb +6 -2
  10. data/lib/apotomo/invoke_event_handler.rb +5 -3
  11. data/lib/apotomo/javascript_generator.rb +19 -16
  12. data/lib/apotomo/rails/controller_methods.rb +84 -131
  13. data/lib/apotomo/rails/view_helper.rb +15 -31
  14. data/lib/apotomo/railtie.rb +24 -0
  15. data/lib/apotomo/request_processor.rb +17 -48
  16. data/lib/apotomo/test_case.rb +5 -5
  17. data/lib/apotomo/tree_node.rb +52 -61
  18. data/lib/apotomo/version.rb +1 -1
  19. data/lib/apotomo/widget.rb +70 -146
  20. data/lib/apotomo/widget/javascript_methods.rb +39 -0
  21. data/lib/apotomo/widget_shortcuts.rb +14 -40
  22. data/lib/generators/apotomo/widget_generator.rb +8 -9
  23. data/lib/generators/erb/widget_generator.rb +17 -0
  24. data/lib/generators/haml/widget_generator.rb +20 -0
  25. data/lib/generators/{apotomo/templates → templates}/view.erb +1 -1
  26. data/lib/generators/templates/view.haml +4 -0
  27. data/lib/generators/{apotomo/templates → templates}/widget.rb +1 -1
  28. data/lib/generators/{apotomo/templates → templates}/widget_test.rb +1 -1
  29. data/lib/generators/test_unit/widget_generator.rb +14 -0
  30. data/test/rails/caching_test.rb +10 -17
  31. data/test/rails/controller_methods_test.rb +9 -81
  32. data/test/rails/rails_integration_test.rb +76 -60
  33. data/test/rails/view_helper_test.rb +17 -28
  34. data/test/rails/widget_generator_test.rb +19 -31
  35. data/test/support/test_case_methods.rb +6 -20
  36. data/test/test_helper.rb +15 -25
  37. data/test/unit/event_handler_test.rb +1 -0
  38. data/test/unit/event_methods_test.rb +20 -8
  39. data/test/unit/event_test.rb +5 -0
  40. data/test/unit/javascript_generator_test.rb +19 -19
  41. data/test/unit/render_test.rb +17 -112
  42. data/test/unit/request_processor_test.rb +73 -111
  43. data/test/unit/test_case_test.rb +13 -7
  44. data/test/unit/widget_shortcuts_test.rb +24 -53
  45. data/test/unit/widget_test.rb +76 -36
  46. data/test/widgets/mouse/eat.erb +1 -0
  47. data/test/{fixtures → widgets}/mouse/eating.html.erb +0 -0
  48. data/test/{fixtures → widgets}/mouse/educate.html.erb +0 -0
  49. data/test/{fixtures → widgets}/mouse/feed.html.erb +0 -0
  50. data/test/{fixtures → widgets}/mouse/make_me_squeak.html.erb +0 -0
  51. data/test/{fixtures → widgets}/mouse/posing.html.erb +0 -0
  52. data/test/widgets/mouse/snuggle.html.erb +1 -0
  53. metadata +32 -50
  54. data/lib/apotomo/container_widget.rb +0 -10
  55. data/lib/apotomo/persistence.rb +0 -112
  56. data/lib/apotomo/rails/view_methods.rb +0 -7
  57. data/lib/apotomo/stateful_widget.rb +0 -29
  58. data/lib/apotomo/transition.rb +0 -46
  59. data/lib/generators/apotomo/templates/view.haml +0 -4
  60. data/test/dummy/log/production.log +0 -0
  61. data/test/dummy/log/server.log +0 -0
  62. data/test/dummy/public/javascripts/application.js +0 -2
  63. data/test/dummy/public/javascripts/controls.js +0 -965
  64. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  65. data/test/dummy/public/javascripts/effects.js +0 -1123
  66. data/test/dummy/public/javascripts/prototype.js +0 -6001
  67. data/test/dummy/public/javascripts/rails.js +0 -175
  68. data/test/dummy/script/rails +0 -6
  69. data/test/dummy/tmp/app/cells/mouse_widget.rb +0 -11
  70. data/test/dummy/tmp/app/cells/mouse_widget/snuggle.html.erb +0 -7
  71. data/test/dummy/tmp/app/cells/mouse_widget/squeak.html.erb +0 -7
  72. data/test/dummy/tmp/test/widgets/mouse_widget_test.rb +0 -12
  73. data/test/fixtures/application_widget_tree.rb +0 -2
  74. data/test/fixtures/mouse/snuggle.html.erb +0 -1
  75. data/test/rails/view_methods_test.rb +0 -38
  76. data/test/unit/container_test.rb +0 -21
  77. data/test/unit/invoke_test.rb +0 -126
  78. data/test/unit/persistence_test.rb +0 -201
  79. data/test/unit/stateful_widget_test.rb +0 -58
  80. data/test/unit/test_addressing.rb +0 -110
  81. data/test/unit/test_jump_to_state.rb +0 -89
  82. data/test/unit/test_tab_panel.rb +0 -71
  83. data/test/unit/transition_test.rb +0 -34
@@ -5,14 +5,12 @@ class ViewHelperTest < Apotomo::TestCase
5
5
  include ActionDispatch::Assertions::DomAssertions
6
6
  include Apotomo::TestCase::TestController
7
7
 
8
- # TODO: move to Apotomo::TestCase, refactor, test.
9
- class MouseWidget < Apotomo::Widget
10
- end
8
+ # TODO: use Cell::TestCase#in_view here.
11
9
  def in_view(subject, &block)
12
10
  if subject.kind_of?(Apotomo::Widget)
13
- subject.opts[:block] = block
11
+ subject.options[:block] = block
14
12
  else
15
- subject = subject.new(@controller, 'mum', :display, :block => block)
13
+ subject = subject.new(@controller, 'mum', :block => block)
16
14
  end
17
15
 
18
16
  setup_test_states_in(subject) unless subject.respond_to?(:in_view)# add #in_view state to subject cell.
@@ -21,8 +19,8 @@ class ViewHelperTest < Apotomo::TestCase
21
19
 
22
20
  subject.invoke(:in_view)
23
21
  end
24
- def mouse_mock(id='mum', start_state=:eat, opts={}, &block)
25
- mouse = MouseWidget.new(parent_controller, id, start_state, opts)
22
+ def mouse_mock(id='mum', opts={}, &block)
23
+ mouse = MouseWidget.new(parent_controller, id, opts)
26
24
  mouse.instance_eval &block if block_given?
27
25
  mouse
28
26
  end
@@ -67,27 +65,18 @@ class ViewHelperTest < Apotomo::TestCase
67
65
  assert_equal('mum', in_view(MouseWidget){ widget_id })
68
66
  end
69
67
 
70
- context "#widget_javascript" do
71
-
72
- should "usually render a javascript block" do
73
- assert_equal("<script type=\"text/javascript\">\n//<![CDATA[\nalert(&quot;Beer!&quot;)\n//]]>\n</script>", in_view(MouseWidget) do
74
- widget_javascript { 'alert("Beer!")' }
75
- end)
76
- end
77
-
78
- # FIXME: get the test running?
79
- should_eventually "be quiet if suppress_js is set" do
80
- @suppress_js = true ### TODO: use a local, not an instance variable.
81
- mum = mouse_mock do
82
- def in_view
83
- render :suppress_js => true
84
- end
85
- end
86
-
87
- assert_equal(nil, in_view(mum) do
88
- widget_javascript { 'alert("Beer!")' }
89
- end)
90
- end
68
+ should "respond to #render_widget" do
69
+ mum = mouse_mock
70
+ mum << mouse_mock('kid')
71
+ assert_equal("<div id=\"kid\">burp!</div>\n", in_view(mum){ render_widget 'kid', :eat })
72
+ end
73
+
74
+ should "respond to #children" do
75
+ mum = mouse_mock
76
+ mum << mouse_mock('kid')
77
+ assert_equal("<div id=\"kid\">burp!</div>\n", in_view(mum) do
78
+ children.inject("") { |html, child| html += render_widget(child, :eat) }.html_safe
79
+ end)
91
80
  end
92
81
  end
93
82
  end
@@ -7,44 +7,32 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
7
7
  tests ::Apotomo::Generators::WidgetGenerator
8
8
 
9
9
  context "Running rails g apotomo::widget" do
10
- context "Mouse squeak snuggle" do
10
+ context "Gerbil squeak snuggle" do
11
11
  should "create the standard assets" do
12
12
 
13
- run_generator %w(MouseWidget squeak snuggle)
13
+ run_generator %w(Gerbil squeak snuggle -t test_unit)
14
14
 
15
- assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/
16
- assert_file "app/cells/mouse_widget.rb", /def snuggle/
17
- assert_file "app/cells/mouse_widget.rb", /def squeak/
18
- assert_file "app/cells/mouse_widget/snuggle.html.erb", %r(app/cells/mouse_widget/snuggle\.html\.erb)
19
- assert_file "app/cells/mouse_widget/snuggle.html.erb", %r(<p>)
20
- assert_file "app/cells/mouse_widget/squeak.html.erb", %r(app/cells/mouse_widget/squeak\.html\.erb)
15
+ assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
16
+ assert_file "app/widgets/gerbil_widget.rb", /def snuggle/
17
+ assert_file "app/widgets/gerbil_widget.rb", /def squeak/
18
+ assert_file "app/widgets/gerbil/snuggle.html.erb", %r(app/widgets/gerbil/snuggle\.html\.erb)
19
+ assert_file "app/widgets/gerbil/snuggle.html.erb", %r(<p>)
20
+ assert_file "app/widgets/gerbil/squeak.html.erb", %r(app/widgets/gerbil/squeak\.html\.erb)
21
21
 
22
- assert_file "test/widgets/mouse_widget_test.rb", %r(class MouseWidgetTest < Apotomo::TestCase)
23
- assert_file "test/widgets/mouse_widget_test.rb", %r(widget\(:mouse_widget, 'me'\))
22
+ assert_file "test/widgets/gerbil_widget_test.rb", %r(class GerbilWidgetTest < Apotomo::TestCase)
23
+ assert_file "test/widgets/gerbil_widget_test.rb", %r(widget\(:gerbil, 'me'\))
24
24
  end
25
25
 
26
- should "create haml assets with --haml" do
27
- run_generator %w(MouseWidget squeak snuggle --haml)
26
+ should "create haml assets with -e haml" do
27
+ run_generator %w(Gerbil squeak snuggle -e haml -t test_unit)
28
28
 
29
- assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/
30
- assert_file "app/cells/mouse_widget.rb", /def snuggle/
31
- assert_file "app/cells/mouse_widget.rb", /def squeak/
32
- assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(app/cells/mouse_widget/snuggle\.html\.haml)
33
- assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(%p)
34
- assert_file "app/cells/mouse_widget/squeak.html.haml", %r(app/cells/mouse_widget/squeak\.html\.haml)
35
- assert_file "test/widgets/mouse_widget_test.rb"
36
- end
37
-
38
- should "create haml assets with -t haml" do
39
- run_generator %w(MouseWidget snuggle squeak -t haml)
40
-
41
- assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/
42
- assert_file "app/cells/mouse_widget.rb", /def snuggle/
43
- assert_file "app/cells/mouse_widget.rb", /def squeak/
44
- assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(app/cells/mouse_widget/snuggle\.html\.haml)
45
- assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(%p)
46
- assert_file "app/cells/mouse_widget/squeak.html.haml", %r(app/cells/mouse_widget/squeak\.html\.haml)
47
- assert_file "test/widgets/mouse_widget_test.rb"
29
+ assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
30
+ assert_file "app/widgets/gerbil_widget.rb", /def snuggle/
31
+ assert_file "app/widgets/gerbil_widget.rb", /def squeak/
32
+ assert_file "app/widgets/gerbil/snuggle.html.haml", %r(app/widgets/gerbil/snuggle\.html\.haml)
33
+ assert_file "app/widgets/gerbil/snuggle.html.haml", %r(%p)
34
+ assert_file "app/widgets/gerbil/squeak.html.haml", %r(app/widgets/gerbil/squeak\.html\.haml)
35
+ assert_file "test/widgets/gerbil_widget_test.rb"
48
36
  end
49
37
  end
50
38
  end
@@ -1,21 +1,21 @@
1
1
  module Apotomo
2
2
  module TestCaseMethods
3
3
  # Provides a ready-to-use mouse widget instance.
4
- def mouse_mock(id='mouse', start_state=:eating, opts={}, &block)
5
- mouse = MouseCell.new(parent_controller, id, start_state, opts)
4
+ def mouse_mock(id='mouse', opts={}, &block)
5
+ mouse = MouseWidget.new(parent_controller, id, opts)
6
6
  mouse.instance_eval &block if block_given?
7
7
  mouse
8
8
  end
9
9
 
10
10
  def mouse_class_mock(&block)
11
- klass = Class.new(MouseCell)
11
+ klass = Class.new(MouseWidget)
12
12
  klass.instance_eval &block if block_given?
13
13
  klass
14
14
  end
15
15
 
16
16
  def mum_and_kid!
17
- @mum = mouse_mock('mum', :answer_squeak)
18
- @mum << @kid = mouse_mock('kid', :peek)
17
+ @mum = mouse_mock('mum')
18
+ @mum << @kid = mouse_mock('kid')
19
19
 
20
20
  @mum.respond_to_event :squeak, :with => :answer_squeak
21
21
  @mum.respond_to_event :squeak, :from => 'kid', :with => :alert
@@ -43,25 +43,11 @@ module Apotomo
43
43
  @controller = Class.new(ActionController::Base) do
44
44
  def self.default_url_options; {:controller => :barn}; end
45
45
  end.new
46
- @controller.class.instance_eval { include Apotomo::Rails::ControllerMethods }
47
46
  @controller.extend ActionController::UrlWriter
48
47
  @controller.params = {}
49
- ### FIXME: @controller.session = {}
50
48
  end
51
49
 
52
- def hibernate_widget(widget, session = {})
53
- Apotomo::StatefulWidget.freeze_for(session, widget)
54
-
55
- session = Marshal.load(Marshal.dump(session))
56
-
57
- Apotomo::StatefulWidget.thaw_for(@controller, session, )
58
- end
59
-
60
- def hibernate(widget, session = {})
61
- Apotomo::StatefulWidget.freeze_for(session, widget)
62
- session = Marshal.load(Marshal.dump(session))
63
- Apotomo::StatefulWidget.thaw_for(session, widget('apotomo/widget', 'root'))
64
- end
50
+
65
51
 
66
52
  module TestController
67
53
  def setup
data/test/test_helper.rb CHANGED
@@ -4,15 +4,15 @@ require 'bundler'
4
4
  Bundler.setup
5
5
 
6
6
  require 'shoulda'
7
- require 'cells'
8
- require 'apotomo'
9
7
 
10
8
  ENV['RAILS_ENV'] = 'test'
11
9
  require "dummy/config/environment"
12
10
  require "rails/test_help" # sets up ActionController::TestCase's @routes
13
11
 
12
+ require 'cells'
13
+ require 'apotomo'
14
14
 
15
- Cell::Base.append_view_path File.expand_path(File.dirname(__FILE__) + "/fixtures")
15
+ Apotomo::Widget.append_view_path(File.expand_path(File.dirname(__FILE__) + "/widgets"))
16
16
 
17
17
  # Load test support files.
18
18
  require File.join(File.dirname(__FILE__), "support/test_case_methods")
@@ -37,33 +37,23 @@ module Farm
37
37
  end
38
38
  end
39
39
 
40
-
41
- class MouseCell < Apotomo::StatefulWidget
42
- def eating; render; end
43
- def squeak; render; end
44
- def educate; render; end
45
- def snooze; render; end
46
- def listen; render; end
47
- def answer_squeak; render; end
48
- def peek; render; end
49
- def alert; end
50
- def escape; end
51
- def snuggle; end
40
+ class MouseWidget < Apotomo::Widget
52
41
  end
53
42
 
54
- ### TODO: 2brm?
55
- class RenderingTestCell < Apotomo::StatefulWidget
56
- attr_reader :brain
57
- attr_reader :rendered_children
58
-
59
-
60
-
61
- def jump
62
- jump_to_state :check_state
43
+
44
+ class MouseWidget < Apotomo::Widget
45
+ def squeak
46
+ render :text => "squeak!"
47
+ end
48
+ def eating
49
+ render
63
50
  end
51
+ def eat
52
+ render
53
+ end
54
+
64
55
  end
65
56
 
66
-
67
57
  # Enable dynamic states so we can do Cell.class_eval { def ... } at runtime.
68
58
  Apotomo::Widget.class_eval do
69
59
  def action_method?(*); true; end
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'apotomo/proc_event_handler'
2
3
 
3
4
  class EventHandlerTest < Test::Unit::TestCase
4
5
  include Apotomo::TestCaseMethods::TestController
@@ -43,13 +43,25 @@ class EventMethodsTest < Test::Unit::TestCase
43
43
  @mum.respond_to_event :answer_squeak
44
44
  @mum.fire :answer_squeak
45
45
  assert_equal ['answer squeak'], @mum.list
46
+ end
47
+
48
+ should "make pass the event into the triggered state" do
49
+ @mum.instance_eval do
50
+ respond_to_event :footsteps
51
+
52
+ def footsteps(evt)
53
+ list << evt
54
+ end
55
+ end
56
+
57
+ @mum.trigger :footsteps, "near"
58
+ assert_kind_of Apotomo::Event, @mum.list.last
46
59
  end
47
60
 
48
61
  should "accept payload data for the event" do
49
62
  @mum.respond_to_event :answer_squeak
50
63
  @mum.instance_eval do
51
- def answer_squeak
52
- evt = @opts[:event]
64
+ def answer_squeak(evt)
53
65
  list << evt.data
54
66
  end
55
67
  end
@@ -60,26 +72,26 @@ class EventMethodsTest < Test::Unit::TestCase
60
72
 
61
73
  context "#responds_to_event in class context" do
62
74
  setup do
63
- class AdultMouseCell < MouseCell
75
+ class AdultMouse < MouseWidget
64
76
  responds_to_event :peep, :with => :answer_squeak
65
77
  end
66
- class BabyMouseCell < AdultMouseCell
78
+ class BabyMouse < AdultMouse
67
79
  responds_to_event :footsteps, :with => :squeak
68
80
  end
69
81
  end
70
82
 
71
83
  should "add the handlers at creation time" do
72
- assert_equal [Apotomo::InvokeEventHandler.new(:widget_id => 'mum', :state => :answer_squeak)], AdultMouseCell.new(parent_controller, 'mum', :show).event_table.all_handlers_for(:peep, 'mum')
84
+ assert_equal [Apotomo::InvokeEventHandler.new(:widget_id => 'mum', :state => :answer_squeak)], AdultMouse.new(parent_controller, 'mum', :show).event_table.all_handlers_for(:peep, 'mum')
73
85
  end
74
86
 
75
87
  should "not inherit handlers for now" do
76
- assert_equal [], BabyMouseCell.new(parent_controller, 'kid', :show).event_table.all_handlers_for(:peep, 'kid')
88
+ assert_equal [], BabyMouse.new(parent_controller, 'kid', :show).event_table.all_handlers_for(:peep, 'kid')
77
89
  end
78
90
 
79
91
  should "not add the same handler to each instance" do
80
- assert_equal [Apotomo::InvokeEventHandler.new(:widget_id => 'mum', :state => :answer_squeak)], AdultMouseCell.new(parent_controller, 'mum', :show).event_table.all_handlers_for(:peep, 'mum')
92
+ assert_equal [Apotomo::InvokeEventHandler.new(:widget_id => 'mum', :state => :answer_squeak)], AdultMouse.new(parent_controller, 'mum', :show).event_table.all_handlers_for(:peep, 'mum')
81
93
 
82
- assert_equal [Apotomo::InvokeEventHandler.new(:widget_id => 'dad', :state => :answer_squeak)], AdultMouseCell.new(parent_controller, 'dad', :show).event_table.all_handlers_for(:peep, 'dad')
94
+ assert_equal [Apotomo::InvokeEventHandler.new(:widget_id => 'dad', :state => :answer_squeak)], AdultMouse.new(parent_controller, 'dad', :show).event_table.all_handlers_for(:peep, 'dad')
83
95
  end
84
96
  end
85
97
 
@@ -17,6 +17,11 @@ class EventTest < Test::Unit::TestCase
17
17
  assert_equal({:volume => :loud}, @event.data)
18
18
  end
19
19
 
20
+ should "delegate #[] to data" do
21
+ @event = Apotomo::Event.new(:footsteps, 'mum', {:volume => :loud})
22
+ assert_equal :loud, @event[:volume]
23
+ end
24
+
20
25
  should "complain when serialized" do
21
26
  assert_raises RuntimeError do
22
27
  Marshal.dump(Apotomo::Event.new(:footsteps, 'mum'))
@@ -16,21 +16,21 @@ class JavascriptGeneratorTest < Test::Unit::TestCase
16
16
  should "respond to prototype" do
17
17
  assert_respond_to @gen, :prototype
18
18
  end
19
-
20
- should "respond to xhr" do
21
- assert_equal "new Ajax.Request(\"/drink/beer?source=nick\")", @gen.xhr('/drink/beer?source=nick')
22
- end
23
19
 
24
20
  should "respond to replace" do
25
21
  assert_equal "$(\"drinks\").replace(\"EMPTY!\")", @gen.replace(:drinks, 'EMPTY!')
26
22
  end
27
23
 
24
+ should "respond to replace_id" do
25
+ assert_equal "$(\"drinks\").replace(\"EMPTY!\")", @gen.replace_id("drinks", 'EMPTY!')
26
+ end
27
+
28
28
  should "respond to update" do
29
29
  assert_equal "$(\"drinks\").update(\"<li id=\\\"beer\\\"><\\/li>\")", @gen.update(:drinks, '<li id="beer"></li>')
30
30
  end
31
31
 
32
- should "respond to <<" do
33
- assert_equal "alert(\"Beer!\")", @gen << 'alert("Beer!")'
32
+ should "respond to update_id" do
33
+ assert_equal "$(\"drinks\").update(\"EMPTY!\")", @gen.update_id("drinks", 'EMPTY!')
34
34
  end
35
35
  end
36
36
 
@@ -42,21 +42,21 @@ class JavascriptGeneratorTest < Test::Unit::TestCase
42
42
  should "respond to right" do
43
43
  assert_respond_to @gen, :right
44
44
  end
45
-
46
- should "respond to xhr" do
47
- assert_equal "new Xhr(\"/drink/beer?source=nick\", {evalScripts:true}).send()", @gen.xhr('/drink/beer?source=nick')
48
- end
49
45
 
50
46
  should "respond to replace" do
51
47
  assert_equal "$(\"drinks\").replace(\"EMPTY!\")", @gen.replace(:drinks, 'EMPTY!')
52
48
  end
53
49
 
50
+ should "respond to replace_id" do
51
+ assert_equal "$(\"drinks\").replace(\"EMPTY!\")", @gen.replace_id("drinks", 'EMPTY!')
52
+ end
53
+
54
54
  should "respond to update" do
55
55
  assert_equal "$(\"drinks\").update(\"<li id=\\\"beer\\\"><\\/li>\")", @gen.update(:drinks, '<li id="beer"></li>')
56
56
  end
57
57
 
58
- should "respond to <<" do
59
- assert_equal "alert(\"Beer!\")", @gen << 'alert("Beer!")'
58
+ should "respond to update_id" do
59
+ assert_equal "$(\"drinks\").update(\"EMPTY!\")", @gen.update_id("drinks", 'EMPTY!')
60
60
  end
61
61
  end
62
62
 
@@ -69,20 +69,20 @@ class JavascriptGeneratorTest < Test::Unit::TestCase
69
69
  assert_respond_to @gen, :jquery
70
70
  end
71
71
 
72
- should "respond to xhr" do
73
- assert_equal "$.ajax({url: \"/drink/beer?source=nick\"})", @gen.xhr('/drink/beer?source=nick')
72
+ should "respond to replace" do
73
+ assert_equal "$(\"#drinks\").replaceWith(\"EMPTY!\")", @gen.replace("#drinks", 'EMPTY!')
74
74
  end
75
75
 
76
- should "respond to replace" do
77
- assert_equal "$(\"#drinks\").replaceWith(\"EMPTY!\")", @gen.replace(:drinks, 'EMPTY!')
76
+ should "respond to replace_id" do
77
+ assert_equal "$(\"#drinks\").replaceWith(\"EMPTY!\")", @gen.replace_id("drinks", 'EMPTY!')
78
78
  end
79
79
 
80
80
  should "respond to update" do
81
- assert_equal "$(\"#drinks\").html(\"<li id=\\\"beer\\\"><\\/li>\")", @gen.update(:drinks, '<li id="beer"></li>')
81
+ assert_equal "$(\"#drinks\").html(\"<li id=\\\"beer\\\"><\\/li>\")", @gen.update("#drinks", '<li id="beer"></li>')
82
82
  end
83
83
 
84
- should "respond to <<" do
85
- assert_equal "alert(\"Beer!\")", @gen << 'alert("Beer!")'
84
+ should "respond to update_id" do
85
+ assert_equal "$(\"#drinks\").html(\"EMPTY!\")", @gen.update_id("drinks", 'EMPTY!')
86
86
  end
87
87
  end
88
88
  end
@@ -3,13 +3,13 @@ require 'test_helper'
3
3
  class RenderTest < ActionView::TestCase
4
4
  include Apotomo::TestCaseMethods::TestController
5
5
 
6
- context "Rendering a single widget" do
6
+ context "#render" do
7
7
  setup do
8
- @mum = mouse_mock
8
+ @mum = mouse_mock('mum', :eating)
9
9
  end
10
10
 
11
11
  should "per default display the state content framed in a div" do
12
- assert_equal '<div id="mouse">burp!</div>', @mum.invoke(:eating)
12
+ assert_equal '<div id="mum">burp!</div>', @mum.invoke(:eating)
13
13
  end
14
14
 
15
15
  context "with :text" do
@@ -18,31 +18,16 @@ class RenderTest < ActionView::TestCase
18
18
  end
19
19
 
20
20
  should "render the :text" do
21
- assert_equal "burp!!!", @mum.invoke
21
+ assert_equal "burp!!!", @mum.invoke(:eating)
22
22
  end
23
23
  end
24
24
 
25
-
26
- context "with :suppress_js" do
27
- setup do
28
- @mum.instance_eval do
29
- def snuggle; render; end
30
- self.class.send :attr_reader, :suppress_js
31
- end
32
- end
33
-
34
- should "per default be false" do
35
- @mum.invoke :snuggle
36
- assert !@mum.suppress_js
37
- end
25
+ should "accept :state and options" do
26
+ @mum.instance_eval { def eat(what); render :text => "#{what} today?"; end }
38
27
 
39
- should "be true when set" do
40
- @mum.instance_eval do
41
- def snuggle; render :suppress_js => true; end
42
- end
43
- @mum.invoke :snuggle
44
- assert @mum.suppress_js
45
- end
28
+ assert_equal "Rice today?", @mum.render({:state => :eat}, "Rice")
29
+ assert_match "Rice today?", @mum.update({:state => :eat}, "Rice")
30
+ assert_match "Rice today?", @mum.replace({:state => :eat}, "Rice")
46
31
  end
47
32
 
48
33
  should "expose its instance variables in the rendered view" do
@@ -57,21 +42,6 @@ class RenderTest < ActionView::TestCase
57
42
  end
58
43
 
59
44
  context "with #emit" do
60
- setup do
61
- @kid = mouse_mock('kid', :squeak)
62
- @kid.instance_eval do
63
- def squeak
64
- render :text => "squeeeeaaak"
65
- end
66
-
67
- def render(*)
68
- @rendered = true
69
- super
70
- end
71
- def rendered?; @rendered; end
72
- end
73
- end
74
-
75
45
  context "and :text" do
76
46
  setup do
77
47
  @mum.instance_eval do
@@ -84,25 +54,6 @@ class RenderTest < ActionView::TestCase
84
54
  should "just return the plain :text" do
85
55
  assert_equal 'squeak();', @mum.invoke(:squeak)
86
56
  end
87
-
88
- should "not render children" do
89
- @mum << @kid
90
- @mum.invoke(:squeak)
91
-
92
- assert_not @kid.rendered?
93
- end
94
-
95
- should "allow rendering children" do
96
- @mum.instance_eval do
97
- def squeak
98
- emit :text => "squeak();", :render_children => true
99
- end
100
- end
101
- @mum << @kid
102
- @mum.invoke(:squeak)
103
-
104
- assert @kid.rendered?
105
- end
106
57
  end
107
58
 
108
59
  context "and no options" do
@@ -115,13 +66,7 @@ class RenderTest < ActionView::TestCase
115
66
  end
116
67
 
117
68
  should "render the view" do
118
- assert_equal "<div id=\"mouse\">burp!</div>", @mum.invoke(:eating)
119
- end
120
-
121
- should "render the children, too" do
122
- @mum << @kid
123
- @mum.invoke(:eating)
124
- assert @kid.rendered?
69
+ assert_equal "<div id=\"mum\">burp!</div>", @mum.invoke(:eating)
125
70
  end
126
71
  end
127
72
 
@@ -129,36 +74,25 @@ class RenderTest < ActionView::TestCase
129
74
  setup do
130
75
  @mum.instance_eval do
131
76
  def squeak
132
- emit :view => :snuggle
77
+ emit :view => :eating
133
78
  end
134
79
  end
135
80
  end
136
81
 
137
82
  should "render the :view" do
138
- assert_equal "<div id=\"mouse\"><snuggle></snuggle></div>\n", @mum.invoke(:squeak)
139
- end
140
-
141
- should "render the children" do
142
- @mum << @kid
143
-
144
- assert_equal "<div id=\"mouse\"><snuggle>squeeeeaaak</snuggle></div>\n", @mum.invoke(:squeak)
145
- assert @kid.rendered?
83
+ assert_equal "<div id=\"mum\">burp!</div>", @mum.invoke(:squeak)
146
84
  end
147
85
  end
148
86
  end
149
87
 
150
88
  context "with #update" do
151
- setup do
152
- Apotomo.js_framework = :prototype
153
- end
154
-
155
89
  should "wrap the :text in an update statement" do
156
90
  @mum.instance_eval do
157
91
  def squeak
158
92
  update :text => "squeak!"
159
93
  end
160
94
  end
161
- assert_equal "$(\"mouse\").update(\"squeak!\")", @mum.invoke(:squeak)
95
+ assert_equal "$(\"#mum\").html(\"squeak!\")", @mum.invoke(:squeak)
162
96
  end
163
97
 
164
98
  should "accept :selector" do
@@ -167,22 +101,18 @@ class RenderTest < ActionView::TestCase
167
101
  update :text => '<div id="mum">squeak!</div>', :selector => "div#mouse"
168
102
  end
169
103
  end
170
- assert_equal "$(\"div#mouse\").update(\"<div id=\\\"mum\\\">squeak!<\\/div>\")", @mum.invoke(:squeak)
104
+ assert_equal "$(\"div#mouse\").html(\"<div id=\\\"mum\\\">squeak!<\\/div>\")", @mum.invoke(:squeak)
171
105
  end
172
106
  end
173
107
 
174
108
  context "with #replace" do
175
- setup do
176
- Apotomo.js_framework = :prototype
177
- end
178
-
179
109
  should "wrap the :text in a replace statement" do
180
110
  @mum.instance_eval do
181
111
  def squeak
182
112
  replace :text => '<div id="mum">squeak!</div>'
183
113
  end
184
114
  end
185
- assert_equal "$(\"mouse\").replace(\"<div id=\\\"mum\\\">squeak!<\\/div>\")", @mum.invoke(:squeak)
115
+ assert_equal "$(\"#mum\").replaceWith(\"<div id=\\\"mum\\\">squeak!<\\/div>\")", @mum.invoke(:squeak)
186
116
  end
187
117
 
188
118
  should "accept :selector" do
@@ -191,33 +121,8 @@ class RenderTest < ActionView::TestCase
191
121
  replace :text => '<div id="mum">squeak!</div>', :selector => "div#mouse"
192
122
  end
193
123
  end
194
- assert_equal "$(\"div#mouse\").replace(\"<div id=\\\"mum\\\">squeak!<\\/div>\")", @mum.invoke(:squeak)
124
+ assert_equal "$(\"div#mouse\").replaceWith(\"<div id=\\\"mum\\\">squeak!<\\/div>\")", @mum.invoke(:squeak)
195
125
  end
196
126
  end
197
- end
198
-
199
- context "rendering a widget family" do
200
- setup do
201
- @mum = mouse_mock('mum', :snuggle) do
202
- def snuggle; render; end
203
- end
204
-
205
- @mum << @kid = mouse_mock('kid')
206
- end
207
-
208
- should "per default render kid's content inside mums div with rendered_children" do
209
- assert_equal "<div id=\"mum\"><snuggle><div id=\"kid\">burp!</div></snuggle></div>\n", @mum.invoke(:snuggle)
210
- end
211
-
212
- should "skip kids if :render_children=>false but still provide a rendered_children hash" do
213
- @mum.instance_eval do
214
- def snuggle; render :render_children => false; end
215
- end
216
-
217
- assert_equal "<div id=\"mum\"><snuggle></snuggle></div>\n", @mum.invoke(:snuggle)
218
- end
219
-
220
- should_eventually "provide an ordered rendered_children hash"
221
- end
222
-
127
+ end
223
128
  end