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,94 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe SimpleNavigation::Renderer::List do
|
|
4
|
+
let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
|
|
5
|
+
|
|
6
|
+
let(:options) { { level: :all } }
|
|
7
|
+
let(:output) { renderer.render(navigation) }
|
|
8
|
+
let(:renderer) { described_class.new(options) }
|
|
9
|
+
|
|
10
|
+
describe '#render' do
|
|
11
|
+
it "renders an 'ul' tag for the navigation" do
|
|
12
|
+
expect(output).to have_css('ul')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "sets the right html id on the rendered 'ul' tag" do
|
|
16
|
+
expect(output).to have_css('ul#nav_id')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "sets the right html classes on the rendered 'ul' tag" do
|
|
20
|
+
expect(output).to have_css('ul.nav_class')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context 'when an item has no specified id' do
|
|
24
|
+
it "renders the item's 'li' tag with the item's stingified key as id" do
|
|
25
|
+
expect(output).to have_css('li#invoices')
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context 'when an item has a specified id' do
|
|
30
|
+
it "renders the item's 'li' tag with the specified id" do
|
|
31
|
+
expect(output).to have_css('li#users_id')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context 'when no item is selected' do
|
|
36
|
+
it "renders each item as 'li' tag without any selected class" do
|
|
37
|
+
expect(output).to have_no_css('ul li.selected')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "renders each item as 'a' tag without any selected class" do
|
|
41
|
+
expect(output).to have_no_css('ul li a.selected')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context 'when an item is selected' do
|
|
46
|
+
before do
|
|
47
|
+
allow(navigation[:invoices]).to \
|
|
48
|
+
receive_messages(selected?: true, selected_by_condition?: true)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "renders the item's 'li' tag with its id and selected classes" do
|
|
52
|
+
expect(output).to have_css('li#invoices.selected')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "renders the item's 'a' tag with the selected classes" do
|
|
56
|
+
expect(output).to have_css('li#invoices a.selected')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "renders the item's 'a' tag with with an 'aria-current' attribute" do
|
|
60
|
+
expect(output).to have_css('li#invoices a[aria-current=page]')
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context 'when the :ordered option is true' do
|
|
65
|
+
let(:options) { { level: :all, ordered: true } }
|
|
66
|
+
|
|
67
|
+
it "renders an 'ol' tag for the navigation" do
|
|
68
|
+
expect(output).to have_css('ol')
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "sets the right html id on the rendered 'ol' tag" do
|
|
72
|
+
expect(output).to have_css('ol#nav_id')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "sets the right html classes on the rendered 'ol' tag" do
|
|
76
|
+
expect(output).to have_css('ol.nav_class')
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
context 'when a sub navigation item is selected' do
|
|
81
|
+
before do
|
|
82
|
+
allow(navigation[:invoices]).to receive_messages(selected?: true)
|
|
83
|
+
|
|
84
|
+
allow(navigation[:invoices].sub_navigation[:unpaid]).to \
|
|
85
|
+
receive_messages(selected?: true, selected_by_condition?: true)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'renders the parent items as selected' do
|
|
89
|
+
expect(output).to have_css('li#invoices.selected')
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "renders the selected nested item's link as selected" do
|
|
93
|
+
expect(output).to have_css('li#unpaid.selected')
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "renders the selected nested item's 'a' tag with with an 'aria-current' attribute" do
|
|
97
|
+
expect(output).to have_css('li#unpaid a[aria-current=page]')
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "does not 'aria-current' to the parent item's link" do
|
|
101
|
+
expect(output).to have_no_css('li#invoices > a[aria-current=page]')
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context 'when skip_if_empty is true and container is empty' do
|
|
106
|
+
let(:empty_navigation) { SimpleNavigation::ItemContainer.new(1) }
|
|
107
|
+
let(:options) { { skip_if_empty: true } }
|
|
108
|
+
let(:output) { renderer.render(empty_navigation) }
|
|
109
|
+
|
|
110
|
+
it 'returns an empty string' do
|
|
111
|
+
expect(output).to eq ''
|
|
92
112
|
end
|
|
93
113
|
end
|
|
94
114
|
end
|
|
@@ -1,49 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
module Renderer
|
|
3
|
-
describe Text do
|
|
4
|
-
let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
|
|
5
|
-
|
|
6
|
-
let(:item) { nil }
|
|
7
|
-
let(:options) {{ level: :all }}
|
|
8
|
-
let(:output) { renderer.render(navigation) }
|
|
9
|
-
let(:renderer) { Text.new(options) }
|
|
10
|
-
|
|
11
|
-
before { select_an_item(navigation[item]) if item }
|
|
12
|
-
|
|
13
|
-
describe '#render' do
|
|
14
|
-
context 'when no item is selected' do
|
|
15
|
-
it 'renders an empty string' do
|
|
16
|
-
expect(output).to eq ''
|
|
17
|
-
end
|
|
18
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
RSpec.describe SimpleNavigation::Renderer::Text do
|
|
4
|
+
let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
|
|
22
5
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
let(:item) { nil }
|
|
7
|
+
let(:options) { { level: :all } }
|
|
8
|
+
let(:output) { renderer.render(navigation) }
|
|
9
|
+
let(:renderer) { described_class.new(options) }
|
|
10
|
+
|
|
11
|
+
before { select_an_item(navigation[item]) if item }
|
|
12
|
+
|
|
13
|
+
describe '#render' do
|
|
14
|
+
context 'when no item is selected' do
|
|
15
|
+
it 'renders an empty string' do
|
|
16
|
+
expect(output).to eq ''
|
|
17
|
+
end
|
|
18
|
+
end
|
|
27
19
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
allow(navigation[:invoices]).to receive_messages(selected?: true)
|
|
20
|
+
context 'when an item is selected' do
|
|
21
|
+
let(:item) { :invoices }
|
|
31
22
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
it "renders the selected item's name" do
|
|
24
|
+
expect(output).to eq 'Invoices'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context 'when a sub navigation item is selected' do
|
|
29
|
+
before do
|
|
30
|
+
allow(navigation[:invoices]).to receive_messages(selected?: true)
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
allow(navigation[:invoices].sub_navigation[:unpaid]).to \
|
|
33
|
+
receive_messages(selected?: true, selected_by_condition?: true)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'separates the items with a space' do
|
|
37
|
+
expect(output).to eq 'Invoices Unpaid'
|
|
38
|
+
end
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
context 'when the :join_with option is set' do
|
|
41
|
+
let(:options) { { level: :all, join_with: ' | ' } }
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
end
|
|
43
|
+
it 'separates the items with the specified separator' do
|
|
44
|
+
expect(output).to eq 'Invoices | Unpaid'
|
|
47
45
|
end
|
|
48
46
|
end
|
|
49
47
|
end
|
|
@@ -1,64 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe SimpleNavigation do
|
|
4
|
+
subject(:simple_navigation) { described_class }
|
|
5
|
+
|
|
6
|
+
before { simple_navigation.config_file_path = 'path_to_config' }
|
|
3
7
|
|
|
4
8
|
describe 'config_file_path=' do
|
|
5
|
-
before {
|
|
9
|
+
before { simple_navigation.config_file_paths = ['existing_path'] }
|
|
6
10
|
|
|
7
11
|
it 'overrides the config_file_paths' do
|
|
8
|
-
|
|
9
|
-
expect(
|
|
12
|
+
simple_navigation.config_file_path = 'new_path'
|
|
13
|
+
expect(simple_navigation.config_file_paths).to eq ['new_path']
|
|
10
14
|
end
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
describe '.default_config_file_path' do
|
|
14
|
-
before { allow(
|
|
18
|
+
before { allow(simple_navigation).to receive_messages(root: 'root') }
|
|
15
19
|
|
|
16
20
|
it 'returns the config file path according to :root setting' do
|
|
17
|
-
expect(
|
|
21
|
+
expect(simple_navigation.default_config_file_path).to eq 'root/config'
|
|
18
22
|
end
|
|
19
23
|
end
|
|
20
24
|
|
|
21
25
|
describe 'Regarding renderers' do
|
|
22
26
|
it 'registers the builtin renderers by default' do
|
|
23
|
-
expect(
|
|
27
|
+
expect(simple_navigation.registered_renderers).not_to be_empty
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
describe '.register_renderer' do
|
|
27
31
|
let(:renderer) { double(:renderer) }
|
|
28
32
|
|
|
29
33
|
it 'adds the specified renderer to the list of renderers' do
|
|
30
|
-
|
|
31
|
-
expect(
|
|
34
|
+
simple_navigation.register_renderer(my_renderer: renderer)
|
|
35
|
+
expect(simple_navigation.registered_renderers[:my_renderer]).to be renderer
|
|
32
36
|
end
|
|
33
37
|
end
|
|
34
38
|
end
|
|
35
39
|
|
|
36
40
|
describe '.set_env' do
|
|
37
41
|
before do
|
|
38
|
-
|
|
39
|
-
allow(
|
|
40
|
-
|
|
42
|
+
simple_navigation.config_file_paths = []
|
|
43
|
+
allow(simple_navigation).to receive_messages(default_config_file_path: 'default_path')
|
|
44
|
+
simple_navigation.set_env('root', 'my_env')
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
it 'sets the root' do
|
|
44
|
-
expect(
|
|
48
|
+
expect(simple_navigation.root).to eq 'root'
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
it 'sets the environment' do
|
|
48
|
-
expect(
|
|
52
|
+
expect(simple_navigation.environment).to eq 'my_env'
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
it 'adds the default-config path to the list of config_file_paths' do
|
|
52
|
-
expect(
|
|
56
|
+
expect(simple_navigation.config_file_paths).to eq ['default_path']
|
|
53
57
|
end
|
|
54
58
|
end
|
|
55
59
|
|
|
56
|
-
describe '.load_config', memfs
|
|
60
|
+
describe '.load_config', :memfs do
|
|
57
61
|
let(:paths) { ['/path/one', '/path/two'] }
|
|
58
62
|
|
|
59
63
|
before do
|
|
60
64
|
FileUtils.mkdir_p(paths)
|
|
61
|
-
allow(
|
|
65
|
+
allow(simple_navigation).to receive_messages(config_file_paths: paths)
|
|
62
66
|
end
|
|
63
67
|
|
|
64
68
|
context 'when the config file for the context exists' do
|
|
@@ -69,60 +73,62 @@ describe SimpleNavigation do
|
|
|
69
73
|
|
|
70
74
|
context 'when no context is provided' do
|
|
71
75
|
it 'stores the configuration in config_files for the default context' do
|
|
72
|
-
|
|
73
|
-
expect(
|
|
76
|
+
simple_navigation.load_config
|
|
77
|
+
expect(simple_navigation.config_files[:default]).to eq "default content\n"
|
|
74
78
|
end
|
|
75
79
|
end
|
|
76
80
|
|
|
77
81
|
context 'when a context is provided' do
|
|
78
82
|
it 'stores the configuration in config_files for the given context' do
|
|
79
|
-
|
|
80
|
-
expect(
|
|
83
|
+
simple_navigation.load_config(:other)
|
|
84
|
+
expect(simple_navigation.config_files[:other]).to eq "other content\n"
|
|
81
85
|
end
|
|
82
86
|
end
|
|
83
87
|
|
|
84
|
-
context '
|
|
85
|
-
before { allow(
|
|
88
|
+
context 'when environment is production' do
|
|
89
|
+
before { allow(simple_navigation).to receive_messages(environment: 'production') }
|
|
86
90
|
|
|
87
91
|
it 'loads the config file only for the first call' do
|
|
88
|
-
|
|
92
|
+
simple_navigation.load_config
|
|
89
93
|
File.open('/path/two/navigation.rb', 'w') { |f| f.puts 'new content' }
|
|
90
|
-
|
|
91
|
-
expect(
|
|
94
|
+
simple_navigation.load_config
|
|
95
|
+
expect(simple_navigation.config_files[:default]).to eq "default content\n"
|
|
92
96
|
end
|
|
93
97
|
end
|
|
94
98
|
|
|
95
|
-
context "
|
|
99
|
+
context "when environment isn't production" do
|
|
96
100
|
it 'loads the config file for every call' do
|
|
97
|
-
|
|
101
|
+
simple_navigation.load_config
|
|
98
102
|
File.open('/path/two/navigation.rb', 'w') { |f| f.puts 'new content' }
|
|
99
|
-
|
|
100
|
-
expect(
|
|
103
|
+
simple_navigation.load_config
|
|
104
|
+
expect(simple_navigation.config_files[:default]).to eq "new content\n"
|
|
101
105
|
end
|
|
102
106
|
end
|
|
103
107
|
end
|
|
104
108
|
|
|
105
109
|
context "when the config file for the context doesn't exists" do
|
|
106
110
|
it 'raises an exception' do
|
|
107
|
-
expect
|
|
111
|
+
expect do
|
|
112
|
+
simple_navigation.load_config
|
|
113
|
+
end.to raise_error(RuntimeError, /Config file 'navigation.rb' not found in path\(s\)/)
|
|
108
114
|
end
|
|
109
115
|
end
|
|
110
116
|
end
|
|
111
117
|
|
|
112
118
|
describe '.config' do
|
|
113
119
|
it 'returns the Configuration singleton instance' do
|
|
114
|
-
expect(
|
|
120
|
+
expect(simple_navigation.config).to be SimpleNavigation::Configuration.instance
|
|
115
121
|
end
|
|
116
122
|
end
|
|
117
123
|
|
|
118
124
|
describe '.active_item_container_for' do
|
|
119
125
|
let(:primary) { double(:primary) }
|
|
120
126
|
|
|
121
|
-
before { allow(
|
|
127
|
+
before { allow(simple_navigation.config).to receive_messages(primary_navigation: primary) }
|
|
122
128
|
|
|
123
129
|
context 'when level is :all' do
|
|
124
130
|
it 'returns the primary_navigation' do
|
|
125
|
-
nav =
|
|
131
|
+
nav = simple_navigation.active_item_container_for(:all)
|
|
126
132
|
expect(nav).to be primary
|
|
127
133
|
end
|
|
128
134
|
end
|
|
@@ -130,29 +136,29 @@ describe SimpleNavigation do
|
|
|
130
136
|
context 'when level is :leaves' do
|
|
131
137
|
it 'returns the currently active leaf-container' do
|
|
132
138
|
expect(primary).to receive(:active_leaf_container)
|
|
133
|
-
|
|
139
|
+
simple_navigation.active_item_container_for(:leaves)
|
|
134
140
|
end
|
|
135
141
|
end
|
|
136
142
|
|
|
137
143
|
context 'when level is a Range' do
|
|
138
144
|
it 'takes the min of the range to lookup the active container' do
|
|
139
145
|
expect(primary).to receive(:active_item_container_for).with(2)
|
|
140
|
-
|
|
146
|
+
simple_navigation.active_item_container_for(2..3)
|
|
141
147
|
end
|
|
142
148
|
end
|
|
143
149
|
|
|
144
150
|
context 'when level is an Integer' do
|
|
145
151
|
it 'considers the Integer to lookup the active container' do
|
|
146
152
|
expect(primary).to receive(:active_item_container_for).with(1)
|
|
147
|
-
|
|
153
|
+
simple_navigation.active_item_container_for(1)
|
|
148
154
|
end
|
|
149
155
|
end
|
|
150
156
|
|
|
151
157
|
context 'when level is something else' do
|
|
152
158
|
it 'raises an exception' do
|
|
153
|
-
expect
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
expect do
|
|
160
|
+
simple_navigation.active_item_container_for('something else')
|
|
161
|
+
end.to raise_error(ArgumentError, 'Invalid navigation level: something else')
|
|
156
162
|
end
|
|
157
163
|
end
|
|
158
164
|
end
|
|
@@ -161,13 +167,13 @@ describe SimpleNavigation do
|
|
|
161
167
|
shared_examples 'loading the right adapter' do |framework, adapter|
|
|
162
168
|
context "when the context is #{framework}" do
|
|
163
169
|
before do
|
|
164
|
-
allow(
|
|
165
|
-
|
|
170
|
+
allow(simple_navigation).to receive_messages(framework: framework)
|
|
171
|
+
simple_navigation.load_adapter
|
|
166
172
|
end
|
|
167
173
|
|
|
168
174
|
it "returns the #{framework} adapter" do
|
|
169
175
|
adapter_class = SimpleNavigation::Adapters.const_get(adapter)
|
|
170
|
-
expect(
|
|
176
|
+
expect(simple_navigation.adapter_class).to be adapter_class
|
|
171
177
|
end
|
|
172
178
|
end
|
|
173
179
|
end
|
|
@@ -175,6 +181,7 @@ describe SimpleNavigation do
|
|
|
175
181
|
it_behaves_like 'loading the right adapter', :rails, :Rails
|
|
176
182
|
it_behaves_like 'loading the right adapter', :padrino, :Padrino
|
|
177
183
|
it_behaves_like 'loading the right adapter', :sinatra, :Sinatra
|
|
184
|
+
it_behaves_like 'loading the right adapter', :nanoc, :Nanoc
|
|
178
185
|
end
|
|
179
186
|
|
|
180
187
|
describe '.init_adapter_from' do
|
|
@@ -182,9 +189,9 @@ describe SimpleNavigation do
|
|
|
182
189
|
let(:adapter_class) { double(:adapter_class, new: adapter) }
|
|
183
190
|
|
|
184
191
|
it 'sets the adapter to a new instance of adapter_class' do
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
expect(
|
|
192
|
+
simple_navigation.adapter_class = adapter_class
|
|
193
|
+
simple_navigation.init_adapter_from(:default)
|
|
194
|
+
expect(simple_navigation.adapter).to be adapter
|
|
188
195
|
end
|
|
189
196
|
end
|
|
190
197
|
end
|