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