menu_maker 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/lib/menu_maker/custom_submenu_renderer.rb +1 -1
- data/lib/menu_maker/menu.rb +11 -9
- data/lib/menu_maker/menu_renderer.rb +4 -5
- data/lib/menu_maker/path.rb +61 -0
- data/lib/menu_maker/version.rb +1 -1
- data/lib/menu_maker.rb +1 -0
- data/test/dummy/log/test.log +13707 -0
- data/test/menu_item_test.rb +26 -2
- data/test/menu_renderer_test.rb +15 -0
- data/test/path_test.rb +84 -0
- metadata +5 -2
data/test/menu_item_test.rb
CHANGED
@@ -10,6 +10,11 @@ module MenuMaker
|
|
10
10
|
assert_equal 'my/path', item.path
|
11
11
|
end
|
12
12
|
|
13
|
+
test 'accepts many paths' do
|
14
|
+
item = Menu::MenuItem.new 'My title', 'path/1', 'path/2', 'path/3'
|
15
|
+
assert_equal ['path/1', 'path/2', 'path/3'], item.paths.map(&:address)
|
16
|
+
end
|
17
|
+
|
13
18
|
test 'submenu_paths returns submenu paths recursively' do
|
14
19
|
item = Menu::MenuItem.new 'Level 1', 'level/1'
|
15
20
|
|
@@ -28,7 +33,7 @@ module MenuMaker
|
|
28
33
|
|
29
34
|
expected = %w[level/2 level/2/1 level/2/2 level/3 level/4 level/5 level/6]
|
30
35
|
|
31
|
-
assert_equal expected, item.submenu_paths.sort
|
36
|
+
assert_equal expected, item.submenu_paths.map(&:address).sort
|
32
37
|
end
|
33
38
|
|
34
39
|
test 'all_paths returns submenu paths + current menu path' do
|
@@ -47,7 +52,7 @@ module MenuMaker
|
|
47
52
|
|
48
53
|
expected = %w[level/1 level/2 level/3 level/4 level/5 level/6]
|
49
54
|
|
50
|
-
assert_equal expected, item.all_paths.sort
|
55
|
+
assert_equal expected, item.all_paths.map(&:address).sort
|
51
56
|
end
|
52
57
|
|
53
58
|
test 'has_path? also checks for submenus' do
|
@@ -69,6 +74,25 @@ module MenuMaker
|
|
69
74
|
refute item.has_path?('level/8')
|
70
75
|
end
|
71
76
|
|
77
|
+
test 'Menu#add accepts multiple paths and options' do
|
78
|
+
menu = Menu.new proc {}
|
79
|
+
menu.add('Item', 'path/1', [:post, 'path/2'], [:put, 'path/3'], option: 'optional')
|
80
|
+
|
81
|
+
result = menu.items.first.paths.map(&:address)
|
82
|
+
|
83
|
+
expected = %w[path/1 path/2 path/3]
|
84
|
+
|
85
|
+
assert_equal expected, result
|
86
|
+
assert_equal 'optional', menu.items.first.option
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'has_path? matches on other restful paths' do
|
90
|
+
item = Menu::MenuItem.new 'Item', 'main_path', [:post, 'other/path']
|
91
|
+
|
92
|
+
assert item.has_path? [:post, 'other/path']
|
93
|
+
assert item.has_path? Path.new(:post, 'other/path')
|
94
|
+
end
|
95
|
+
|
72
96
|
test "has_submenu? when returns false" do
|
73
97
|
item = Menu::MenuItem.new 'Level 1', 'level/1'
|
74
98
|
refute item.has_submenu?
|
data/test/menu_renderer_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
4
|
module MenuMaker
|
4
5
|
class MenuRendererTest < ActiveSupport::TestCase
|
@@ -60,5 +61,19 @@ module MenuMaker
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
64
|
+
|
65
|
+
context 'with a MenuRenderer class renderer' do
|
66
|
+
should 'detect the path when not provided and the context responds to request' do
|
67
|
+
request = Class.new do
|
68
|
+
def method; 'POST' end
|
69
|
+
def path; '/path' end
|
70
|
+
end.new
|
71
|
+
|
72
|
+
context = OpenStruct.new request: request
|
73
|
+
renderer = MenuRenderer.new context
|
74
|
+
|
75
|
+
assert_equal Path.new(:post, '/path'), renderer.current_path
|
76
|
+
end
|
77
|
+
end
|
63
78
|
end
|
64
79
|
end
|
data/test/path_test.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module MenuMaker
|
4
|
+
class PathTest < ActionView::TestCase
|
5
|
+
test 'accepts get, post, put, patch and delete' do
|
6
|
+
%i[get post put patch delete].each do |method|
|
7
|
+
Path.new method, '/path'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
test "doesn't accept a method other than get, post, put, patch and delete" do
|
12
|
+
assert_raise Path::PathError do
|
13
|
+
Path.new :ouch, '/path'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'to_s returns the address' do
|
18
|
+
assert_equal '/path', Path.new(:get, '/path').to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'creates a get path from a given string' do
|
22
|
+
assert_equal Path.new(:get, '/path'), Path.convert('/path')
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'creates a path from an array' do
|
26
|
+
assert_equal Path.new(:post, '/path'), Path.convert([:post, '/path'])
|
27
|
+
end
|
28
|
+
|
29
|
+
test "creates a path from an array assumes get when can't find request method" do
|
30
|
+
assert_equal Path.new(:get, '/path'), Path.convert(['/path'])
|
31
|
+
end
|
32
|
+
|
33
|
+
test "creates a path from an array on empty array creates empty get path" do
|
34
|
+
assert_equal Path.new(:get, ''), Path.convert([])
|
35
|
+
end
|
36
|
+
|
37
|
+
test "returns back the path if already a Path" do
|
38
|
+
path = Path.new :put, '/path'
|
39
|
+
assert_equal path, Path.convert(path)
|
40
|
+
end
|
41
|
+
|
42
|
+
test "creates a path from an object wich responds to path and method" do
|
43
|
+
request = Class.new do
|
44
|
+
def path
|
45
|
+
'/path'
|
46
|
+
end
|
47
|
+
|
48
|
+
def method
|
49
|
+
'PUT'
|
50
|
+
end
|
51
|
+
end.new
|
52
|
+
|
53
|
+
assert_equal Path.new(:put, '/path'), Path.convert(request)
|
54
|
+
end
|
55
|
+
|
56
|
+
test "fails if can't create path from object which responds to path and method" do
|
57
|
+
assert_raise Path::PathError do
|
58
|
+
Path.convert(Object.new)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test "from_path fails when not a path" do
|
63
|
+
assert_raise Path::PathError do
|
64
|
+
Path.from_path(Object.new)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
test "equality works with an equal path" do
|
69
|
+
assert_equal Path.new(:put, '/path'), Path.new(:put, '/path')
|
70
|
+
end
|
71
|
+
|
72
|
+
test "equality works with a convertible string" do
|
73
|
+
assert_equal Path.new(:get, '/path'), '/path'
|
74
|
+
end
|
75
|
+
|
76
|
+
test "equality works with a convertible array" do
|
77
|
+
assert Path.new(:post, '/path') == [:post, '/path']
|
78
|
+
end
|
79
|
+
|
80
|
+
test "a Path global conversion method is also available" do
|
81
|
+
assert_equal Path.new(:post, '/path'), Path(:post, '/path')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: menu_maker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago A. Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/menu_maker/menu.rb
|
58
58
|
- lib/menu_maker/menu_renderer.rb
|
59
59
|
- lib/menu_maker/menu_renderer_container.rb
|
60
|
+
- lib/menu_maker/path.rb
|
60
61
|
- lib/menu_maker/version.rb
|
61
62
|
- lib/tasks/menu_maker_tasks.rake
|
62
63
|
- test/dummy/README.rdoc
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- test/menu_item_test.rb
|
101
102
|
- test/menu_maker_test.rb
|
102
103
|
- test/menu_renderer_test.rb
|
104
|
+
- test/path_test.rb
|
103
105
|
- test/test_helper.rb
|
104
106
|
homepage: http://github.com/thiagoa/menu_maker
|
105
107
|
licenses:
|
@@ -167,4 +169,5 @@ test_files:
|
|
167
169
|
- test/menu_item_test.rb
|
168
170
|
- test/menu_maker_test.rb
|
169
171
|
- test/menu_renderer_test.rb
|
172
|
+
- test/path_test.rb
|
170
173
|
- test/test_helper.rb
|