apotomo 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,216 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TreeNodeTest < MiniTest::Spec
4
+ include Apotomo::TestCaseMethods::TestController
5
+
4
6
  describe "initialization" do
5
- it "return true for #root? without parent" do
6
- assert MouseWidget.new(nil, :mum).root?
7
+ before do
8
+ @mum = mouse('mum')
9
+ @mum << mouse_mock(:kid)
10
+ @kid = @mum[:kid]
11
+ @kid << mouse_mock(:grandchild)
12
+ @grandchild = @kid[:grandchild]
13
+ @mum << mouse_mock(:another_kid)
14
+ @another_kid = @mum[:another_kid]
15
+ @another_mum = mouse('another_mum')
16
+ end
17
+
18
+ it "respond to #setup_tree_node" do
19
+ @another_mum.setup_tree_node(@mum)
20
+
21
+ assert @another_mum, @mum[:another_mum]
22
+ assert @mum, @another_mum.parent
23
+ end
24
+
25
+ describe "#to_s" do
26
+ it "return its description" do
27
+ assert_match /^Node ID\: \w+ Parent\: \w+ Children\: \d+ Total Nodes\: \d+$/, @mum.to_s
28
+ end
29
+
30
+ it "return correct Node ID" do
31
+ @kid.stub :widget_id, 'awesome_widget' do
32
+ assert_match /Node ID\: awesome_widget/, @kid.to_s
33
+ end
34
+ end
35
+
36
+ it "return correct Node ID if it's non-String" do
37
+ @kid.stub :widget_id, :awesome_widget do
38
+ assert_match /Node ID\: awesome_widget/, @kid.to_s
39
+ end
40
+ end
41
+
42
+ it "return correct Parent ID" do
43
+ @mum.stub :name, 'awesome_mum' do
44
+ assert_match /Parent\: awesome_mum/, @kid.to_s
45
+ end
46
+ end
47
+
48
+ it "return correct Parent ID if it's non-String" do
49
+ @mum.stub :name, :awesome_mum do
50
+ assert_match /Parent\: awesome_mum/, @kid.to_s
51
+ end
52
+ end
53
+
54
+ it "return correct Total Nodes" do
55
+ @kid.stub :size, 123 do
56
+ assert_match /Total Nodes\: 123/, @kid.to_s
57
+ end
58
+ end
59
+
60
+ # TODO: test Children after #children_size will be extracted
61
+ end
62
+
63
+ describe "#add_widget" do
64
+ it "add widget if it is not already added and return it" do
65
+ mouse_sister = mouse(:mouse_sister)
66
+ @mum.add_widget(mouse_sister)
67
+
68
+ assert_equal mouse_sister, @mum[:mouse_sister]
69
+ end
70
+
71
+ it "raise an exception if widget is already added" do
72
+ assert_raises RuntimeError do
73
+ @mum.add_widget(@kid)
74
+ end
75
+ end
76
+
77
+ it "raise an exception if widget with the same name is already added" do
78
+ assert_raises RuntimeError do
79
+ new_kid = mouse(:kid)
80
+ @mum.add_widget(new_kid)
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "#remove!" do
86
+ describe "when try to remove a child" do
87
+ it "remove child" do
88
+ @mum.remove!(@kid)
89
+
90
+ assert_nil @mum[:kid]
91
+ end
92
+
93
+ it "make child #root?'ed" do
94
+ @mum.remove!(@kid)
95
+
96
+ assert @kid.root?
97
+ end
98
+
99
+ it "return child" do
100
+ assert_equal @kid, @mum.remove!(@kid)
101
+ end
102
+ end
103
+
104
+ describe "when try to remove a foreign widget" do
105
+ it "make widget #root?'ed" do
106
+ @kid.remove!(@another_mum)
107
+ assert @another_mum.root?
108
+ end
109
+
110
+ it "return widget" do
111
+ assert_equal @another_kid, @kid.remove!(@another_kid)
112
+ end
113
+ end
7
114
  end
