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,4 +1,4 @@
1
- require 'forwardable'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module SimpleNavigation
4
4
  module Renderer
@@ -13,7 +13,7 @@ module SimpleNavigation
13
13
 
14
14
  def_delegators :adapter, :link_to, :content_tag
15
15
 
16
- def initialize(options) #:nodoc:
16
+ def initialize(options) # :nodoc:
17
17
  @options = options
18
18
  @adapter = SimpleNavigation.adapter
19
19
  end
@@ -44,7 +44,7 @@ module SimpleNavigation
44
44
  # include_sub_navigation? to determine whether an item's sub_navigation
45
45
  # should be rendered or not.
46
46
  def render(item_container)
47
- fail NotImplementedError, 'subclass responsibility'
47
+ raise NotImplementedError, 'subclass responsibility'
48
48
  end
49
49
 
50
50
  protected
@@ -89,11 +89,11 @@ module SimpleNavigation
89
89
  end
90
90
 
91
91
  # Extracts the options relevant for the generated link
92
- def link_options_for(item)
92
+ def link_options_for(item) # rubocop:disable Metrics/MethodLength
93
93
  special_options = {
94
94
  method: item.method,
95
95
  class: item.selected_class
96
- }.reject { |_, v| v.nil? }
96
+ }.compact
97
97
 
98
98
  link_options = item.link_html_options
99
99
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleNavigation
2
4
  module Renderer
3
5
  # Renders an ItemContainer as a <div> element and its containing items as
@@ -25,11 +27,10 @@ module SimpleNavigation
25
27
  def a_tags(item_container)
26
28
  item_container.items.each_with_object([]) do |item, list|
27
29
  next unless item.selected?
30
+
28
31
  list << tag_for(item)
29
32
 
30
- if include_sub_navigation?(item)
31
- list.concat a_tags(item.sub_navigation)
32
- end
33
+ list.concat a_tags(item.sub_navigation) if include_sub_navigation?(item)
33
34
  end
34
35
  end
35
36
 
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module SimpleNavigation
4
4
  module Renderer
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleNavigation
2
4
  module Renderer
3
5
  # Renders an ItemContainer as a <div> element and its containing items as
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleNavigation
2
4
  module Renderer
3
5
  # Renders an ItemContainer as a <ul> element and its containing items as
@@ -28,14 +30,12 @@ module SimpleNavigation
28
30
  private
29
31
 
30
32
  def list_content(item_container)
31
- item_container.items.map { |item|
33
+ item_container.items.map do |item|
32
34
  li_options = item.html_options.except(:link)
33
35
  li_content = tag_for(item)
34
- if include_sub_navigation?(item)
35
- li_content << render_sub_navigation_for(item)
36
- end
36
+ li_content << render_sub_navigation_for(item) if include_sub_navigation?(item)
37
37
  content_tag(:li, li_content, li_options)
38
- }.join
38
+ end.join
39
39
  end
40
40
  end
41
41
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleNavigation
2
4
  module Renderer
3
5
  # Renders the 'chain' of selected navigation items as simple text items,
@@ -13,7 +15,7 @@ module SimpleNavigation
13
15
  def list(item_container)
14
16
  item_container.items.keep_if(&:selected?).map do |item|
15
17
  [item.name(apply_generator: false)] +
16
- (include_sub_navigation?(item) ? list(item.sub_navigation) : [])
18
+ (include_sub_navigation?(item) ? list(item.sub_navigation) : [])
17
19
  end
18
20
  end
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleNavigation
2
- VERSION = '4.4.1'
4
+ VERSION = '4.5.0'
3
5
  end
@@ -1,24 +1,30 @@
1
- # cherry picking active_support stuff
1
+ # frozen_string_literal: true
2
+
3
+ # require ruby dependencies
4
+ require 'cgi/escape'
5
+ require 'forwardable'
6
+ require 'json'
7
+ require 'singleton'
8
+
9
+ # require external dependencies
2
10
  require 'active_support/core_ext/array'
