simple-navigation 3.11.0 → 3.12.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.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CHANGELOG +11 -0
- data/Gemfile +2 -16
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +40 -0
- data/Rakefile +6 -39
- data/generators/navigation_config/templates/config/navigation.rb +7 -5
- data/init.rb +1 -0
- data/install.rb +5 -0
- data/lib/simple_navigation/adapters/rails.rb +5 -1
- data/lib/simple_navigation/core/configuration.rb +5 -1
- data/lib/simple_navigation/core/item.rb +2 -1
- data/lib/simple_navigation/core/item_adapter.rb +4 -4
- data/lib/simple_navigation/core/item_container.rb +6 -1
- data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/links.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/list.rb +1 -1
- data/lib/simple_navigation/version.rb +3 -0
- data/lib/simple_navigation.rb +1 -0
- data/simple-navigation.gemspec +40 -0
- data/spec/initializers/have_css_matcher.rb +13 -0
- data/spec/lib/simple_navigation/adapters/padrino_spec.rb +23 -25
- data/spec/lib/simple_navigation/adapters/rails_spec.rb +276 -250
- data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +64 -53
- data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -106
- data/spec/lib/simple_navigation/core/item_adapter_spec.rb +144 -168
- data/spec/lib/simple_navigation/core/item_container_spec.rb +361 -339
- data/spec/lib/simple_navigation/core/item_spec.rb +571 -434
- data/spec/lib/simple_navigation/core/items_provider_spec.rb +35 -49
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +194 -173
- data/spec/lib/simple_navigation/rendering/helpers_spec.rb +381 -225
- data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +205 -164
- data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +87 -67
- data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +52 -31
- data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +75 -48
- data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +62 -174
- data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -28
- data/spec/lib/simple_navigation_spec.rb +207 -225
- data/spec/spec_helper.rb +53 -82
- data/uninstall.rb +1 -0
- metadata +100 -22
- data/README +0 -22
- data/VERSION +0 -1
@@ -1,209 +1,185 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module SimpleNavigation
|
4
|
+
describe ItemAdapter do
|
5
|
+
let(:item_adapter) { ItemAdapter.new(item) }
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
@item_adapter = SimpleNavigation::ItemAdapter.new(@item)
|
8
|
-
end
|
7
|
+
context 'when item is an object' do
|
8
|
+
let(:item) { double(:item, key: 'key', name: 'name', url: 'url') }
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
shared_examples 'delegating to item' do |meth|
|
11
|
+
it "delegates #{meth} to item" do
|
12
|
+
expect(item).to receive(meth)
|
13
|
+
item_adapter.public_send(meth)
|
14
|
+
end
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@item_adapter.url
|
21
|
-
end
|
22
|
-
end
|
17
|
+
it_behaves_like 'delegating to item', :key
|
18
|
+
it_behaves_like 'delegating to item', :url
|
19
|
+
it_behaves_like 'delegating to item', :name
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
21
|
+
describe '#initialize' do
|
22
|
+
it 'sets the item' do
|
23
|
+
expect(item_adapter.item).to be item
|
24
|
+
end
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
27
|
+
describe '#options' do
|
28
|
+
context 'when item responds to options' do
|
29
|
+
let(:options) { double(:options) }
|
36
30
|
|
37
|
-
|
38
|
-
context 'item does respond to options' do
|
39
|
-
before(:each) do
|
40
|
-
@options = stub(:options)
|
41
|
-
@item.stub!(:options => @options)
|
42
|
-
end
|
43
|
-
it "should return the item's options'" do
|
44
|
-
@item_adapter.options.should == @options
|
45
|
-
end
|
46
|
-
end
|
47
|
-
context 'item does not respond to options' do
|
48
|
-
it "should return an empty hash" do
|
49
|
-
@item_adapter.options.should == {}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
31
|
+
before { item.stub(options: options) }
|
53
32
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
before(:each) do
|
58
|
-
@item.stub!(:items => nil)
|
33
|
+
it "returns the item's options" do
|
34
|
+
expect(item_adapter.options).to be options
|
35
|
+
end
|
59
36
|
end
|
60
|
-
|
61
|
-
|
37
|
+
|
38
|
+
context 'item does not respond to options' do
|
39
|
+
it 'returns an empty hash' do
|
40
|
+
expect(item_adapter.options).to eq({})
|
41
|
+
end
|
62
42
|
end
|
63
43
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
44
|
+
|
45
|
+
describe '#items' do
|
46
|
+
context 'when item responds to items' do
|
47
|
+
context 'and items is nil' do
|
48
|
+
before { item.stub(items: nil) }
|
49
|
+
|
50
|
+
it 'returns nil' do
|
51
|
+
expect(item_adapter.items).to be_nil
|
52
|
+
end
|
68
53
|
end
|
69
|
-
|
70
|
-
|
54
|
+
|
55
|
+
context 'when items is not nil' do
|
56
|
+
context 'and items is empty' do
|
57
|
+
before { item.stub(items: []) }
|
58
|
+
|
59
|
+
it 'returns nil' do
|
60
|
+
expect(item_adapter.items).to be_nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'and items is not empty' do
|
65
|
+
let(:items) { double(:items, empty?: false) }
|
66
|
+
|
67
|
+
before { item.stub(items: items) }
|
68
|
+
|
69
|
+
it 'returns the items' do
|
70
|
+
expect(item_adapter.items).to eq items
|
71
|
+
end
|
72
|
+
end
|
71
73
|
end
|
72
74
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
it "should return the items" do
|
79
|
-
@item_adapter.items.should == @items
|
75
|
+
|
76
|
+
context "when item doesn't respond to items" do
|
77
|
+
it 'returns nil' do
|
78
|
+
expect(item_adapter.items).to be_nil
|
80
79
|
end
|
81
80
|
end
|
82
81
|
end
|
83
|
-
end
|
84
|
-
context 'item does not respond to items' do
|
85
|
-
it "should return nil" do
|
86
|
-
@item_adapter.items.should be_nil
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
82
|
|
91
|
-
|
92
|
-
|
93
|
-
@container = stub(:container)
|
94
|
-
@item.stub!(:url => 'url', :name => 'name', :key => 'key', :options => {}, :items => [])
|
95
|
-
end
|
96
|
-
it "should create a SimpleNavigation::Item" do
|
97
|
-
SimpleNavigation::Item.should_receive(:new).with(@container, 'key', 'name', 'url', {}, nil)
|
98
|
-
@item_adapter.to_simple_navigation_item(@container)
|
99
|
-
end
|
100
|
-
end
|
83
|
+
describe '#to_simple_navigation_item' do
|
84
|
+
let(:container) { double(:container) }
|
101
85
|
|
102
|
-
|
86
|
+
before { item.stub(items: [], options: {}) }
|
103
87
|
|
104
|
-
|
88
|
+
it 'creates an Item' do
|
89
|
+
expect(Item).to receive(:new)
|
90
|
+
.with(container, 'key', 'name', 'url', {}, nil)
|
91
|
+
item_adapter.to_simple_navigation_item(container)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
105
95
|
|
106
|
-
|
107
|
-
|
108
|
-
@item_adapter = SimpleNavigation::ItemAdapter.new(@item)
|
109
|
-
end
|
96
|
+
context 'when item is a kind of hash' do
|
97
|
+
class ModifiedHash < Hash; end
|
110
98
|
|
111
|
-
|
112
|
-
it "should delegate key to item" do
|
113
|
-
@item_adapter.item.should_receive(:key)
|
114
|
-
@item_adapter.key
|
115
|
-
end
|
116
|
-
end
|
99
|
+
let(:item) { ModifiedHash[key: 'key', url: 'url', name: 'name'] }
|
117
100
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
101
|
+
shared_examples 'delegating to item' do |meth|
|
102
|
+
it "delegates #{meth} to item" do
|
103
|
+
expect(item_adapter.item).to receive(meth)
|
104
|
+
item_adapter.public_send(meth)
|
105
|
+
end
|
106
|
+
end
|
124
107
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
@item_adapter.name
|
129
|
-
end
|
130
|
-
end
|
108
|
+
it_behaves_like 'delegating to item', :key
|
109
|
+
it_behaves_like 'delegating to item', :url
|
110
|
+
it_behaves_like 'delegating to item', :name
|
131
111
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
it "should have converted the item into an object" do
|
137
|
-
@item_adapter.item.should respond_to(:url)
|
138
|
-
end
|
139
|
-
end
|
112
|
+
describe '#initialize' do
|
113
|
+
it 'sets the item' do
|
114
|
+
expect(item_adapter.item).not_to be_nil
|
115
|
+
end
|
140
116
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
@item = {:key => 'key', :url => 'url', :name => 'name', :options => {:my => :options}}
|
145
|
-
@item_adapter = SimpleNavigation::ItemAdapter.new(@item)
|
146
|
-
end
|
147
|
-
it "should return the item's options'" do
|
148
|
-
@item_adapter.options.should == {:my => :options}
|
149
|
-
end
|
150
|
-
end
|
151
|
-
context 'item does not respond to options' do
|
152
|
-
it "should return an empty hash" do
|
153
|
-
@item_adapter.options.should == {}
|
117
|
+
it 'converts the item into an object' do
|
118
|
+
expect(item_adapter.item).to respond_to(:url)
|
119
|
+
end
|
154
120
|
end
|
155
|
-
end
|
156
|
-
end
|
157
121
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
122
|
+
describe '#options' do
|
123
|
+
context 'when item responds to options' do
|
124
|
+
before { item[:options] = { my: :options } }
|
125
|
+
|
126
|
+
it "returns the item's options" do
|
127
|
+
expect(item_adapter.options).to eq({ my: :options })
|
128
|
+
end
|
164
129
|
end
|
165
|
-
|
166
|
-
|
130
|
+
|
131
|
+
context 'when item does not respond to options' do
|
132
|
+
it 'returns an empty hash' do
|
133
|
+
expect(item_adapter.options).to eq({})
|
134
|
+
end
|
167
135
|
end
|
168
136
|
end
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
137
|
+
|
138
|
+
describe '#items' do
|
139
|
+
context 'when item responds to items' do
|
140
|
+
context 'and items is nil' do
|
141
|
+
before { item[:items] = nil }
|
142
|
+
|
143
|
+
it 'returns nil' do
|
144
|
+
expect(item_adapter.items).to be_nil
|
145
|
+
end
|
174
146
|
end
|
175
|
-
|
176
|
-
|
147
|
+
|
148
|
+
context 'when items is not nil' do
|
149
|
+
context 'and items is empty' do
|
150
|
+
it 'returns nil' do
|
151
|
+
expect(item_adapter.items).to be_nil
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'and items is not empty' do
|
156
|
+
before { item[:items] = ['not', 'empty'] }
|
157
|
+
|
158
|
+
it 'returns the items' do
|
159
|
+
expect(item_adapter.items).to eq ['not', 'empty']
|
160
|
+
end
|
161
|
+
end
|
177
162
|
end
|
178
163
|
end
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
end
|
184
|
-
it "should return the items" do
|
185
|
-
@item_adapter.items.should == ['not', 'empty']
|
164
|
+
|
165
|
+
context 'when item does not respond to items' do
|
166
|
+
it 'returns nil' do
|
167
|
+
expect(item_adapter.items).to be_nil
|
186
168
|
end
|
187
169
|
end
|
188
170
|
end
|
189
|
-
end
|
190
|
-
context 'item does not respond to items' do
|
191
|
-
it "should return nil" do
|
192
|
-
@item_adapter.items.should be_nil
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
171
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
172
|
+
describe '#to_simple_navigation_item' do
|
173
|
+
let(:container) { double(:container) }
|
174
|
+
|
175
|
+
before { item.merge(items: [], options: {}) }
|
176
|
+
|
177
|
+
it 'creates an Item' do
|
178
|
+
expect(Item).to receive(:new)
|
179
|
+
.with(container, 'key', 'name', 'url', {}, nil)
|
180
|
+
item_adapter.to_simple_navigation_item(container)
|
181
|
+
end
|
182
|
+
end
|
206
183
|
end
|
207
184
|
end
|
208
|
-
|
209
|
-
end
|
185
|
+
end
|