apotomo 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -3
  3. data/.travis.yml +6 -8
  4. data/CHANGES.textile +9 -5
  5. data/README.md +211 -0
  6. data/apotomo.gemspec +4 -4
  7. data/config/routes.rb +1 -1
  8. data/gemfiles/Gemfile.rails3-0 +6 -0
  9. data/gemfiles/Gemfile.rails3-1 +6 -0
  10. data/gemfiles/Gemfile.rails3-2 +6 -0
  11. data/gemfiles/Gemfile.rails4-0 +6 -0
  12. data/lib/apotomo/javascript_generator.rb +3 -3
  13. data/lib/apotomo/test_case.rb +14 -8
  14. data/lib/apotomo/version.rb +1 -1
  15. data/lib/apotomo/widget/javascript_methods.rb +3 -3
  16. data/lib/apotomo/widget/tree_node.rb +1 -1
  17. data/lib/apotomo/widget.rb +3 -3
  18. data/lib/generators/apotomo/widget_generator.rb +1 -1
  19. data/lib/generators/templates/view.slim +3 -4
  20. data/test/apotomo_test.rb +25 -14
  21. data/test/dummy/config/routes.rb +2 -57
  22. data/test/event_handler_test.rb +30 -60
  23. data/test/event_methods_test.rb +62 -62
  24. data/test/event_test.rb +11 -11
  25. data/test/invoke_event_handler_test.rb +59 -0
  26. data/test/javascript_generator_test.rb +57 -72
  27. data/test/rails/caching_test.rb +11 -11
  28. data/test/rails/controller_methods_test.rb +63 -57
  29. data/test/rails/rails_integration_test.rb +47 -47
  30. data/test/rails/view_helper_test.rb +31 -26
  31. data/test/rails/widget_generator_test.rb +16 -16
  32. data/test/render_test.rb +50 -50
  33. data/test/request_processor_test.rb +74 -74
  34. data/test/test_case_test.rb +45 -45
  35. data/test/test_helper.rb +14 -10
  36. data/test/tree_node_test.rb +5 -10
  37. data/test/widget_shortcuts_test.rb +25 -25
  38. data/test/widget_test.rb +82 -80
  39. metadata +73 -49
  40. data/README.rdoc +0 -205
  41. data/TODO +0 -36
  42. data/lib/apotomo/proc_event_handler.rb +0 -18
  43. data/test/onfire_integration_test.rb +0 -22
@@ -1,106 +1,107 @@
1
1
  require 'test_helper'
2
-
3
- class ControllerMethodsTest < ActionController::TestCase
2
+
3
+ class ControllerMethodsTest < MiniTest::Spec
4
4
  include Apotomo::TestCaseMethods::TestController
5
-
6
- context "A Rails controller" do
7
- context "responding to #apotomo_root" do
8
- should "initially return a root widget" do
5
+
6
+ describe "A Rails controller" do
7
+ describe "responding to #apotomo_root" do
8
+ it "initially return a root widget" do
9
9
  assert_equal 1, @controller.apotomo_root.size
10
10
  end
11
-
12
- should "allow tree modifications" do
11
+
12
+ it "allow tree modifications" do
13
13
  @controller.apotomo_root << mouse_mock
14
14
  assert_equal 2, @controller.apotomo_root.size
15
15
  end
16
16
  end
17
-
18
- context "responding to #apotomo_request_processor" do
19
- should "initially return the processor which has an empty root" do
17
+
18
+ describe "responding to #apotomo_request_processor" do
19
+ it "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
23
23
  end
24
-
25
- context "invoking #has_widgets" do
26
- setup do
24
+
25
+ describe "invoking #has_widgets" do
26
+ before do
27
27
  @controller.class.has_widgets do |root|
28
28
  root << widget(:mouse, 'mum')
29
29
  end
30
30
  end
31
-
32
- should "add the widgets to apotomo_root" do
31
+
32
+ it "add the widgets to apotomo_root" do
33
33
  assert_equal 'mum', @controller.apotomo_root['mum'].name
34
34
  end
35
-
36
- should "add the widgets only once in apotomo_root" do
35
+
36
+ it "add the widgets only once in apotomo_root" do
37
37
  @controller.apotomo_root
38
38
  assert @controller.apotomo_root['mum']
39
39
  end
40
-
41
- should "allow multiple calls to has_widgets" do
40
+
41
+ it "allow multiple calls to has_widgets" do
42
42
  @controller.class.has_widgets do |root|
43
43
  root << widget(:mouse, 'kid')
44
44
  end
45
-
45
+
46
46
  assert @controller.apotomo_root['mum']
