apotomo 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -3
- data/.travis.yml +6 -8
- data/CHANGES.textile +9 -5
- data/README.md +211 -0
- data/apotomo.gemspec +4 -4
- data/config/routes.rb +1 -1
- data/gemfiles/Gemfile.rails3-0 +6 -0
- data/gemfiles/Gemfile.rails3-1 +6 -0
- data/gemfiles/Gemfile.rails3-2 +6 -0
- data/gemfiles/Gemfile.rails4-0 +6 -0
- data/lib/apotomo/javascript_generator.rb +3 -3
- data/lib/apotomo/test_case.rb +14 -8
- data/lib/apotomo/version.rb +1 -1
- data/lib/apotomo/widget/javascript_methods.rb +3 -3
- data/lib/apotomo/widget/tree_node.rb +1 -1
- data/lib/apotomo/widget.rb +3 -3
- data/lib/generators/apotomo/widget_generator.rb +1 -1
- data/lib/generators/templates/view.slim +3 -4
- data/test/apotomo_test.rb +25 -14
- data/test/dummy/config/routes.rb +2 -57
- data/test/event_handler_test.rb +30 -60
- data/test/event_methods_test.rb +62 -62
- data/test/event_test.rb +11 -11
- data/test/invoke_event_handler_test.rb +59 -0
- data/test/javascript_generator_test.rb +57 -72
- data/test/rails/caching_test.rb +11 -11
- data/test/rails/controller_methods_test.rb +63 -57
- data/test/rails/rails_integration_test.rb +47 -47
- data/test/rails/view_helper_test.rb +31 -26
- data/test/rails/widget_generator_test.rb +16 -16
- data/test/render_test.rb +50 -50
- data/test/request_processor_test.rb +74 -74
- data/test/test_case_test.rb +45 -45
- data/test/test_helper.rb +14 -10
- data/test/tree_node_test.rb +5 -10
- data/test/widget_shortcuts_test.rb +25 -25
- data/test/widget_test.rb +82 -80
- metadata +73 -49
- data/README.rdoc +0 -205
- data/TODO +0 -36
- data/lib/apotomo/proc_event_handler.rb +0 -18
- data/test/onfire_integration_test.rb +0 -22
data/test/event_handler_test.rb
CHANGED
@@ -1,69 +1,39 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'apotomo/proc_event_handler'
|
3
2
|
|
4
|
-
class EventHandlerTest <
|
3
|
+
class EventHandlerTest < MiniTest::Spec
|
5
4
|
include Apotomo::TestCaseMethods::TestController
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
|
6
|
+
describe "EventHandler" do
|
7
|
+
before do
|
9
8
|
@mum = mouse
|
10
9
|
@mum << mouse_mock(:kid)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
end
|
11
|
+
|
12
|
+
it "respond to #process_event" do
|
13
|
+
h = Apotomo::EventHandler.new
|
14
|
+
e = Apotomo::Event.new(:squeak, @mum)
|
15
|
+
assert_equal nil, h.process_event(e)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#call" do
|
19
|
+
it "push #process_events' results ordered to root's #page_updates" do
|
20
|
+
[@mum, @mum[:kid], @mum].each_with_index do |source, i|
|
21
|
+
e = Apotomo::Event.new(:squeak, source)
|
22
|
+
h = Apotomo::EventHandler.new
|
23
|
+
h.stub :process_event, "tick#{i}" do
|
24
|
+
h.call(e)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
assert_equal 3, @mum.page_updates.size
|
29
|
+
assert_equal "tick0", @mum.page_updates[0]
|
30
|
+
assert_equal "tick1", @mum.page_updates[1]
|
31
|
+
assert_equal "tick2", @mum.page_updates[2]
|
32
|
+
assert_equal 0, @mum[:kid].page_updates.size
|
16
33
|
end
|
17
|
-
|
18
|
-
#
|
19
|
-
assert_equal 3, @mum.page_updates.size
|
20
|
-
assert_equal 0, @mum[:kid].page_updates.size
|
21
|
-
assert_equal(nil, @mum.page_updates[0])
|
22
|
-
assert_equal(nil, @mum.page_updates[1])
|
23
|
-
assert_equal(nil, @mum.page_updates[2])
|
34
|
+
|
35
|
+
#TODO: handler expect #process_event
|
24
36
|
end
|
25
37
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def test_invoke_to_s
|
30
|
-
h = Apotomo::InvokeEventHandler.new
|
31
|
-
h.widget_id = :widget_id
|
32
|
-
h.state = :my_state
|
33
|
-
assert_equal "InvokeEventHandler:widget_id#my_state", h.to_s
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_proc_to_s
|
37
|
-
h = Apotomo::ProcEventHandler.new
|
38
|
-
h.proc = :my_method
|
39
|
-
assert_equal "ProcEventHandler:my_method", h.to_s
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_constructor_for_proc
|
43
|
-
h = Apotomo::ProcEventHandler.new
|
44
|
-
assert_nil h.proc
|
45
|
-
h = Apotomo::ProcEventHandler.new(:proc => :method)
|
46
|
-
assert_equal :method, h.proc
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_constructor_for_invoke
|
50
|
-
h = Apotomo::InvokeEventHandler.new
|
51
|
-
assert_nil h.widget_id
|
52
|
-
assert_nil h.state
|
53
|
-
h = Apotomo::InvokeEventHandler.new(:widget_id => :widget, :state => :state)
|
54
|
-
assert_equal :widget, h.widget_id
|
55
|
-
assert_equal :state, h.state
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_equal
|
59
|
-
h1 = Apotomo::ProcEventHandler.new(:proc => :run)
|
60
|
-
h2 = Apotomo::ProcEventHandler.new(:proc => :run)
|
61
|
-
h3 = Apotomo::ProcEventHandler.new(:proc => :walk)
|
62
|
-
|
63
|
-
assert h1 == h2
|
64
|
-
assert h1 != h3
|
65
|
-
end
|
66
|
-
|
67
|
-
### TODO: test #call
|
68
|
-
|
38
|
+
|
69
39
|
end
|
data/test/event_methods_test.rb
CHANGED
@@ -1,105 +1,105 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
|
3
|
-
class EventMethodsTest <
|
2
|
+
|
3
|
+
class EventMethodsTest < MiniTest::Spec
|
4
4
|
include Apotomo::TestCaseMethods::TestController
|
5
|
-
|
5
|
+
|
6
6
|
def handler(id, state)
|
7
7
|
Apotomo::InvokeEventHandler.new(:widget_id => id, :state => state)
|
8
8
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
|
10
|
+
|
11
|
+
describe "#respond_to_event and #fire" do
|
12
|
+
before do
|
13
13
|
mum_and_kid!
|
14
14
|
end
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
it "alert @mum first, then make her squeak when @kid squeaks" do
|
17
17
|
@kid.fire :squeak
|
18
18
|
assert_equal ['be alerted', 'answer squeak'], @mum.list
|
19
19
|
end
|
20
|
-
|
21
|
-
|
20
|
+
|
21
|
+
it "make @mum just squeak back when jerry squeaks" do
|
22
22
|
@mum << mouse_mock(:jerry)
|
23
23
|
@mum[:jerry].fire :squeak
|
24
24
|
assert_equal ['answer squeak'], @mum.list
|
25
25
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
|
27
|
+
|
28
|
+
it "make @mum run away while @kid keeps watching" do
|
29
29
|
@kid.fire :footsteps
|
30
30
|
assert_equal ['peek', 'escape'], @mum.list
|
31
31
|
end
|
32
|
-
|
33
|
-
|
32
|
+
|
33
|
+
it "by default add a handler only once" do
|
34
34
|
@mum.respond_to_event :peep, :with => :answer_squeak
|
35
35
|
@mum.respond_to_event :peep, :with => :answer_squeak
|
36
36
|
@mum.fire :peep
|
37
37
|
assert_equal ['answer squeak'], @mum.list
|
38
38
|
end
|
39
|
-
|
40
|
-
|
39
|
+
|
40
|
+
it "squeak back twice when using the :once => false option" do
|
41
41
|
@mum.respond_to_event :peep, :with => :answer_squeak
|
42
42
|
@mum.respond_to_event :peep, :with => :answer_squeak, :once => false
|
43
43
|
@mum.fire :peep
|
44
44
|
assert_equal ['answer squeak', 'answer squeak'], @mum.list
|
45
45
|
end
|
46
|
-
|
47
|
-
|
46
|
+
|
47
|
+
it "also accept an event argument only" do
|
48
48
|
@mum.respond_to_event :answer_squeak
|
49
49
|
@mum.fire :answer_squeak
|
50
50
|
assert_equal ['answer squeak'], @mum.list
|
51
|
-
end
|
52
|
-
|
53
|
-
|
51
|
+
end
|
52
|
+
|
53
|
+
it "make pass the event into the triggered state" do
|
54
54
|
@mum.instance_eval do
|
55
55
|
respond_to_event :footsteps
|
56
|
-
|
56
|
+
|
57
57
|
def footsteps(evt)
|
58
58
|
list << evt
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
@mum.trigger :footsteps, "near"
|
63
63
|
assert_kind_of Apotomo::Event, @mum.list.last
|
64
64
|
end
|
65
|
-
|
66
|
-
|
65
|
+
|
66
|
+
it "accept payload data for the event" do
|
67
67
|
@mum.respond_to_event :answer_squeak
|
68
68
|
@mum.instance_eval do
|
69
69
|
def answer_squeak(evt)
|
70
70
|
list << evt.data
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
@mum.fire :answer_squeak, :volume => 9
|
75
75
|
assert_equal [{:volume => 9}], @mum.list
|
76
76
|
end
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
|
78
|
+
|
79
|
+
describe "#responds_to_event with :passing" do
|
80
|
+
before do
|
81
81
|
class AdolescentMouse < MouseWidget
|
82
82
|
responds_to_event :squeak, :passing => :root
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
@root = mouse(:root)
|
86
86
|
end
|
87
|
-
|
88
|
-
|
87
|
+
|
88
|
+
it "add handlers to root when called with :passing" do
|
89
89
|
AdolescentMouse.new(@root, 'jerry')
|
90
|
-
|
90
|
+
|
91
91
|
assert_equal [handler('jerry', :squeak)], @root.event_table.all_handlers_for(:squeak, 'jerry')
|
92
92
|
end
|
93
|
-
|
94
|
-
|
93
|
+
|
94
|
+
it "inherit :passing handlers" do
|
95
95
|
Class.new(AdolescentMouse).new(@root, 'jerry')
|
96
|
-
|
96
|
+
|
97
97
|
assert_equal [handler('jerry', :squeak)], @root.event_table.all_handlers_for(:squeak, 'jerry')
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
end
|
101
|
-
|
102
|
-
|
101
|
+
|
102
|
+
describe "#responds_to_event in class context" do
|
103
103
|
class AdultMouse < Apotomo::Widget
|
104
104
|
responds_to_event :peep, :with => :answer_squeak
|
105
105
|
end
|
@@ -107,46 +107,46 @@ class EventMethodsTest < Test::Unit::TestCase
|
|
107
107
|
responds_to_event :peep
|
108
108
|
responds_to_event :footsteps, :with => :squeak
|
109
109
|
end
|
110
|
-
|
111
|
-
|
110
|
+
|
111
|
+
before do
|
112
112
|
@mum = AdultMouse.new(parent_controller, 'mum')
|
113
113
|
end
|
114
|
-
|
115
|
-
|
114
|
+
|
115
|
+
it "add the handlers at creation time" do
|
116
116
|
assert_equal [handler('mum', :answer_squeak)], @mum.event_table.all_handlers_for(:peep, 'mum')
|
117
117
|
end
|
118
|
-
|
119
|
-
|
118
|
+
|
119
|
+
it "inherit handlers" do
|
120
120
|
assert_equal [[:peep, {:with=>:answer_squeak}]], AdultMouse.responds_to_event_options
|
121
121
|
assert_equal [[:peep, {:with=>:answer_squeak}], [:peep], [:footsteps, {:with=>:squeak}]], BabyMouse.responds_to_event_options
|
122
122
|
end
|
123
|
-
|
124
|
-
|
123
|
+
|
124
|
+
it "not share responds_to_event options between different instances" do
|
125
125
|
assert_equal [handler('mum', :answer_squeak)], @mum.event_table.all_handlers_for(:peep, 'mum')
|
126
|
-
|
126
|
+
|
127
127
|
assert_equal [handler('dad', :answer_squeak)], AdultMouse.new(parent_controller, 'dad', :show).event_table.all_handlers_for(:peep, 'dad')
|
128
128
|
end
|
129
129
|
end
|
130
|
-
|
131
|
-
|
132
|
-
|
130
|
+
|
131
|
+
describe "#trigger" do
|
132
|
+
it "be an alias for #fire" do
|
133
133
|
@kid.trigger :footsteps
|
134
134
|
assert_equal ['peek', 'escape'], @mum.list
|
135
135
|
end
|
136
136
|
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
137
|
+
|
138
|
+
|
139
|
+
describe "page_updates" do
|
140
|
+
it "expose a simple Array for now" do
|
141
141
|
assert_kind_of Array, @mum.page_updates
|
142
142
|
assert_equal 0, @mum.page_updates.size
|
143
143
|
end
|
144
|
-
|
145
|
-
|
144
|
+
|
145
|
+
it "be queued in root#page_updates after #fire" do
|
146
146
|
@mum.fire :footsteps
|
147
147
|
assert_equal ["escape"], @mum.page_updates
|
148
148
|
end
|
149
149
|
end
|
150
|
-
|
151
|
-
end
|
150
|
+
|
151
|
+
end
|
152
152
|
end
|
data/test/event_test.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
|
3
|
-
class EventTest <
|
2
|
+
|
3
|
+
class EventTest < MiniTest::Spec
|
4
4
|
include Apotomo::TestCaseMethods::TestController
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
|
6
|
+
describe "An Event" do
|
7
|
+
it "respond to #type and #source" do
|
8
8
|
@event = Apotomo::Event.new(:footsteps, 'mum')
|
9
9
|
assert_equal :footsteps, @event.type
|
10
10
|
assert_equal 'mum', @event.source
|
11
11
|
end
|
12
|
-
|
13
|
-
|
12
|
+
|
13
|
+
it "accept an additional data object and respond to #data" do
|
14
14
|
@event = Apotomo::Event.new(:footsteps, 'mum', {:volume => :loud})
|
15
15
|
assert_equal({:volume => :loud}, @event.data)
|
16
16
|
end
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
it "delegate #[] to data" do
|
19
19
|
@event = Apotomo::Event.new(:footsteps, 'mum', {:volume => :loud})
|
20
20
|
assert_equal :loud, @event[:volume]
|
21
21
|
end
|
22
|
-
|
23
|
-
|
22
|
+
|
23
|
+
it "respond to #to_s" do
|
24
24
|
@event = Apotomo::Event.new(:footsteps, mouse('mum'))
|
25
25
|
assert_equal "<Event :footsteps source=mum>", @event.to_s
|
26
26
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class EventHandlerTest < MiniTest::Spec
|
4
|
+
include Apotomo::TestCaseMethods::TestController
|
5
|
+
|
6
|
+
describe "InvokeEventHandler" do
|
7
|
+
describe "constructor" do
|
8
|
+
it "accept no arguments" do
|
9
|
+
h = Apotomo::InvokeEventHandler.new
|
10
|
+
assert_nil h.widget_id
|
11
|
+
assert_nil h.state
|
12
|
+
end
|
13
|
+
|
14
|
+
it "accept options" do
|
15
|
+
h = Apotomo::InvokeEventHandler.new(:widget_id => :widget, :state => :state)
|
16
|
+
assert_equal :widget, h.widget_id
|
17
|
+
assert_equal :state, h.state
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "equality methods" do
|
22
|
+
it "repond to #==" do
|
23
|
+
h1 = Apotomo::InvokeEventHandler.new(:widget_id => :widget, :state => :state)
|
24
|
+
h2 = Apotomo::InvokeEventHandler.new(:widget_id => :widget, :state => :state)
|
25
|
+
|
26
|
+
assert h1 == h2
|
27
|
+
assert h2 == h1
|
28
|
+
end
|
29
|
+
|
30
|
+
it "repond to #!=" do
|
31
|
+
h1 = Apotomo::InvokeEventHandler.new(:widget_id => :widget, :state => :state)
|
32
|
+
|
33
|
+
h3 = Apotomo::InvokeEventHandler.new(:widget_id => :another_widget, :state => :state)
|
34
|
+
assert h1 != h3
|
35
|
+
assert h3 != h1
|
36
|
+
|
37
|
+
h4 = Apotomo::InvokeEventHandler.new(:widget_id => :widget, :state => :another_state)
|
38
|
+
assert h1 != h4
|
39
|
+
assert h4 != h1
|
40
|
+
|
41
|
+
h5 = Apotomo::InvokeEventHandler.new
|
42
|
+
assert h1 != h5
|
43
|
+
assert h5 != h1
|
44
|
+
|
45
|
+
# TODO: test InvokeEventHandler == EventHandler
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "respond to #to_s" do
|
50
|
+
h = Apotomo::InvokeEventHandler.new
|
51
|
+
h.widget_id = :widget_id
|
52
|
+
h.state = :my_state
|
53
|
+
assert_equal "InvokeEventHandler:widget_id#my_state", h.to_s
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
### TODO: test #process_event
|
58
|
+
|
59
|
+
end
|
@@ -1,89 +1,74 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class JavascriptGeneratorTest <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Apotomo::JavascriptGenerator.new(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
context "in prototype mode" do
|
12
|
-
setup do
|
13
|
-
@gen = Apotomo::JavascriptGenerator.new(:prototype)
|
14
|
-
end
|
15
|
-
|
16
|
-
should "respond to prototype" do
|
17
|
-
assert_respond_to @gen, :prototype
|
18
|
-
end
|
19
|
-
|
20
|
-
should "respond to replace" do
|
21
|
-
assert_equal "$(\"drinks\").replace(\"EMPTY!\");", @gen.replace(:drinks, 'EMPTY!')
|
22
|
-
end
|
23
|
-
|
24
|
-
should "respond to replace_id" do
|
25
|
-
assert_equal "$(\"drinks\").replace(\"EMPTY!\");", @gen.replace_id("drinks", 'EMPTY!')
|
26
|
-
end
|
27
|
-
|
28
|
-
should "respond to update" do
|
29
|
-
assert_equal "$(\"drinks\").update(\"<li id=\\\"beer\\\"><\\/li>\");", @gen.update(:drinks, '<li id="beer"></li>')
|
3
|
+
class JavascriptGeneratorTest < MiniTest::Spec
|
4
|
+
describe "The JavascriptGenerator" do
|
5
|
+
describe "constructor" do
|
6
|
+
it "accept framework name and return an correct instance" do
|
7
|
+
@gen = Apotomo::JavascriptGenerator.new(:Jquery)
|
8
|
+
|
9
|
+
assert_kind_of Apotomo::JavascriptGenerator, @gen
|
10
|
+
assert_kind_of Apotomo::JavascriptGenerator::Jquery, @gen
|
30
11
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
12
|
+
|
13
|
+
it "raise an error if no framework passed" do
|
14
|
+
assert_raises RuntimeError do
|
15
|
+
Apotomo::JavascriptGenerator.new(nil)
|
16
|
+
end
|
34
17
|
end
|
35
18
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
assert_equal "$(\"drinks\").replace(\"EMPTY!\");", @gen.replace(:drinks, 'EMPTY!')
|
48
|
-
end
|
49
|
-
|
50
|
-
should "respond to replace_id" do
|
51
|
-
assert_equal "$(\"drinks\").replace(\"EMPTY!\");", @gen.replace_id("drinks", 'EMPTY!')
|
52
|
-
end
|
53
|
-
|
54
|
-
should "respond to update" do
|
55
|
-
assert_equal "$(\"drinks\").update(\"<li id=\\\"beer\\\"><\\/li>\");", @gen.update(:drinks, '<li id="beer"></li>')
|
19
|
+
|
20
|
+
it "respond to ::escape" do
|
21
|
+
assert_equal '', Apotomo::JavascriptGenerator.escape(nil)
|
22
|
+
assert_equal %(This \\"thing\\" is really\\n netos\\'), Apotomo::JavascriptGenerator.escape(%(This "thing" is really\n netos'))
|
23
|
+
assert_equal %(backslash\\\\test), Apotomo::JavascriptGenerator.escape(%(backslash\\test))
|
24
|
+
assert_equal %(dont <\\/close> tags), Apotomo::JavascriptGenerator.escape(%(dont </close> tags))
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "in jQuery mode" do
|
28
|
+
before do
|
29
|
+
@gen = Apotomo::JavascriptGenerator.new(:Jquery)
|
56
30
|
end
|
57
|
-
|
58
|
-
|
59
|
-
assert_equal
|
31
|
+
|
32
|
+
it "respond to #escape" do
|
33
|
+
assert_equal '', @gen.escape(nil)
|
34
|
+
assert_equal %(This \\"thing\\" is really\\n netos\\'), @gen.escape(%(This "thing" is really\n netos'))
|
35
|
+
assert_equal %(backslash\\\\test), @gen.escape(%(backslash\\test))
|
36
|
+
assert_equal %(dont <\\/close> tags), @gen.escape(%(dont </close> tags))
|
60
37
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@gen = Apotomo::JavascriptGenerator.new(:jquery)
|
38
|
+
|
39
|
+
it "respond to #<< and return argument converted to String" do
|
40
|
+
assert_equal "bla_bla", (@gen << "bla_bla")
|
41
|
+
assert_equal "bla_bla", (@gen << :bla_bla)
|
66
42
|
end
|
67
|
-
|
68
|
-
|
43
|
+
|
44
|
+
it "respond to #jquery" do
|
69
45
|
assert_respond_to @gen, :jquery
|
70
46
|
end
|
71
|
-
|
72
|
-
|
73
|
-
assert_equal "
|
47
|
+
|
48
|
+
it "respond to #element" do
|
49
|
+
assert_equal "jQuery(\"#drinks\")", @gen.element("#drinks")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "respond to #replace" do
|
53
|
+
assert_equal "jQuery(\"#drinks\").replaceWith(\"EMPTY!\");", @gen.replace("#drinks", 'EMPTY!')
|
74
54
|
end
|
75
|
-
|
76
|
-
|
77
|
-
assert_equal "
|
55
|
+
|
56
|
+
it "respond to #replace_id" do
|
57
|
+
assert_equal "jQuery(\"#drinks\").replaceWith(\"EMPTY!\");", @gen.replace_id("drinks", 'EMPTY!')
|
78
58
|
end
|
79
|
-
|
80
|
-
|
81
|
-
assert_equal "
|
59
|
+
|
60
|
+
it "respond to #update" do
|
61
|
+
assert_equal "jQuery(\"#drinks\").html(\"<li id=\\\"beer\\\"><\\/li>\");", @gen.update("#drinks", '<li id="beer"></li>')
|
82
62
|
end
|
83
|
-
|
84
|
-
|
85
|
-
assert_equal "
|
63
|
+
|
64
|
+
it "respond to #update_id" do
|
65
|
+
assert_equal "jQuery(\"#drinks\").html(\"EMPTY!\");", @gen.update_id("drinks", 'EMPTY!')
|
86
66
|
end
|
67
|
+
|
68
|
+
# TODO: Prototype mode
|
69
|
+
|
70
|
+
# TODO: Right mode
|
71
|
+
|
87
72
|
end
|
88
73
|
end
|
89
74
|
end
|
data/test/rails/caching_test.rb
CHANGED
@@ -2,28 +2,28 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
# TODO: assert that same-named cells and widgets don't overwrite their caches.
|
4
4
|
|
5
|
-
class CachingTest <
|
5
|
+
class CachingTest < MiniTest::Spec
|
6
6
|
include Apotomo::TestCaseMethods::TestController
|
7
|
-
|
7
|
+
|
8
8
|
class CheeseWidget < Apotomo::Widget
|
9
9
|
cache :holes
|
10
|
-
|
10
|
+
|
11
11
|
def holes(count)
|
12
12
|
render :text => count
|
13
|
-
end
|
13
|
+
end
|
14
14
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
|
16
|
+
describe "A caching widget" do
|
17
|
+
before do
|
18
18
|
ActionController::Base.perform_caching = true
|
19
19
|
@cheese = CheeseWidget.new(parent_controller, 'cheese', :holes)
|
20
20
|
end
|
21
|
-
|
22
|
-
|
21
|
+
|
22
|
+
after do
|
23
23
|
ActionController::Base.perform_caching = false
|
24
24
|
end
|
25
|
-
|
26
|
-
|
25
|
+
|
26
|
+
it "invoke the cached state only once" do
|
27
27
|
assert_equal "1", @cheese.invoke(:holes, 1)
|
28
28
|
assert_equal "1", @cheese.invoke(:holes, 2)
|
29
29
|
end
|