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
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class StatefulWidgetTest < Test::Unit::TestCase
|
4
|
-
include Apotomo::TestCaseMethods::TestController
|
5
|
-
|
6
|
-
context "The StatefulWidget" do
|
7
|
-
setup do
|
8
|
-
@mum = Apotomo::StatefulWidget.new(parent_controller, 'mum', :squeak)
|
9
|
-
end
|
10
|
-
|
11
|
-
should "accept an id as first option" do
|
12
|
-
assert_equal 'mum', @mum.name
|
13
|
-
end
|
14
|
-
|
15
|
-
should "accept a start state as second option" do
|
16
|
-
assert_equal :squeak, @mum.instance_variable_get('@start_state')
|
17
|
-
end
|
18
|
-
|
19
|
-
should "respond to #version" do
|
20
|
-
assert_equal 0, mouse_mock.version
|
21
|
-
end
|
22
|
-
|
23
|
-
should "have a version setter" do
|
24
|
-
@mum = mouse_mock
|
25
|
-
@mum.version = 1
|
26
|
-
assert_equal 1, @mum.version
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "mum having a family" do
|
31
|
-
setup do
|
32
|
-
mum_and_kid!
|
33
|
-
@mum << @berry = mouse_mock('berry')
|
34
|
-
@berry << @pet = mouse_mock('pet')
|
35
|
-
end
|
36
|
-
|
37
|
-
context "responding to #render_children" do
|
38
|
-
should "return an OrderedHash for the rendered kids" do
|
39
|
-
kids = @mum.render_children
|
40
|
-
assert_kind_of ::ActiveSupport::OrderedHash, kids
|
41
|
-
assert_equal 2, kids.size
|
42
|
-
end
|
43
|
-
|
44
|
-
should "return an OrderedHash even if there are no kids" do
|
45
|
-
kids = @kid.render_children
|
46
|
-
assert_kind_of ::ActiveSupport::OrderedHash, kids
|
47
|
-
assert_equal 0, kids.size
|
48
|
-
end
|
49
|
-
|
50
|
-
should "return an empty OrderedHash when all kids are invisible" do
|
51
|
-
@pet.visible = false
|
52
|
-
kids = @berry.render_children
|
53
|
-
assert_kind_of ::ActiveSupport::OrderedHash, kids
|
54
|
-
assert_equal 0, kids.size
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class AddressingTest < Test::Unit::TestCase
|
4
|
-
include Apotomo::UnitTestCase
|
5
|
-
|
6
|
-
def test_url_fragment
|
7
|
-
frag = Apotomo::DeepLinkMethods::UrlFragment.new("tabs=first/mouse=eating")
|
8
|
-
|
9
|
-
assert_equal "tabs=first/mouse=eating", frag.to_s
|
10
|
-
assert_equal "first", frag[:tabs]
|
11
|
-
assert_equal "first", frag['tabs']
|
12
|
-
assert_equal "eating", frag[:mouse]
|
13
|
-
assert_equal "eating", frag['mouse']
|
14
|
-
assert_equal nil, frag[:non_existent]
|
15
|
-
|
16
|
-
frag = Apotomo::DeepLinkMethods::UrlFragment.new(nil)
|
17
|
-
assert_equal nil, frag[:non_existent]
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_url_fragment_accessor
|
21
|
-
assert_kind_of Apotomo::DeepLinkMethods::UrlFragment, mouse_mock.url_fragment
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_url_fragment_blank?
|
25
|
-
assert Apotomo::DeepLinkMethods::UrlFragment.new("").blank?
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
def test_responds_to_url_change?
|
30
|
-
m = mouse_mock
|
31
|
-
assert ! m.responds_to_url_change?
|
32
|
-
|
33
|
-
m.respond_to_event :urlChange, :with => :eating
|
34
|
-
assert m.responds_to_url_change?, "should be true as an :urlChanged listener is attached."
|
35
|
-
|
36
|
-
# test with explicit source:
|
37
|
-
m = mouse_mock
|
38
|
-
m.respond_to_event :urlChange, :with => :eating, :from => 'mouse'
|
39
|
-
assert m.responds_to_url_change?, "should be true as an :urlChanged listener is attached."
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_deep_link_addressing
|
43
|
-
t = mouse_mock('top', :upside) do
|
44
|
-
def local_fragment; "top=upside"; end
|
45
|
-
end
|
46
|
-
b = mouse_mock('bottom', :downside) do
|
47
|
-
def local_fragment; "bottom=downside"; end
|
48
|
-
end
|
49
|
-
|
50
|
-
t.respond_to_event :urlChange, :with => :eating
|
51
|
-
b.respond_to_event :urlChange, :with => :eating
|
52
|
-
|
53
|
-
t << b
|
54
|
-
b << j = cell(:mouse, :eating, 'jerry')
|
55
|
-
|
56
|
-
|
57
|
-
assert_equal "top=upside", t.local_fragment
|
58
|
-
assert_equal "v", t.url_fragment_for("v")
|
59
|
-
|
60
|
-
assert_equal "bottom=downside", b.local_fragment
|
61
|
-
assert_equal "top=upside/bottom=downside", b.url_fragment_for
|
62
|
-
assert_equal "top=upside/v", b.url_fragment_for('v')
|
63
|
-
|
64
|
-
assert_equal nil, j.local_fragment
|
65
|
-
assert_equal "top=upside/bottom=downside", j.url_fragment_for
|
66
|
-
assert_equal "top=upside/bottom=downside/jerry", j.url_fragment_for('jerry')
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
def test_default_local_fragment
|
71
|
-
assert_equal nil, mouse_mock.local_fragment
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
def test_responds_to_url_change_for
|
76
|
-
m = mouse_mock do
|
77
|
-
def eating; render :nothing => :true; end
|
78
|
-
end
|
79
|
-
|
80
|
-
assert ! m.responds_to_url_change_for?(""), "should return false by default"
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
def test_path
|
85
|
-
w= cell(:my_test, :some, 'root')
|
86
|
-
assert_equal w.path, 'root'
|
87
|
-
|
88
|
-
w << a= cell(:my_test, :some, 'a')
|
89
|
-
|
90
|
-
assert_equal a.path, 'root/a'
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
def test_find
|
95
|
-
root = widget("apotomo/stateful_widget", :widget_content, 'root')
|
96
|
-
root << a = widget("apotomo/stateful_widget", :widget_content, 'a')
|
97
|
-
a << aa = widget("apotomo/stateful_widget", :widget_content, 'a')
|
98
|
-
|
99
|
-
assert_equal a, root.find_by_id("a")
|
100
|
-
assert_equal a, root.find_by_path("a")
|
101
|
-
assert_equal a, root.find_by_path(:a)
|
102
|
-
assert_equal aa, root.find_by_path("a a")
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
class MyTestCell < Apotomo::StatefulWidget
|
108
|
-
|
109
|
-
|
110
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
### DISCUSS: move some tests from PersistenceTest to this test file.
|
4
|
-
|
5
|
-
|
6
|
-
class InterStateTest < ActionController::TestCase
|
7
|
-
include Apotomo::UnitTestCase
|
8
|
-
|
9
|
-
# do we really jump to the correct state?
|
10
|
-
# and: are all state ivars remembered while jumping?
|
11
|
-
def test_three_state_jumps
|
12
|
-
w = StateJumpCell.new('x', :one)
|
13
|
-
w.controller = @controller
|
14
|
-
|
15
|
-
c = w.invoke # :one -> :two -> :three
|
16
|
-
|
17
|
-
assert_state w, :three
|
18
|
-
puts "brain dump:"
|
19
|
-
puts w.brain.inspect
|
20
|
-
|
21
|
-
assert w.brain.include?("@var")
|
22
|
-
assert w.brain.include?("@one");
|
23
|
-
assert_equal "three,one", c
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
def test_brain_reset_when_invoking_a_start_state
|
28
|
-
w = StateJumpCell.new('x', :counter)
|
29
|
-
w.controller = @controller
|
30
|
-
|
31
|
-
assert_equal "1", w.invoke
|
32
|
-
# another #invoke will flush brain:
|
33
|
-
assert_equal "1", w.invoke
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_brain_reset_when_jumping_to_a_start_state
|
37
|
-
w = StateJumpCell.new('x', :counter)
|
38
|
-
w.controller = @controller
|
39
|
-
w.instance_eval do
|
40
|
-
def back_to_start
|
41
|
-
jump_to_state :counter # :counter is a start state.
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
assert_equal "1", w.invoke
|
46
|
-
# if using #jump_to_state there should be NO brain flush:
|
47
|
-
assert_equal "2", w.invoke_state(:back_to_start)
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
def test_last_state
|
52
|
-
w = StateJumpCell.new('x', :four)
|
53
|
-
w.controller = @controller
|
54
|
-
c = w.invoke
|
55
|
-
assert_equal w.last_state, :four
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
class StateJumpCell < Apotomo::StatefulWidget
|
62
|
-
attr_reader :brain
|
63
|
-
def one
|
64
|
-
@var = "one"
|
65
|
-
@one = "one"
|
66
|
-
jump_to_state :two
|
67
|
-
end
|
68
|
-
|
69
|
-
def two
|
70
|
-
@var = "two"
|
71
|
-
jump_to_state :three
|
72
|
-
end
|
73
|
-
|
74
|
-
def three
|
75
|
-
@var = "three"
|
76
|
-
render :text => "#{@var},#{@one}"
|
77
|
-
end
|
78
|
-
|
79
|
-
def four
|
80
|
-
render :text => ""
|
81
|
-
end
|
82
|
-
|
83
|
-
def counter
|
84
|
-
@counter ||= 0
|
85
|
-
@counter += 1
|
86
|
-
render :text => @counter.to_s
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
data/test/unit/test_tab_panel.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TabPanelTest < Test::Unit::TestCase
|
4
|
-
include Apotomo::UnitTestCase
|
5
|
-
|
6
|
-
def test_responds_to_url_change_for?
|
7
|
-
fragment = Apotomo::DeepLinkMethods::UrlFragment
|
8
|
-
|
9
|
-
w = tab_panel('mice', :is_url_listener => true)
|
10
|
-
w.current_child_id = 'jerry'
|
11
|
-
|
12
|
-
assert ! w.responds_to_url_change_for?(fragment.new ""), "shouldn't respond to emtpy url"
|
13
|
-
assert ! w.responds_to_url_change_for?(fragment.new "cats=tom"), "shouldn't respond to foreign url"
|
14
|
-
assert ! w.responds_to_url_change_for?(fragment.new "mice=jerry")
|
15
|
-
assert ! w.responds_to_url_change_for?(fragment.new "mice="), "shouldn't respond to invalid url"
|
16
|
-
assert w.responds_to_url_change_for?(fragment.new "mice=berry")
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_local_fragment
|
20
|
-
w = tab_panel('mice')
|
21
|
-
w.current_child_id = 'jerry'
|
22
|
-
|
23
|
-
assert_equal "mice=jerry", w.local_fragment
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_find_current_child_from_query
|
27
|
-
w = tab_panel('mice')
|
28
|
-
w << tab('jerry')
|
29
|
-
w << tab('berry')
|
30
|
-
w << tab('micky')
|
31
|
-
|
32
|
-
w.controller = controller
|
33
|
-
|
34
|
-
|
35
|
-
# default child:
|
36
|
-
assert_equal 'jerry', w.find_current_child.name
|
37
|
-
### FIXME: i hate the usage of global parameters:
|
38
|
-
controller.params = {'mice' => 'micky', :deep_link => 'mice=berry'}
|
39
|
-
|
40
|
-
assert_equal 'micky', w.find_current_child.name, "didn't process the query string ?mice=micky"
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_find_current_child_from_fragment
|
44
|
-
w = tab_panel('mice', :is_url_listener => true)
|
45
|
-
w << tab('jerry')
|
46
|
-
w << tab('berry')
|
47
|
-
w << tab('micky')
|
48
|
-
|
49
|
-
w.controller = controller
|
50
|
-
|
51
|
-
### FIXME: i hate the usage of global parameters:
|
52
|
-
controller.params = {'mice' => 'micky', :deep_link => 'mice=berry'}
|
53
|
-
|
54
|
-
assert_equal 'berry', w.find_current_child.name, "didn't process the url fragment 'mice=berry'"
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_url_fragment_for_tab
|
58
|
-
w = tab_panel('mice', :is_url_listener => true)
|
59
|
-
w << j= tab('jerry')
|
60
|
-
j << c= tab_panel('jerrys_kids', :is_url_listener => true)
|
61
|
-
c << r= tab('jerry_jr')
|
62
|
-
w << b= tab('berry')
|
63
|
-
|
64
|
-
w.current_child_id = 'jerry'
|
65
|
-
|
66
|
-
assert_equal "mice=berry", w.url_fragment_for_tab(b)
|
67
|
-
assert_equal "mice=jerry", w.url_fragment_for_tab(j)
|
68
|
-
|
69
|
-
assert_equal "mice=jerry/jerrys_kids=jerry_jr", c.url_fragment_for_tab(r)
|
70
|
-
end
|
71
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TransitionTest < Test::Unit::TestCase
|
4
|
-
context "Calling #next_state_for" do
|
5
|
-
setup do
|
6
|
-
@mum = Object.new
|
7
|
-
@mum.class.instance_eval do
|
8
|
-
include Apotomo::Transition
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
should "return nil when no transition is defined" do
|
13
|
-
assert_not @mum.send(:next_state_for, :snuggle)
|
14
|
-
end
|
15
|
-
|
16
|
-
should "return the defined next state" do
|
17
|
-
@mum.class.instance_eval do
|
18
|
-
transition :from => :snuggle, :to => :sleep
|
19
|
-
end
|
20
|
-
|
21
|
-
assert_equal :sleep, @mum.send(:next_state_for, :snuggle)
|
22
|
-
assert_equal :sleep, @mum.send(:next_state_for, "snuggle")
|
23
|
-
end
|
24
|
-
|
25
|
-
should "return the state that was defined last" do
|
26
|
-
@mum.class.instance_eval do
|
27
|
-
transition :from => :snuggle, :to => :sleep
|
28
|
-
transition :from => :snuggle, :to => :snore
|
29
|
-
end
|
30
|
-
|
31
|
-
assert_equal :snore, @mum.send(:next_state_for, :snuggle)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|