3
11
  require 'active_support/core_ext/hash'
12
+ require 'active_support/core_ext/string'
4
13
  require 'active_support/core_ext/module/attribute_accessors'
14
+ require 'zeitwerk'
5
15
 
6
- require 'simple_navigation/version'
7
- require 'simple_navigation/configuration'
8
- require 'simple_navigation/item_adapter'
9
- require 'simple_navigation/item'
10
- require 'simple_navigation/item_container'
11
- require 'simple_navigation/items_provider'
12
- require 'simple_navigation/renderer'
13
- require 'simple_navigation/adapters'
14
- require 'simple_navigation/config_file_finder'
15
- require 'simple_navigation/railtie' if defined?(::Rails::Railtie)
16
-
17
- require 'forwardable'
16
+ # load zeitwerk
17
+ Zeitwerk::Loader.for_gem.tap do |loader|
18
+ loader.ignore("#{__dir__}/generators")
19
+ loader.ignore("#{__dir__}/simple-navigation.rb")
20
+ loader.setup
21
+ end
18
22
 
19
23
  # A plugin for generating a simple navigation. See README for resources on
20
24
  # usage instructions.
21
25
  module SimpleNavigation
26
+ require_relative 'simple_navigation/railtie' if defined?(Rails::Railtie)
27
+
22
28
  mattr_accessor :adapter,
23
29
  :adapter_class,
24
30
  :config_files,
@@ -38,21 +44,21 @@ module SimpleNavigation
38
44
  # Maps renderer keys to classes. The keys serve as shortcut in the
39
45
  # render_navigation calls (renderer: :list)
40
46
  self.registered_renderers = {
41
- list: SimpleNavigation::Renderer::List,
42
- links: SimpleNavigation::Renderer::Links,
47
+ list: SimpleNavigation::Renderer::List,
48
+ links: SimpleNavigation::Renderer::Links,
43
49
  breadcrumbs: SimpleNavigation::Renderer::Breadcrumbs,
44
- text: SimpleNavigation::Renderer::Text,
45
- json: SimpleNavigation::Renderer::Json
50
+ text: SimpleNavigation::Renderer::Text,
51
+ json: SimpleNavigation::Renderer::Json
46
52
  }
47
53
 
48
54
  class << self
49
55
  extend Forwardable
50
56
 
51
57
  def_delegators :adapter, :context_for_eval,
52
- :current_page?,
53
- :request,
54
- :request_path,
55
- :request_uri
58
+ :current_page?,
59
+ :request,
60
+ :request_path,
61
+ :request_uri
56
62
 
57
63
  def_delegators :adapter_class, :register
58
64
 
@@ -67,11 +73,13 @@ module SimpleNavigation
67
73
  # Returns the current framework in which the plugin is running.
68
74
  def framework
69
75
  return :rails if defined?(Rails)
76
+ # :nocov:
70
77
  return :padrino if defined?(Padrino)
71
78
  return :sinatra if defined?(Sinatra)
72
79
  return :nanoc if defined?(Nanoc3)
73
- fail 'simple_navigation currently only works for Rails, Sinatra and ' \
74
- 'Padrino apps'
80
+
81
+ raise 'simple_navigation currently only works for Rails, Sinatra and Padrino apps'
82
+ # :nocov:
75
83
  end
76
84
 
77
85
  # Loads the adapter for the current framework
@@ -138,7 +146,7 @@ module SimpleNavigation
138
146
  when Integer then primary_navigation.active_item_container_for(level)
139
147
  when Range then primary_navigation.active_item_container_for(level.min)
140
148
  else
141
- fail ArgumentError, "Invalid navigation level: #{level}"
149
+ raise ArgumentError, "Invalid navigation level: #{level}"
142
150
  end
143
151
  end
144
152
 
@@ -1,42 +1,31 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'simple_navigation/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/simple_navigation/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = 'simple-navigation'
8
7
  spec.version = SimpleNavigation::VERSION