47
47
  assert @controller.apotomo_root['kid']
48
48
  end
49
-
50
- should "inherit has_widgets blocks to sub-controllers" do
49
+
50
+ it "inherit has_widgets blocks to sub-controllers" do
51
51
  berry = widget(:mouse, 'berry')
52
52
  @sub_controller = Class.new(@controller.class) do
53
53
  has_widgets { |root| root << berry }
54
54
  end.new
55
55
  @sub_controller.params = {}
56
-
56
+
57
57
  assert @sub_controller.apotomo_root['mum']
58
58
  assert @sub_controller.apotomo_root['berry']
59
59
  end
60
-
61
- should "be executed in controller context" do
60
+
61
+ it "be executed in controller describe" do
62
62
  @controller.instance_eval do
63
63
  def roomies; ['mice', 'cows']; end
64
64
  end
65
-
65
+
66
66
  @controller.class.has_widgets do |root|
67
67
  root << widget(:mouse, 'kid', :display, :roomies => roomies)
68
68
  end
69
-
69
+
70
70
  assert_equal ['mice', 'cows'], @controller.apotomo_root['kid'].options[:roomies]
71
71
  end
72
72
  end
73
-
74
-
75
-
76
- context "invoking #url_for_event" do
77
- should "compute an url for any widget" do
73
+
74
+
75
+
76
+ describe "invoking #url_for_event" do
77
+ it "compute an url for any widget" do
78
78
  assert_equal "/barn/render_event_response?source=mouse&type=footsteps&volume=9", @controller.url_for_event(:footsteps, :source => :mouse, :volume => 9)
79
79
  end
80
80
  end
81
81
  end
82
-
83
- context "invoking #render_widget" do
84
- setup do
82
+
83
+ describe "invoking #render_widget" do
84
+ before do
85
85
  @mum = mouse_mock('mum', 'eating')
86
86
  end
87
-
88
- should "render the widget" do
87
+
88
+ it "render the widget" do
89
89
  @controller.apotomo_root << @mum
90
90
  assert_equal "<div id=\"mum\">burp!</div>\n", @controller.render_widget('mum', :eat)
91
91
  end
92
92
  end
93
-
94
-
95
- context "processing an event request" do
96
- setup do
97
- @mum = mouse_mock('mum', :eating)
98
- @mum << @kid = mouse_mock('kid', :squeak)
99
-
93
+
94
+
95
+ describe "processing an event request" do
96
+ before do
97
+ @mum = mouse
98
+ @mum << mouse_mock(:kid)
99
+ @kid = @mum[:kid]
100
+
100
101
  @kid.respond_to_event :doorSlam, :with => :eating, :on => 'mum'
101
102
  @kid.respond_to_event :doorSlam, :with => :squeak
102
103
  @mum.respond_to_event :doorSlam, :with => :squeak
103
-
104
+
104
105
  @mum.instance_eval do
105
106
  def squeak; render :js => 'squeak();'; end
106
107
  end
@@ -108,27 +109,32 @@ class ControllerMethodsTest < ActionController::TestCase
108
109
  def squeak; render :text => 'squeak!', :update => :true; end
109
110
  end
110
111
  end
111
-
112
+
112
113
  ### DISCUSS: needed?
113
- context "in event mode" do
114
- should_eventually "set the MIME type to text/javascript" do
114
+ ### FIXME: could somebody get that working?
115
+ describe "in event mode" do
116
+ it "set the MIME type to text/javascript" do
117
+ skip
118
+
115
119
  @controller.apotomo_root << @mum
116
-
120
+
117
121
  get :render_event_response, :source => :kid, :type => :doorSlam
118
-
122
+
119
123
  assert_equal Mime::JS, @response.content_type
120
- assert_equal "$(\"mum\").replace(\"<div id=\\\"mum\\\">burp!<\\/div>\")\n$(\"kid\").update(\"squeak!\")\nsqueak();", @response.body
124
+ assert_equal "jQuery(\"mum\").replace(\"<div id=\\\"mum\\\">burp!<\\/div>\")\njQuery(\"kid\").update(\"squeak!\")\nsqueak();", @response.body
121
125
  end
122
126
  end
123
127
  end
124
-
128
+
125
129
  ### FIXME: could somebody get that working?
126
- context "Routing" do
127
- should_eventually "generate routes to the render_event_response action" do
130
+ describe "Routing" do
131
+ it "generate routes to the render_event_response action" do
132
+ skip
133
+
128
134
  assert_generates "/barn/render_event_response?type=squeak", { :controller => "barn", :action => "render_event_response", :type => "squeak" }