8
115
 
9
- it "return false for #root? with parent" do
10
- @mum = MouseWidget.new(nil, :mum)
11
- assert_not MouseWidget.new(@mum, :kid).root?
116
+ describe "#parent=" do
117
+ it "set instance as parent" do
118
+ @kid.send(:parent=, @another_mum)
119
+
120
+ assert_equal "another_mum", @kid.parent.name
121
+ end
12
122
  end
123
+
124
+ describe "#root!" do
125
+ it "set instance as root" do
126
+ @kid.send(:root!)
127
+
128
+ assert_equal :kid, @grandchild.root.name
129
+ end
130
+ end
131
+
132
+ describe "#root?" do
133
+ it "return true if parent doesn't exist" do
134
+ assert @mum.root?
135
+ end
136
+
137
+ it "return false if parent exists" do
138
+ assert_not @kid.root?
139
+ end
140
+ end
141
+
142
+ describe "#parent" do
143
+ it "return parent if it exists" do
144
+ assert_equal @mum, @kid.parent
145
+ end
146
+
147
+ it "return nil if it doesn't exist" do
148
+ assert_equal nil, @mum.parent
149
+ end
150
+ end
151
+
152
+ describe "#children" do
153
+ it "return children unless a block given" do
154
+ assert_equal [@kid, @another_kid], @mum.children
155
+ end
156
+
157
+ it "return children if a block given" do
158
+ assert_equal [@kid, @another_kid], @mum.children { |child| child }
159
+ end
160
+
161
+ # TODO: check if block yielded
162
+ end
163
+
164
+ describe "#each" do
165
+ it "return children" do
166
+ assert_equal [@kid, @another_kid], @mum.each { |widget| widget }
167
+ end
168
+
169
+ # TODO: check if block yielded
170
+ end
171
+
172
+ describe "accessing children by #[]" do
173
+ it "return child by its name" do
174
+ assert_equal @kid, @mum[:kid]
175
+ end
176
+
177
+ it "return child by its number" do
178
+ assert_equal @kid, @mum[0]
179
+ assert_equal @another_kid, @mum[1]
180
+ end
181
+ end
182
+
183
+ describe "#size" do
184
+ it "return subnodes count + 1" do
185
+ assert_equal 4, @mum.size
186
+ assert_equal 2, @kid.size
187
+ assert_equal 1, @grandchild.size
188
+ assert_equal 1, @another_kid.size
189
+ assert_equal 1, @another_mum.size
190
+ end
191
+ end
192
+
193
+ describe "#root" do
194
+ it "return root widget for a kid" do
195
+ assert_equal @mum, @mum.root
196
+ assert_equal @mum, @kid.root
197
+ assert_equal @mum, @grandchild.root
198
+ end
199
+ end
200
+
201
+ describe "#path" do
202
+ it "return the path from the widget to root" do
203
+ assert_equal "mum", @mum.path
204
+ assert_equal "mum/kid", @kid.path
205
+ assert_equal "mum/kid/grandchild", @grandchild.path
206
+ end
207
+ end
208
+
209
+ # TODO: test #printTree
210
+
211
+ # TODO: test #<=>
212
+
213
+ # TODO: test #find_by_path
214
+
13
215
  end
14
216
  end
@@ -1,7 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
- class MumWidget < MouseWidget; end
4
- class MouseTabsWidget;end
3
+ class MumWidget < MouseWidget
4
+ end
5
+
6
+ class MouseTabsWidget < Apotomo::Widget
7
+ end
5
8
 
6
9
  class WidgetShortcutsTest < MiniTest::Spec
7
10
  describe "FactoryProxy" do
@@ -9,6 +12,7 @@ class WidgetShortcutsTest < MiniTest::Spec
9
12
  @factory = Apotomo::WidgetShortcuts::FactoryProxy