9
8
  spec.authors = ['Andi Schacke', 'Mark J. Titorenko', 'Simon Courtois']
10
9
  spec.email = ['andi@codeplant.ch']
11
- spec.description = "With the simple-navigation gem installed you can easily " \
12
- "create multilevel navigations for your Rails, Sinatra or "\
13
- "Padrino applications. The navigation is defined in a " \
14
- "single configuration file. It supports automatic as well "\
15
- "as explicit highlighting of the currently active " \
16
- "navigation through regular expressions."
17
- spec.summary = "simple-navigation is a ruby library for creating navigations "\
18
- "(with multiple levels) for your Rails, Sinatra or " \
19
- "Padrino application."
10
+ spec.description = 'With the simple-navigation gem installed you can easily ' \
11
+ 'create multilevel navigations for your Rails, Sinatra or ' \
12
+ 'Padrino applications. The navigation is defined in a ' \
13
+ 'single configuration file. It supports automatic as well ' \
14
+ 'as explicit highlighting of the currently active ' \
15
+ 'navigation through regular expressions.'
16
+ spec.summary = 'simple-navigation is a ruby library for creating navigations ' \
17
+ '(with multiple levels) for your Rails, Sinatra or ' \
18
+ 'Padrino application.'
20
19
  spec.homepage = 'http://github.com/codeplant/simple-navigation'
21
20
  spec.license = 'MIT'
22
21
 
23
22
  spec.files = `git ls-files -z`.split("\x0")
24
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
- spec.require_paths = ['lib']
27
23
 
28
24
  spec.rdoc_options = ['--inline-source', '--charset=UTF-8']
29
25
 
30
- spec.add_runtime_dependency 'activesupport', '>= 2.3.2'
31
- spec.add_runtime_dependency 'ostruct'
26
+ spec.required_ruby_version = '>= 3.0.0'
32
27
 
33
- spec.add_development_dependency 'bundler'
34
- spec.add_development_dependency 'capybara'
35
- spec.add_development_dependency 'coveralls', '~> 0.7'
36
- spec.add_development_dependency 'guard-rspec', '~> 4.2'
37
- spec.add_development_dependency 'memfs', '~> 0.4.1'
38
- spec.add_development_dependency 'rake'
39
- spec.add_development_dependency 'rdoc'
40
- spec.add_development_dependency 'rspec', '~> 3.0'
41
- spec.add_development_dependency 'tzinfo', '>= 0'
28
+ spec.add_dependency 'activesupport', '>= 6.1.0'
29
+ spec.add_dependency 'json'
30
+ spec.add_dependency 'zeitwerk'
42
31
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  SimpleNavigation::Configuration.run do |navigation|
2
4
  navigation.items do |nav|
3
- nav.item :item_1, 'Item 1', '/item_1', html: {class: 'item_1'}, link_html: {id: 'link_1'}
4
- nav.item :item_2, 'Item 2', '/item_2', html: {class: 'item_2'}, link_html: {id: 'link_2'}
5
+ nav.item :item1, 'Item 1', '/item_1', html: { class: 'item_1' }, link_html: { id: 'link_1' }
6
+ nav.item :item2, 'Item 2', '/item_2', html: { class: 'item_2' }, link_html: { id: 'link_2' }
5
7
  end
6
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ENV['RAILS_ENV'] ||= 'test'
2
4
 
3
5
  require 'action_controller/railtie'
@@ -9,20 +11,20 @@ module RailsApp
9
11
  config.cache_classes = true
10
12
  config.eager_load = false
11
13
  config.root = __dir__
12
- config.secret_token = 'x'*100
14
+ config.secret_token = 'x' * 100
13
15
  config.session_store :cookie_store, key: '_myapp_session'
14
16
  end
15
17
 
16
18
  class TestsController < ActionController::Base
17
19
  def base
18
- render inline: <<-END
20
+ render inline: <<-HTML
19
21
  <!DOCTYPE html>