129
-
135
+
130
136
  assert_recognizes({ :controller => "apotomo", :action => "render_event_response", :type => "squeak" }, "/apotomo/render_event_response?type=squeak")
131
137
  end
132
138
  end
133
-
139
+
134
140
  end
@@ -2,115 +2,115 @@ require 'test_helper'
2
2
 
3
3
  class RailsIntegrationTest < ActionController::TestCase
4
4
  include Apotomo::TestCaseMethods::TestController
5
-
5
+
6
6
  class KidWidget < MouseWidget
7
7
  responds_to_event :squeak, :passing => :root
8
-
8
+
9
9
  def feed
10
10
  render # invokes #url_for_event.
11
11
  end
12
-
12
+
13
13
  def squeak
14
14
  render :text => "squeak!"
15
15
  end
16
16
  end
17
-
18
-
17
+
18
+
19
19
  class MumWidget < MouseWidget
20
20
  responds_to_event :squeak
21
21
  responds_to_event :sniff
22
-
22
+
23
23
  has_widgets do |me|
24
24
  me << widget("rails_integration_test/kid", :kid)
25
25
  end
26
-
26
+
27
27
  def eat
28
28
  render
29
29
  end
30
-
30
+
31
31
  def make_me_squeak
32
32
  render
33
33
  end
34
-
35
- def squeak(evt)
34
+
35
+ def squeak(evt)
36
36
  render :text => evt.data
37
37
  end
38
-
38
+
39
39
  def sniff(evt)
40
40
  render :text => "<b>sniff sniff</b>"
41
41
  end
42
-
42
+
43
43
  def child
44
44
  render :text => render_widget(:kid, :feed)
45
45
  end
46
46
  end
47
-
48
-
49
- context "ActionController" do
47
+
48
+
49
+ describe "ActionController" do
50
50
  setup do
51
51
  @controller.class.has_widgets do |root|
52
52
  MumWidget.new(root, 'mum')
53
53
  end
54
-
54
+
55
55
  @controller.instance_eval do
56
56
  def mum
57
57
  render :text => render_widget('mum', params[:state])
58
58
  end
59
59
  end
60
60
  end
61
-
62
- should "provide the rails view helpers in state views" do
61
+
62
+ test "provide the rails view helpers in state views" do
63
63
  get 'mum', :state => :make_me_squeak
64
64
  assert_select "a", "mum"
65
65
  end
66
-
67
- context "nested widgets" do
68
- should "render" do
66
+
67
+ # describe "nested widgets" do
68
+ test "render" do
69
69
  get 'mum', :state => :child
70
70
  assert_equal "/barn/render_event_response?source=kid&amp;type=click\n", @response.body
71
71
  end
72
-
73
- should "process events" do
72
+
73
+ test "process events" do
74
74
  get 'render_event_response', :source => 'root', :type => :squeak
75
75
  assert_equal "squeak!", @response.body
76
76
  end
77
- end
78
-
79
- should "pass the event with all params data as state-args" do
80
- get 'render_event_response', :source => 'mum', :type => :squeak, :pitch => :high
77
+ # end
78
+
79
+ test "pass the event with all params data as state-args" do
80
+ get 'render_event_response', :source => "mum", :type => "squeak", :pitch => "high"
81
81
  assert_equal "{\"source\"=>\"mum\", \"type\"=>\"squeak\", \"pitch\"=>\"high\", \"controller\"=>\"barn\", \"action\"=>\"render_event_response\"}\nsqueak!", @response.body
82
82
  end
83
-
84
- should "render updates to the parent window for an iframe request" do
83
+
84
+ test "render updates to the parent window for an iframe request" do
85
85
  get 'render_event_response', :source => 'mum', :type => :sniff, :apotomo_iframe => true
86
-
86
+
87
87
  assert_response :success
88
88
  assert_equal 'text/html', @response.content_type
89
89
  assert_equal "<html><body><script type='text/javascript' charset='utf-8'>\nvar loc = document.location;\nwith(window.parent) { setTimeout(function() { window.eval('<b>sniff sniff<\\/b>'); window.loc && loc.replace('about:blank'); }, 1) }\n</script></body></html>", @response.body
90
- end
91
-
92
-
93
- context "ActionView" do
94
- setup do
90
+ # end
91
+
92
+
93
+ # describe "ActionView" do
94
+ before do
95
95
  @controller.instance_eval do
96
96
  def mum
97
97
  render :inline => "<%= render_widget 'mum', :eat %>"
98
98
  end
99
99
  end
100
100
  end
101
-
102
- should "respond to #render_widget" do
101
+
102
+ test "respond to #render_widget" do
103
103
  get :mum