10
13
  end
11
14
 
15
+ # DISCISS: needed?
12
16
  describe "#constant_for" do
13
17
  before do
14
18
  @dsl = @factory.new(:class, :id)
@@ -18,6 +22,7 @@ class WidgetShortcutsTest < MiniTest::Spec
18
22
  assert_equal MouseWidget, @dsl.send(:constant_for, :mouse)
19
23
  end
20
24
 
25
+ # DISCISS: needed?
21
26
  it "not try to singularize the widget class" do
22
27
  assert_equal MouseTabsWidget, @dsl.send(:constant_for, :mouse_tabs)
23
28
  end
@@ -28,18 +33,16 @@ class WidgetShortcutsTest < MiniTest::Spec
28
33
  @root = Apotomo::Widget.new(nil, :root)
29
34
  end
30
35
 
31
- describe "with all arguments" do
32
- it "create a MumWidget instance with options" do
33
- proxy = widget(:mum, :mummy, :eating, :color => 'grey', :type => :hungry)
34
- @root << proxy
36
+ it "create a widget instance with options and set them" do
37
+ proxy = widget(:mum, :mummy, :eating, :color => 'grey', :type => :hungry)
38
+ @root << proxy
35
39
 
36
- assert_kind_of MumWidget, @root[:mummy]
37
- assert_equal :mummy, @root[:mummy].name
38
- assert_equal({:color => "grey", :type => :hungry}, @root[:mummy].options)
39
- end
40
+ assert_kind_of MumWidget, @root[:mummy]
41
+ assert_equal :mummy, @root[:mummy].name
42
+ assert_equal({:color => "grey", :type => :hungry}, @root[:mummy].options)
40
43
  end
41
44
 
42
- it "not set options with 2 arguments" do
45
+ it "create a widget instance without options" do
43
46
  @root << widget(:mum, :mummy)
44
47
  @mum = @root[:mummy]
45
48
 
@@ -48,7 +51,7 @@ class WidgetShortcutsTest < MiniTest::Spec
48
51
  assert_equal({}, @mum.options)
49
52
  end
50
53
 
51
- it "set defaults with prefix, only" do
54
+ it "create a widget instance with prefix argument only (id is equal to prefix)" do
52
55
  @root << widget(:mum)
53
56
  @mum = @root[:mum]
54
57
 
@@ -57,11 +60,13 @@ class WidgetShortcutsTest < MiniTest::Spec
57
60
  assert_equal({}, @mum.options)
58
61
  end
59
62
 
60
- it "yield itself" do
63
+ it "create a widget instance and yield itself" do
64
+ # TODO: don't create a subwidget but use expectations
61
65
  ficken = widget(:mum) do |mum|
62
66
  mum << widget(:mouse, :kid)
63
67
  end
64
68
  @root << ficken
69
+
65
70
  assert_equal 2, @root[:mum].size
66
71
  assert_kind_of MouseWidget, @root[:mum][:kid]
67
72
  end
data/test/widget_test.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
+ # TODO: there are *many* things in Apotomo::Widget *isn't* tested here
4
+
3
5
  class WidgetTest < MiniTest::Spec
4
6
  include Apotomo::TestCaseMethods::TestController
5
7
 
@@ -112,7 +114,7 @@ class WidgetTest < MiniTest::Spec
112
114
  it "respond to .view_paths" do
113
115
  if Cell.rails3_2_or_more?
114
116
  assert_equal ActionView::PathSet.new(Apotomo::Widget::DEFAULT_VIEW_PATHS + ["test/widgets"]).paths, Apotomo::Widget.view_paths.paths
115
- elsif Cell.rails4_0_or_more?
117
+ elsif Cell.rails4_0? or Cell.rails4_1_or_more?
116
118
  Apotomo::Widget.view_paths.paths.to_s.must_match("app/widgets")
117
119
  else
