simple-navigation 4.4.1 → 4.5.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/.github/workflows/ci.yml +84 -0
- data/.rspec +1 -2
- data/.rubocop.yml +49 -0
- data/.rubocop_todo.yml +38 -0
- data/Appraisals +55 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +21 -0
- data/Guardfile +4 -2
- data/README.md +11 -23
- data/Rakefile +2 -27
- data/bin/_guard-core +16 -0
- data/bin/appraisal +16 -0
- data/bin/guard +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/rubocop +16 -0
- data/gemfiles/rails_6.1.gemfile +35 -0
- data/gemfiles/rails_7.0.gemfile +23 -0
- data/gemfiles/rails_7.1.gemfile +23 -0
- data/gemfiles/rails_7.2.gemfile +23 -0
- data/gemfiles/rails_8.0.gemfile +23 -0
- data/gemfiles/rails_8.1.gemfile +23 -0
- data/generators/navigation_config/navigation_config_generator.rb +2 -0
- data/generators/navigation_config/templates/config/navigation.rb +30 -26
- data/lib/generators/navigation_config/navigation_config_generator.rb +2 -0
- data/lib/simple-navigation.rb +3 -1
- data/lib/simple_navigation/adapters/base.rb +2 -0
- data/lib/simple_navigation/adapters/nanoc.rb +8 -3
- data/lib/simple_navigation/adapters/padrino.rb +3 -1
- data/lib/simple_navigation/adapters/rails.rb +12 -14
- data/lib/simple_navigation/adapters/sinatra.rb +4 -6
- data/lib/simple_navigation/config_file.rb +1 -1
- data/lib/simple_navigation/config_file_finder.rb +3 -3
- data/lib/simple_navigation/configuration.rb +5 -5
- data/lib/simple_navigation/helpers.rb +9 -11
- data/lib/simple_navigation/item.rb +26 -20
- data/lib/simple_navigation/item_adapter.rb +16 -5
- data/lib/simple_navigation/item_container.rb +13 -7
- data/lib/simple_navigation/items_provider.rb +6 -4
- data/lib/simple_navigation/railtie.rb +3 -1
- data/lib/simple_navigation/renderer/base.rb +5 -5
- data/lib/simple_navigation/renderer/breadcrumbs.rb +4 -3
- data/lib/simple_navigation/renderer/json.rb +1 -1
- data/lib/simple_navigation/renderer/links.rb +2 -0
- data/lib/simple_navigation/renderer/list.rb +5 -5
- data/lib/simple_navigation/renderer/text.rb +3 -1
- data/lib/simple_navigation/version.rb +3 -1
- data/lib/simple_navigation.rb +32 -24
- data/simple-navigation.gemspec +16 -27
- data/spec/fake_app/config/navigation.rb +4 -2
- data/spec/fake_app/rails_app.rb +5 -3
- data/spec/integration/rendering_navigation_spec.rb +7 -5
- data/spec/simple_navigation/adapters/nanoc_spec.rb +97 -0
- data/spec/simple_navigation/adapters/padrino_spec.rb +41 -22
- data/spec/simple_navigation/adapters/rails_spec.rb +199 -206
- data/spec/simple_navigation/adapters/sinatra_spec.rb +21 -5
- data/spec/simple_navigation/config_file_finder_spec.rb +32 -28
- data/spec/simple_navigation/config_file_spec.rb +14 -14
- data/spec/simple_navigation/configuration_spec.rb +128 -121
- data/spec/simple_navigation/helpers_spec.rb +282 -284
- data/spec/simple_navigation/item_adapter_spec.rb +109 -122
- data/spec/simple_navigation/item_container_spec.rb +407 -408
- data/spec/simple_navigation/item_spec.rb +333 -301
- data/spec/simple_navigation/items_provider_spec.rb +30 -27
- data/spec/simple_navigation/renderer/base_spec.rb +166 -168
- data/spec/simple_navigation/renderer/breadcrumbs_spec.rb +81 -83
- data/spec/simple_navigation/renderer/json_spec.rb +49 -56
- data/spec/simple_navigation/renderer/links_spec.rb +81 -83
- data/spec/simple_navigation/renderer/list_spec.rb +111 -91
- data/spec/simple_navigation/renderer/text_spec.rb +37 -39
- data/spec/simple_navigation_spec.rb +54 -47
- data/spec/spec_helper.rb +146 -53
- metadata +25 -164
- data/.travis.yml +0 -23
- data/gemfiles/rails-3-2-stable.gemfile +0 -11
- data/gemfiles/rails-4-1-stable.gemfile +0 -7
- data/gemfiles/rails-4-2-stable.gemfile +0 -7
- data/gemfiles/rails-5-2-stable.gemfile +0 -7
- data/gemfiles/rails-6-0-stable.gemfile +0 -9
- data/gemfiles/rails-6-1-stable.gemfile +0 -9
- data/init.rb +0 -1
- data/install.rb +0 -5
- data/lib/simple_navigation/adapters.rb +0 -10
- data/lib/simple_navigation/renderer.rb +0 -12
- data/spec/initializers/coveralls.rb +0 -3
- data/spec/initializers/have_css_matcher.rb +0 -19
- data/spec/initializers/memfs.rb +0 -7
- data/spec/initializers/rails.rb +0 -4
- data/spec/initializers/rspec.rb +0 -7
- data/uninstall.rb +0 -1
|
@@ -1,187 +1,174 @@
|
|
|
1
|
-
|
|
2
|
-
describe ItemAdapter do
|
|
3
|
-
let(:item_adapter) { ItemAdapter.new(item) }
|
|
1
|
+
# frozen_string_literal: true
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
let(:item) { double(:item, key: 'key', name: 'name', url: 'url') }
|
|
3
|
+
class ModifiedHash < Hash; end
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
RSpec.describe SimpleNavigation::ItemAdapter do
|
|
6
|
+
let(:item_adapter) { described_class.new(item) }
|
|
7
|
+
|
|
8
|
+
context 'when item is an object' do
|
|
9
|
+
let(:item) { double(:item, key: 'key', name: 'name', url: 'url') }
|
|
10
|
+
|
|
11
|
+
shared_examples 'delegating to item' do |meth|
|
|
12
|
+
it "delegates #{meth} to item" do
|
|
13
|
+
expect(item).to receive(meth)
|
|
14
|
+
item_adapter.public_send(meth)
|
|
13
15
|
end
|
|
16
|
+
end
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
it_behaves_like 'delegating to item', :key
|
|
19
|
+
it_behaves_like 'delegating to item', :url
|
|
20
|
+
it_behaves_like 'delegating to item', :name
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
22
|
+
describe '#initialize' do
|
|
23
|
+
it 'sets the item' do
|
|
24
|
+
expect(item_adapter.item).to be item
|
|
23
25
|
end
|
|
26
|
+
end
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
describe '#options' do
|
|
29
|
+
context 'when item responds to options' do
|
|
30
|
+
let(:options) { double(:options) }
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
before { allow(item).to receive_messages(options: options) }
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
+
it "returns the item's options" do
|
|
35
|
+
expect(item_adapter.options).to be options
|
|
34
36
|
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe '#items' do
|
|
41
|
+
context 'when item responds to items' do
|
|
42
|
+
context 'when items is nil' do
|
|
43
|
+
before { allow(item).to receive_messages(items: nil) }
|
|
35
44
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(item_adapter.options).to eq({})
|
|
45
|
+
it 'returns nil' do
|
|
46
|
+
expect(item_adapter.items).to be_nil
|
|
39
47
|
end
|
|
40
48
|
end
|
|
41
|
-
end
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
before { allow(item).to receive_messages(items: nil) }
|
|
50
|
+
context 'when items is not nil' do
|
|
51
|
+
context 'when items is empty' do
|
|
52
|
+
before { allow(item).to receive_messages(items: []) }
|
|
47
53
|
|
|
48
54
|
it 'returns nil' do
|
|
49
55
|
expect(item_adapter.items).to be_nil
|
|
50
56
|
end
|
|
51
57
|
end
|
|
52
58
|
|
|
53
|
-
context 'when items is not
|
|
54
|
-
|
|
55
|
-
before { allow(item).to receive_messages(items: []) }
|
|
59
|
+
context 'when items is not empty' do
|
|
60
|
+
let(:items) { [true] }
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
expect(item_adapter.items).to be_nil
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
context 'and items is not empty' do
|
|
63
|
-
let(:items) { [true] }
|
|
64
|
-
|
|
65
|
-
before { allow(item).to receive_messages(items: items) }
|
|
62
|
+
before { allow(item).to receive_messages(items: items) }
|
|
66
63
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
end
|
|
64
|
+
it 'returns the items' do
|
|
65
|
+
expect(item_adapter.items).to eq items
|
|
70
66
|
end
|
|
71
67
|
end
|
|
72
68
|
end
|
|
73
|
-
|
|
74
|
-
context "when item doesn't respond to items" do
|
|
75
|
-
it 'returns nil' do
|
|
76
|
-
expect(item_adapter.items).to be_nil
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
69
|
end
|
|
70
|
+
end
|
|
80
71
|
|
|
81
|
-
|
|
82
|
-
|
|
72
|
+
describe '#to_simple_navigation_item' do
|
|
73
|
+
let(:container) { double(:container) }
|
|
83
74
|
|
|
84
|
-
|
|
75
|
+
before { allow(item).to receive_messages(items: [], options: {}) }
|
|
85
76
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
end
|
|
77
|
+
it 'creates an Item' do
|
|
78
|
+
expect(SimpleNavigation::Item).to receive(:new)
|
|
79
|
+
.with(container, 'key', 'name', 'url', {})
|
|
80
|
+
item_adapter.to_simple_navigation_item(container)
|
|
91
81
|
end
|
|
92
82
|
end
|
|
83
|
+
end
|
|
93
84
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
let(:item) { ModifiedHash[key: 'key', url: 'url', name: 'name'] }
|
|
85
|
+
context 'when item is a kind of hash' do
|
|
86
|
+
let(:item) { ModifiedHash[key: 'key', url: 'url', name: 'name'] }
|
|
98
87
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
end
|
|
88
|
+
shared_examples 'delegating to item' do |meth|
|
|
89
|
+
it "delegates #{meth} to item" do
|
|
90
|
+
expect(item_adapter.item).to receive(meth)
|
|
91
|
+
item_adapter.public_send(meth)
|
|
104
92
|
end
|
|
93
|
+
end
|
|
105
94
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
it_behaves_like 'delegating to item', :key
|
|
96
|
+
it_behaves_like 'delegating to item', :url
|
|
97
|
+
it_behaves_like 'delegating to item', :name
|
|
109
98
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
99
|
+
describe '#initialize' do
|
|
100
|
+
it 'sets the item' do
|
|
101
|
+
expect(item_adapter.item).not_to be_nil
|
|
102
|
+
end
|
|
114
103
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
end
|
|
104
|
+
it 'converts the item into an object' do
|
|
105
|
+
expect(item_adapter.item).to respond_to(:url)
|
|
118
106
|
end
|
|
107
|
+
end
|
|
119
108
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
describe '#options' do
|
|
110
|
+
context 'when item responds to options' do
|
|
111
|
+
before { item[:options] = { my: :options } }
|
|
123
112
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
end
|
|
113
|
+
it "returns the item's options" do
|
|
114
|
+
expect(item_adapter.options).to eq({ my: :options })
|
|
127
115
|
end
|
|
116
|
+
end
|
|
128
117
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
end
|
|
118
|
+
context 'when item does not respond to options' do
|
|
119
|
+
it 'returns an empty hash' do
|
|
120
|
+
expect(item_adapter.options).to eq({})
|
|
133
121
|
end
|
|
134
122
|
end
|
|
123
|
+
end
|
|
135
124
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
125
|
+
describe '#items' do
|
|
126
|
+
context 'when item responds to items' do
|
|
127
|
+
context 'when items is nil' do
|
|
128
|
+
before { item[:items] = nil }
|
|
140
129
|
|
|
130
|
+
it 'returns nil' do
|
|
131
|
+
expect(item_adapter.items).to be_nil
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context 'when items is not nil' do
|
|
136
|
+
context 'when items is empty' do
|
|
141
137
|
it 'returns nil' do
|
|
142
138
|
expect(item_adapter.items).to be_nil
|
|
143
139
|
end
|
|
144
140
|
end
|
|
145
141
|
|
|
146
|
-
context 'when items is not
|
|
147
|
-
|
|
148
|
-
it 'returns nil' do
|
|
149
|
-
expect(item_adapter.items).to be_nil
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
context 'and items is not empty' do
|
|
154
|
-
before { item[:items] = ['not', 'empty'] }
|
|
142
|
+
context 'when items is not empty' do
|
|
143
|
+
before { item[:items] = %w[not empty] }
|
|
155
144
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
end
|
|
145
|
+
it 'returns the items' do
|
|
146
|
+
expect(item_adapter.items).to eq %w[not empty]
|
|
159
147
|
end
|
|
160
148
|
end
|
|
161
149
|
end
|
|
150
|
+
end
|
|
162
151
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
end
|
|
152
|
+
context 'when item does not respond to items' do
|
|
153
|
+
it 'returns nil' do
|
|
154
|
+
expect(item_adapter.items).to be_nil
|
|
167
155
|
end
|
|
168
156
|
end
|
|
157
|
+
end
|
|
169
158
|
|
|
170
|
-
|
|
171
|
-
|
|
159
|
+
describe '#to_simple_navigation_item' do
|
|
160
|
+
let(:container) { double(:container) }
|
|
172
161
|
|
|
173
|
-
|
|
162
|
+
before { item.merge(options: {}) }
|
|
174
163
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
end
|
|
164
|
+
it 'passes the right arguments to Item' do
|
|
165
|
+
expect(SimpleNavigation::Item).to receive(:new).with(container, 'key', 'name', 'url', {})
|
|
166
|
+
item_adapter.to_simple_navigation_item(container)
|
|
167
|
+
end
|
|
180
168
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
end
|
|
169
|
+
it 'creates an Item' do
|
|
170
|
+
created_item = item_adapter.to_simple_navigation_item(container)
|
|
171
|
+
expect(created_item).to be_an(SimpleNavigation::Item)
|
|
185
172
|
end
|
|
186
173
|
end
|
|
187
174
|
end
|