simple-navigation 3.14.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/.travis.yml +10 -2
- data/CHANGELOG.md +400 -0
- data/Guardfile +4 -2
- data/README.md +1 -1
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails-3-2-stable.gemfile +10 -0
- data/gemfiles/rails-4-1-stable.gemfile +6 -0
- data/gemfiles/rails-4-2-stable.gemfile +7 -0
- data/generators/navigation_config/navigation_config_generator.rb +0 -1
- data/generators/navigation_config/templates/config/navigation.rb +18 -15
- data/lib/simple_navigation.rb +25 -42
- data/lib/simple_navigation/adapters/rails.rb +1 -24
- data/lib/simple_navigation/adapters/sinatra.rb +2 -11
- data/lib/simple_navigation/config_file.rb +36 -0
- data/lib/simple_navigation/config_file_finder.rb +42 -0
- data/lib/simple_navigation/{core/configuration.rb → configuration.rb} +7 -1
- data/lib/simple_navigation/{rendering/helpers.rb → helpers.rb} +0 -4
- data/lib/simple_navigation/{core/item.rb → item.rb} +76 -85
- data/lib/simple_navigation/{core/item_adapter.rb → item_adapter.rb} +3 -17
- data/lib/simple_navigation/{core/item_container.rb → item_container.rb} +23 -14
- data/lib/simple_navigation/{core/items_provider.rb → items_provider.rb} +0 -0
- data/lib/simple_navigation/railtie.rb +7 -0
- data/lib/simple_navigation/renderer.rb +12 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/base.rb +1 -1
- data/lib/simple_navigation/{rendering/renderer → renderer}/breadcrumbs.rb +0 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/json.rb +2 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/links.rb +0 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/list.rb +0 -0
- data/lib/simple_navigation/{rendering/renderer → renderer}/text.rb +0 -0
- data/lib/simple_navigation/version.rb +1 -1
- data/simple-navigation.gemspec +5 -4
- data/spec/fake_app/config/navigation.rb +6 -0
- data/spec/fake_app/rails_app.rb +35 -0
- data/spec/initializers/coveralls.rb +3 -0
- data/spec/initializers/have_css_matcher.rb +8 -3
- data/spec/initializers/memfs.rb +7 -0
- data/spec/initializers/rails.rb +4 -0
- data/spec/initializers/rspec.rb +7 -0
- data/spec/integration/rendering_navigation_spec.rb +12 -0
- data/spec/{lib/simple_navigation → simple_navigation}/adapters/padrino_spec.rb +0 -2
- data/spec/{lib/simple_navigation → simple_navigation}/adapters/rails_spec.rb +36 -93
- data/spec/{lib/simple_navigation → simple_navigation}/adapters/sinatra_spec.rb +4 -6
- data/spec/simple_navigation/config_file_finder_spec.rb +50 -0
- data/spec/simple_navigation/config_file_spec.rb +25 -0
- data/spec/{lib/simple_navigation/core → simple_navigation}/configuration_spec.rb +29 -19
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/helpers_spec.rb +10 -13
- data/spec/{lib/simple_navigation/core → simple_navigation}/item_adapter_spec.rb +14 -11
- data/spec/{lib/simple_navigation/core → simple_navigation}/item_container_spec.rb +130 -42
- data/spec/simple_navigation/item_spec.rb +467 -0
- data/spec/{lib/simple_navigation/core → simple_navigation}/items_provider_spec.rb +1 -3
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/base_spec.rb +34 -36
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/breadcrumbs_spec.rb +4 -7
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/json_spec.rb +5 -11
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/links_spec.rb +5 -8
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/list_spec.rb +4 -7
- data/spec/{lib/simple_navigation/rendering → simple_navigation}/renderer/text_spec.rb +4 -7
- data/spec/simple_navigation_spec.rb +190 -0
- data/spec/spec_helper.rb +29 -35
- metadata +103 -68
- data/CHANGELOG +0 -292
- data/lib/simple_navigation/core.rb +0 -5
- data/lib/simple_navigation/rails_controller_methods.rb +0 -164
- data/lib/simple_navigation/rendering.rb +0 -12
- data/rails/init.rb +0 -1
- data/spec/lib/simple_navigation/core/item_spec.rb +0 -703
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +0 -270
- data/spec/lib/simple_navigation_spec.rb +0 -300
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'forwardable'
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
4
|
module SimpleNavigation
|
4
5
|
# This class acts as an adapter to items that are not defined using the DSL
|
@@ -30,7 +31,7 @@ module SimpleNavigation
|
|
30
31
|
attr_reader :item
|
31
32
|
|
32
33
|
def initialize(item)
|
33
|
-
@item = item.is_a?(Hash) ?
|
34
|
+
@item = item.is_a?(Hash) ? OpenStruct.new(item) : item
|
34
35
|
end
|
35
36
|
|
36
37
|
# Returns the options for this item. If the wrapped item does not implement
|
@@ -47,22 +48,7 @@ module SimpleNavigation
|
|
47
48
|
|
48
49
|
# Converts this Item into a SimpleNavigation::Item
|
49
50
|
def to_simple_navigation_item(item_container)
|
50
|
-
SimpleNavigation::Item.new(item_container, key, name, url, options
|
51
|
-
end
|
52
|
-
|
53
|
-
protected
|
54
|
-
|
55
|
-
# Converts the specified hash into an object. Each key will be added
|
56
|
-
# as method.
|
57
|
-
def to_object(hash)
|
58
|
-
mod = Module.new do
|
59
|
-
hash.each_pair do |key, value|
|
60
|
-
define_method key do
|
61
|
-
value
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
Object.new.extend(mod)
|
51
|
+
SimpleNavigation::Item.new(item_container, key, name, url, options)
|
66
52
|
end
|
67
53
|
end
|
68
54
|
end
|
@@ -59,22 +59,18 @@ module SimpleNavigation
|
|
59
59
|
# set a regexp which is matched againstthe current URI.
|
60
60
|
#
|
61
61
|
# The <tt>block</tt> - if specified - will hold the item's sub_navigation.
|
62
|
-
def item(key, name,
|
63
|
-
options = url_or_options.is_a?(Hash) ? url_or_options : options_or_nil
|
62
|
+
def item(key, name, url = nil, options = {}, &block)
|
64
63
|
return unless should_add_item?(options)
|
65
|
-
|
66
|
-
|
67
|
-
name,
|
68
|
-
url_or_options,
|
69
|
-
options_or_nil,
|
70
|
-
nil,
|
71
|
-
&block)
|
64
|
+
item = Item.new(self, key, name, url, options, &block)
|
65
|
+
add_item item, options
|
72
66
|
end
|
73
67
|
|
74
68
|
def items=(new_items)
|
75
|
-
|
76
|
-
|
77
|
-
|
69
|
+
new_items.each do |item|
|
70
|
+
item_adapter = ItemAdapter.new(item)
|
71
|
+
next unless should_add_item?(item_adapter.options)
|
72
|
+
add_item item_adapter.to_simple_navigation_item(self), item_adapter.options
|
73
|
+
end
|
78
74
|
end
|
79
75
|
|
80
76
|
# Returns the Item with the specified key, nil otherwise.
|
@@ -148,6 +144,19 @@ module SimpleNavigation
|
|
148
144
|
|
149
145
|
private
|
150
146
|
|
147
|
+
def add_item(item, options)
|
148
|
+
items << item
|
149
|
+
modify_dom_attributes(options)
|
150
|
+
end
|
151
|
+
|
152
|
+
def modify_dom_attributes(options)
|
153
|
+
return unless container_options = options[:container]
|
154
|
+
self.dom_attributes = container_options.fetch(:attributes) { dom_attributes }
|
155
|
+
self.dom_class = container_options.fetch(:class) { dom_class }
|
156
|
+
self.dom_id = container_options.fetch(:id) { dom_id }
|
157
|
+
self.selected_class = container_options.fetch(:selected_class) { selected_class }
|
158
|
+
end
|
159
|
+
|
151
160
|
# FIXME: raise an exception if :rederer is a symbol and it is not registred
|
152
161
|
# in SimpleNavigation.registered_renderers
|
153
162
|
def renderer_instance(options)
|
@@ -166,8 +175,8 @@ module SimpleNavigation
|
|
166
175
|
end
|
167
176
|
|
168
177
|
def should_add_item?(options)
|
169
|
-
[options
|
170
|
-
[options
|
178
|
+
[options[:if]].flatten.compact.all? { |m| evaluate_method(m) } &&
|
179
|
+
[options[:unless]].flatten.compact.none? { |m| evaluate_method(m) }
|
171
180
|
end
|
172
181
|
|
173
182
|
def evaluate_method(method)
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'simple_navigation/helpers'
|
2
|
+
require 'simple_navigation/renderer/base'
|
3
|
+
|
4
|
+
module SimpleNavigation
|
5
|
+
module Renderer
|
6
|
+
autoload :List, 'simple_navigation/renderer/list'
|
7
|
+
autoload :Links, 'simple_navigation/renderer/links'
|
8
|
+
autoload :Breadcrumbs, 'simple_navigation/renderer/breadcrumbs'
|
9
|
+
autoload :Text, 'simple_navigation/renderer/text'
|
10
|
+
autoload :Json, 'simple_navigation/renderer/json'
|
11
|
+
end
|
12
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/simple-navigation.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'simple_navigation/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'simple-navigation'
|
8
8
|
spec.version = SimpleNavigation::VERSION
|
9
|
-
spec.authors = ['Andi Schacke', 'Mark J. Titorenko']
|
9
|
+
spec.authors = ['Andi Schacke', 'Mark J. Titorenko', 'Simon Courtois']
|
10
10
|
spec.email = ['andi@codeplant.ch']
|
11
11
|
spec.description = "With the simple-navigation gem installed you can easily " \
|
12
12
|
"create multilevel navigations for your Rails, Sinatra or "\
|
@@ -29,12 +29,13 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_runtime_dependency 'activesupport', '>= 2.3.2'
|
31
31
|
|
32
|
-
spec.add_development_dependency 'actionpack', '>= 2.3.2'
|
33
32
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
33
|
+
spec.add_development_dependency 'capybara'
|
34
34
|
spec.add_development_dependency 'coveralls', '~> 0.7'
|
35
35
|
spec.add_development_dependency 'guard-rspec', '~> 4.2'
|
36
|
-
spec.add_development_dependency '
|
36
|
+
spec.add_development_dependency 'memfs', '~> 0.4.1'
|
37
37
|
spec.add_development_dependency 'rake'
|
38
38
|
spec.add_development_dependency 'rdoc'
|
39
|
-
spec.add_development_dependency 'rspec', '~>
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
|
+
spec.add_development_dependency 'tzinfo', '>= 0'
|
40
41
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require 'action_controller/railtie'
|
4
|
+
require 'simple_navigation'
|
5
|
+
|
6
|
+
module RailsApp
|
7
|
+
class Application < Rails::Application
|
8
|
+
config.active_support.deprecation = :log
|
9
|
+
config.cache_classes = true
|
10
|
+
config.eager_load = false
|
11
|
+
config.root = __dir__
|
12
|
+
config.secret_token = 'x'*100
|
13
|
+
config.session_store :cookie_store, key: '_myapp_session'
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestsController < ActionController::Base
|
17
|
+
def base
|
18
|
+
render inline: <<-END
|
19
|
+
<!DOCTYPE html>
|
20
|
+
<html>
|
21
|
+
<body>
|
22
|
+
<%= render_navigation %>
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
END
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Rails.backtrace_cleaner.remove_silencers!
|
31
|
+
RailsApp::Application.initialize!
|
32
|
+
|
33
|
+
RailsApp::Application.routes.draw do
|
34
|
+
get '/base_spec' => 'rails_app/tests#base'
|
35
|
+
end
|
@@ -1,13 +1,18 @@
|
|
1
1
|
RSpec::Matchers.define :have_css do |expected, times|
|
2
2
|
match do |actual|
|
3
|
-
HTML::Selector.new(expected).select(actual)
|
3
|
+
selector = HTML::Selector.new(expected).select(actual)
|
4
|
+
if times
|
5
|
+
expect(selector.size).to eq times
|
6
|
+
else
|
7
|
+
expect(selector.size).to be >= 1
|
8
|
+
end
|
4
9
|
end
|
5
10
|
|
6
|
-
|
11
|
+
failure_message do |actual|
|
7
12
|
"expected #{actual.to_s} to have #{times || 1} elements matching '#{expected}'"
|
8
13
|
end
|
9
14
|
|
10
|
-
|
15
|
+
failure_message_when_negated do |actual|
|
11
16
|
"expected #{actual.to_s} not to have #{times || 1} elements matching '#{expected}'"
|
12
17
|
end
|
13
18
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
RSpec.feature 'Rendering navigation' do
|
2
|
+
background do
|
3
|
+
SimpleNavigation.set_env(RailsApp::Application.root, 'test')
|
4
|
+
end
|
5
|
+
|
6
|
+
scenario 'Rendering basic navigation', type: :feature do
|
7
|
+
visit '/base_spec'
|
8
|
+
|
9
|
+
expect(page).to have_content('Item 1')
|
10
|
+
expect(page).to have_content('Item 2')
|
11
|
+
end
|
12
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
module SimpleNavigation
|
4
2
|
module Adapters
|
5
3
|
describe Rails do
|
6
4
|
let(:action_controller) { ActionController::Base }
|
7
|
-
let(:adapter) {
|
5
|
+
let(:adapter) { Rails.new(context) }
|
8
6
|
let(:context) { double(:context, controller: controller) }
|
9
7
|
let(:controller) { double(:controller) }
|
10
8
|
let(:request) { double(:request) }
|
@@ -12,10 +10,11 @@ module SimpleNavigation
|
|
12
10
|
let(:template) { double(:template, request: request) }
|
13
11
|
|
14
12
|
describe '.register' do
|
15
|
-
before { action_controller.
|
13
|
+
before { allow(action_controller).to receive(:include) }
|
16
14
|
|
17
15
|
it 'calls set_env' do
|
18
|
-
|
16
|
+
app_path = RailsApp::Application.root
|
17
|
+
expect(simple_navigation).to receive(:set_env).with(app_path, 'test')
|
19
18
|
simple_navigation.register
|
20
19
|
end
|
21
20
|
|
@@ -25,19 +24,25 @@ module SimpleNavigation
|
|
25
24
|
simple_navigation.register
|
26
25
|
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
shared_examples 'installing helper method' do |method|
|
28
|
+
it "installs the #{method} method as helper method" do
|
29
|
+
simple_navigation.register
|
30
|
+
|
31
|
+
helper_methods = action_controller.send(:_helper_methods)
|
32
|
+
expect(helper_methods).to include(method)
|
33
|
+
end
|
35
34
|
end
|
35
|
+
|
36
|
+
it_behaves_like 'installing helper method', :render_navigation
|
37
|
+
it_behaves_like 'installing helper method', :active_navigation_item_name
|
38
|
+
it_behaves_like 'installing helper method', :active_navigation_item_key
|
39
|
+
it_behaves_like 'installing helper method', :active_navigation_item
|
40
|
+
it_behaves_like 'installing helper method', :active_navigation_item_container
|
36
41
|
end
|
37
42
|
|
38
43
|
describe '#initialize' do
|
39
44
|
context "when the controller's template is set" do
|
40
|
-
before { controller.
|
45
|
+
before { allow(controller).to receive_messages(instance_variable_get: template) }
|
41
46
|
|
42
47
|
it "sets the adapter's request accordingly" do
|
43
48
|
expect(adapter.request).to be request
|
@@ -45,7 +50,7 @@ module SimpleNavigation
|
|
45
50
|
end
|
46
51
|
|
47
52
|
context "when the controller's template is not set" do
|
48
|
-
before { controller.
|
53
|
+
before { allow(controller).to receive_messages(instance_variable_get: nil) }
|
49
54
|
|
50
55
|
it "sets the adapter's request to nil" do
|
51
56
|
expect(adapter.request).to be_nil
|
@@ -58,7 +63,7 @@ module SimpleNavigation
|
|
58
63
|
|
59
64
|
context "when the controller's template is stored as instance var (Rails2)" do
|
60
65
|
context "when the controller's template is set" do
|
61
|
-
before { controller.
|
66
|
+
before { allow(controller).to receive_messages(instance_variable_get: template) }
|
62
67
|
|
63
68
|
it "sets the adapter's template accordingly" do
|
64
69
|
expect(adapter.template).to be template
|
@@ -66,7 +71,7 @@ module SimpleNavigation
|
|
66
71
|
end
|
67
72
|
|
68
73
|
context "when the controller's template is not set" do
|
69
|
-
before { controller.
|
74
|
+
before { allow(controller).to receive_messages(instance_variable_get: nil) }
|
70
75
|
|
71
76
|
it "set the adapter's template to nil" do
|
72
77
|
expect(adapter.template).to be_nil
|
@@ -76,7 +81,7 @@ module SimpleNavigation
|
|
76
81
|
|
77
82
|
context "when the controller's template is stored as view_context (Rails3)" do
|
78
83
|
context 'and the template is set' do
|
79
|
-
before { controller.
|
84
|
+
before { allow(controller).to receive_messages(view_context: template) }
|
80
85
|
|
81
86
|
it "sets the adapter's template accordingly" do
|
82
87
|
expect(adapter.template).to be template
|
@@ -84,7 +89,7 @@ module SimpleNavigation
|
|
84
89
|
end
|
85
90
|
|
86
91
|
context 'and the template is not set' do
|
87
|
-
before { controller.
|
92
|
+
before { allow(controller).to receive_messages(view_context: nil) }
|
88
93
|
|
89
94
|
it "sets the adapter's template to nil" do
|
90
95
|
expect(adapter.template).to be_nil
|
@@ -92,10 +97,10 @@ module SimpleNavigation
|
|
92
97
|
end
|
93
98
|
end
|
94
99
|
end
|
95
|
-
|
100
|
+
|
96
101
|
describe '#request_uri' do
|
97
102
|
context "when the adapter's request is set" do
|
98
|
-
before { adapter.
|
103
|
+
before { allow(adapter).to receive_messages(request: request) }
|
99
104
|
|
100
105
|
context 'and request.fullpath is defined' do
|
101
106
|
let(:request) { double(:request, fullpath: '/fullpath') }
|
@@ -108,7 +113,7 @@ module SimpleNavigation
|
|
108
113
|
context 'and request.fullpath is not defined' do
|
109
114
|
let(:request) { double(:request, request_uri: '/request_uri') }
|
110
115
|
|
111
|
-
before { adapter.
|
116
|
+
before { allow(adapter).to receive_messages(request: request) }
|
112
117
|
|
113
118
|
it "sets the adapter's request_uri to the request.request_uri" do
|
114
119
|
expect(adapter.request_uri).to eq '/request_uri'
|
@@ -117,19 +122,19 @@ module SimpleNavigation
|
|
117
122
|
end
|
118
123
|
|
119
124
|
context "when the adapter's request is not set" do
|
120
|
-
before { adapter.
|
125
|
+
before { allow(adapter).to receive_messages(request: nil) }
|
121
126
|
|
122
127
|
it "sets the adapter's request_uri to an empty string" do
|
123
128
|
expect(adapter.request_uri).to eq ''
|
124
129
|
end
|
125
130
|
end
|
126
131
|
end
|
127
|
-
|
132
|
+
|
128
133
|
describe '#request_path' do
|
129
134
|
context "when the adapter's request is set" do
|
130
135
|
let(:request) { double(:request, path: '/request_path') }
|
131
136
|
|
132
|
-
before { adapter.
|
137
|
+
before { allow(adapter).to receive_messages(request: request) }
|
133
138
|
|
134
139
|
it "sets the adapter's request_path to the request.path" do
|
135
140
|
expect(adapter.request_path).to eq '/request_path'
|
@@ -137,7 +142,7 @@ module SimpleNavigation
|
|
137
142
|
end
|
138
143
|
|
139
144
|
context "when the adapter's request is not set" do
|
140
|
-
before { adapter.
|
145
|
+
before { allow(adapter).to receive_messages(request: nil) }
|
141
146
|
|
142
147
|
it "sets the adapter's request_path to an empty string" do
|
143
148
|
expect(adapter.request_path).to eq ''
|
@@ -189,7 +194,7 @@ module SimpleNavigation
|
|
189
194
|
|
190
195
|
describe '#current_page?' do
|
191
196
|
context "when the adapter's template is set" do
|
192
|
-
before { adapter.
|
197
|
+
before { allow(adapter).to receive_messages(template: template) }
|
193
198
|
|
194
199
|
it 'delegates the call to the template' do
|
195
200
|
expect(template).to receive(:current_page?).with(:page)
|
@@ -198,7 +203,7 @@ module SimpleNavigation
|
|
198
203
|
end
|
199
204
|
|
200
205
|
context "when the adapter's template is not set" do
|
201
|
-
before { adapter.
|
206
|
+
before { allow(adapter).to receive_messages(template: nil) }
|
202
207
|
|
203
208
|
it 'returns false' do
|
204
209
|
expect(adapter).not_to be_current_page(:page)
|
@@ -210,7 +215,7 @@ module SimpleNavigation
|
|
210
215
|
let(:options) { double(:options) }
|
211
216
|
|
212
217
|
context "when the adapter's template is set" do
|
213
|
-
before { adapter.
|
218
|
+
before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
|
214
219
|
|
215
220
|
context 'with considering item names as safe' do
|
216
221
|
before { SimpleNavigation.config.consider_item_names_as_safe = true }
|
@@ -232,11 +237,10 @@ module SimpleNavigation
|
|
232
237
|
end
|
233
238
|
end
|
234
239
|
|
235
|
-
|
236
240
|
end
|
237
241
|
|
238
242
|
context "when the adapter's template is not set" do
|
239
|
-
before { adapter.
|
243
|
+
before { allow(adapter).to receive_messages(template: nil) }
|
240
244
|
|
241
245
|
it 'returns nil' do
|
242
246
|
expect(adapter.link_to('text', 'url', options)).to be_nil
|
@@ -248,7 +252,7 @@ module SimpleNavigation
|
|
248
252
|
let(:options) { double(:options) }
|
249
253
|
|
250
254
|
context "when the adapter's template is set" do
|
251
|
-
before { adapter.
|
255
|
+
before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
|
252
256
|
|
253
257
|
it 'delegates the call to the template (with html_safe text)' do
|
254
258
|
expect(template).to receive(:content_tag)
|
@@ -258,7 +262,7 @@ module SimpleNavigation
|
|
258
262
|
end
|
259
263
|
|
260
264
|
context "when the adapter's template is not set" do
|
261
|
-
before { adapter.
|
265
|
+
before { allow(adapter).to receive_messages(template: nil) }
|
262
266
|
|
263
267
|
it 'returns nil' do
|
264
268
|
expect(adapter.content_tag(:div, 'text', options)).to be_nil
|
@@ -266,67 +270,6 @@ module SimpleNavigation
|
|
266
270
|
end
|
267
271
|
end
|
268
272
|
|
269
|
-
describe '#extract_controller_from' do
|
270
|
-
context 'when context responds to controller' do
|
271
|
-
it 'returns the controller' do
|
272
|
-
expect(adapter.send(:extract_controller_from, context)).to be controller
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context 'when context does not respond to controller' do
|
277
|
-
let(:context) { double(:context) }
|
278
|
-
|
279
|
-
it 'returns the context' do
|
280
|
-
expect(adapter.send(:extract_controller_from, context)).to be context
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
describe '#html_safe' do
|
286
|
-
let(:input) { double(:input) }
|
287
|
-
|
288
|
-
context 'when input responds to html_safe' do
|
289
|
-
let(:safe) { double(:safe) }
|
290
|
-
|
291
|
-
before { input.stub(html_safe: safe) }
|
292
|
-
|
293
|
-
it 'returns the html safe version of the input' do
|
294
|
-
expect(adapter.send(:html_safe, input)).to be safe
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
context 'when input does not respond to html_safe' do
|
299
|
-
it 'returns the input' do
|
300
|
-
expect(adapter.send(:html_safe, input)).to be input
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
describe '#link_title' do
|
306
|
-
let(:name) { double(:name, html_safe: safe) }
|
307
|
-
let(:safe) { double(:safe) }
|
308
|
-
|
309
|
-
context 'when config option consider_item_names_as_safe is true' do
|
310
|
-
before { SimpleNavigation.config.consider_item_names_as_safe = true }
|
311
|
-
after { SimpleNavigation.config.consider_item_names_as_safe = false }
|
312
|
-
|
313
|
-
it 'uses the html_safe version of the name' do
|
314
|
-
expect(adapter.send(:link_title, name)).to be safe
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
# TODO: Does it make sense ?
|
319
|
-
context 'when config option consider_item_names_as_safe is false (default)' do
|
320
|
-
before do
|
321
|
-
SimpleNavigation.config.consider_item_names_as_safe = false
|
322
|
-
adapter.stub(template: template)
|
323
|
-
end
|
324
|
-
|
325
|
-
it 'uses the item name' do
|
326
|
-
expect(adapter.send(:link_title, name)).to be name
|
327
|
-
end
|
328
|
-
end
|
329
|
-
end
|
330
273
|
end
|
331
274
|
end
|
332
275
|
end
|