20
22
  <html>
21
23
  <body>
22
24
  <%= render_navigation %>
23
25
  </body>
24
26
  </html>
25
- END
27
+ HTML
26
28
  end
27
29
  end
28
30
  end
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.feature 'Rendering navigation' do
2
4
  background do
3
5
  SimpleNavigation.set_env(RailsApp::Application.root, 'test')
4
6
  end
5
7
 
6
- scenario 'Rendering basic navigation', type: :feature do
8
+ scenario 'Rendering basic navigation', type: :feature do # rubocop:disable RSpec/MultipleExpectations
7
9
  visit '/base_spec'
8
10
 
9
- expect(page).to have_content('Item 1')
10
- expect(page).to have_content('Item 2')
11
- expect(page).to have_selector('li.item_1 a#link_1')
12
- expect(page).to have_selector('li.item_2 a#link_2')
11
+ expect(page).to have_text('Item 1')
12
+ expect(page).to have_text('Item 2')
13
+ expect(page).to have_css('li.item_1 a#link_1')
14
+ expect(page).to have_css('li.item_2 a#link_2')
13
15
  end
14
16
  end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ # NOTE: This adapter is deprecated. It supports Nanoc3 (circa 2011-2012) which is obsolete.
4
+ # These tests are maintained for backward compatibility only.
5
+ RSpec.describe SimpleNavigation::Adapters::Nanoc do
6
+ let(:adapter) { described_class.new(context) }
7
+ let(:context) { double(:context, item: item) }
8
+ let(:item) { double(:item, path: '/test/path/') }
9
+
10
+ describe '.register' do
11
+ let(:nanoc_context) { double(:nanoc_context) }
12
+
13
+ before do
14
+ stub_const('Nanoc3::Context', nanoc_context)
15
+ allow(SimpleNavigation).to receive(:set_env)
16
+ allow(nanoc_context).to receive(:include)
17
+ end
18
+
19
+ it 'calls SimpleNavigation.set_env with root and development environment' do
20
+ expect(SimpleNavigation).to receive(:set_env).with('/root/path', 'development')
21
+ described_class.register('/root/path')
22
+ end
23
+
24
+ it 'includes SimpleNavigation::Helpers in Nanoc3::Context' do
25
+ expect(nanoc_context).to receive(:include).with(SimpleNavigation::Helpers)
26
+ described_class.register('/root/path')
27
+ end
28
+ end
29
+
30
+ describe '#initialize' do
31
+ it 'sets the context' do
32
+ expect(adapter.instance_variable_get(:@context)).to eq context
33
+ end
34
+ end
35
+
36
+ describe '#context_for_eval' do
37
+ it 'returns the context' do
38
+ expect(adapter.context_for_eval).to eq context
39
+ end
40
+ end
41
+
42
+ describe '#current_page?' do
43
+ context 'when the path matches the url (after chomping the trailing slash)' do
44
+ it 'returns true' do
45
+ expect(adapter.current_page?('/test/path')).to be true
46
+ end
47
+ end
48
+
49
+ context 'when the path does not match the url' do
50
+ it 'returns false' do
51
+ expect(adapter.current_page?('/other/path')).to be false
52
+ end
53
+ end
54
+
55
+ context 'when path is nil' do
56
+ let(:item) { double(:item, path: nil) }
57
+
58
+ it 'returns nil' do
59
+ expect(adapter.current_page?('/test/path')).to be_nil
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '#link_to' do
65
+ it 'returns a link with the correct attributes' do
66
+ link = adapter.link_to('Test Link', '/url', class: 'nav-link', id: 'link1')
67
+ expect(link).to eq "<a href='/url' class='nav-link' id='link1'>Test Link</a>"
68
+ end
69
+
70
+ it 'handles options without values' do
71
+ link = adapter.link_to('Test', '/url', {})
72
+ expect(link).to eq "<a href='/url' >Test</a>"
73
+ end
74
+
75
+ it 'filters out nil values' do
76
+ link = adapter.link_to('Test', '/url', class: 'nav', id: nil)
77
+ expect(link).to eq "<a href='/url' class='nav'>Test</a>"
78
+ end
79
+ end
80
+
81
+ describe '#content_tag' do
82
+ it 'returns a tag with the correct type, content and attributes' do
83
+ tag = adapter.content_tag(:div, 'Content', class: 'container', id: 'main')
84
+ expect(tag).to eq "<div class='container' id='main'>Content</div>"
85
+ end
86
+
87
+ it 'handles tags without attributes' do
88
+ tag = adapter.content_tag(:span, 'Text', {})
89
+ expect(tag).to eq '<span >Text</span>'
90
+ end
91
+
92
+ it 'filters out nil values from attributes' do
93
+ tag = adapter.content_tag(:p, 'Paragraph', class: 'text', id: nil)
94
+ expect(tag).to eq "<p class='text'>Paragraph</p>"
95
+ end
96
+ end
97
+ end
@@ -1,27 +1,46 @@
1
- module SimpleNavigation
2
- module Adapters
3
- describe Padrino do
4
- let(:adapter) { SimpleNavigation::Adapters::Padrino.new(context) }
5
- let(:content) { double(:content) }
6
- let(:context) { double(:context, request: request) }
7
- let(:request) { double(:request) }
1
+ # frozen_string_literal: true
8
2
 