104
104
  assert_select "#mum", "burp!"
105
105
  end
106
-
107
- should "respond to #url_for_event" do
106
+
107
+ test "respond to #url_for_event" do
108
108
  @controller.instance_eval do
109
109
  def mum
110
110
  render :inline => "<%= url_for_event :footsteps, :source => 'mum' %>"
111
111
  end
112
112
  end
113
-
113
+
114
114
  get :mum
115
115
  assert_equal "/barn/render_event_response?source=mum&amp;type=footsteps", @response.body
116
116
  end
@@ -120,24 +120,24 @@ end
120
120
 
121
121
 
122
122
  class IncludingApotomoSupportTest < ActiveSupport::TestCase
123
- context "A controller not including ControllerMethods explicitely" do
123
+ # describe "A controller not including ControllerMethods explicitely" do
124
124
  setup do
125
125
  @class = Class.new(ActionController::Base)
126
126
  @controller = @class.new
127
127
  @controller.request = ActionController::TestRequest.new
128
128
  end
129
-
130
- should "respond to .has_widgets only" do
129
+
130
+ test "respond to .has_widgets only" do
131
131
  assert_respond_to @class, :has_widgets
132
132
  assert_not_respond_to @class, :apotomo_request_processor
133
133
  end
134
-
135
- should "mixin all methods after first use of .has_widgets" do
134
+
135
+ test "mixin all methods after first use of .has_widgets" do
136
136
  @class.has_widgets do |root|
137
137
  end
138
-
138
+
139
139
  assert_respond_to @class, :has_widgets
140
140
  assert_respond_to @controller, :apotomo_request_processor
141
141
  end
142
- end
142
+ # end
143
143
  end
@@ -2,9 +2,9 @@ require 'test_helper'
2
2
  require 'action_view/test_case'
3
3
 
4
4
  class ViewHelperTest < Apotomo::TestCase
5
+ include Apotomo::TestCaseMethods::TestController
5
6
  include ActionDispatch::Assertions::DomAssertions
6
- include Apotomo::TestCase::TestController
7
-
7
+
8
8
  # TODO: use Cell::TestCase#in_view here.
9
9
  def in_view(subject, &block)
10
10
  subject = subject.new(@controller, :mum) unless subject.kind_of?(Apotomo::Widget)
@@ -16,61 +16,66 @@ class ViewHelperTest < Apotomo::TestCase
16
16
  mouse.instance_eval &block if block_given?
17
17
  mouse
18
18
  end
19
-
20
-
21
- context "A widget state view" do
19
+
20
+
21
+ # describe "A widget state view" do
22
+ ### DISCUSS: what is this for?
22
23
  teardown do
23
24
  Apotomo.js_framework = :prototype
24
25
  end
25
-
26
- should_eventually "respond to #multipart_form_to_event" do
26
+
27
+ ### DISCUSS: needed?
28
+ ### FIXME: could somebody get that working?
29
+ test "respond to #multipart_form_to_event" do
30
+ skip
31
+
27
32
  assert_dom_equal( "<iframe id=\"apotomo_iframe\" name=\"apotomo_iframe\" style=\"display: none;\"></iframe><form accept-charset=\"UTF-8\" action=\"/barn/render_event_response?apotomo_iframe=true&amp;source=mum&amp;type=footsteps\" enctype=\"multipart/form-data\" method=\"post\" target=\"apotomo_iframe\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div></form>",
28
33
  in_view(MouseWidget) do
29
34
  multipart_form_to_event(:footsteps)
30
35
  end)
31
36
  end