118
120
  assert_equal ActionView::PathSet.new(Apotomo::Widget::DEFAULT_VIEW_PATHS + ["test/widgets"]), Apotomo::Widget.view_paths
metadata CHANGED
@@ -1,125 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apotomo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cells
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.6.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.6.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: onfire
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hooks
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.0
47
+ version: 0.4.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.0
54
+ version: 0.4.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: slim
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: haml
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: tzinfo
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: minitest
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: 4.7.5
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 4.7.5
125
125
  description: Web component framework for Rails providing widgets that trigger events
@@ -130,8 +130,8 @@ executables: []
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
- - .gitignore
134
- - .travis.yml
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
135
  - CHANGES.textile
136
136
  - Gemfile
137
137
  - README.md
@@ -231,18 +231,68 @@ require_paths:
231
231
  - lib
232
232
  required_ruby_version: !ruby/object:Gem::Requirement
233
233
  requirements:
234
- - - '>='
234
+ - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  requirements:
239
- - - '>='
239
+ - - ">="
240
240
  - !ruby/object:Gem::Version
241
241
  version: '0'
242
242
  requirements: []
243
243
  rubyforge_project:
244
- rubygems_version: 2.0.3
244
+ rubygems_version: 2.2.1
245
245
  signing_key:
246
246
  specification_version: 4
247
247
  summary: Web components for Rails.
248
- test_files: []
248
+ test_files:
249
+ - test/apotomo_test.rb
250
+ - test/dummy/Rakefile
251
+ - test/dummy/app/controllers/application_controller.rb
252
+ - test/dummy/app/helpers/application_helper.rb
253
+ - test/dummy/app/views/layouts/application.html.erb
254
+ - test/dummy/config.ru
255
+ - test/dummy/config/application.rb
256
+ - test/dummy/config/boot.rb
257
+ - test/dummy/config/database.yml
258
+ - test/dummy/config/environment.rb
259
+ - test/dummy/config/environments/development.rb
260
+ - test/dummy/config/environments/production.rb
261
+ - test/dummy/config/environments/test.rb
262
+ - test/dummy/config/initializers/backtrace_silencers.rb
263
+ - test/dummy/config/initializers/inflections.rb
264
+ - test/dummy/config/initializers/mime_types.rb
265
+ - test/dummy/config/initializers/secret_token.rb
266
+ - test/dummy/config/initializers/session_store.rb
267
+ - test/dummy/config/locales/en.yml
268
+ - test/dummy/config/routes.rb
269
+ - test/dummy/db/test.sqlite3
270
+ - test/dummy/public/404.html
271
+ - test/dummy/public/422.html
272
+ - test/dummy/public/500.html
273
+ - test/dummy/public/favicon.ico
274
+ - test/dummy/public/stylesheets/.gitkeep
275
+ - test/event_handler_test.rb
276
+ - test/event_methods_test.rb
277
+ - test/event_test.rb
278
+ - test/invoke_event_handler_test.rb
279
+ - test/javascript_generator_test.rb
280
+ - test/rails/caching_test.rb
281
+ - test/rails/controller_methods_test.rb
282
+ - test/rails/rails_integration_test.rb
283
+ - test/rails/view_helper_test.rb
284
+ - test/rails/widget_generator_test.rb
285
+ - test/render_test.rb
286
+ - test/request_processor_test.rb
287
+ - test/test_case_methods.rb
288
+ - test/test_case_test.rb
289
+ - test/test_helper.rb
290
+ - test/tree_node_test.rb
291
+ - test/widget_shortcuts_test.rb
292
+ - test/widget_test.rb
293
+ - test/widgets/mouse/eat.erb
294
+ - test/widgets/mouse/eating.html.erb
295
+ - test/widgets/mouse/educate.html.erb
296
+ - test/widgets/mouse/feed.html.erb
297
+ - test/widgets/mouse/make_me_squeak.html.erb
298
+ - test/widgets/mouse/snuggle.html.erb