9
- describe '#link_to' do
10
- it 'delegates to context' do
11
- expect(context).to receive(:link_to)
12
- .with('name', 'url', :my_option => true)
13
- adapter.link_to('name', 'url', :my_option => true)
14
- end
15
- end
3
+ RSpec.describe SimpleNavigation::Adapters::Padrino do
4
+ let(:adapter) { described_class.new(context) }
5
+ let(:content) { double(:content) }
6
+ let(:context) { double(:context, request: request) }
7
+ let(:request) { double(:request) }
16
8
 
17
- describe '#content_tag' do
18
- it 'delegates to context' do
19
- expect(content).to receive(:html_safe).and_return('content')
20
- expect(context).to receive(:content_tag)
21
- .with('type', 'content', my_option: true)
22
- adapter.content_tag('type', content, my_option: true)
23
- end
24
- end
9
+ describe '.register' do
10
+ let(:padrino_module) { Module.new }
11
+ let(:padrino_application) { Module.new }
12
+
13
+ before do
14
+ stub_const('Padrino', padrino_module)
15
+ stub_const('Padrino::Application', padrino_application)
16
+ allow(padrino_module).to receive_messages(root: '/padrino/root', env: 'production')
17
+ allow(SimpleNavigation).to receive(:set_env)
18
+ allow(padrino_application).to receive(:send)
19
+ end
20
+
21
+ it 'calls SimpleNavigation.set_env with Padrino root and env' do
22
+ expect(SimpleNavigation).to receive(:set_env).with('/padrino/root', 'production')
23
+ described_class.register(nil)
24
+ end
25
+
26
+ it 'includes SimpleNavigation::Helpers in Padrino::Application' do
27
+ expect(padrino_application).to receive(:send).with(:helpers, SimpleNavigation::Helpers)
28
+ described_class.register(nil)
29
+ end
30
+ end
31
+
32
+ describe '#link_to' do
33
+ it 'delegates to context' do
34
+ expect(context).to receive(:link_to).with('name', 'url', { my_option: true })
35
+ adapter.link_to('name', 'url', my_option: true)
36
+ end
37
+ end
38
+
39
+ describe '#content_tag' do
40
+ it 'delegates to context' do # rubocop:disable RSpec/MultipleExpectations
41
+ expect(content).to receive(:html_safe).and_return('content') # rubocop:disable RSpec/StubbedMock
42
+ expect(context).to receive(:content_tag).with('type', 'content', { my_option: true })
43
+ adapter.content_tag('type', content, my_option: true)
25
44
  end
26
45
  end
27
46
  end