32
-
33
- should "respond to #url_for_event" do
34
- assert_equal("/barn/render_event_response?source=mum&amp;type=footsteps", in_view(MouseWidget) do
37
+
38
+ test "respond to #url_for_event" do
39
+ assert_equal("/barn/render_event_response?source=mum&amp;type=footsteps", in_view(MouseWidget) do
35
40
  url_for_event(:footsteps)
36
41
  end)
37
42
  end
38
-
39
- should "respond to #url_for_event with a namespaced controller" do
43
+
44
+ test "respond to #url_for_event with a namespaced controller" do
40
45
  @controller = namespaced_controller
41
- assert_equal("/farm/barn/render_event_response?source=mum&amp;type=footsteps", in_view(MouseWidget) do
46
+ assert_equal("/farm/barn/render_event_response?source=mum&amp;type=footsteps", in_view(MouseWidget) do
42
47
  url_for_event(:footsteps)
43
48
  end)
44
49
  end
45
-
46
- should "respond to #widget_div" do
50
+
51
+ test "respond to #widget_div" do
47
52
  assert_equal('<div id="mum">squeak!</div>', in_view(MouseWidget) do widget_div { "squeak!" } end)
48
53
  end
49
-
50
- should "respond to #widget_div with options" do
54
+
55
+ test "respond to #widget_div with options" do
51
56
  assert_equal('<div class="mouse" id="kid">squeak!</div>', in_view(MouseWidget) do
52
57
  widget_div(:id => 'kid', :class => "mouse") { "squeak!" }
53
58
  end)
54
59
  end
55
-
56
- should "respond to #widget_id" do
60
+
61
+ test "respond to #widget_id" do
57
62
  assert_equal('mum', in_view(MouseWidget){ widget_id })
58
63
  end
59
-
60
- should "respond to #render_widget" do
64
+
65
+ test "respond to #render_widget" do
61
66
  mum = mouse
62
67
  MouseWidget.new(mum, :kid)
63
-
68
+
64
69
  assert_equal("<div id=\"kid\">burp!</div>\n", in_view(mum){ render_widget 'kid', :eat })
65
70
  end
66
-
67
- should "respond to #children" do
71
+
72
+ test "respond to #children" do
68
73
  mum = mouse
69
74
  MouseWidget.new(mum, :kid)
70
-
75
+
71
76
  assert_equal("<div id=\"kid\">burp!</div>\n", in_view(mum) do
72
77
  children.inject("") { |html, child| html += render_widget(child, :eat) }.html_safe
73
78
  end)
74
79
  end
75
- end
80
+ # end
76
81
  end
@@ -5,13 +5,13 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
5
5
  destination File.join(Rails.root, "tmp")
6
6
  setup :prepare_destination
7
7
  tests ::Apotomo::Generators::WidgetGenerator
8
-
9
- context "Running rails g apotomo::widget" do
10
- context "Gerbil squeak snuggle" do
11
- should "create the standard assets" do
12
-
8
+
9
+ # describe "Running rails g apotomo::widget" do
10
+ # describe "Gerbil squeak snuggle" do
11
+ test "create the standard assets" do
12
+
13
13
  run_generator %w(Gerbil squeak snuggle -t test_unit)
14
-
14
+
15
15
  assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
16
16
  assert_file "app/widgets/gerbil_widget.rb", /def snuggle/
17
17
  assert_file "app/widgets/gerbil_widget.rb", /def squeak/
@@ -22,10 +22,10 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
22
22
  assert_file "test/widgets/gerbil_widget_test.rb", %r(class GerbilWidgetTest < Apotomo::TestCase)
23
23
  assert_file "test/widgets/gerbil_widget_test.rb", %r(widget\(:gerbil\))
24
24
  end
25
-
26
- should "create haml assets with -e haml" do
25
+
26
+ test "create haml assets with -e haml" do
27
27
  run_generator %w(Gerbil squeak snuggle -e haml -t test_unit)
28
-
28
+
29
29
  assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
30
30
  assert_file "app/widgets/gerbil_widget.rb", /def snuggle/
31
31
  assert_file "app/widgets/gerbil_widget.rb", /def squeak/
@@ -35,9 +35,9 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
35
35
  assert_file "test/widgets/gerbil_widget_test.rb"
36
36
  end
37
37
 
38
- should "create slim assets with -e slim" do
38
+ test "create slim assets with -e slim" do
39
39
  run_generator %w(Gerbil squeak snuggle -e slim -t test_unit)
40
-
40
+
41
41
  assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
42
42
  assert_file "app/widgets/gerbil_widget.rb", /def snuggle/
43
43
  assert_file "app/widgets/gerbil_widget.rb", /def squeak/
@@ -46,8 +46,8 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
46
46
  assert_file "app/widgets/gerbil/squeak.html.slim", %r(app/widgets/gerbil/squeak\.html\.slim)
47
47
  assert_file "test/widgets/gerbil_widget_test.rb"
48
48
  end
49
-
50
- should "work with namespaces" do
49
+
50
+ test "work with namespaces" do
51
51
  run_generator %w(Gerbil::Mouse squeak -t test_unit)
52
52
 
53
53
  assert_file "app/widgets/gerbil/mouse_widget.rb", /class Gerbil::MouseWidget < Apotomo::Widget/
@@ -55,7 +55,7 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
55
55
  assert_file "app/widgets/gerbil/mouse/squeak.html.erb", %r(app/widgets/gerbil/mouse/squeak\.html\.erb)
56
56
  assert_file "test/widgets/gerbil/mouse_widget_test.rb"
57
57
  end
58
-
59
- end
60
- end
58
+
59
+ # end
60
+ # end
61
61
  end