element.
- #
- class Links < SimpleNavigation::Renderer::Base
- def render(item_container)
- div_content = item_container.items.inject([]) do |list, item|
- list << tag_for(item)
- end.join(join_with)
- content_tag(:div, div_content, {:id => item_container.dom_id, :class => item_container.dom_class})
- end
-
- protected
-
- def join_with
- @join_with ||= options[:join_with] || ""
- end
-
- def options_for(item)
- {:method => item.method}.merge(item.html_options)
- end
- end
- end
-end
diff -Nru ruby-simple-navigation-3.11.0/lib/simple_navigation/rendering/renderer/list.rb ruby-simple-navigation-4.0.3/lib/simple_navigation/rendering/renderer/list.rb
--- ruby-simple-navigation-3.11.0/lib/simple_navigation/rendering/renderer/list.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/lib/simple_navigation/rendering/renderer/list.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,29 +0,0 @@
-module SimpleNavigation
- module Renderer
-
- # Renders an ItemContainer as a
element and its containing items as - elements.
- # It adds the 'selected' class to li element AND the link inside the li element that is currently active.
- #
- # If the sub navigation should be included (based on the level and expand_all options), it renders another
containing the sub navigation inside the active - element.
- #
- # By default, the renderer sets the item's key as dom_id for the rendered
- element unless the config option autogenerate_item_ids is set to false.
- # The id can also be explicitely specified by setting the id in the html-options of the 'item' method in the config/navigation.rb file.
- class List < SimpleNavigation::Renderer::Base
- def render(item_container)
- list_content = item_container.items.inject([]) do |list, item|
- li_options = item.html_options.reject {|k, v| k == :link}
- li_content = tag_for(item)
- if include_sub_navigation?(item)
- li_content << render_sub_navigation_for(item)
- end
- list << content_tag(:li, li_content, li_options)
- end.join
- if skip_if_empty? && item_container.empty?
- ''
- else
- content_tag((options[:ordered] ? :ol : :ul), list_content, {:id => item_container.dom_id, :class => item_container.dom_class})
- end
- end
- end
- end
-end
diff -Nru ruby-simple-navigation-3.11.0/lib/simple_navigation/rendering/renderer/text.rb ruby-simple-navigation-4.0.3/lib/simple_navigation/rendering/renderer/text.rb
--- ruby-simple-navigation-3.11.0/lib/simple_navigation/rendering/renderer/text.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/lib/simple_navigation/rendering/renderer/text.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,26 +0,0 @@
-module SimpleNavigation
- module Renderer
-
- # Renders the 'chain' of selected navigation items as simple text items, joined with an optional separator (similar to breadcrumbs, but without markup).
- #
- class Text < SimpleNavigation::Renderer::Base
-
- def render(item_container)
- list(item_container).compact.join(options[:join_with] || " ")
- end
-
- private
-
- def list(item_container)
- item_container.items.inject([]) do |array, item|
- if item.selected?
- array + [item.name(:apply_generator => false)] + (include_sub_navigation?(item) ? list(item.sub_navigation) : [])
- else
- array
- end
- end
- end
-
- end
- end
-end
diff -Nru ruby-simple-navigation-3.11.0/lib/simple_navigation/rendering.rb ruby-simple-navigation-4.0.3/lib/simple_navigation/rendering.rb
--- ruby-simple-navigation-3.11.0/lib/simple_navigation/rendering.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/lib/simple_navigation/rendering.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,12 +0,0 @@
-require 'simple_navigation/rendering/helpers'
-require 'simple_navigation/rendering/renderer/base'
-
-module SimpleNavigation
- module Renderer
- autoload :List, 'simple_navigation/rendering/renderer/list'
- autoload :Links, 'simple_navigation/rendering/renderer/links'
- autoload :Breadcrumbs, 'simple_navigation/rendering/renderer/breadcrumbs'
- autoload :Text, 'simple_navigation/rendering/renderer/text'
- autoload :Json, 'simple_navigation/rendering/renderer/json'
- end
-end
diff -Nru ruby-simple-navigation-3.11.0/lib/simple_navigation/version.rb ruby-simple-navigation-4.0.3/lib/simple_navigation/version.rb
--- ruby-simple-navigation-3.11.0/lib/simple_navigation/version.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/lib/simple_navigation/version.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,3 @@
+module SimpleNavigation
+ VERSION = '4.0.3'
+end
diff -Nru ruby-simple-navigation-3.11.0/lib/simple_navigation.rb ruby-simple-navigation-4.0.3/lib/simple_navigation.rb
--- ruby-simple-navigation-3.11.0/lib/simple_navigation.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/lib/simple_navigation.rb 2015-04-16 17:17:37.000000000 +0000
@@ -3,43 +3,65 @@
require 'active_support/core_ext/hash'
require 'active_support/core_ext/module/attribute_accessors'
-require 'simple_navigation/core'
-require 'simple_navigation/rendering'
+require 'simple_navigation/version'
+require 'simple_navigation/configuration'
+require 'simple_navigation/item_adapter'
+require 'simple_navigation/item'
+require 'simple_navigation/item_container'
+require 'simple_navigation/items_provider'
+require 'simple_navigation/renderer'
require 'simple_navigation/adapters'
+require 'simple_navigation/config_file_finder'
+require 'simple_navigation/railtie' if defined?(::Rails)
require 'forwardable'
-# A plugin for generating a simple navigation. See README for resources on usage instructions.
+# A plugin for generating a simple navigation. See README for resources on
+# usage instructions.
module SimpleNavigation
-
- mattr_accessor :adapter_class, :adapter, :config_files, :config_file_paths, :default_renderer, :registered_renderers, :root, :environment
+ mattr_accessor :adapter,
+ :adapter_class,
+ :config_files,
+ :config_file_paths,
+ :default_renderer,
+ :environment,
+ :registered_renderers,
+ :root
# Cache for loaded config files
self.config_files = {}
- # Allows for multiple config_file_paths. Needed if a plugin itself uses simple-navigation and therefore has its own config file
+ # Allows for multiple config_file_paths. Needed if a plugin itself uses
+ # simple-navigation and therefore has its own config file
self.config_file_paths = []
-
- # Maps renderer keys to classes. The keys serve as shortcut in the render_navigation calls (:renderer => :list)
+
+ # Maps renderer keys to classes. The keys serve as shortcut in the
+ # render_navigation calls (renderer: :list)
self.registered_renderers = {
- :list => SimpleNavigation::Renderer::List,
- :links => SimpleNavigation::Renderer::Links,
- :breadcrumbs => SimpleNavigation::Renderer::Breadcrumbs,
- :text => SimpleNavigation::Renderer::Text,
- :json => SimpleNavigation::Renderer::Json
+ list: SimpleNavigation::Renderer::List,
+ links: SimpleNavigation::Renderer::Links,
+ breadcrumbs: SimpleNavigation::Renderer::Breadcrumbs,
+ text: SimpleNavigation::Renderer::Text,
+ json: SimpleNavigation::Renderer::Json
}
-
+
class << self
extend Forwardable
-
- def_delegators :adapter, :request, :request_uri, :request_path, :context_for_eval, :current_page?
+
+ def_delegators :adapter, :context_for_eval,
+ :current_page?,
+ :request,
+ :request_path,
+ :request_uri
+
def_delegators :adapter_class, :register
- # Sets the root path and current environment as specified. Also sets the default config_file_path.
+ # Sets the root path and current environment as specified. Also sets the
+ # default config_file_path.
def set_env(root, environment)
self.root = root
self.environment = environment
- self.config_file_paths << SimpleNavigation.default_config_file_path
+ config_file_paths << default_config_file_path
end
# Returns the current framework in which the plugin is running.
@@ -48,61 +70,43 @@
return :padrino if defined?(Padrino)
return :sinatra if defined?(Sinatra)
return :nanoc if defined?(Nanoc3)
- raise 'simple_navigation currently only works for Rails, Sinatra and Padrino apps'
+ fail 'simple_navigation currently only works for Rails, Sinatra and ' \
+ 'Padrino apps'
end
-
+
# Loads the adapter for the current framework
def load_adapter
- self.adapter_class = case framework
- when :rails
- SimpleNavigation::Adapters::Rails
- when :sinatra
- SimpleNavigation::Adapters::Sinatra
- when :padrino
- SimpleNavigation::Adapters::Padrino
- when :nanoc
- SimpleNavigation::Adapters::Nanoc
- end
+ self.adapter_class =
+ case framework
+ when :rails then SimpleNavigation::Adapters::Rails
+ when :sinatra then SimpleNavigation::Adapters::Sinatra
+ when :padrino then SimpleNavigation::Adapters::Padrino
+ when :nanoc then SimpleNavigation::Adapters::Nanoc
+ end
end
- # Creates a new adapter instance based on the context in which render_navigation has been called.
+ # Creates a new adapter instance based on the context in which
+ # render_navigation has been called.
def init_adapter_from(context)
- self.adapter = self.adapter_class.new(context)
- end
-
- def default_config_file_path
- File.join(SimpleNavigation.root, 'config')
+ self.adapter = adapter_class.new(context)
end
- # Returns true if the config_file for specified context does exist.
- def config_file?(navigation_context = :default)
- !!config_file(navigation_context)
- end
-
- # Returns the path to the config file for the given navigation context or nil if no matching config file can be found.
- # If multiple config_paths are set, it returns the first matching path.
- def config_file(navigation_context = :default)
- config_file_paths.collect { |path| File.join(path, config_file_name(navigation_context)) }.detect {|full_path| File.exists?(full_path)}
+ def default_config_file_path
+ File.join(root, 'config')
end
- # Returns the name of the config file for the given navigation_context
- def config_file_name(navigation_context = :default)
- prefix = navigation_context == :default ? '' : "#{navigation_context.to_s.underscore}_"
- "#{prefix}navigation.rb"
- end
-
# Resets the list of config_file_paths to the specified path
def config_file_path=(path)
self.config_file_paths = [path]
end
- # Reads the config_file for the specified navigation_context and stores it for later evaluation.
+ # Reads the config_file for the specified navigation_context and stores it
+ # for later evaluation.
def load_config(navigation_context = :default)
- raise "Config file '#{config_file_name(navigation_context)}' not found in path(s) #{config_file_paths.join(', ')}!" unless config_file?(navigation_context)
- if self.environment == 'production'
- self.config_files[navigation_context] ||= IO.read(config_file(navigation_context))
+ if environment == 'production'
+ update_config(navigation_context)
else
- self.config_files[navigation_context] = IO.read(config_file(navigation_context))
+ update_config!(navigation_context)
end
end
@@ -111,57 +115,65 @@
SimpleNavigation::Configuration.instance
end
- # Returns the ItemContainer that contains the items for the primary navigation
+ # Returns the ItemContainer that contains the items for the
+ # primary navigation
def primary_navigation
config.primary_navigation
end
- # Returns the active item container for the specified level. Valid levels are
+ # Returns the active item container for the specified level.
+ # Valid levels are
# * :all - in this case the primary_navigation is returned.
# * :leaves - the 'deepest' active item_container will be returned
- # * a specific level - the active item_container for the specified level will be returned
- # * a range of levels - the active item_container for the range's minimum will be returned
+ # * a specific level - the active item_container for the specified level
+ # will be returned
+ # * a range of levels - the active item_container for the range's minimum
+ # will be returned
#
# Returns nil if there is no active item_container for the specified level.
def active_item_container_for(level)
case level
- when :all
- self.primary_navigation
- when :leaves
- self.primary_navigation.active_leaf_container
- when Integer
- self.primary_navigation.active_item_container_for(level)
- when Range
- self.primary_navigation.active_item_container_for(level.min)
+ when :all then primary_navigation
+ when :leaves then primary_navigation.active_leaf_container
+ when Integer then primary_navigation.active_item_container_for(level)
+ when Range then primary_navigation.active_item_container_for(level.min)
else
- raise ArgumentError, "Invalid navigation level: #{level}"
+ fail ArgumentError, "Invalid navigation level: #{level}"
end
end
-
+
# Registers a renderer.
#
# === Example
# To register your own renderer:
#
- # SimpleNavigation.register_renderer :my_renderer => My::RendererClass
+ # SimpleNavigation.register_renderer my_renderer: My::RendererClass
#
# Then in the view you can call:
#
- # render_navigation(:renderer => :my_renderer)
+ # render_navigation(renderer: :my_renderer)
def register_renderer(renderer_hash)
- self.registered_renderers.merge!(renderer_hash)
+ registered_renderers.merge!(renderer_hash)
end
-
+
private
-
- def apply_defaults(options)
- options[:level] = options.delete(:levels) if options[:levels]
- {:context => :default, :level => :all}.merge(options)
+
+ def config_file(navigation_context)
+ ConfigFileFinder.new(config_file_paths).find(navigation_context)
end
-
- end
+ def read_config(navigation_context)
+ File.read config_file(navigation_context)
+ end
+
+ def update_config(navigation_context)
+ config_files[navigation_context] ||= read_config(navigation_context)
+ end
+ def update_config!(navigation_context)
+ config_files[navigation_context] = read_config(navigation_context)
+ end
+ end
end
SimpleNavigation.load_adapter
diff -Nru ruby-simple-navigation-3.11.0/lib/simple-navigation.rb ruby-simple-navigation-4.0.3/lib/simple-navigation.rb
--- ruby-simple-navigation-3.11.0/lib/simple-navigation.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/lib/simple-navigation.rb 2015-04-16 17:17:37.000000000 +0000
@@ -1 +1 @@
-require 'simple_navigation'
\ No newline at end of file
+require 'simple_navigation'
diff -Nru ruby-simple-navigation-3.11.0/LICENSE ruby-simple-navigation-4.0.3/LICENSE
--- ruby-simple-navigation-3.11.0/LICENSE 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/LICENSE 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,22 @@
+Copyright (c) 2014 codeplant GmbH
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff -Nru ruby-simple-navigation-3.11.0/metadata.yml ruby-simple-navigation-4.0.3/metadata.yml
--- ruby-simple-navigation-3.11.0/metadata.yml 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/metadata.yml 2015-04-16 17:17:37.000000000 +0000
@@ -1,131 +1,185 @@
--- !ruby/object:Gem::Specification
name: simple-navigation
version: !ruby/object:Gem::Version
- version: 3.11.0
- prerelease:
+ version: 4.0.3
platform: ruby
authors:
- Andi Schacke
- Mark J. Titorenko
+- Simon Courtois
autorequire:
bindir: bin
cert_chain: []
-date: 2013-06-05 00:00:00.000000000 Z
+date: 2015-04-09 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: activesupport
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: 2.3.2
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: 2.3.2
- !ruby/object:Gem::Dependency
- name: rspec
+ name: bundler
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '1.5'
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '1.5'
+- !ruby/object:Gem::Dependency
+ name: capybara
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
+- !ruby/object:Gem::Dependency
+ name: coveralls
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - "~>"
- !ruby/object:Gem::Version
- version: 2.0.1
+ version: '0.7'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - "~>"
- !ruby/object:Gem::Version
- version: 2.0.1
+ version: '0.7'
- !ruby/object:Gem::Dependency
- name: json_spec
+ name: guard-rspec
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ~>
+ - - "~>"
- !ruby/object:Gem::Version
- version: 1.1.1
+ version: '4.2'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ~>
+ - - "~>"
- !ruby/object:Gem::Version
- version: 1.1.1
+ version: '4.2'
+- !ruby/object:Gem::Dependency
+ name: memfs
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: 0.4.1
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: 0.4.1
- !ruby/object:Gem::Dependency
name: rake
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: rdoc
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
- name: jeweler
+ name: rspec
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '3.0'
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '3.0'
+- !ruby/object:Gem::Dependency
+ name: tzinfo
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
description: With the simple-navigation gem installed you can easily create multilevel
navigations for your Rails, Sinatra or Padrino applications. The navigation is defined
in a single configuration file. It supports automatic as well as explicit highlighting
of the currently active navigation through regular expressions.
-email: andreas.schacke@gmail.com
+email:
+- andi@codeplant.ch
executables: []
extensions: []
-extra_rdoc_files:
-- README
+extra_rdoc_files: []
files:
-- CHANGELOG
+- ".gitignore"
+- ".rspec"
+- ".travis.yml"
+- CHANGELOG.md
- Gemfile
-- README
+- Guardfile
+- LICENSE
+- README.md
- Rakefile
-- VERSION
+- gemfiles/.bundle/config
+- gemfiles/rails-3-2-stable.gemfile
+- gemfiles/rails-4-1-stable.gemfile
+- gemfiles/rails-4-2-stable.gemfile
- generators/navigation_config/USAGE
- generators/navigation_config/navigation_config_generator.rb
- generators/navigation_config/templates/config/navigation.rb
+- init.rb
+- install.rb
- lib/generators/navigation_config/navigation_config_generator.rb
- lib/simple-navigation.rb
- lib/simple_navigation.rb
@@ -135,65 +189,104 @@
- lib/simple_navigation/adapters/padrino.rb
- lib/simple_navigation/adapters/rails.rb
- lib/simple_navigation/adapters/sinatra.rb
-- lib/simple_navigation/core.rb
-- lib/simple_navigation/core/configuration.rb
-- lib/simple_navigation/core/item.rb
-- lib/simple_navigation/core/item_adapter.rb
-- lib/simple_navigation/core/item_container.rb
-- lib/simple_navigation/core/items_provider.rb
-- lib/simple_navigation/rails_controller_methods.rb
-- lib/simple_navigation/rendering.rb
-- lib/simple_navigation/rendering/helpers.rb
-- lib/simple_navigation/rendering/renderer/base.rb
-- lib/simple_navigation/rendering/renderer/breadcrumbs.rb
-- lib/simple_navigation/rendering/renderer/json.rb
-- lib/simple_navigation/rendering/renderer/links.rb
-- lib/simple_navigation/rendering/renderer/list.rb
-- lib/simple_navigation/rendering/renderer/text.rb
-- rails/init.rb
-- spec/lib/simple_navigation/adapters/padrino_spec.rb
-- spec/lib/simple_navigation/adapters/rails_spec.rb
-- spec/lib/simple_navigation/adapters/sinatra_spec.rb
-- spec/lib/simple_navigation/core/configuration_spec.rb
-- spec/lib/simple_navigation/core/item_adapter_spec.rb
-- spec/lib/simple_navigation/core/item_container_spec.rb
-- spec/lib/simple_navigation/core/item_spec.rb
-- spec/lib/simple_navigation/core/items_provider_spec.rb
-- spec/lib/simple_navigation/rails_controller_methods_spec.rb
-- spec/lib/simple_navigation/rendering/helpers_spec.rb
-- spec/lib/simple_navigation/rendering/renderer/base_spec.rb
-- spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb
-- spec/lib/simple_navigation/rendering/renderer/json_spec.rb
-- spec/lib/simple_navigation/rendering/renderer/links_spec.rb
-- spec/lib/simple_navigation/rendering/renderer/list_spec.rb
-- spec/lib/simple_navigation/rendering/renderer/text_spec.rb
-- spec/lib/simple_navigation_spec.rb
+- lib/simple_navigation/config_file.rb
+- lib/simple_navigation/config_file_finder.rb
+- lib/simple_navigation/configuration.rb
+- lib/simple_navigation/helpers.rb
+- lib/simple_navigation/item.rb
+- lib/simple_navigation/item_adapter.rb
+- lib/simple_navigation/item_container.rb
+- lib/simple_navigation/items_provider.rb
+- lib/simple_navigation/railtie.rb
+- lib/simple_navigation/renderer.rb
+- lib/simple_navigation/renderer/base.rb
+- lib/simple_navigation/renderer/breadcrumbs.rb
+- lib/simple_navigation/renderer/json.rb
+- lib/simple_navigation/renderer/links.rb
+- lib/simple_navigation/renderer/list.rb
+- lib/simple_navigation/renderer/text.rb
+- lib/simple_navigation/version.rb
+- simple-navigation.gemspec
+- spec/fake_app/config/navigation.rb
+- spec/fake_app/rails_app.rb
+- spec/initializers/coveralls.rb
+- spec/initializers/have_css_matcher.rb
+- spec/initializers/memfs.rb
+- spec/initializers/rails.rb
+- spec/initializers/rspec.rb
+- spec/integration/rendering_navigation_spec.rb
+- spec/simple_navigation/adapters/padrino_spec.rb
+- spec/simple_navigation/adapters/rails_spec.rb
+- spec/simple_navigation/adapters/sinatra_spec.rb
+- spec/simple_navigation/config_file_finder_spec.rb
+- spec/simple_navigation/config_file_spec.rb
+- spec/simple_navigation/configuration_spec.rb
+- spec/simple_navigation/helpers_spec.rb
+- spec/simple_navigation/item_adapter_spec.rb
+- spec/simple_navigation/item_container_spec.rb
+- spec/simple_navigation/item_spec.rb
+- spec/simple_navigation/items_provider_spec.rb
+- spec/simple_navigation/renderer/base_spec.rb
+- spec/simple_navigation/renderer/breadcrumbs_spec.rb
+- spec/simple_navigation/renderer/json_spec.rb
+- spec/simple_navigation/renderer/links_spec.rb
+- spec/simple_navigation/renderer/list_spec.rb
+- spec/simple_navigation/renderer/text_spec.rb
+- spec/simple_navigation_spec.rb
- spec/spec_helper.rb
-homepage: http://github.com/andi/simple-navigation
-licenses: []
+- uninstall.rb
+homepage: http://github.com/codeplant/simple-navigation
+licenses:
+- MIT
+metadata: {}
post_install_message:
rdoc_options:
-- --inline-source
-- --charset=UTF-8
+- "--inline-source"
+- "--charset=UTF-8"
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
- none: false
requirements:
- - - ! '>='
+ - - ">="
- !ruby/object:Gem::Version
version: '0'
requirements: []
-rubyforge_project: andi
-rubygems_version: 1.8.24
+rubyforge_project:
+rubygems_version: 2.2.2
signing_key:
-specification_version: 3
+specification_version: 4
summary: simple-navigation is a ruby library for creating navigations (with multiple
- levels) for your Rails2, Rails3, Sinatra or Padrino application.
-test_files: []
+ levels) for your Rails2, Rails3, Rails4, Sinatra or Padrino application.
+test_files:
+- spec/fake_app/config/navigation.rb
+- spec/fake_app/rails_app.rb
+- spec/initializers/coveralls.rb
+- spec/initializers/have_css_matcher.rb
+- spec/initializers/memfs.rb
+- spec/initializers/rails.rb
+- spec/initializers/rspec.rb
+- spec/integration/rendering_navigation_spec.rb
+- spec/simple_navigation/adapters/padrino_spec.rb
+- spec/simple_navigation/adapters/rails_spec.rb
+- spec/simple_navigation/adapters/sinatra_spec.rb
+- spec/simple_navigation/config_file_finder_spec.rb
+- spec/simple_navigation/config_file_spec.rb
+- spec/simple_navigation/configuration_spec.rb
+- spec/simple_navigation/helpers_spec.rb
+- spec/simple_navigation/item_adapter_spec.rb
+- spec/simple_navigation/item_container_spec.rb
+- spec/simple_navigation/item_spec.rb
+- spec/simple_navigation/items_provider_spec.rb
+- spec/simple_navigation/renderer/base_spec.rb
+- spec/simple_navigation/renderer/breadcrumbs_spec.rb
+- spec/simple_navigation/renderer/json_spec.rb
+- spec/simple_navigation/renderer/links_spec.rb
+- spec/simple_navigation/renderer/list_spec.rb
+- spec/simple_navigation/renderer/text_spec.rb
+- spec/simple_navigation_spec.rb
+- spec/spec_helper.rb
diff -Nru ruby-simple-navigation-3.11.0/rails/init.rb ruby-simple-navigation-4.0.3/rails/init.rb
--- ruby-simple-navigation-3.11.0/rails/init.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/rails/init.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1 +0,0 @@
-SimpleNavigation.register
diff -Nru ruby-simple-navigation-3.11.0/Rakefile ruby-simple-navigation-4.0.3/Rakefile
--- ruby-simple-navigation-3.11.0/Rakefile 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/Rakefile 2015-04-16 17:17:37.000000000 +0000
@@ -1,47 +1,14 @@
-require 'rake'
+require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rdoc/task'
-desc 'Default: run specs.'
-task :default => :spec
+RSpec::Core::RakeTask.new(:spec)
-desc 'Run the specs'
-RSpec::Core::RakeTask.new(:spec) do |t|
- t.rspec_opts = ['--colour --format progress']
-end
-
-namespace :spec do
- desc "Run all specs with RCov"
- RSpec::Core::RakeTask.new(:rcov) do |t|
- t.rspec_opts = ['--colour --format progress']
- t.rcov = true
- t.rcov_opts = ['--exclude', 'spec,/Users/']
- end
-end
+task default: :spec
-desc 'Generate documentation for the simple_navigation plugin.'
-RDoc::Task.new(:rdoc) do |rdoc|
+RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'SimpleNavigation'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gemspec|
- gemspec.name = "simple-navigation"
- gemspec.summary = "simple-navigation is a ruby library for creating navigations (with multiple levels) for your Rails2, Rails3, Sinatra or Padrino application."
- gemspec.email = "andreas.schacke@gmail.com"
- gemspec.homepage = "http://github.com/andi/simple-navigation"
- gemspec.description = "With the simple-navigation gem installed you can easily create multilevel navigations for your Rails, Sinatra or Padrino applications. The navigation is defined in a single configuration file. It supports automatic as well as explicit highlighting of the currently active navigation through regular expressions."
- gemspec.authors = ["Andi Schacke", "Mark J. Titorenko"]
- gemspec.rdoc_options = ["--inline-source", "--charset=UTF-8"]
- gemspec.files = FileList["[A-Z]*", "{lib,spec,rails,generators}/**/*"] - FileList["**/*.log", "Gemfile.lock"]
- gemspec.rubyforge_project = 'andi'
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError => e
- puts "Jeweler not available (#{e}). Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+ rdoc.options << '--inline-source'
+ rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
end
diff -Nru ruby-simple-navigation-3.11.0/README ruby-simple-navigation-4.0.3/README
--- ruby-simple-navigation-3.11.0/README 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/README 1970-01-01 00:00:00.000000000 +0000
@@ -1,22 +0,0 @@
-
-== Simple Navigation
-
-Simple Navigation is a ruby library for creating navigations (with multiple levels) for your Rails 2, Rails 3, Sinatra or Padrino applications.
-
-Source code:
- git://github.com/andi/simple-navigation.git
-
-Documentation:
- http://wiki.github.com/andi/simple-navigation
-
-RDoc:
- Please checkout the repository and execute 'rake rdoc'.
-
-Online Demo:
- http://simple-navigation-demo.andischacke.com
-
-Discussion Group for Feedback and Questions
- http://groups.google.com/group/simple-navigation
-
-Copyright (c) 2012 Andi Schacke, released under the MIT license
-
diff -Nru ruby-simple-navigation-3.11.0/README.md ruby-simple-navigation-4.0.3/README.md
--- ruby-simple-navigation-3.11.0/README.md 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/README.md 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,40 @@
+# Simple Navigation
+
+[![Gem Version](https://badge.fury.io/rb/simple-navigation.png)](http://badge.fury.io/rb/simple-navigation)
+[![Build Status](https://secure.travis-ci.org/codeplant/simple-navigation.png?branch=master)](http://travis-ci.org/codeplant/simple-navigation)
+[![Code Climate](https://codeclimate.com/github/codeplant/simple-navigation.png)](https://codeclimate.com/github/codeplant/simple-navigation)
+[![Coverage Status](https://coveralls.io/repos/codeplant/simple-navigation/badge.png)](https://coveralls.io/r/codeplant/simple-navigation)
+
+Simple Navigation is a ruby library for creating navigations (with multiple levels) for your Rails 2, Rails 3, Rails 4, Sinatra or Padrino applications. It runs with all ruby versions (including ruby 2.x).
+
+## Documentation
+
+For the complete documentation, take a look at the [project's wiki](http://wiki.github.com/codeplant/simple-navigation).
+
+## RDoc
+
+You can consult the project's RDoc on [RubyDoc.info](http://rubydoc.info/github/codeplant/simple-navigation/frames).
+
+If you need to generate the RDoc files locally, check out the repository and simply call the `rake rdoc` in the project's folder.
+
+## Online Demo
+
+You can try simple-navigation with the [online demo](http://simple-navigation-demo.codeplant.ch).
+
+The source code of this online demo is [available on Github](http://github.com/codeplant/simple-navigation-demo).
+
+## Feedback and Questions
+
+Don't hesitate to come talk on the [project's group](http://groups.google.com/group/simple-navigation).
+
+## Contributing
+
+1. Fork it (https://github.com/codeplant/simple-navigation/fork)
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
+
+## License
+
+Copyright (c) 2014 codeplant GmbH, released under the MIT license
diff -Nru ruby-simple-navigation-3.11.0/.rspec ruby-simple-navigation-4.0.3/.rspec
--- ruby-simple-navigation-3.11.0/.rspec 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/.rspec 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,3 @@
+--color
+--format=documentation
+--require spec_helper
diff -Nru ruby-simple-navigation-3.11.0/simple-navigation.gemspec ruby-simple-navigation-4.0.3/simple-navigation.gemspec
--- ruby-simple-navigation-3.11.0/simple-navigation.gemspec 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/simple-navigation.gemspec 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,41 @@
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'simple_navigation/version'
+
+Gem::Specification.new do |spec|
+ spec.name = 'simple-navigation'
+ spec.version = SimpleNavigation::VERSION
+ spec.authors = ['Andi Schacke', 'Mark J. Titorenko', 'Simon Courtois']
+ spec.email = ['andi@codeplant.ch']
+ spec.description = "With the simple-navigation gem installed you can easily " \
+ "create multilevel navigations for your Rails, Sinatra or "\
+ "Padrino applications. The navigation is defined in a " \
+ "single configuration file. It supports automatic as well "\
+ "as explicit highlighting of the currently active " \
+ "navigation through regular expressions."
+ spec.summary = "simple-navigation is a ruby library for creating navigations "\
+ "(with multiple levels) for your Rails2, Rails3, Rails4, Sinatra or " \
+ "Padrino application."
+ spec.homepage = 'http://github.com/codeplant/simple-navigation'
+ spec.license = 'MIT'
+
+ spec.files = `git ls-files -z`.split("\x0")
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
+ spec.require_paths = ['lib']
+
+ spec.rdoc_options = ['--inline-source', '--charset=UTF-8']
+
+ spec.add_runtime_dependency 'activesupport', '>= 2.3.2'
+
+ spec.add_development_dependency 'bundler', '~> 1.5'
+ spec.add_development_dependency 'capybara'
+ spec.add_development_dependency 'coveralls', '~> 0.7'
+ spec.add_development_dependency 'guard-rspec', '~> 4.2'
+ spec.add_development_dependency 'memfs', '~> 0.4.1'
+ spec.add_development_dependency 'rake'
+ spec.add_development_dependency 'rdoc'
+ spec.add_development_dependency 'rspec', '~> 3.0'
+ spec.add_development_dependency 'tzinfo', '>= 0'
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/fake_app/config/navigation.rb ruby-simple-navigation-4.0.3/spec/fake_app/config/navigation.rb
--- ruby-simple-navigation-3.11.0/spec/fake_app/config/navigation.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/fake_app/config/navigation.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,6 @@
+SimpleNavigation::Configuration.run do |navigation|
+ navigation.items do |nav|
+ nav.item :item_1, 'Item 1', '/item_1'
+ nav.item :item_2, 'Item 2', '/item_2'
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/fake_app/rails_app.rb ruby-simple-navigation-4.0.3/spec/fake_app/rails_app.rb
--- ruby-simple-navigation-3.11.0/spec/fake_app/rails_app.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/fake_app/rails_app.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,35 @@
+ENV['RAILS_ENV'] ||= 'test'
+
+require 'action_controller/railtie'
+require 'simple_navigation'
+
+module RailsApp
+ class Application < Rails::Application
+ config.active_support.deprecation = :log
+ config.cache_classes = true
+ config.eager_load = false
+ config.root = __dir__
+ config.secret_token = 'x'*100
+ config.session_store :cookie_store, key: '_myapp_session'
+ end
+
+ class TestsController < ActionController::Base
+ def base
+ render inline: <<-END
+
+
+
+ <%= render_navigation %>
+
+
+ END
+ end
+ end
+end
+
+Rails.backtrace_cleaner.remove_silencers!
+RailsApp::Application.initialize!
+
+RailsApp::Application.routes.draw do
+ get '/base_spec' => 'rails_app/tests#base'
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/initializers/coveralls.rb ruby-simple-navigation-4.0.3/spec/initializers/coveralls.rb
--- ruby-simple-navigation-3.11.0/spec/initializers/coveralls.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/initializers/coveralls.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,3 @@
+require 'coveralls'
+
+Coveralls.wear!
diff -Nru ruby-simple-navigation-3.11.0/spec/initializers/have_css_matcher.rb ruby-simple-navigation-4.0.3/spec/initializers/have_css_matcher.rb
--- ruby-simple-navigation-3.11.0/spec/initializers/have_css_matcher.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/initializers/have_css_matcher.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,18 @@
+RSpec::Matchers.define :have_css do |expected, times|
+ match do |actual|
+ selector = HTML::Selector.new(expected).select(actual)
+ if times
+ expect(selector.size).to eq times
+ else
+ expect(selector.size).to be >= 1
+ end
+ end
+
+ failure_message do |actual|
+ "expected #{actual.to_s} to have #{times || 1} elements matching '#{expected}'"
+ end
+
+ failure_message_when_negated do |actual|
+ "expected #{actual.to_s} not to have #{times || 1} elements matching '#{expected}'"
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/initializers/memfs.rb ruby-simple-navigation-4.0.3/spec/initializers/memfs.rb
--- ruby-simple-navigation-3.11.0/spec/initializers/memfs.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/initializers/memfs.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,7 @@
+require 'memfs'
+
+RSpec.configure do |config|
+ config.around(memfs: true) do |example|
+ MemFs.activate { example.run }
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/initializers/rails.rb ruby-simple-navigation-4.0.3/spec/initializers/rails.rb
--- ruby-simple-navigation-3.11.0/spec/initializers/rails.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/initializers/rails.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,4 @@
+begin
+ require 'rails'
+rescue LoadError
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/initializers/rspec.rb ruby-simple-navigation-4.0.3/spec/initializers/rspec.rb
--- ruby-simple-navigation-3.11.0/spec/initializers/rspec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/initializers/rspec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,7 @@
+RSpec.configure do |config|
+ config.expect_with(:rspec) do |c|
+ c.syntax = :expect
+ end
+
+ config.order = :random
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/integration/rendering_navigation_spec.rb ruby-simple-navigation-4.0.3/spec/integration/rendering_navigation_spec.rb
--- ruby-simple-navigation-3.11.0/spec/integration/rendering_navigation_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/integration/rendering_navigation_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,12 @@
+RSpec.feature 'Rendering navigation' do
+ background do
+ SimpleNavigation.set_env(RailsApp::Application.root, 'test')
+ end
+
+ scenario 'Rendering basic navigation', type: :feature do
+ visit '/base_spec'
+
+ expect(page).to have_content('Item 1')
+ expect(page).to have_content('Item 2')
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/adapters/padrino_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/adapters/padrino_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/adapters/padrino_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/adapters/padrino_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,31 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::Adapters::Padrino do
-
- def create_adapter
- SimpleNavigation::Adapters::Padrino.new(@context)
- end
-
- before(:each) do
- @request = stub(:request)
- @content = stub(:content)
- @context = stub(:context, :request => @request)
- @adapter = create_adapter
- end
-
- describe 'link_to' do
- it "should delegate to context" do
- @context.should_receive(:link_to).with('name', 'url', :my_option => true)
- @adapter.link_to('name', 'url', :my_option => true)
- end
- end
-
- describe 'content_tag' do
- it "should delegate to context" do
- @content.should_receive(:html_safe).and_return('content')
- @context.should_receive(:content_tag).with('type', 'content', :my_option => true)
- @adapter.content_tag('type', @content, :my_option => true)
- end
- end
-
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/adapters/rails_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/adapters/rails_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/adapters/rails_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/adapters/rails_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,287 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::Adapters::Rails do
-
- def create_adapter
- SimpleNavigation::Adapters::Rails.new(@context)
- end
-
- before(:each) do
- @context = stub(:context)
- @controller = stub(:controller)
- @context.stub!(:controller => @controller)
- @request = stub(:request)
- @template = stub(:template, :request => @request)
- @adapter = create_adapter
- end
-
- describe 'self.register' do
- before(:each) do
- ActionController::Base.stub!(:include)
- end
- it "should call set_env" do
- SimpleNavigation.should_receive(:set_env).with('./', 'test')
- SimpleNavigation.register
- end
- it "should extend the ActionController::Base with the Helpers" do
- ActionController::Base.should_receive(:include).with(SimpleNavigation::Helpers)
- SimpleNavigation.register
- end
- it "should install the helper methods in the controller" do
- ActionController::Base.should_receive(:helper_method).with(:render_navigation)
- ActionController::Base.should_receive(:helper_method).with(:active_navigation_item_name)
- ActionController::Base.should_receive(:helper_method).with(:active_navigation_item_key)
- ActionController::Base.should_receive(:helper_method).with(:active_navigation_item)
- ActionController::Base.should_receive(:helper_method).with(:active_navigation_item_container)
- SimpleNavigation.register
- end
-
- end
-
- describe 'initialize' do
- context 'regarding setting the request' do
- context 'template is present' do
- before(:each) do
- @controller.stub!(:instance_variable_get => @template)
- @adapter = create_adapter
- end
- it {@adapter.request.should == @request}
- end
- context 'template is not present' do
- before(:each) do
- @controller.stub!(:instance_variable_get => nil)
- end
- it {@adapter.request.should be_nil}
- end
- end
- context 'regarding setting the controller' do
- it "should set the controller" do
- @adapter.controller.should == @controller
- end
- end
- context 'regarding setting the template' do
- context 'template is stored in controller as instance_var (Rails2)' do
- context 'template is set' do
- before(:each) do
- @controller.stub!(:instance_variable_get => @template)
- @adapter = create_adapter
- end
- it {@adapter.template.should == @template}
- end
- context 'template is not set' do
- before(:each) do
- @controller.stub!(:instance_variable_get => nil)
- @adapter = create_adapter
- end
- it {@adapter.template.should be_nil}
- end
- end
- context 'template is stored in controller as view_context (Rails3)' do
- context 'template is set' do
- before(:each) do
- @controller.stub!(:view_context => @template)
- @adapter = create_adapter
- end
- it {@adapter.template.should == @template}
- end
- context 'template is not set' do
- before(:each) do
- @controller.stub!(:view_context => nil)
- @adapter = create_adapter
- end
- it {@adapter.template.should be_nil}
- end
- end
- end
- end
-
- describe 'request_uri' do
- context 'request is set' do
- context 'fullpath is defined on request' do
- before(:each) do
- @request = stub(:request, :fullpath => '/fullpath')
- @adapter.stub!(:request => @request)
- end
- it {@adapter.request_uri.should == '/fullpath'}
- end
- context 'fullpath is not defined on request' do
- before(:each) do
- @request = stub(:request, :request_uri => '/request_uri')
- @adapter.stub!(:request => @request)
- end
- it {@adapter.request_uri.should == '/request_uri'}
- end
- end
- context 'request is not set' do
- before(:each) do
- @adapter.stub!(:request => nil)
- end
- it {@adapter.request_uri.should == ''}
- end
- end
-
- describe 'request_path' do
- context 'request is set' do
- before(:each) do
- @request = stub(:request, :path => '/request_path')
- @adapter.stub!(:request => @request)
- end
- it {@adapter.request_path.should == '/request_path'}
- end
- context 'request is not set' do
- before(:each) do
- @adapter.stub!(:request => nil)
- end
- it {@adapter.request_path.should == ''}
- end
- end
-
- describe 'context_for_eval' do
- context 'controller is present' do
- before(:each) do
- @controller = stub(:controller)
- @adapter.instance_variable_set(:@controller, @controller)
- end
- context 'template is present' do
- before(:each) do
- @template = stub(:template)
- @adapter.instance_variable_set(:@template, @template)
- end
- it {@adapter.context_for_eval.should == @template}
- end
- context 'template is not present' do
- before(:each) do
- @adapter.instance_variable_set(:@template, nil)
- end
- it {@adapter.context_for_eval.should == @controller}
- end
- end
- context 'controller is not present' do
- before(:each) do
- @adapter.instance_variable_set(:@controller, nil)
- end
- context 'template is present' do
- before(:each) do
- @template = stub(:template)
- @adapter.instance_variable_set(:@template, @template)
- end
- it {@adapter.context_for_eval.should == @template}
- end
- context 'template is not present' do
- before(:each) do
- @adapter.instance_variable_set(:@template, nil)
- end
- it {lambda {@adapter.context_for_eval}.should raise_error}
- end
- end
- end
-
- describe 'current_page?' do
- context 'template is set' do
- before(:each) do
- @adapter.stub!(:template => @template)
- end
- it "should delegate the call to the template" do
- @template.should_receive(:current_page?).with(:page)
- @adapter.current_page?(:page)
- end
- end
- context 'template is not set' do
- before(:each) do
- @adapter.stub!(:template => nil)
- end
- it {@adapter.should_not be_current_page(:page)}
- end
- end
-
- describe 'link_to' do
- context 'template is set' do
- before(:each) do
- @adapter.stub!(:template => @template)
- @adapter.stub!(:html_safe => 'safe_text')
- @options = stub(:options)
- end
- it "should delegate the call to the template (with html_safe text)" do
- @template.should_receive(:link_to).with('safe_text', 'url', @options)
- @adapter.link_to('text', 'url', @options)
- end
- end
- context 'template is not set' do
- before(:each) do
- @adapter.stub!(:template => nil)
- end
- it {@adapter.link_to('text', 'url', @options).should be_nil}
- end
- end
-
- describe 'content_tag' do
- context 'template is set' do
- before(:each) do
- @adapter.stub!(:template => @template)
- @adapter.stub!(:html_safe => 'safe_text')
- @options = stub(:options)
- end
- it "should delegate the call to the template (with html_safe text)" do
- @template.should_receive(:content_tag).with(:div, 'safe_text', @options)
- @adapter.content_tag(:div, 'text', @options)
- end
- end
- context 'template is not set' do
- before(:each) do
- @adapter.stub!(:template => nil)
- end
- it {@adapter.content_tag(:div, 'text', @options).should be_nil}
- end
- end
-
- describe 'self.extract_controller_from' do
- context 'object responds to controller' do
- before(:each) do
- @context.stub!(:controller => @controller)
- end
- it "should return the controller" do
- @adapter.send(:extract_controller_from, @context).should == @controller
- end
- end
- context 'object does not respond to controller' do
- before(:each) do
- @context = stub(:context)
- end
- it "should return the context" do
- @adapter.send(:extract_controller_from, @context).should == @context
- end
- end
- end
-
- describe 'html_safe' do
- before(:each) do
- @input = stub :input
- end
- context 'input does respond to html_safe' do
- before(:each) do
- @safe = stub :safe
- @input.stub!(:html_safe => @safe)
- end
- it {@adapter.send(:html_safe, @input).should == @safe}
- end
- context 'input does not respond to html_safe' do
- it {@adapter.send(:html_safe, @input).should == @input}
- end
- end
-
- describe 'template_from' do
- context 'Rails3' do
- before(:each) do
- @controller.stub!(:view_context => 'view')
- end
- it {@adapter.send(:template_from, @controller).should == 'view'}
- end
- context 'Rails2' do
- before(:each) do
- @controller.instance_variable_set(:@template, 'view')
- end
- it {@adapter.send(:template_from, @controller).should == 'view'}
- end
- end
-
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/adapters/sinatra_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/adapters/sinatra_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/adapters/sinatra_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/adapters/sinatra_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,80 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::Adapters::Sinatra do
-
- def create_adapter
- SimpleNavigation::Adapters::Sinatra.new(@context)
- end
-
- before(:each) do
- @context = stub(:context)
- @request = stub(:request, :fullpath => '/full?param=true', :path => '/full')
- @context.stub!(:request => @request)
- @adapter = create_adapter
- end
-
- describe 'context_for_eval' do
- it "should raise error if no context" do
- @adapter.stub!(:context => nil)
- lambda {@adapter.context_for_eval}.should raise_error
- end
- it "should return the context" do
- @adapter.context_for_eval.should == @context
- end
- end
-
- describe 'request_uri' do
- it {@adapter.request_uri.should == '/full?param=true'}
- end
-
- describe 'request_path' do
- it {@adapter.request_path.should == '/full'}
- end
-
- describe 'current_page?' do
- before(:each) do
- @request.stub!(:scheme => 'http', :host_with_port => 'my_host:5000')
- end
-
- describe 'when URL is not encoded' do
- it {@adapter.current_page?('/full?param=true').should be_true}
- it {@adapter.current_page?('/full?param3=true').should be_false}
- it {@adapter.current_page?('/full').should be_true}
- it {@adapter.current_page?('http://my_host:5000/full?param=true').should be_true}
- it {@adapter.current_page?('http://my_host:5000/full?param3=true').should be_false}
- it {@adapter.current_page?('http://my_host:5000/full').should be_true}
- it {@adapter.current_page?('https://my_host:5000/full').should be_false}
- it {@adapter.current_page?('http://my_host:6000/full').should be_false}
- it {@adapter.current_page?('http://my_other_host:5000/full').should be_false}
- end
-
- describe 'when URL is encoded' do
- before(:each) do
- @request.stub!(:fullpath => '/full%20with%20spaces?param=true', :path => '/full%20with%20spaces')
- end
-
- it {@adapter.current_page?('/full%20with%20spaces?param=true').should be_true}
- it {@adapter.current_page?('/full%20with%20spaces?param3=true').should be_false}
- it {@adapter.current_page?('/full%20with%20spaces').should be_true}
- it {@adapter.current_page?('http://my_host:5000/full%20with%20spaces?param=true').should be_true}
- it {@adapter.current_page?('http://my_host:5000/full%20with%20spaces?param3=true').should be_false}
- it {@adapter.current_page?('http://my_host:5000/full%20with%20spaces').should be_true}
- it {@adapter.current_page?('https://my_host:5000/full%20with%20spaces').should be_false}
- it {@adapter.current_page?('http://my_host:6000/full%20with%20spaces').should be_false}
- it {@adapter.current_page?('http://my_other_host:5000/full%20with%20spaces').should be_false}
- end
- end
-
- describe 'link_to' do
- it "should return a link" do
- @adapter.link_to('link', 'url', :class => 'clazz', :id => 'id').should == "link"
- end
- end
-
- describe 'content_tag' do
- it "should return a tag" do
- @adapter.content_tag(:div, 'content', :class => 'clazz', :id => 'id').should == "
content
"
- end
- end
-
-end
\ No newline at end of file
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/configuration_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/configuration_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/configuration_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/configuration_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,128 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::Configuration do
-
- before(:each) do
- @config = SimpleNavigation::Configuration.instance
- end
-
- describe 'self.run' do
- it "should yield the singleton Configuration object" do
- SimpleNavigation::Configuration.run do |c|
- c.should == @config
- end
- end
- end
-
- describe 'self.eval_config' do
- before(:each) do
- @context = mock(:context)
- @context.stub!(:instance_eval)
- SimpleNavigation.stub!(:context_for_eval => @context)
- @config_files = {:default => 'default', :my_context => 'my_context'}
- SimpleNavigation.stub!(:config_files).and_return(@config_files)
- end
- context "with default navigation context" do
- it "should instance_eval the default config_file-string inside the context" do
- @context.should_receive(:instance_eval).with('default')
- SimpleNavigation::Configuration.eval_config
- end
- end
- context 'with non default navigation context' do
- it "should instance_eval the specified config_file-string inside the context" do
- @context.should_receive(:instance_eval).with('my_context')
- SimpleNavigation::Configuration.eval_config(:my_context)
- end
- end
- end
-
- describe 'initialize' do
- it "should set the List-Renderer as default upon initialize" do
- @config.renderer.should == SimpleNavigation::Renderer::List
- end
- it "should set the selected_class to 'selected' as default" do
- @config.selected_class.should == 'selected'
- end
- it "should set the active_leaf_class to 'simple-navigation-active-leaf' as default" do
- @config.active_leaf_class.should == 'simple-navigation-active-leaf'
- end
- it "should set autogenerate_item_ids to true as default" do
- @config.autogenerate_item_ids.should be_true
- end
- it "should set auto_highlight to true as default" do
- @config.auto_highlight.should be_true
- end
- it "should set the id_generator" do
- @config.id_generator.should_not be_nil
- end
- it "should set the name_generator" do
- @config.name_generator.should_not be_nil
- end
- end
- describe 'items' do
- before(:each) do
- @container = stub(:items_container)
- SimpleNavigation::ItemContainer.stub!(:new).and_return(@container)
- end
- context 'block given' do
- context 'items_provider specified' do
- it {lambda {@config.items(stub(:provider)) {}}.should raise_error}
- end
- context 'no items_provider specified' do
- it "should should yield an new ItemContainer" do
- @config.items do |container|
- container.should == @container
- end
- end
- it "should assign the ItemContainer to an instance-var" do
- @config.items {}
- @config.primary_navigation.should == @container
- end
- it "should not set the items on the container" do
- @container.should_not_receive(:items=)
- @config.items {}
- end
- end
- end
- context 'no block given' do
- context 'items_provider specified' do
- before(:each) do
- @external_provider = stub(:external_provider)
- @items = stub(:items)
- @items_provider = stub(:items_provider, :items => @items)
- SimpleNavigation::ItemsProvider.stub!(:new => @items_provider)
- @container.stub!(:items=)
- end
- it "should create an new Provider object for the specified provider" do
- SimpleNavigation::ItemsProvider.should_receive(:new).with(@external_provider)
- @config.items(@external_provider)
- end
- it "should call items on the provider object" do
- @items_provider.should_receive(:items)
- @config.items(@external_provider)
- end
- it "should set the items on the container" do
- @container.should_receive(:items=).with(@items)
- @config.items(@external_provider)
- end
- end
- context 'items_provider not specified' do
- it {lambda {@config.items}.should raise_error}
- end
- end
- end
-
- describe 'loaded?' do
- it "should return true if primary_nav is set" do
- @config.instance_variable_set(:@primary_navigation, :bla)
- @config.should be_loaded
- end
- it "should return false if no primary_nav is set" do
- @config.instance_variable_set(:@primary_navigation, nil)
- @config.should_not be_loaded
- end
- end
-
-end
-
-
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/item_adapter_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/item_adapter_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/item_adapter_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/item_adapter_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,209 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::ItemAdapter, 'when item is an object' do
-
- before(:each) do
- @item = stub(:item)
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
- end
-
- describe 'key' do
- it "should delegate key to item" do
- @item.should_receive(:key)
- @item_adapter.key
- end
- end
-
- describe 'url' do
- it "should delegate url to item" do
- @item.should_receive(:url)
- @item_adapter.url
- end
- end
-
- describe 'name' do
- it "should delegate name to item" do
- @item.should_receive(:name)
- @item_adapter.name
- end
- end
-
- describe 'initialize' do
- it "should set the item" do
- @item_adapter.item.should == @item
- end
- end
-
- describe 'options' do
- context 'item does respond to options' do
- before(:each) do
- @options = stub(:options)
- @item.stub!(:options => @options)
- end
- it "should return the item's options'" do
- @item_adapter.options.should == @options
- end
- end
- context 'item does not respond to options' do
- it "should return an empty hash" do
- @item_adapter.options.should == {}
- end
- end
- end
-
- describe 'items' do
- context 'item does respond to items' do
- context 'items is nil' do
- before(:each) do
- @item.stub!(:items => nil)
- end
- it "should return nil" do
- @item_adapter.items.should be_nil
- end
- end
- context 'items is not nil' do
- context 'items is empty' do
- before(:each) do
- @item.stub!(:items => [])
- end
- it "should return nil" do
- @item_adapter.items.should be_nil
- end
- end
- context 'items is not empty' do
- before(:each) do
- @items = stub(:items, :empty? => false)
- @item.stub!(:items => @items)
- end
- it "should return the items" do
- @item_adapter.items.should == @items
- end
- end
- end
- end
- context 'item does not respond to items' do
- it "should return nil" do
- @item_adapter.items.should be_nil
- end
- end
- end
-
- describe 'to_simple_navigation_item' do
- before(:each) do
- @container = stub(:container)
- @item.stub!(:url => 'url', :name => 'name', :key => 'key', :options => {}, :items => [])
- end
- it "should create a SimpleNavigation::Item" do
- SimpleNavigation::Item.should_receive(:new).with(@container, 'key', 'name', 'url', {}, nil)
- @item_adapter.to_simple_navigation_item(@container)
- end
- end
-
-end
-
-describe SimpleNavigation::ItemAdapter, 'when item is a hash' do
-
- before(:each) do
- @item = {:key => 'key', :url => 'url', :name => 'name'}
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
- end
-
- describe 'key' do
- it "should delegate key to item" do
- @item_adapter.item.should_receive(:key)
- @item_adapter.key
- end
- end
-
- describe 'url' do
- it "should delegate url to item" do
- @item_adapter.item.should_receive(:url)
- @item_adapter.url
- end
- end
-
- describe 'name' do
- it "should delegate name to item" do
- @item_adapter.item.should_receive(:name)
- @item_adapter.name
- end
- end
-
- describe 'initialize' do
- it "should set the item" do
- @item_adapter.item.should_not be_nil
- end
- it "should have converted the item into an object" do
- @item_adapter.item.should respond_to(:url)
- end
- end
-
- describe 'options' do
- context 'item does respond to options' do
- before(:each) do
- @item = {:key => 'key', :url => 'url', :name => 'name', :options => {:my => :options}}
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
- end
- it "should return the item's options'" do
- @item_adapter.options.should == {:my => :options}
- end
- end
- context 'item does not respond to options' do
- it "should return an empty hash" do
- @item_adapter.options.should == {}
- end
- end
- end
-
- describe 'items' do
- context 'item does respond to items' do
- context 'items is nil' do
- before(:each) do
- @item = {:key => 'key', :url => 'url', :name => 'name', :items => nil}
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
- end
- it "should return nil" do
- @item_adapter.items.should be_nil
- end
- end
- context 'items is not nil' do
- context 'items is empty' do
- before(:each) do
- @item = {:key => 'key', :url => 'url', :name => 'name', :items => []}
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
- end
- it "should return nil" do
- @item_adapter.items.should be_nil
- end
- end
- context 'items is not empty' do
- before(:each) do
- @item = {:key => 'key', :url => 'url', :name => 'name', :items => ['not', 'empty']}
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
- end
- it "should return the items" do
- @item_adapter.items.should == ['not', 'empty']
- end
- end
- end
- end
- context 'item does not respond to items' do
- it "should return nil" do
- @item_adapter.items.should be_nil
- end
- end
- end
-
- describe 'to_simple_navigation_item' do
- before(:each) do
- @container = stub(:container)
- @item = {:key => 'key', :url => 'url', :name => 'name', :items => [], :options => {}}
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
- end
- it "should create a SimpleNavigation::Item" do
- SimpleNavigation::Item.should_receive(:new).with(@container, 'key', 'name', 'url', {}, nil)
- @item_adapter.to_simple_navigation_item(@container)
- end
- end
-
-end
\ No newline at end of file
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/item_container_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/item_container_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/item_container_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/item_container_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,451 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::ItemContainer do
- before(:each) do
- @item_container = SimpleNavigation::ItemContainer.new
- end
- describe 'initialize' do
- it "should set the renderer to the globally-configured renderer per default" do
- SimpleNavigation::Configuration.instance.should_receive(:renderer)
- @item_container = SimpleNavigation::ItemContainer.new
- end
- it "should have an empty items-array" do
- @item_container = SimpleNavigation::ItemContainer.new
- @item_container.items.should be_empty
- end
- end
-
- describe 'items=' do
- before(:each) do
- @item = stub(:item)
- @items = [@item]
- @item_adapter = stub(:item_adapter).as_null_object
- SimpleNavigation::ItemAdapter.stub(:new => @item_adapter)
- @item_container.stub!(:should_add_item? => true)
- end
- it "should wrap each item in an ItemAdapter" do
- SimpleNavigation::ItemAdapter.should_receive(:new)
- @item_container.items = @items
- end
- context 'item should be added' do
- before(:each) do
- @item_container.stub!(:should_add_item? => true)
- @simple_navigation_item = stub(:simple_navigation_item)
- @item_adapter.stub!(:to_simple_navigation_item => @simple_navigation_item)
- end
- it "should convert the item to a SimpleNavigation::Item" do
- @item_adapter.should_receive(:to_simple_navigation_item).with(@item_container)
- @item_container.items = @items
- end
- it "should add the item to the items-collection" do
- @item_container.items.should_receive(:<<).with(@simple_navigation_item)
- @item_container.items = @items
- end
- end
- context 'item should not be added' do
- before(:each) do
- @item_container.stub!(:should_add_item? => false)
- end
- it "should not convert the item to a SimpleNavigation::Item" do
- @item_adapter.should_not_receive(:to_simple_navigation_item)
- @item_container.items = @items
- end
- it "should not add the item to the items-collection" do
- @item_container.items.should_not_receive(:<<)
- @item_container.items = @items
- end
- end
- end
-
- describe 'selected?' do
- before(:each) do
- @item_1 = stub(:item, :selected? => false)
- @item_2 = stub(:item, :selected? => false)
- @item_container.instance_variable_set(:@items, [@item_1, @item_2])
- end
- it "should return nil if no item is selected" do
- @item_container.should_not be_selected
- end
- it "should return true if one item is selected" do
- @item_1.stub!(:selected? => true)
- @item_container.should be_selected
- end
- end
-
- describe 'selected_item' do
- before(:each) do
- SimpleNavigation.stub!(:current_navigation_for => :nav)
- @item_container.stub!(:[] => nil)
- @item_1 = stub(:item, :selected? => false)
- @item_2 = stub(:item, :selected? => false)
- @item_container.instance_variable_set(:@items, [@item_1, @item_2])
- end
- context 'navigation not explicitely set' do
- context 'no item selected' do
- it "should return nil" do
- @item_container.selected_item.should be_nil
- end
- end
- context 'one item selected' do
- before(:each) do
- @item_1.stub!(:selected? => true)
- end
- it "should return the selected item" do
- @item_container.selected_item.should == @item_1
- end
- end
- end
- end
-
- describe 'selected_sub_navigation?' do
- context 'with an item selected' do
- before(:each) do
- @selected_item = stub(:selected_item)
- @item_container.stub!(:selected_item => @selected_item)
- end
- context 'selected item has sub_navigation' do
- before(:each) do
- @sub_navigation = stub(:sub_navigation)
- @selected_item.stub!(:sub_navigation => @sub_navigation)
- end
- it {@item_container.send(:selected_sub_navigation?).should be_true}
- end
- context 'selected item does not have sub_navigation' do
- before(:each) do
- @selected_item.stub!(:sub_navigation => nil)
- end
- it {@item_container.send(:selected_sub_navigation?).should be_false}
- end
- end
- context 'without an item selected' do
- before(:each) do
- @item_container.stub!(:selected_item => nil)
- end
- it {@item_container.send(:selected_sub_navigation?).should be_false}
- end
-
- end
-
- describe 'active_item_container_for' do
- context "the desired level is the same as the container's" do
- it {@item_container.active_item_container_for(1).should == @item_container}
- end
- context "the desired level is different than the container's" do
- context 'with no selected subnavigation' do
- before(:each) do
- @item_container.stub!(:selected_sub_navigation? => false)
- end
- it {@item_container.active_item_container_for(2).should be_nil}
- end
- context 'with selected subnavigation' do
- before(:each) do
- @item_container.stub!(:selected_sub_navigation? => true)
- @sub_nav = stub(:sub_nav)
- @selected_item = stub(:selected_item)
- @item_container.stub!(:selected_item => @selected_item)
- @selected_item.stub!(:sub_navigation => @sub_nav)
- end
- it "should call recursively on the sub_navigation" do
- @sub_nav.should_receive(:active_item_container_for).with(2)
- @item_container.active_item_container_for(2)
- end
- end
- end
- end
-
- describe 'active_leaf_container' do
- context 'the current container has a selected subnavigation' do
- before(:each) do
- @item_container.stub!(:selected_sub_navigation? => true)
- @sub_nav = stub(:sub_nav)
- @selected_item = stub(:selected_item)
- @item_container.stub!(:selected_item => @selected_item)
- @selected_item.stub!(:sub_navigation => @sub_nav)
- end
- it "should call recursively on the sub_navigation" do
- @sub_nav.should_receive(:active_leaf_container)
- @item_container.active_leaf_container
- end
- end
- context 'the current container is the leaf already' do
- before(:each) do
- @item_container.stub!(:selected_sub_navigation? => false)
- end
- it "should return itsself" do
- @item_container.active_leaf_container.should == @item_container
- end
- end
- end
-
- describe 'item' do
-
- context 'unconditional item' do
-
- before(:each) do
- @item_container.stub!(:should_add_item?).and_return(true)
- @options = {}
- end
-
- context 'block given' do
- before(:each) do
- @sub_container = stub(:sub_container)
- SimpleNavigation::ItemContainer.stub!(:new).and_return(@sub_container)
- end
-
- it "should should yield an new ItemContainer" do
- @item_container.item('key', 'name', 'url', @options) do |container|
- container.should == @sub_container
- end
- end
- it "should create a new Navigation-Item with the given params and the specified block" do
- SimpleNavigation::Item.should_receive(:new).with(@item_container, 'key', 'name', 'url', @options, nil, &@proc)
- @item_container.item('key', 'name', 'url', @options, &@proc)
- end
- it "should add the created item to the list of items" do
- @item_container.items.should_receive(:<<)
- @item_container.item('key', 'name', 'url', @options) {}
- end
- end
-
- context 'no block given' do
- it "should create a new Navigation_item with the given params and nil as sub_navi" do
- SimpleNavigation::Item.should_receive(:new).with(@item_container, 'key', 'name', 'url', @options, nil)
- @item_container.item('key', 'name', 'url', @options)
- end
- it "should add the created item to the list of items" do
- @item_container.items.should_receive(:<<)
- @item_container.item('key', 'name', 'url', @options)
- end
- end
-
- end
-
- context 'optional url and optional options' do
- context 'item specifed without url or options' do
- it 'should add the create item to the list of items' do
- @item_container.items.should_receive(:<<)
- @item_container.item('key', 'name')
- end
- end
- context 'item specified with only a url' do
- it 'should add the item to the list' do
- @item_container.items.should_receive(:<<)
- @item_container.item('key', 'name', 'url')
- end
- end
- context 'item specified with only options' do
- context 'containing no conditions' do
- it 'should add the created item to the list of items' do
- @item_container.items.should_receive(:<<)
- @item_container.item('key', 'name', {:option => true})
- end
- end
- context 'containing negative condition' do
- it 'should not add the created item to the list of items' do
- @item_container.items.should_not_receive(:<<)
- @item_container.item('key', 'name', {:if => lambda{false}, :option => true})
- end
- end
- context 'containing positive condition' do
- it 'should add the created item to the list of items' do
- @item_container.items.should_receive(:<<)
- @item_container.item('key', 'name', {:if => lambda{true}, :option => true})
- end
- end
- end
- context 'item specified with a url and options' do
- context 'containing no conditions' do
- it 'should add the created item to the list of items' do
- @item_container.items.should_receive(:<<)
- @item_container.item('key', 'name', 'url', {:option => true})
- end
- end
- context 'containing negative condition' do
- it 'should not add the created item to the list of items' do
- @item_container.items.should_not_receive(:<<)
- @item_container.item('key', 'name', 'url', {:if => lambda{false}, :option => true})
- end
- end
- context 'containing positive condition' do
- it 'should add the created item to the list of items' do
- @item_container.items.should_receive(:<<)
- @item_container.item('key', 'name', 'url', {:if => lambda{true}, :option => true})
- end
- end
- end
- end
-
- context 'conditions given for item' do
-
- context '"if" given' do
-
- before(:each) do
- @options = {:if => Proc.new {@condition}}
- end
-
- it "should remove if from options" do
- @item_container.item('key', 'name', 'url', @options)
- @options[:if].should be_nil
- end
-
- context 'if evals to true' do
- before(:each) do
- @condition = true
- end
- it "should create a new Navigation-Item" do
- SimpleNavigation::Item.should_receive(:new)
- @item_container.item('key', 'name', 'url', @options)
- end
- end
-
- context 'if evals to false' do
- before(:each) do
- @condition = false
- end
- it "should not create a new Navigation-Item" do
- SimpleNavigation::Item.should_not_receive(:new)
- @item_container.item('key', 'name', 'url', @options)
- end
- end
-
- context 'if is not a proc or method' do
- it "should raise an error" do
- lambda {@item_container.item('key', 'name', 'url', {:if => 'text'})}.should raise_error
- end
- end
-
- context '"unless" given' do
-
- before(:each) do
- @options = {:unless => Proc.new {@condition}}
- end
-
-
- it "should remove unless from options" do
- @item_container.item('key', 'name', 'url', @options)
- @options[:unless].should be_nil
- end
-
- context 'unless evals to false' do
- before(:each) do
- @condition = false
- end
- it "should create a new Navigation-Item" do
- SimpleNavigation::Item.should_receive(:new)
- @item_container.item('key', 'name', 'url', @options)
- end
- end
-
- context 'unless evals to true' do
- before(:each) do
- @condition = true
- end
- it "should not create a new Navigation-Item" do
- SimpleNavigation::Item.should_not_receive(:new)
- @item_container.item('key', 'name', 'url', @options)
- end
- end
-
- end
- end
- end
- end
-
- describe '[]' do
-
- before(:each) do
- @item_container.item(:first, 'first', 'bla')
- @item_container.item(:second, 'second', 'bla')
- @item_container.item(:third, 'third', 'bla')
- end
-
- it "should return the item with the specified navi_key" do
- @item_container[:second].name.should == 'second'
- end
- it "should return nil if no item exists for the specified navi_key" do
- @item_container[:invalid].should be_nil
- end
- end
-
- describe 'render' do
- before(:each) do
- @renderer_instance = stub(:renderer).as_null_object
- @renderer_class = stub(:renderer_class, :new => @renderer_instance)
- end
- context 'renderer specified as option' do
- context 'renderer-class specified' do
- it "should instantiate the passed renderer_class with the options" do
- @renderer_class.should_receive(:new).with(:renderer => @renderer_class)
- end
- it "should call render on the renderer and pass self" do
- @renderer_instance.should_receive(:render).with(@item_container)
- end
- after(:each) do
- @item_container.render(:renderer => @renderer_class)
- end
- end
- context 'renderer-symbol specified' do
- before(:each) do
- SimpleNavigation.registered_renderers = {:my_renderer => @renderer_class}
- end
- it "should instantiate the passed renderer_class with the options" do
- @renderer_class.should_receive(:new).with(:renderer => :my_renderer)
- end
- it "should call render on the renderer and pass self" do
- @renderer_instance.should_receive(:render).with(@item_container)
- end
- after(:each) do
- @item_container.render(:renderer => :my_renderer)
- end
- end
- end
- context 'no renderer specified' do
- before(:each) do
- @item_container.stub!(:renderer => @renderer_class)
- @options = {}
- end
- it "should instantiate the container's renderer with the options" do
- @renderer_class.should_receive(:new).with(@options)
- end
- it "should call render on the renderer and pass self" do
- @renderer_instance.should_receive(:render).with(@item_container)
- end
- after(:each) do
- @item_container.render(@options)
- end
- end
- end
-
- describe 'level_for_item' do
- before(:each) do
- @item_container.item(:p1, 'p1', 'p1')
- @item_container.item(:p2, 'p2', 'p2') do |p2|
- p2.item(:s1, 's1', 's1')
- p2.item(:s2, 's2', 's2') do |s2|
- s2.item(:ss1, 'ss1', 'ss1')
- s2.item(:ss2, 'ss2', 'ss2')
- end
- p2.item(:s3, 's3', 's3')
- end
- @item_container.item(:p3, 'p3', 'p3')
- end
- it {@item_container.level_for_item(:p1).should == 1}
- it {@item_container.level_for_item(:p3).should == 1}
- it {@item_container.level_for_item(:s1).should == 2}
- it {@item_container.level_for_item(:ss1).should == 3}
- it {@item_container.level_for_item(:x).should be_nil}
-
- end
-
- describe 'empty?' do
- it "should be empty if there are no items" do
- @item_container.instance_variable_set(:@items, [])
- @item_container.should be_empty
- end
- it "should not be empty if there are some items" do
- @item_container.instance_variable_set(:@items, [stub(:item)])
- @item_container.should_not be_empty
- end
- end
-
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/item_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/item_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/item_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/item_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,566 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::Item do
-
- before(:each) do
- @item_container = stub(:item_container, :level => 1, :selected_class => nil).as_null_object
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
- @adapter = stub(:adapter)
- SimpleNavigation.stub!(:adapter => @adapter)
- end
-
- describe 'initialize' do
- context 'subnavigation' do
- before(:each) do
- @subnav_container = stub(:subnav_container).as_null_object
- SimpleNavigation::ItemContainer.stub!(:new => @subnav_container)
- end
- context 'block given' do
- it "should create a new ItemContainer with a level+1" do
- SimpleNavigation::ItemContainer.should_receive(:new).with(2)
- SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {}) {}
- end
- it "should call the block" do
- @subnav_container.should_receive(:test)
- SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {}) {|subnav| subnav.test}
- end
- end
- context 'no block given' do
- context 'items given' do
- before(:each) do
- @items = stub(:items)
- end
- it "should create a new ItemContainer with a level+1" do
- SimpleNavigation::ItemContainer.should_receive(:new).with(2)
- SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {}, @items)
- end
- it "should set the items on the subnav_container" do
- @subnav_container.should_receive(:items=).with(@items)
- SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {}, @items)
- end
- end
- context 'no items given' do
- it "should not create a new ItemContainer" do
- SimpleNavigation::ItemContainer.should_not_receive(:new)
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
- end
- end
- end
- end
- context ':method option' do
- context 'defined' do
- before(:each) do
- @options = {:method => :delete}
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
- end
- it 'should set the method as instance_var' do
- @item.method.should == :delete
- end
- it 'should set the html-options without the method' do
- @item.instance_variable_get(:@html_options).key?(:method).should be_false
- end
- end
-
- context 'undefined' do
- it 'should set the instance-var to nil' do
- @item.method.should be_nil
- end
- end
- end
-
- context 'setting class and id on the container' do
- before(:each) do
- @options = {:container_class => 'container_class', :container_id => 'container_id'}
- end
- it {@item_container.should_receive(:dom_class=).with('container_class')}
- it {@item_container.should_receive(:dom_id=).with('container_id')}
- after(:each) do
- SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
- end
- end
-
- context ':highlights_on option' do
- context 'defined' do
- before(:each) do
- @highlights_on = stub(:option)
- @options = {:highlights_on => @highlights_on}
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
- end
- it 'should set the method as instance_var' do
- @item.highlights_on.should == @highlights_on
- end
- it 'should set the html-options without the method' do
- @item.instance_variable_get(:@html_options).key?(:highlights_on).should be_false
- end
- end
-
- context 'undefined' do
- it 'should set the instance-var to nil' do
- @item.highlights_on.should be_nil
- end
- end
- end
-
- context 'url' do
- context 'url is a string' do
- before(:each) do
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
- end
- it {@item.url.should == 'url'}
- end
- context 'url is a proc' do
- before(:each) do
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', Proc.new {"my_" + "url"}, {})
- end
- it {@item.url.should == 'my_url'}
- end
- context 'url is nil' do
- before(:each) do
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', nil, {})
- end
- it {@item.url.should == nil}
- end
- context 'url is unspecified' do
- before(:each) do
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name')
- end
- it {@item.url.should == nil}
- end
- end
-
- context 'optional url and optional options' do
- context 'when constructed without any optional parameters' do
- before(:each) do
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name')
- end
- it {@item.url.should == nil}
- it {@item.instance_variable_get(:@html_options).should == {}}
- end
- context 'when constructed with only a url' do
- before(:each) do
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url')
- end
- it {@item.url.should == 'url'}
- it {@item.instance_variable_get(:@html_options).should == {}}
- end
- context 'when constructed with only options' do
- before(:each) do
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', {:option => true})
- end
- it {@item.url.should == nil}
- it {@item.instance_variable_get(:@html_options).should == {:option => true}}
- end
- context 'when constructed with a url and options' do
- before(:each) do
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {:option => true})
- end
- it {@item.url.should == 'url'}
- it {@item.instance_variable_get(:@html_options).should == {:option => true}}
- end
- end
- end
-
- describe 'name' do
- before(:each) do
- SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "#{name}"})
- end
- context 'default (generator is applied)' do
- it {@item.name.should == "name"}
- end
- context 'generator is skipped' do
- it {@item.name(:apply_generator => false).should == 'name'}
- end
- end
-
- describe 'selected?' do
- context 'explicitly selected' do
- before(:each) do
- @item.stub!(:selected_by_config? => true)
- end
- it {@item.should be_selected}
- it "should not evaluate the subnav or urls" do
- @item.should_not_receive(:selected_by_subnav?)
- @item.should_not_receive(:selected_by_condition?)
- @item.selected?
- end
- end
- context 'not explicitly selected' do
- before(:each) do
- @item.stub!(:selected_by_config? => false)
- end
- context 'subnav is selected' do
- before(:each) do
- @item.stub!(:selected_by_subnav? => true)
- end
- it {@item.should be_selected}
- end
- context 'subnav is not selected' do
- before(:each) do
- @item.stub!(:selected_by_subnav? => false)
- end
- context 'selected by condition' do
- before(:each) do
- @item.stub!(:selected_by_condition? => true)
- end
- it {@item.should be_selected}
- end
- context 'not selected by condition' do
- before(:each) do
- @item.stub!(:selected_by_condition? => false)
- end
- it {@item.should_not be_selected}
- end
- end
- end
- end
-
- describe 'selected_class' do
- context 'selected_class is defined in context' do
- before(:each) do
- @item_container = stub(:item_container, :level => 1, :selected_class => 'context_defined').as_null_object
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
- @item.stub!(:selected? => true)
- end
- it {@item.instance_eval {selected_class.should == 'context_defined'}}
- end
- context 'item is selected' do
- before(:each) do
- @item.stub!(:selected? => true)
- end
- it {@item.instance_eval {selected_class.should == 'selected'}}
- end
-
- context 'item is not selected' do
- before(:each) do
- @item.stub!(:selected? => false)
- end
- it {@item.instance_eval {selected_class.should == nil}}
- end
- end
-
- describe 'html_options' do
- describe 'class' do
- context 'with classes defined in options' do
- before(:each) do
- @options = {:class => 'my_class'}
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
- end
- context 'with item selected' do
- before(:each) do
- @item.stub!(:selected? => true, :selected_by_condition? => true)
- end
- it {@item.html_options[:class].should == 'my_class selected simple-navigation-active-leaf'}
- end
-
- context 'with item not selected' do
- before(:each) do
- @item.stub!(:selected? => false, :selected_by_condition? => false)
- end
- it {@item.html_options[:class].should == 'my_class'}
- end
- end
-
- context 'without classes in options' do
- before(:each) do
- @options = {}
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', @options)
- end
- context 'with item selected' do
- before(:each) do
- @item.stub!(:selected? => true, :selected_by_condition? => true)
- end
- it {@item.html_options[:class].should == 'selected simple-navigation-active-leaf'}
- end
-
- context 'with item not selected' do
- before(:each) do
- @item.stub!(:selected? => false, :selected_by_condition? => false)
- end
- it {@item.html_options[:class].should be_blank}
- end
- end
-
- end
-
- describe 'id' do
- context 'with autogenerate_item_ids == true' do
- before(:each) do
- @item.stub!(:autogenerate_item_ids? => true)
- @item.stub!(:selected? => false, :selected_by_condition? => false)
- end
- context 'with id defined in options' do
- before(:each) do
- @item.html_options = {:id => 'my_id'}
- end
- it {@item.html_options[:id].should == 'my_id'}
- end
-
- context 'with no id defined in options (using default id)' do
- before(:each) do
- @item.html_options = {}
- end
- it {@item.html_options[:id].should == 'my_key'}
- end
- end
-
- context 'with autogenerate_item_ids == false' do
- before(:each) do
- @item.stub!(:autogenerate_item_ids? => false)
- @item.stub!(:selected? => false, :selected_by_condition? => false)
- end
- context 'with id defined in options' do
- before(:each) do
- @item.html_options = {:id => 'my_id'}
- end
- it {@item.html_options[:id].should == 'my_id'}
- end
-
- context 'with no id definied in options (using default id)' do
- before(:each) do
- @item.html_options = {}
- end
- it {@item.html_options[:id].should be_nil}
- end
-
- end
-
- end
-
- end
-
- describe 'selected_by_subnav?' do
- context 'item has subnav' do
- before(:each) do
- @sub_navigation = stub(:sub_navigation)
- @item.stub!(:sub_navigation => @sub_navigation)
- end
- it "should return true if subnav is selected" do
- @sub_navigation.stub!(:selected? => true, :selected_by_condition? => true)
- @item.should be_selected_by_subnav
- end
- it "should return false if subnav is not selected" do
- @sub_navigation.stub!(:selected? => false, :selected_by_condition? => true)
- @item.should_not be_selected_by_subnav
- end
- end
- context 'item does not have subnav' do
- before(:each) do
- @item.stub!(:sub_navigation => @sub_navigation)
- end
- it {@item.should_not be_selected_by_subnav}
- end
- end
-
- describe 'selected_by_condition?' do
- context ':highlights_on option is set' do
- before(:each) do
- @item.stub!(:highlights_on => /^\/current/)
- SimpleNavigation.stub!(:request_uri => '/current_url')
- end
- it "should not check for autohighlighting" do
- @item.should_not_receive(:auto_highlight?)
- @item.send(:selected_by_condition?)
- end
- context ':highlights_on is a regexp' do
- context 'regexp matches current_url' do
- it {@item.send(:selected_by_condition?).should be_true}
- end
- context 'regexp does not match current_url' do
- before(:each) do
- @item.stub!(:highlights_on => /^\/no_match/)
- end
- it {@item.send(:selected_by_condition?).should be_false}
- end
- end
- context ':highlights_on is a lambda' do
- context 'truthy lambda results in selection' do
- before(:each) do
- @item.stub!(:highlights_on => lambda{true})
- end
- it {@item.send(:selected_by_condition?).should be_true}
- end
- context 'falsey lambda results in no selection' do
- before(:each) do
- @item.stub!(:highlights_on => lambda{false})
- end
- it {@item.send(:selected_by_condition?).should be_false}
- end
- end
- context ':highlights_on is :subpath' do
- before(:each) do
- @item.stub!(:url => '/resources')
- @item.stub!(:highlights_on => :subpath)
- end
- context 'we are in a route beginning with this item path' do
- before(:each) do
- SimpleNavigation.stub!(:request_uri => '/resources/id')
- end
- it {@item.send(:selected_by_condition?).should be_true}
- end
- context 'we are in a route that has a similar name' do
- before(:each) do
- SimpleNavigation.stub!(:request_uri => '/resources_group/id')
- end
- it {@item.send(:selected_by_condition?).should be_false}
- end
- context 'we are in a route not beginning with this item path' do
- before(:each) do
- SimpleNavigation.stub!(:request_uri => '/another_resource/id')
- end
- it {@item.send(:selected_by_condition?).should be_false}
- end
- end
- context ':highlights_on is not a regexp or a proc' do
- before(:each) do
- @item.stub!(:highlights_on => "not a regexp")
- end
- it "should raise an error" do
- lambda {@item.send(:selected_by_condition?).should raise_error(ArgumentError)}
- end
- end
- end
- context ':highlights_on option is not set' do
- before(:each) do
- @item.stub!(:highlights_on => nil)
- end
- it "should check for autohighlighting" do
- @item.should_receive(:auto_highlight?)
- @item.send(:selected_by_condition?)
- end
- end
- context 'auto_highlight is turned on' do
- before(:each) do
- @item.stub!(:auto_highlight? => true)
- end
- context 'root path matches' do
- before(:each) do
- @item.stub!(:root_path_match? => true)
- end
- it {@item.send(:selected_by_condition?).should be_true}
- end
- context 'root path does not match' do
- before(:each) do
- @item.stub!(:root_path_match? => false)
- end
- context 'current request url matches url' do
- before(:each) do
- @adapter.stub!(:current_page? => true)
- end
- it "should test with the item's url" do
- @adapter.should_receive(:current_page?).with('url')
- @item.send(:selected_by_condition?)
- end
- it "should remove anchors before testing the item's url" do
- @item.stub!(:url => 'url#anchor')
- @adapter.should_receive(:current_page?).with('url')
- @item.send(:selected_by_condition?)
- end
- it "should not be queried when url is nil" do
- @item.stub!(:url => nil)
- @adapter.should_not_receive(:current_page?)
- @item.send(:selected_by_condition?)
- end
- it {@item.send(:selected_by_condition?).should be_true}
- end
- context 'no match' do
- before(:each) do
- @adapter.stub!(:current_page? => false)
- end
- it {@item.send(:selected_by_condition?).should be_false}
- end
- end
- end
- context 'auto_highlight is turned off' do
- before(:each) do
- @item.stub!(:auto_highlight? => false)
- end
- it {@item.send(:selected_by_condition?).should be_false}
- end
- end
-
- describe 'root_path_match?' do
- it "should match if both url == /" do
- @adapter.stub!(:request_path => '/')
- @item.stub!(:url => '/')
- @item.send(:root_path_match?).should be_true
- end
- it "should not match if item url is not /" do
- @adapter.stub(:request_path => '/')
- @item.stub!(:url => '/bla')
- @item.send(:root_path_match?).should be_false
- end
- it "should not match if request url is not /" do
- @adapter.stub(:request_path => '/bla')
- @item.stub!(:url => '/')
- @item.send(:root_path_match?).should be_false
- end
- it "should not match if urls do not match" do
- @adapter.stub(:request_path => 'bla')
- @item.stub!(:url => '/bli')
- @item.send(:root_path_match?).should be_false
- end
- it "should not match if url is nil" do
- @adapter.stub(:request_path => 'bla')
- @item.stub!(:url => nil)
- @item.send(:root_path_match?).should be_false
- end
- end
-
- describe 'auto_highlight?' do
- before(:each) do
- @global = stub(:config)
- SimpleNavigation.stub!(:config => @global)
- end
- context 'global auto_highlight on' do
- before(:each) do
- @global.stub!(:auto_highlight => true)
- end
- context 'container auto_highlight on' do
- before(:each) do
- @item_container.stub!(:auto_highlight => true)
- end
- it {@item.send(:auto_highlight?).should be_true}
- end
- context 'container auto_highlight off' do
- before(:each) do
- @item_container.stub!(:auto_highlight => false)
- end
- it {@item.send(:auto_highlight?).should be_false}
- end
- end
- context 'global auto_highlight off' do
- before(:each) do
- @global.stub!(:auto_highlight => false)
- end
- context 'container auto_highlight on' do
- before(:each) do
- @item_container.stub!(:auto_highlight => true)
- end
- it {@item.send(:auto_highlight?).should be_false}
- end
- context 'container auto_highlight off' do
- before(:each) do
- @item_container.stub!(:auto_highlight => false)
- end
- it {@item.send(:auto_highlight?).should be_false}
- end
- end
- end
-
- describe 'autogenerated_item_id' do
- context 'calls' do
- before(:each) do
- @id_generator = stub(:id_generator)
- SimpleNavigation.config.stub!(:id_generator => @id_generator)
- end
- it "should call the configured generator with the key as param" do
- @id_generator.should_receive(:call).with(:my_key)
- @item.send(:autogenerated_item_id)
- end
- end
- context 'default generator' do
- it {@item.send(:autogenerated_item_id).should == 'my_key'}
- end
- end
-
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/items_provider_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/items_provider_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/core/items_provider_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/core/items_provider_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,60 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::ItemsProvider do
-
- before(:each) do
- @provider = stub(:provider)
- @items_provider = SimpleNavigation::ItemsProvider.new(@provider)
- end
-
- describe 'initialize' do
- it "should set the provider" do
- @items_provider.provider.should == @provider
- end
- end
-
- describe 'items' do
- before(:each) do
- @items = stub(:items)
- end
- context 'provider is symbol' do
- before(:each) do
- @items_provider.instance_variable_set(:@provider, :provider_method)
- @context = stub(:context, :provider_method => @items)
- SimpleNavigation.stub!(:context_for_eval => @context)
- end
- it "should call the method specified by symbol on the context" do
- @context.should_receive(:provider_method)
- @items_provider.items
- end
- it "should return the items returned by the helper method" do
- @items_provider.items.should == @items
- end
- end
- context 'provider responds to items' do
- before(:each) do
- @provider.stub!(:items => @items)
- end
- it "should get the items from the items_provider" do
- @provider.should_receive(:items)
- @items_provider.items
- end
- it "should return the items of the provider" do
- @items_provider.items.should == @items
- end
- end
- context 'provider is a collection' do
- before(:each) do
- @items_collection = []
- @items_provider.instance_variable_set(:@provider, @items_collection)
- end
- it "should return the collection itsself" do
- @items_provider.items.should == @items_collection
- end
- end
- context 'neither symbol nor items_provider.items nor collection' do
- it {lambda {@items_provider.items}.should raise_error}
- end
- end
-
-end
\ No newline at end of file
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rails_controller_methods_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rails_controller_methods_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rails_controller_methods_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rails_controller_methods_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,249 +0,0 @@
-require 'spec_helper'
-
-describe 'explicit navigation in rails' do
- require 'simple_navigation/rails_controller_methods'
-
- it 'should have enhanced the ActionController after loading the extensions' do
- ActionController::Base.instance_methods.map {|m| m.to_s}.should include('current_navigation')
- end
-
- describe SimpleNavigation::ControllerMethods do
-
- def stub_loading_config
- SimpleNavigation::Configuration.stub!(:load)
- end
-
- before(:each) do
- stub_loading_config
- class TestController
- class << self
- def helper_method(*args)
- @helper_methods = args
- end
- def before_filter(*args)
- @before_filters = args
- end
- end
- end
- TestController.send(:include, SimpleNavigation::ControllerMethods)
- @controller = TestController.new
- end
-
- describe 'when being included' do
- it "should extend the ClassMethods" do
- @controller.class.should respond_to(:navigation)
- end
- it "should include the InstanceMethods" do
- @controller.should respond_to(:current_navigation)
- end
- end
-
- describe 'class_methods' do
-
- describe 'navigation' do
-
- def call_navigation(key1, key2=nil)
- @controller.class_eval do
- navigation key1, key2
- end
- end
-
- it "should not have an instance-method 'sn_set_navigation' if navigation-method has not been called" do
- @controller.respond_to?(:sn_set_navigation).should be_false
- end
- it 'should create an instance-method "sn_set_navigation" when being called' do
- call_navigation(:key)
- @controller.respond_to?(:sn_set_navigation, true).should be_true
- end
- it "the created method should not be public" do
- call_navigation(:key)
- @controller.public_methods.map(&:to_sym).should_not include(:sn_set_navigation)
- end
- it "the created method should be protected" do
- call_navigation(:key)
- @controller.protected_methods.map(&:to_sym).should include(:sn_set_navigation)
- end
- it 'the created method should call current_navigation with the specified keys' do
- call_navigation(:primary, :secondary)
- @controller.should_receive(:current_navigation).with(:primary, :secondary)
- @controller.send(:sn_set_navigation)
- end
- end
-
- end
-
- describe 'instance_methods' do
-
- describe 'current_navigation' do
- it "should set the sn_current_navigation_args as specified" do
- @controller.current_navigation(:first)
- @controller.instance_variable_get(:@sn_current_navigation_args).should == [:first]
- end
- it "should set the sn_current_navigation_args as specified" do
- @controller.current_navigation(:first, :second)
- @controller.instance_variable_get(:@sn_current_navigation_args).should == [:first, :second]
- end
- end
-
- end
-
- end
-
- describe 'SimpleNavigation module additions' do
-
- describe 'handle_explicit_navigation' do
- def args(*args)
- SimpleNavigation.stub!(:explicit_navigation_args => args.compact.empty? ? nil : args)
- end
-
- before(:each) do
- @controller = stub(:controller)
- @adapter = stub(:adapter, :controller => @controller)
- SimpleNavigation.stub!(:adapter => @adapter)
- end
-
- context 'with explicit navigation set' do
- context 'list of navigations' do
- before(:each) do
- args :first, :second, :third
- end
- it "should set the correct instance var in the controller" do
- @controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_3, :third)
- SimpleNavigation.handle_explicit_navigation
- end
- end
- context 'single navigation' do
- context 'specified key is a valid navigation item' do
- before(:each) do
- @primary = stub(:primary, :level_for_item => 2)
- SimpleNavigation.stub!(:primary_navigation => @primary)
- args :key
- end
- it "should set the correct instance var in the controller" do
- @controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_2, :key)
- SimpleNavigation.handle_explicit_navigation
- end
- end
- context 'specified key is an invalid navigation item' do
- before(:each) do
- @primary = stub(:primary, :level_for_item => nil)
- SimpleNavigation.stub!(:primary_navigation => @primary)
- args :key
- end
- it "should raise an ArgumentError" do
- lambda {SimpleNavigation.handle_explicit_navigation}.should raise_error(ArgumentError)
- end
- end
- end
- context 'hash with level' do
- before(:each) do
- args :level_2 => :key
- end
- it "should set the correct instance var in the controller" do
- @controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_2, :key)
- SimpleNavigation.handle_explicit_navigation
- end
- end
- context 'hash with multiple_levels' do
- before(:each) do
- args :level_2 => :key, :level_1 => :bla
- end
- it "should set the correct instance var in the controller" do
- @controller.should_receive(:instance_variable_set).with(:@sn_current_navigation_2, :key)
- SimpleNavigation.handle_explicit_navigation
- end
- end
- end
- context 'without explicit navigation set' do
- before(:each) do
- args nil
- end
- it "should not set the current_navigation instance var in the controller" do
- @controller.should_not_receive(:instance_variable_set)
- SimpleNavigation.handle_explicit_navigation
- end
- end
- end
-
- describe 'current_navigation_for' do
- before(:each) do
- @controller = stub(:controller)
- @adapter = stub(:adapter, :controller => @controller)
- SimpleNavigation.stub!(:adapter => @adapter)
- end
- it "should access the correct instance_var in the controller" do
- @controller.should_receive(:instance_variable_get).with(:@sn_current_navigation_1)
- SimpleNavigation.current_navigation_for(1)
- end
- end
-
- end
-
- describe SimpleNavigation::Item do
- before(:each) do
- @item_container = stub(:item_container, :level => 1)
- @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
-
- end
- describe 'selected_by_config?' do
- context 'navigation explicitly set' do
- it "should return true if current matches key" do
- SimpleNavigation.stub!(:current_navigation_for => :my_key)
- @item.should be_selected_by_config
- end
- it "should return false if current does not match key" do
- SimpleNavigation.stub!(:current_navigation_for => :other_key)
- @item.should_not be_selected_by_config
- end
- end
- context 'navigation not explicitly set' do
- before(:each) do
- SimpleNavigation.stub!(:current_navigation_for => nil)
- end
- it {@item.should_not be_selected_by_config}
- end
- end
- end
-
- describe SimpleNavigation::ItemContainer do
- describe 'selected_item' do
- before(:each) do
- SimpleNavigation.stub!(:current_navigation_for)
- @item_container = SimpleNavigation::ItemContainer.new
-
- @item_1 = stub(:item, :selected? => false)
- @item_2 = stub(:item, :selected? => false)
- @item_container.instance_variable_set(:@items, [@item_1, @item_2])
- end
- context 'navigation explicitely set' do
- before(:each) do
- @item_container.stub!(:[] => @item_1)
- end
- it "should return the explicitely selected item" do
- @item_container.selected_item.should == @item_1
- end
- end
- context 'navigation not explicitely set' do
- before(:each) do
- @item_container.stub!(:[] => nil)
- end
- context 'no item selected' do
- it "should return nil" do
- @item_container.selected_item.should be_nil
- end
- end
- context 'one item selected' do
- before(:each) do
- @item_1.stub!(:selected? => true)
- end
- it "should return the selected item" do
- @item_container.selected_item.should == @item_1
- end
- end
- end
- end
-
- end
-
-end
-
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/helpers_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/helpers_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/helpers_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/helpers_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,276 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::Helpers do
- class ControllerMock
- include SimpleNavigation::Helpers
- end
-
- def blackbox_setup()
- @controller = ControllerMock.new
- SimpleNavigation.stub!(:load_config)
- SimpleNavigation::Configuration.stub!(:eval_config)
- setup_adapter_for :rails
- @primary_container, @subnav_container = containers
- @subnav1_item = sub_item(:subnav1)
- @invoices_item = primary_item(:invoices)
- SimpleNavigation.stub!(:primary_navigation => @primary_container)
- end
-
- def whitebox_setup
- @controller = ControllerMock.new
- SimpleNavigation.stub!(:load_config)
- SimpleNavigation::Configuration.stub!(:eval_config)
- @primary_navigation = stub(:primary_navigation).as_null_object
- SimpleNavigation.stub!(:primary_navigation).and_return(@primary_navigation)
- SimpleNavigation.stub!(:config_file? => true)
- end
-
- describe 'active_navigation_item_name' do
- before(:each) do
- blackbox_setup
- end
- context 'active item_container for desired level exists' do
- context 'container has selected item' do
- before(:each) do
- select_item(:subnav1)
- end
- it {@controller.active_navigation_item_name(:level => 2).should == 'subnav1'}
- it {@controller.active_navigation_item_name.should == 'subnav1'}
- it {@controller.active_navigation_item_name(:level => 1).should == 'invoices'}
- it {@controller.active_navigation_item_name(:level => :all).should == 'subnav1'}
- end
- context 'container does not have selected item' do
- it {@controller.active_navigation_item_name.should == ''}
- end
- context 'custom name generator set' do
- before(:each) do
- select_item(:subnav1)
- SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "name"})
- end
- it "should not apply the generator" do
- @controller.active_navigation_item_name(:level => 1).should == 'invoices'
- end
- end
- end
- context 'no active item_container for desired level' do
- it {@controller.active_navigation_item_name(:level => 5).should == ''}
- end
- end
-
- describe 'active_navigation_item_key' do
- before(:each) do
- blackbox_setup
- end
- context 'active item_container for desired level exists' do
- context 'container has selected item' do
- before(:each) do
- select_item(:subnav1)
- end
- it {@controller.active_navigation_item_key(:level => 2).should == :subnav1}
- it {@controller.active_navigation_item_key.should == :subnav1}
- it {@controller.active_navigation_item_key(:level => 1).should == :invoices}
- it {@controller.active_navigation_item_key(:level => :all).should == :subnav1}
- end
- context 'container does not have selected item' do
- it {@controller.active_navigation_item_key.should == nil}
- end
- end
- context 'no active item_container for desired level' do
- it {@controller.active_navigation_item_key(:level => 5).should == nil}
- end
- end
-
- describe 'active_navigation_item' do
- before(:each) do
- blackbox_setup
- end
- context 'active item_container for desired level exists' do
- context 'container has selected item' do
- before(:each) do
- select_item(:subnav1)
- end
- it {@controller.active_navigation_item(:level => 2).should eq(@subnav1_item)}
- it {@controller.active_navigation_item.should eq(@subnav1_item)}
- it {@controller.active_navigation_item(:level => 1).should eq(@invoices_item)}
- it {@controller.active_navigation_item(:level => :all).should eq(@subnav1_item)}
- end
- context 'container does not have selected item' do
- context 'return value defaults to nil' do
- it {@controller.active_navigation_item.should == nil}
- end
- context 'return value reflects passed in value' do
- it {@controller.active_navigation_item({},'none').should == 'none'}
- it {@controller.active_navigation_item({},@invoices_item).should eq(@invoices_item)}
- end
- end
- end
- context 'no active item_container for desired level' do
- it {@controller.active_navigation_item(:level => 5).should == nil}
- end
- end
-
- describe 'active_navigation_item_container' do
- before(:each) do
- blackbox_setup
- end
- context 'active item_container for desired level exists' do
- before(:each) do
- select_item(:subnav1)
- end
- it {@controller.active_navigation_item_container(:level => 2).should == @subnav_container}
- it {@controller.active_navigation_item_container.should == @primary_container}
- it {@controller.active_navigation_item_container(:level => 1).should == @primary_container}
- it {@controller.active_navigation_item_container(:level => :all).should == @primary_container}
- end
- context 'no active item_container for desired level' do
- it {@controller.active_navigation_item_container(:level => 5).should == nil}
- end
- end
-
- describe 'render_navigation' do
-
- before(:each) do
- whitebox_setup
- end
-
- describe 'regarding loading of the config-file' do
- context 'no options specified' do
- it "should load the config-file for the default context" do
- SimpleNavigation.should_receive(:load_config).with(:default)
- @controller.render_navigation
- end
- end
-
- context 'with options specified' do
- it "should load the config-file for the specified context" do
- SimpleNavigation.should_receive(:load_config).with(:my_context)
- @controller.render_navigation(:context => :my_context)
- end
- end
- end
-
- it "should eval the config on every request" do
- SimpleNavigation::Configuration.should_receive(:eval_config).with(:default)
- @controller.render_navigation
- end
-
- describe 'regarding setting of items' do
- context 'not items specified in options' do
- it "should not set the items directly" do
- SimpleNavigation.config.should_not_receive(:items)
- @controller.render_navigation
- end
- end
- context 'items specified in options' do
- before(:each) do
- @items = stub(:items)
- end
- it "should set the items directly" do
- SimpleNavigation.config.should_receive(:items).with(@items)
- @controller.render_navigation(:items => @items)
- end
- end
- context 'block given' do
- it 'should use block' do
- block_executed = 0
- expect do
- @controller.render_navigation do |menu|
- menu.class.should == SimpleNavigation::ItemContainer
- block_executed += 1
- end
- end.to change{block_executed}.by(1)
- end
- end
- end
-
- describe 'no primary navigation defined' do
- before(:each) do
- SimpleNavigation.stub!(:primary_navigation => nil)
- end
- it {lambda {@controller.render_navigation}.should raise_error}
- end
-
- context 'rendering of the item_container' do
- before(:each) do
- @active_item_container = stub(:item_container).as_null_object
- SimpleNavigation.stub!(:active_item_container_for => @active_item_container)
- end
- it "should lookup the active_item_container based on the level" do
- SimpleNavigation.should_receive(:active_item_container_for).with(:all)
- @controller.render_navigation
- end
- context 'active_item_container is nil' do
- before(:each) do
- SimpleNavigation.stub!(:active_item_container_for => nil)
- end
- it "should not call render" do
- @active_item_container.should_not_receive(:render)
- @controller.render_navigation
- end
- end
- context 'active_item_container is not nil' do
- it "should call render on the container" do
- @active_item_container.should_receive(:render)
- @controller.render_navigation
- end
- end
- end
-
- context 'primary' do
- it "should call render on the primary_navigation (specifying level through options)" do
- @primary_navigation.should_receive(:render).with(:level => 1)
- @controller.render_navigation(:level => 1)
- end
- end
-
- context 'secondary' do
- context 'with current_primary_navigation set' do
- before(:each) do
- @selected_item_container = stub(:selected_container).as_null_object
- SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
- end
- it "should find the selected sub_navigation for the specified level" do
- SimpleNavigation.should_receive(:active_item_container_for).with(2)
- @controller.render_navigation(:level => 2)
- end
- it "should find the selected sub_navigation for the specified level" do
- SimpleNavigation.should_receive(:active_item_container_for).with(1)
- @controller.render_navigation(:level => 1)
- end
- it "should call render on the active item_container" do
- @selected_item_container.should_receive(:render).with(:level => 2)
- @controller.render_navigation(:level => 2)
- end
- end
- context 'without an active item_container set' do
- before(:each) do
- SimpleNavigation.stub!(:active_item_container_for => nil)
- end
- it "should not raise an error" do
- lambda {@controller.render_navigation(:level => 2)}.should_not raise_error
- end
- end
-
- end
-
- context 'unknown level' do
- it "should raise an error" do
- lambda {@controller.render_navigation(:level => :unknown)}.should raise_error(ArgumentError)
- end
- end
-
- end
-
- describe "should treat :level and :levels options the same" do
- before(:each) do
- whitebox_setup
- @selected_item_container = stub(:selected_container).as_null_object
- SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
- end
- it "should pass a valid levels options as level" do
- @selected_item_container.should_receive(:render).with(:level => 2)
- @controller.render_navigation(:levels => 2)
- end
- end
-
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/base_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/base_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/base_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/base_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,199 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::Renderer::Base do
- before(:each) do
- @options = stub(:options).as_null_object
- @adapter = stub(:adapter)
- SimpleNavigation.stub!(:adapter => @adapter)
- @base_renderer = SimpleNavigation::Renderer::Base.new(@options)
- end
-
- describe 'delegated methods' do
- it {@base_renderer.should respond_to(:link_to)}
- it {@base_renderer.should respond_to(:content_tag)}
- end
-
- describe 'initialize' do
- it {@base_renderer.adapter.should == @adapter}
- it {@base_renderer.options.should == @options}
- end
-
- describe 'render' do
- it "be subclass responsability" do
- lambda {@base_renderer.render(:container)}.should raise_error('subclass responsibility')
- end
- end
-
- describe 'expand_all?' do
- context 'option is set' do
- context 'expand_all is true' do
- before(:each) do
- @base_renderer.stub!(:options => {:expand_all => true})
- end
- it {@base_renderer.expand_all?.should be_true}
- end
- context 'expand_all is false' do
- before(:each) do
- @base_renderer.stub!(:options => {:expand_all => false})
- end
- it {@base_renderer.expand_all?.should be_false}
- end
- end
- context 'option is not set' do
- before(:each) do
- @base_renderer.stub!(:options => {})
- end
- it {@base_renderer.expand_all?.should be_false}
- end
- end
-
- describe 'skip_if_empty?' do
- context 'option is set' do
- context 'skip_if_empty is true' do
- before(:each) do
- @base_renderer.stub!(:options => {:skip_if_empty => true})
- end
- it {@base_renderer.skip_if_empty?.should be_true}
- end
- context 'skip_if_empty is false' do
- before(:each) do
- @base_renderer.stub!(:options => {:skip_if_empty => false})
- end
- it {@base_renderer.skip_if_empty?.should be_false}
- end
- end
- context 'option is not set' do
- before(:each) do
- @base_renderer.stub!(:options => {})
- end
- it {@base_renderer.skip_if_empty?.should be_false}
- end
- end
-
- describe 'level' do
- context 'options[level] is set' do
- before(:each) do
- @base_renderer.stub!(:options => {:level => 1})
- end
- it {@base_renderer.level.should == 1}
- end
- context 'options[level] is not set' do
- before(:each) do
- @base_renderer.stub!(:options => {})
- end
- it {@base_renderer.level.should == :all}
- end
- end
-
- describe 'consider_sub_navigation?' do
- before(:each) do
- @item = stub(:item)
- end
- context 'item has no subnavigation' do
- before(:each) do
- @item.stub!(:sub_navigation => nil)
- end
- it {@base_renderer.send(:consider_sub_navigation?, @item).should be_false}
- end
- context 'item has subnavigation' do
- before(:each) do
- @sub_navigation = stub(:sub_navigation)
- @item.stub!(:sub_navigation => @sub_navigation)
- end
- context 'level is something unknown' do
- before(:each) do
- @base_renderer.stub!(:level => 'unknown')
- end
- it {@base_renderer.send(:consider_sub_navigation?, @item).should be_false}
- end
- context 'level is :all' do
- before(:each) do
- @base_renderer.stub!(:level => :all)
- end
- it {@base_renderer.send(:consider_sub_navigation?, @item).should be_true}
- end
- context 'level is an Integer' do
- before(:each) do
- @base_renderer.stub!(:level => 2)
- end
- it {@base_renderer.send(:consider_sub_navigation?, @item).should be_false}
- end
- context 'level is a Range' do
- before(:each) do
- @base_renderer.stub!(:level => 2..3)
- end
- context 'subnavs level > range.max' do
- before(:each) do
- @sub_navigation.stub!(:level => 4)
- end
- it {@base_renderer.send(:consider_sub_navigation?, @item).should be_false}
- end
- context 'subnavs level = range.max' do
- before(:each) do
- @sub_navigation.stub!(:level => 3)
- end
- it {@base_renderer.send(:consider_sub_navigation?, @item).should be_true}
-
- end
- context 'subnavs level < range.max' do
- before(:each) do
- @sub_navigation.stub!(:level => 2)
- end
- it {@base_renderer.send(:consider_sub_navigation?, @item).should be_true}
- end
- end
- end
- end
-
- describe 'include_sub_navigation?' do
- before(:each) do
- @item = stub(:item)
- end
- context 'consider_sub_navigation? is true' do
- before(:each) do
- @base_renderer.stub!(:consider_sub_navigation? => true)
- end
- context 'expand_sub_navigation? is true' do
- before(:each) do
- @base_renderer.stub!(:expand_sub_navigation? => true)
- end
- it {@base_renderer.include_sub_navigation?(@item).should be_true}
- end
- context 'expand_sub_navigation? is false' do
- before(:each) do
- @base_renderer.stub!(:expand_sub_navigation? => false)
- end
- it {@base_renderer.include_sub_navigation?(@item).should be_false}
- end
- end
- context 'consider_sub_navigation is false' do
- before(:each) do
- @base_renderer.stub!(:consider_sub_navigation? => false)
- end
- context 'expand_sub_navigation? is true' do
- before(:each) do
- @base_renderer.stub!(:expand_sub_navigation? => true)
- end
- it {@base_renderer.include_sub_navigation?(@item).should be_false}
- end
- context 'expand_sub_navigation? is false' do
- before(:each) do
- @base_renderer.stub!(:expand_sub_navigation? => false)
- end
- it {@base_renderer.include_sub_navigation?(@item).should be_false}
- end
- end
- end
-
- describe 'render_sub_navigation_for' do
- before(:each) do
- @sub_navigation = stub(:sub_navigation)
- @item = stub(:item, :sub_navigation => @sub_navigation)
- end
- it "should call render on the sub_navigation (passing the options)" do
- @sub_navigation.should_receive(:render).with(@options)
- @base_renderer.render_sub_navigation_for(@item)
- end
- end
-
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,101 +0,0 @@
-require 'spec_helper'
-require 'html/document'# unless defined? HTML::Document
-
-describe SimpleNavigation::Renderer::Breadcrumbs do
-
- describe 'render' do
-
- def render(current_nav=nil, options={:level => :all})
- primary_navigation = primary_container
- select_item(current_nav) if current_nav
- setup_renderer_for SimpleNavigation::Renderer::Breadcrumbs, :rails, options
- HTML::Document.new(@renderer.render(primary_navigation)).root
- end
-
- context 'regarding result' do
-
- it "should render a div-tag around the items" do
- HTML::Selector.new('div').select(render).should have(1).entries
- end
- it "the rendered div-tag should have the specified dom_id" do
- HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
- end
- it "the rendered div-tag should have the specified class" do
- HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
- end
-
- context 'without current_navigation set' do
- it "should not render any a-tag in the div-tag" do
- HTML::Selector.new('div a').select(render).should have(0).entries
- end
- end
-
- context 'with current_navigation set' do
- before(:each) do
- @selection = HTML::Selector.new('div a').select(render(:invoices))
- end
- it "should render the selected a tags" do
- @selection.should have(1).entries
- end
-
- it "should not render class or id" do
- @selection.each do |tag|
- raise unless tag.name == "a"
- tag["id"].should be_nil
- tag["class"].should be_nil
- end
- end
-
- context 'with allow_classes_and_ids option' do
- before(:each) do
- @selection = HTML::Selector.new('div a').select(render(:users, :level => :all, :allow_classes_and_ids => true))
- end
- it "should render class and id" do
- @selection.each do |tag|
- raise unless tag.name == "a"
- tag["id"].should_not be_nil
- tag["class"].should_not be_nil
- end
- end
- end
-
- context 'with prefix option' do
- it 'should render prefix before breadcrumbs' do
- selection = HTML::Selector.new('div').select(render(:subnav1, :level => :all, :prefix => 'You are here: '))
- raise unless selection.count == 1
- tag = selection.first
- tag.to_s.should =~ /^\You are here\: /
- end
-
- it 'should not render prefix if there is no available breadcrumb' do
- allow_message_expectations_on_nil
- selection = HTML::Selector.new('div').select(render('', :prefix => 'You are here: '))
- tag = selection.first
- tag.to_s.should =~ /^\\<\/div\>/
- end
- end
-
- context 'with static_leaf option' do
- before(:each) do
- @selection = HTML::Selector.new('div *').select(render(:subnav1, :level => :all, :static_leaf => true))
- end
- it "should render link for non-leaes" do
- @selection[0..-2].each do |tag|
- tag.name.should == 'a'
- end
- end
- it "should not render link for leaf" do
- @selection.last.name.should == 'span'
- end
- end
- end
-
-
- context 'nested sub_navigation' do
- it "should add an a tag for each selected item" do
- HTML::Selector.new('div a').select(render(:subnav1)).should have(2).entries
- end
- end
- end
- end
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/json_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/json_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/json_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/json_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,48 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::Renderer::Json do
-
- describe 'render' do
-
- def render(current_nav=nil, options={})
- primary_navigation = primary_container
- select_item(current_nav)
- setup_renderer_for SimpleNavigation::Renderer::Json, :rails, options
- @renderer.render(primary_navigation)
- end
-
- def prerendered_menu
- '[{"name":"users","url":"first_url","selected":false,"items":null},{"name":"invoices","url":"second_url","selected":true,"items":[{"name":"subnav1","url":"subnav1_url","selected":false,"items":null},{"name":"subnav2","url":"subnav2_url","selected":false,"items":null}]},{"name":"accounts","url":"third_url","selected":false,"items":null},{"name":"miscellany","url":null,"selected":false,"items":null}]'
- end
-
- context 'regarding result' do
-
- it "should return a string" do
- render(:invoices).class.should == String
- end
-
- it "should render the selected page" do
- json = parse_json(render(:invoices))
- found = json.any? do |item|
- item["name"] == "invoices" and item["selected"]
- end
- found.should == true
- end
-
- end
-
- context 'regarding hash result' do
- it "should return a hash" do
- render(:invoices, :as_hash => true).class.should == Array
- end
-
- it "should render the selected page" do
- found = render(:invoices, :as_hash => true).any? do |item|
- item[:name] == "invoices" and item[:selected]
- end
- found.should == true
- end
-
- end
- end
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/links_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/links_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/links_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/links_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,64 +0,0 @@
-require 'spec_helper'
-require 'html/document' unless defined? HTML::Document
-
-describe SimpleNavigation::Renderer::Links do
-
-
- describe 'render' do
-
- def render(current_nav=nil, options={:level => :all})
- primary_navigation = primary_container
- select_item(current_nav) if current_nav
- setup_renderer_for SimpleNavigation::Renderer::Links, :rails, options
- HTML::Document.new(@renderer.render(primary_navigation)).root
- end
-
- context 'regarding result' do
-
- it "should render a div-tag around the items" do
- HTML::Selector.new('div').select(render).should have(1).entries
- end
- it "the rendered div-tag should have the specified dom_id" do
- HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
- end
- it "the rendered div-tag should have the specified class" do
- HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
- end
- it "should render an a-tag for each item" do
- HTML::Selector.new('a').select(render).should have(3).entries
- end
- it "should pass the specified html_options to the a element" do
- HTML::Selector.new('a[style=float:right]').select(render).should have(1).entries
- end
- it "should give the a-tag the id specified in the html_options" do
- HTML::Selector.new('a#my_id').select(render).should have(1).entries
- end
- it "should give the a-tag the default id (stringified key) if no id is specified in the html_options" do
- HTML::Selector.new('a#invoices').select(render).should have(1).entries
- end
- it "should not apply the the default id where there is an id specified in the html_options" do
- HTML::Selector.new('a#users').select(render).should be_empty
- end
-
- context 'with current_navigation set' do
- it "should mark the matching a-item as selected (with the css_class specified in configuration)" do
- HTML::Selector.new('a.selected').select(render(:invoices)).should have(1).entries
- end
- end
-
- context 'without current_navigation set' do
- it "should not mark any of the items as selected" do
- HTML::Selector.new('a.selected').select(render).should be_empty
- end
- end
-
- context 'with a custom seperator specified' do
- it "should separate the items with the separator" do
- HTML::Selector.new('div').select_first(render(:subnav1, :join_with => " | ")).to_s.split(" | ").should have(4).entries
- end
- end
-
- end
-
- end
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/list_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/list_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/list_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/list_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,211 +0,0 @@
-require 'spec_helper'
-require 'html/document' unless defined? HTML::Document
-
-describe SimpleNavigation::Renderer::List do
-
- describe 'render' do
-
- def render(current_nav=nil, options={:level => :all})
- primary_navigation = primary_container
- select_item(current_nav) if current_nav
- setup_renderer_for SimpleNavigation::Renderer::List, :rails, options
- HTML::Document.new(@renderer.render(primary_navigation)).root
- end
-
- context 'regarding result' do
-
- it "should render a ul-tag around the items" do
- HTML::Selector.new('ul').select(render).should have(1).entries
- end
- it "the rendered ul-tag should have the specified dom_id" do
- HTML::Selector.new('ul#nav_dom_id').select(render).should have(1).entries
- end
- it "the rendered ul-tag should have the specified class" do
- HTML::Selector.new('ul.nav_dom_class').select(render).should have(1).entries
- end
- it "should render a li tag for each item" do
- HTML::Selector.new('li').select(render).should have(4).entries
- end
- it "should render an a-tag inside each li-tag (for items with links)" do
- HTML::Selector.new('li a').select(render).should have(3).entries
- end
- it "should render a span-tag inside each li-tag (for items without links)" do
- HTML::Selector.new('li span').select(render).should have(1).entries
- end
-
- context 'concerning item names' do
- context 'with a custom name generator defined' do
- before(:each) do
- SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "name"})
- end
- it "should apply the name generator" do
- HTML::Selector.new('li a span').select(render).should have(3).entries
- end
- end
- context 'no customer generator defined' do
- before(:each) do
- SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "name"})
- end
- it "should apply the name generator" do
- HTML::Selector.new('li a span').select(render).should have(0).entries
- end
- end
- end
-
- context 'concerning html attributes' do
- context 'default case (no options defined for link tag)' do
- it "should pass the specified html_options to the li element" do
- HTML::Selector.new('li[style=float:right]').select(render).should have(1).entries
- end
- it "should give the li the id specified in the html_options" do
- HTML::Selector.new('li#my_id').select(render).should have(1).entries
- end
- it "should give the li the default id (stringified key) if no id is specified in the html_options" do
- HTML::Selector.new('ul li#invoices').select(render).should have(1).entries
- end
- it "should not apply the the default id where there is an id specified in the html_options" do
- HTML::Selector.new('ul li#users').select(render).should be_empty
- end
- end
- context 'with attributes defined for the link tag as well' do
- it "should add the link attributes to the link" do
- HTML::Selector.new('a[style=float:left]').select(render).should have(1).entries
- end
- it "should add the li attributes to the li element" do
- HTML::Selector.new('li[style=float:right]').select(render).should have(1).entries
- end
- it "should give the li the default id (stringified key) if no id is specified in the html_options for the li-element" do
- HTML::Selector.new('ul li#invoices').select(render).should have(1).entries
- end
- it "should not apply the the default id where there is an id specified in the html_options for th li-element" do
- HTML::Selector.new('ul li#users').select(render).should be_empty
- end
- end
- end
-
- context 'with current_navigation set' do
- it "should mark the matching li-item as selected (with the css_class specified in configuration)" do
- HTML::Selector.new('li.selected').select(render(:invoices)).should have(1).entries
- end
- it "should also mark the links inside the selected li's as selected" do
- HTML::Selector.new('li.selected a.selected').select(render(:invoices)).should have(1).entries
- end
- end
-
- context 'without current_navigation set' do
- it "should not mark any of the items as selected" do
- HTML::Selector.new('li.selected').select(render).should be_empty
- end
- it "should not mark any links as selected" do
- HTML::Selector.new('a.selected').select(render).should be_empty
- end
- end
-
- context 'nested sub_navigation' do
- it "should nest the current_primary's subnavigation inside the selected li-element" do
- HTML::Selector.new('li.selected ul li').select(render(:invoices)).should have(2).entries
- end
- it "should be possible to identify sub items using an html selector (using ids)" do
- HTML::Selector.new('#invoices #subnav1').select(render(:invoices)).should have(1).entries
- end
- context 'expand_all => false' do
- it "should not render the invoices submenu if the user-primary is active" do
- HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => false)).should be_empty
- HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => false)).should be_empty
- end
- end
-
- context 'expand_all => true' do
- it "should render the invoices submenu even if the user-primary is active" do
- HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
- HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
- end
- end
-
- end
-
- context 'skip_if_empty' do
-
- def render_container(options={})
- setup_renderer_for SimpleNavigation::Renderer::List, :rails, options
- HTML::Document.new(@renderer.render(@container)).root
- end
-
- context 'container is empty' do
- before(:each) do
- @container = SimpleNavigation::ItemContainer.new(0)
- end
- context 'skip_if_empty is true' do
- it "should not render a ul tag for the empty container" do
- HTML::Selector.new('ul').select(render_container(:skip_if_empty => true)).should be_empty
- end
- end
- context 'skip_if_empty is false' do
- it "should render a ul tag for the empty container" do
- HTML::Selector.new('ul').select(render_container(:skip_if_empty => false)).should have(1).entry
- end
- end
- end
-
- context 'container is not empty' do
- before(:each) do
- @container = primary_container
- end
- context 'skip_if_empty is true' do
- it "should render a ul tag for the container" do
- HTML::Selector.new('ul').select(render_container(:skip_if_empty => true)).should have(1).entry
- end
- end
- context 'skip_if_empty is false' do
- it "should render a ul tag for the container" do
- HTML::Selector.new('ul').select(render_container(:skip_if_empty => false)).should have(1).entry
- end
- end
- end
- end
- end
-
- describe 'link_options_for' do
- before(:each) do
- setup_renderer_for SimpleNavigation::Renderer::List, :rails, {}
- end
- context 'no link options specified' do
- context 'method specified' do
- context 'item selected' do
- before(:each) do
- @item = stub(:item, :method => :delete, :selected_class => 'selected', :html_options => {})
- end
- it {@renderer.send(:link_options_for, @item).should == {:method => :delete, :class => 'selected'}}
- end
- context 'item not selected' do
- before(:each) do
- @item = stub(:item, :method => :delete, :selected_class => nil, :html_options => {})
- end
- it {@renderer.send(:link_options_for, @item).should == {:method => :delete}}
- end
- end
- context 'method not specified' do
- context 'item selected' do
- before(:each) do
- @item = stub(:item, :method => nil, :selected_class => 'selected', :html_options => {})
- end
- it {@renderer.send(:link_options_for, @item).should == {:class => 'selected'}}
- end
- context 'item not selected' do
- before(:each) do
- @item = stub(:item, :method => nil, :selected_class => nil, :html_options => {})
- end
- it {@renderer.send(:link_options_for, @item).should == {}}
- end
- end
- end
- context 'link options specified' do
- before(:each) do
- @item = stub(:item, :method => :delete, :selected_class => 'selected', :html_options => {:link => {:class => 'link_class', :style => 'float:left'}})
- end
- it {@renderer.send(:link_options_for, @item).should == {:method => :delete, :class => 'link_class selected', :style => 'float:left'}}
- end
- end
-
- end
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/text_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/text_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation/rendering/renderer/text_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation/rendering/renderer/text_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,41 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation::Renderer::Text do
-
- describe 'render' do
-
- def render(current_nav=nil, options={:level => :all})
- primary_navigation = primary_container
- select_item(current_nav)
- setup_renderer_for SimpleNavigation::Renderer::Text, :rails, options
- @renderer.render(primary_navigation)
- end
- context 'regarding result' do
-
- it "should render the selected page" do
- render(:invoices).should == "invoices"
- end
-
- context 'nested sub_navigation' do
- it "should add an entry for each selected item" do
- render(:subnav1).should == "invoices subnav1"
- end
- end
-
- context 'with a custom seperator specified' do
- it "should separate the items with the separator" do
- render(:subnav1, :join_with => " | ").should == "invoices | subnav1"
- end
- end
-
- context 'custom name generator is set' do
- before(:each) do
- SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "name"})
- end
- it "should not apply the name generator (since it is text only)" do
- render(:subnav1, :join_with => " | ").should == "invoices | subnav1"
- end
- end
- end
- end
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/lib/simple_navigation_spec.rb ruby-simple-navigation-4.0.3/spec/lib/simple_navigation_spec.rb
--- ruby-simple-navigation-3.11.0/spec/lib/simple_navigation_spec.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/lib/simple_navigation_spec.rb 1970-01-01 00:00:00.000000000 +0000
@@ -1,307 +0,0 @@
-require 'spec_helper'
-
-describe SimpleNavigation do
-
- before(:each) do
- SimpleNavigation.config_file_path = 'path_to_config'
- end
-
- describe 'config_file_name' do
- context 'for :default navigation_context' do
- it "should return the name of the default config file" do
- SimpleNavigation.config_file_name.should == 'navigation.rb'
- end
- end
- context 'for other navigation_context' do
- it "should return the name of the config file matching the specified context" do
- SimpleNavigation.config_file_name(:my_other_context).should == 'my_other_context_navigation.rb'
- end
- it "should convert camelcase-contexts to underscore" do
- SimpleNavigation.config_file_name(:WhyWouldYouDoThis).should == 'why_would_you_do_this_navigation.rb'
- end
- end
- end
-
- describe 'config_file_path=' do
- before(:each) do
- SimpleNavigation.config_file_paths = ['existing_path']
- end
- it "should override the config_file_paths" do
- SimpleNavigation.config_file_path = 'new_path'
- SimpleNavigation.config_file_paths.should == ['new_path']
- end
- end
-
- describe 'config_file' do
- context 'no config_file_paths are set' do
- before(:each) do
- SimpleNavigation.config_file_paths = []
- end
- it "should return nil" do
- SimpleNavigation.config_file.should be_nil
- end
- end
- context 'one config_file_path is set' do
- before(:each) do
- SimpleNavigation.config_file_paths = ['my_config_file_path']
- end
- context 'requested config file does exist' do
- before(:each) do
- File.stub!(:exists? => true)
- end
- it "should return the path to the config_file" do
- SimpleNavigation.config_file.should == 'my_config_file_path/navigation.rb'
- end
- end
- context 'requested config file does not exist' do
- before(:each) do
- File.stub!(:exists? => false)
- end
- it "should return nil" do
- SimpleNavigation.config_file.should be_nil
- end
- end
- end
- context 'multiple config_file_paths are set' do
- before(:each) do
- SimpleNavigation.config_file_paths = ['first_path', 'second_path']
- end
- context 'requested config file does exist' do
- before(:each) do
- File.stub!(:exists? => true)
- end
- it "should return the path to the first matching config_file" do
- SimpleNavigation.config_file.should == 'first_path/navigation.rb'
- end
- end
- context 'requested config file does not exist' do
- before(:each) do
- File.stub!(:exists? => false)
- end
- it "should return nil" do
- SimpleNavigation.config_file.should be_nil
- end
- end
- end
- end
-
- describe 'config_file?' do
- context 'config_file present' do
- before(:each) do
- SimpleNavigation.stub!(:config_file => 'file')
- end
- it {SimpleNavigation.config_file?.should be_true}
- end
- context 'config_file not present' do
- before(:each) do
- SimpleNavigation.stub!(:config_file => nil)
- end
- it {SimpleNavigation.config_file?.should be_false}
- end
- end
-
- describe 'self.default_config_file_path' do
- before(:each) do
- SimpleNavigation.stub!(:root => 'root')
- end
- it {SimpleNavigation.default_config_file_path.should == 'root/config'}
- end
-
- describe 'regarding renderers' do
- it "should have registered the builtin renderers by default" do
- SimpleNavigation.registered_renderers.should_not be_empty
- end
-
- describe 'register_renderer' do
- before(:each) do
- @renderer = stub(:renderer)
- end
- it "should add the specified renderer to the list of renderers" do
- SimpleNavigation.register_renderer(:my_renderer => @renderer)
- SimpleNavigation.registered_renderers[:my_renderer].should == @renderer
- end
- end
-
- end
-
- describe 'set_env' do
- before(:each) do
- SimpleNavigation.config_file_paths = []
- SimpleNavigation.stub!(:default_config_file_path => 'default_path')
- SimpleNavigation.set_env('root', 'my_env')
- end
- it "should set the root" do
- SimpleNavigation.root.should == 'root'
- end
- it "should set the environment" do
- SimpleNavigation.environment.should == 'my_env'
- end
- it "should add the default-config path to the list of config_file_paths" do
- SimpleNavigation.config_file_paths.should == ['default_path']
- end
- end
-
- describe 'load_config' do
- context 'config_file_path is set' do
- before(:each) do
- SimpleNavigation.stub!(:config_file => 'path_to_config_file')
- end
- context 'config_file does exist' do
- before(:each) do
- SimpleNavigation.stub!(:config_file? => true)
- IO.stub!(:read => 'file_content')
- end
- it "should not raise an error" do
- lambda{SimpleNavigation.load_config}.should_not raise_error
- end
- it "should read the specified config file from disc" do
- IO.should_receive(:read).with('path_to_config_file')
- SimpleNavigation.load_config
- end
- it "should store the read content in the module (default context)" do
- SimpleNavigation.should_receive(:config_file).with(:default)
- SimpleNavigation.load_config
- SimpleNavigation.config_files[:default].should == 'file_content'
- end
- it "should store the content in the module (non default context)" do
- SimpleNavigation.should_receive(:config_file).with(:my_context)
- SimpleNavigation.load_config(:my_context)
- SimpleNavigation.config_files[:my_context].should == 'file_content'
- end
- end
-
- context 'config_file does not exist' do
- before(:each) do
- SimpleNavigation.stub!(:config_file? => false)
- end
- it {lambda{SimpleNavigation.load_config}.should raise_error}
- end
- end
-
- context 'config_file_path is not set' do
- before(:each) do
- SimpleNavigation.config_file_path = nil
- end
- it {lambda{SimpleNavigation.load_config}.should raise_error}
- end
-
- describe 'regarding caching of the config-files' do
- before(:each) do
- IO.stub!(:read).and_return('file_content')
- SimpleNavigation.config_file_path = 'path_to_config'
- File.stub!(:exists? => true)
- end
- context "environment undefined" do
- before(:each) do
- SimpleNavigation.stub!(:environment => nil)
- end
- it "should load the config file twice" do
- IO.should_receive(:read).twice
- SimpleNavigation.load_config
- SimpleNavigation.load_config
- end
- end
- context "environment defined" do
- before(:each) do
- SimpleNavigation.stub!(:environment => 'production')
- end
- context "environment=production" do
- it "should load the config file only once" do
- IO.should_receive(:read).once
- SimpleNavigation.load_config
- SimpleNavigation.load_config
- end
- end
-
- context "environment=development" do
- before(:each) do
- SimpleNavigation.stub!(:environment => 'development')
- end
- it "should load the config file twice" do
- IO.should_receive(:read).twice
- SimpleNavigation.load_config
- SimpleNavigation.load_config
- end
- end
-
- context "environment=test" do
- before(:each) do
- SimpleNavigation.stub!(:environment => 'test')
- end
- it "should load the config file twice" do
- IO.should_receive(:read).twice
- SimpleNavigation.load_config
- SimpleNavigation.load_config
- end
- end
- end
- after(:each) do
- SimpleNavigation.config_files = {}
- end
- end
- end
-
- describe 'config' do
- it {SimpleNavigation.config.should == SimpleNavigation::Configuration.instance}
- end
-
- describe 'active_item_container_for' do
- before(:each) do
- @primary = stub(:primary)
- SimpleNavigation.config.stub!(:primary_navigation => @primary)
- end
- context 'level is :all' do
- it "should return the primary_navigation" do
- SimpleNavigation.active_item_container_for(:all).should == @primary
- end
- end
- context 'level is :leaves' do
- it "should return the currently active leaf-container" do
- @primary.should_receive(:active_leaf_container)
- SimpleNavigation.active_item_container_for(:leaves)
- end
- end
- context 'level is a Range' do
- it "should take the min of the range to lookup the active container" do
- @primary.should_receive(:active_item_container_for).with(2)
- SimpleNavigation.active_item_container_for(2..3)
- end
- end
- context 'level is an Integer' do
- it "should consider the Integer to lookup the active container" do
- @primary.should_receive(:active_item_container_for).with(1)
- SimpleNavigation.active_item_container_for(1)
- end
- end
- context 'level is something else' do
- it "should raise an ArgumentError" do
- lambda {SimpleNavigation.active_item_container_for('something else')}.should raise_error(ArgumentError)
- end
- end
- end
-
- describe 'load_adapter' do
- context 'Rails' do
- before(:each) do
- SimpleNavigation.stub!(:framework => :rails)
- SimpleNavigation.load_adapter
- end
- it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Rails}
- end
- context 'Padrino' do
- before(:each) do
- SimpleNavigation.stub!(:framework => :padrino)
- SimpleNavigation.load_adapter
- end
- it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Padrino}
- end
- context 'Sinatra' do
- before(:each) do
- SimpleNavigation.stub!(:framework => :sinatra)
- SimpleNavigation.load_adapter
- end
- it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Sinatra}
- end
- end
-
-end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/adapters/padrino_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/adapters/padrino_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/adapters/padrino_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/adapters/padrino_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,27 @@
+module SimpleNavigation
+ module Adapters
+ describe Padrino do
+ let(:adapter) { SimpleNavigation::Adapters::Padrino.new(context) }
+ let(:content) { double(:content) }
+ let(:context) { double(:context, request: request) }
+ let(:request) { double(:request) }
+
+ describe '#link_to' do
+ it 'delegates to context' do
+ expect(context).to receive(:link_to)
+ .with('name', 'url', :my_option => true)
+ adapter.link_to('name', 'url', :my_option => true)
+ end
+ end
+
+ describe '#content_tag' do
+ it 'delegates to context' do
+ expect(content).to receive(:html_safe).and_return('content')
+ expect(context).to receive(:content_tag)
+ .with('type', 'content', my_option: true)
+ adapter.content_tag('type', content, my_option: true)
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/adapters/rails_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/adapters/rails_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/adapters/rails_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/adapters/rails_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,281 @@
+module SimpleNavigation
+ module Adapters
+ describe Rails do
+ let(:action_controller) { ActionController::Base }
+ let(:adapter) { Rails.new(context) }
+ let(:context) { double(:context, controller: controller) }
+ let(:controller) { double(:controller) }
+ let(:request) { double(:request) }
+ let(:simple_navigation) { SimpleNavigation }
+ let(:template) { double(:template, request: request) }
+
+ describe '.register' do
+ before { allow(action_controller).to receive(:include) }
+
+ it 'calls set_env' do
+ app_path = RailsApp::Application.root
+ expect(simple_navigation).to receive(:set_env).with(app_path, 'test')
+ simple_navigation.register
+ end
+
+ it 'extends the ActionController::Base with the Helpers' do
+ expect(action_controller).to receive(:include)
+ .with(SimpleNavigation::Helpers)
+ simple_navigation.register
+ end
+
+ shared_examples 'installing helper method' do |method|
+ it "installs the #{method} method as helper method" do
+ simple_navigation.register
+
+ helper_methods = action_controller.send(:_helper_methods)
+ expect(helper_methods).to include(method)
+ end
+ end
+
+ it_behaves_like 'installing helper method', :render_navigation
+ it_behaves_like 'installing helper method', :active_navigation_item_name
+ it_behaves_like 'installing helper method', :active_navigation_item_key
+ it_behaves_like 'installing helper method', :active_navigation_item
+ it_behaves_like 'installing helper method', :active_navigation_item_container
+ end
+
+ describe '#initialize' do
+ context "when the controller's template is set" do
+ before { allow(controller).to receive_messages(instance_variable_get: template) }
+
+ it "sets the adapter's request accordingly" do
+ expect(adapter.request).to be request
+ end
+ end
+
+ context "when the controller's template is not set" do
+ before { allow(controller).to receive_messages(instance_variable_get: nil) }
+
+ it "sets the adapter's request to nil" do
+ expect(adapter.request).to be_nil
+ end
+ end
+
+ it "sets the adapter's controller to the context's controller" do
+ expect(adapter.controller).to be controller
+ end
+
+ context "when the controller's template is stored as instance var (Rails2)" do
+ context "when the controller's template is set" do
+ before { allow(controller).to receive_messages(instance_variable_get: template) }
+
+ it "sets the adapter's template accordingly" do
+ expect(adapter.template).to be template
+ end
+ end
+
+ context "when the controller's template is not set" do
+ before { allow(controller).to receive_messages(instance_variable_get: nil) }
+
+ it "set the adapter's template to nil" do
+ expect(adapter.template).to be_nil
+ end
+ end
+ end
+
+ context "when the controller's template is stored as view_context (Rails3)" do
+ context 'and the template is set' do
+ before { allow(controller).to receive_messages(view_context: template) }
+
+ it "sets the adapter's template accordingly" do
+ expect(adapter.template).to be template
+ end
+ end
+
+ context 'and the template is not set' do
+ before { allow(controller).to receive_messages(view_context: nil) }
+
+ it "sets the adapter's template to nil" do
+ expect(adapter.template).to be_nil
+ end
+ end
+ end
+ end
+
+ describe '#request_uri' do
+ context "when the adapter's request is set" do
+ before { allow(adapter).to receive_messages(request: request) }
+
+ context 'and request.fullpath is defined' do
+ let(:request) { double(:request, fullpath: '/fullpath') }
+
+ it "sets the adapter's request_uri to the request.fullpath" do
+ expect(adapter.request_uri).to eq '/fullpath'
+ end
+ end
+
+ context 'and request.fullpath is not defined' do
+ let(:request) { double(:request, request_uri: '/request_uri') }
+
+ before { allow(adapter).to receive_messages(request: request) }
+
+ it "sets the adapter's request_uri to the request.request_uri" do
+ expect(adapter.request_uri).to eq '/request_uri'
+ end
+ end
+ end
+
+ context "when the adapter's request is not set" do
+ before { allow(adapter).to receive_messages(request: nil) }
+
+ it "sets the adapter's request_uri to an empty string" do
+ expect(adapter.request_uri).to eq ''
+ end
+ end
+ end
+
+ describe '#request_path' do
+ context "when the adapter's request is set" do
+ let(:request) { double(:request, path: '/request_path') }
+
+ before { allow(adapter).to receive_messages(request: request) }
+
+ it "sets the adapter's request_path to the request.path" do
+ expect(adapter.request_path).to eq '/request_path'
+ end
+ end
+
+ context "when the adapter's request is not set" do
+ before { allow(adapter).to receive_messages(request: nil) }
+
+ it "sets the adapter's request_path to an empty string" do
+ expect(adapter.request_path).to eq ''
+ end
+ end
+ end
+
+ describe '#context_for_eval' do
+ context "when the adapter's controller is set" do
+ before { adapter.instance_variable_set(:@controller, controller) }
+
+ context "and the adapter's template is set" do
+ before { adapter.instance_variable_set(:@template, template) }
+
+ it "sets the adapter's context_for_eval to the template" do
+ expect(adapter.context_for_eval).to be template
+ end
+ end
+
+ context "and the adapter's template is not set" do
+ before { adapter.instance_variable_set(:@template, nil) }
+
+ it "sets the adapter's context_for_eval to the controller" do
+ expect(adapter.context_for_eval).to be controller
+ end
+ end
+ end
+
+ context "when the adapter's controller is not set" do
+ before { adapter.instance_variable_set(:@controller, nil) }
+
+ context "and the adapter's template is set" do
+ before { adapter.instance_variable_set(:@template, template) }
+
+ it "sets the adapter's context_for_eval to the template" do
+ expect(adapter.context_for_eval).to be template
+ end
+ end
+
+ context "and the adapter's template is not set" do
+ before { adapter.instance_variable_set(:@template, nil) }
+
+ it 'raises an exception' do
+ expect{ adapter.context_for_eval }.to raise_error
+ end
+ end
+ end
+ end
+
+ describe '#current_page?' do
+ context "when the adapter's template is set" do
+ before { allow(adapter).to receive_messages(template: template) }
+
+ it 'delegates the call to the template' do
+ expect(template).to receive(:current_page?).with(:page)
+ adapter.current_page?(:page)
+ end
+ end
+
+ context "when the adapter's template is not set" do
+ before { allow(adapter).to receive_messages(template: nil) }
+
+ it 'returns false' do
+ expect(adapter.current_page?(:page)).to be_falsey
+ end
+ end
+
+ context 'when the given url is nil' do
+ it 'returns false' do
+ expect(adapter.current_page?(nil)).to be_falsey
+ end
+ end
+ end
+
+ describe '#link_to' do
+ let(:options) { double(:options) }
+
+ context "when the adapter's template is set" do
+ before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
+
+ context 'with considering item names as safe' do
+ before { SimpleNavigation.config.consider_item_names_as_safe = true }
+ after { SimpleNavigation.config.consider_item_names_as_safe = false }
+
+ it 'delegates the call to the template (with html_safe text)' do
+ expect(template).to receive(:link_to)
+ .with('safe_text', 'url', options)
+ adapter.link_to('text', 'url', options)
+ end
+ end
+
+ context 'with considering item names as UNsafe (default)' do
+
+ it 'delegates the call to the template (with html_safe text)' do
+ expect(template).to receive(:link_to)
+ .with('text', 'url', options)
+ adapter.link_to('text', 'url', options)
+ end
+ end
+
+ end
+
+ context "when the adapter's template is not set" do
+ before { allow(adapter).to receive_messages(template: nil) }
+
+ it 'returns nil' do
+ expect(adapter.link_to('text', 'url', options)).to be_nil
+ end
+ end
+ end
+
+ describe '#content_tag' do
+ let(:options) { double(:options) }
+
+ context "when the adapter's template is set" do
+ before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
+
+ it 'delegates the call to the template (with html_safe text)' do
+ expect(template).to receive(:content_tag)
+ .with(:div, 'safe_text', options)
+ adapter.content_tag(:div, 'text', options)
+ end
+ end
+
+ context "when the adapter's template is not set" do
+ before { allow(adapter).to receive_messages(template: nil) }
+
+ it 'returns nil' do
+ expect(adapter.content_tag(:div, 'text', options)).to be_nil
+ end
+ end
+ end
+
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/adapters/sinatra_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/adapters/sinatra_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/adapters/sinatra_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/adapters/sinatra_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,89 @@
+describe SimpleNavigation::Adapters::Sinatra do
+ let(:adapter) { SimpleNavigation::Adapters::Sinatra.new(context) }
+ let(:context) { double(:context) }
+ let(:request) { double(:request, fullpath: '/full?param=true', path: '/full') }
+
+ before { allow(context).to receive_messages(request: request) }
+
+ describe '#context_for_eval' do
+ context "when adapter's context is not set" do
+ it 'raises an exception' do
+ allow(adapter).to receive_messages(context: nil)
+ expect{ adapter.context_for_eval }.to raise_error
+ end
+ end
+
+ context "when adapter's context is set" do
+ it 'returns the context' do
+ expect(adapter.context_for_eval).to be context
+ end
+ end
+ end
+
+ describe '#request_uri' do
+ it 'returns the request.fullpath' do
+ expect(adapter.request_uri).to eq '/full?param=true'
+ end
+ end
+
+ describe '#request_path' do
+ it 'returns the request.path' do
+ expect(adapter.request_path).to eq '/full'
+ end
+ end
+
+ describe '#current_page?' do
+ before { allow(request).to receive_messages(scheme: 'http', host_with_port: 'my_host:5000') }
+
+ shared_examples 'detecting current page' do |url, expected|
+ context "when url is #{url}" do
+ it "returns #{expected}" do
+ expect(adapter.current_page?(url)).to be expected
+ end
+ end
+ end
+
+ context 'when URL is not encoded' do
+ it_behaves_like 'detecting current page', '/full?param=true', true
+ it_behaves_like 'detecting current page', '/full?param3=true', false
+ it_behaves_like 'detecting current page', '/full', true
+ it_behaves_like 'detecting current page', 'http://my_host:5000/full?param=true', true
+ it_behaves_like 'detecting current page', 'http://my_host:5000/full?param3=true', false
+ it_behaves_like 'detecting current page', 'http://my_host:5000/full', true
+ it_behaves_like 'detecting current page', 'https://my_host:5000/full', false
+ it_behaves_like 'detecting current page', 'http://my_host:6000/full', false
+ it_behaves_like 'detecting current page', 'http://my_other_host:5000/full', false
+ end
+
+ context 'when URL is encoded' do
+ before do
+ allow(request).to receive_messages(fullpath: '/full%20with%20spaces?param=true',
+ path: '/full%20with%20spaces')
+ end
+
+ it_behaves_like 'detecting current page', '/full%20with%20spaces?param=true', true
+ it_behaves_like 'detecting current page', '/full%20with%20spaces?param3=true', false
+ it_behaves_like 'detecting current page', '/full%20with%20spaces', true
+ it_behaves_like 'detecting current page', 'http://my_host:5000/full%20with%20spaces?param=true', true
+ it_behaves_like 'detecting current page', 'http://my_host:5000/full%20with%20spaces?param3=true', false
+ it_behaves_like 'detecting current page', 'http://my_host:5000/full%20with%20spaces', true
+ it_behaves_like 'detecting current page', 'https://my_host:5000/full%20with%20spaces', false
+ it_behaves_like 'detecting current page', 'http://my_host:6000/full%20with%20spaces', false
+ it_behaves_like 'detecting current page', 'http://my_other_host:5000/full%20with%20spaces', false
+ end
+ end
+
+ describe '#link_to' do
+ it 'returns a link with the correct class and id' do
+ link = adapter.link_to('link', 'url', class: 'clazz', id: 'id')
+ expect(link).to eq "link"
+ end
+ end
+
+ describe '#content_tag' do
+ it 'returns a tag with the correct class and id' do
+ tag = adapter.content_tag(:div, 'content', class: 'clazz', id: 'id')
+ expect(tag).to eq "content
"
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/config_file_finder_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/config_file_finder_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/config_file_finder_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/config_file_finder_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,50 @@
+require 'fileutils'
+require 'simple_navigation/config_file_finder'
+
+module SimpleNavigation
+ describe ConfigFileFinder do
+ subject(:finder) { ConfigFileFinder.new(paths) }
+
+ let(:paths) { ['/path/one', '/path/two'] }
+
+ describe '#find', memfs: true do
+ before { FileUtils.mkdir_p(paths) }
+
+ context 'when the context is :default' do
+ let(:context) { :default }
+
+ context 'and a navigation.rb file is found in one of the paths' do
+ before { FileUtils.touch('/path/one/navigation.rb') }
+
+ it 'returns its full path' do
+ expect(finder.find(context)).to eq '/path/one/navigation.rb'
+ end
+ end
+
+ context 'and no navigation.rb file is found in the paths' do
+ it 'raises an exception' do
+ expect{ finder.find(context) }.to raise_error
+ end
+ end
+ end
+
+ context 'when the context is :other' do
+ let(:context) { :other }
+
+ context 'and a other_navigation.rb file is found in one of the paths' do
+ before { FileUtils.touch('/path/two/other_navigation.rb') }
+
+ it 'returns its full path' do
+ expect(finder.find(context)).to eq '/path/two/other_navigation.rb'
+ end
+ end
+
+ context 'and no other_navigation.rb file is found in the paths' do
+ it 'raise an exception' do
+ expect{ finder.find(context) }.to raise_error
+ end
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/config_file_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/config_file_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/config_file_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/config_file_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,25 @@
+require 'simple_navigation/config_file'
+
+module SimpleNavigation
+ describe ConfigFile do
+ subject(:config_file) { ConfigFile.new(context) }
+
+ let(:context) { :default }
+
+ describe '#name' do
+ context 'when the context is :default' do
+ it 'returns navigation.rb' do
+ expect(config_file.name).to eq 'navigation.rb'
+ end
+ end
+
+ context 'when the context is different from :default' do
+ let(:context) { :HelloWorld }
+
+ it 'returns UNDERSCORED_CONTEXT_navigation.rb' do
+ expect(config_file.name).to eq 'hello_world_navigation.rb'
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/configuration_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/configuration_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/configuration_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/configuration_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,164 @@
+module SimpleNavigation
+ describe Configuration do
+ subject(:config) { Configuration.instance }
+
+ describe '.run' do
+ it "yields the singleton Configuration object" do
+ expect{ |blk| Configuration.run(&blk) }.to yield_with_args(config)
+ end
+ end
+
+ describe '.eval_config' do
+ let(:config_files) {{ default: 'default', my_context: 'my_context' }}
+ let(:eval_context) { double(:eval_context) }
+
+ before do
+ allow(eval_context).to receive(:instance_eval)
+ allow(SimpleNavigation).to \
+ receive_messages(context_for_eval: eval_context, config_files: config_files)
+ end
+
+ context "with default navigation context" do
+ it "calls instance_eval with the default config_file-string inside the context" do
+ expect(eval_context).to receive(:instance_eval).with('default')
+ Configuration.eval_config
+ end
+ end
+
+ context 'with non default navigation context' do
+ it "calls instance_eval with the specified config_file-string inside the context" do
+ expect(eval_context).to receive(:instance_eval).with('my_context')
+ Configuration.eval_config(:my_context)
+ end
+ end
+ end
+
+ describe '#initialize' do
+ it 'sets the List-Renderer as default' do
+ expect(config.renderer).to be Renderer::List
+ end
+
+ it 'sets the selected_class to "selected" as default' do
+ expect(config.selected_class).to eq 'selected'
+ end
+
+ it 'sets the active_leaf_class to "simple-navigation-active-leaf" as default' do
+ expect(config.active_leaf_class).to eq 'simple-navigation-active-leaf'
+ end
+
+ it 'sets autogenerate_item_ids to true as default' do
+ expect(config.autogenerate_item_ids).to be true
+ end
+
+ it 'sets auto_highlight to true as default' do
+ expect(config.auto_highlight).to be true
+ end
+
+ it 'sets the id_generator to a callable object' do
+ expect(config.id_generator).to respond_to(:call)
+ end
+
+ it 'sets the name_generator to a callable object' do
+ expect(config.name_generator).to respond_to(:call)
+ end
+
+ it 'sets the consider_item_names_as_safe to false' do
+ expect(config.consider_item_names_as_safe).to be false
+ end
+
+ it 'sets highlights_on_subpath to false as default' do
+ expect(config.highlight_on_subpath).to be false
+ end
+
+ it 'sets ignore_query_params_on_auto_highlight to true as default' do
+ expect(config.ignore_query_params_on_auto_highlight).to be true
+ end
+
+ it 'sets ignore_anchors_on_auto_highlight to true as default' do
+ expect(config.ignore_anchors_on_auto_highlight).to be true
+ end
+ end
+
+ describe '#items' do
+ let(:container) { double(:items_container) }
+
+ before { allow(ItemContainer).to receive_messages(new: container) }
+
+ context 'when a block is given' do
+ context 'and items_provider is specified' do
+ let(:provider) { double(:provider) }
+
+ it 'raises an exception' do
+ expect{ config.items(provider) {} }.to raise_error
+ end
+ end
+
+ context 'when no items_provider is specified' do
+ it 'yields an new ItemContainer' do
+ expect{ |blk| config.items(&blk) }.to yield_with_args(container)
+ end
+
+ it 'assigns the ItemContainer to an instance-var' do
+ config.items {}
+ expect(config.primary_navigation).to be container
+ end
+
+ it "doesn't set the items on the container" do
+ expect(container).not_to receive(:items=)
+ config.items {}
+ end
+ end
+ end
+
+ context 'when no block is given' do
+ context 'and items_provider is specified' do
+ let(:external_provider) { double(:external_provider) }
+ let(:items) { double(:items) }
+ let(:items_provider) { double(:items_provider, items: items) }
+
+ before do
+ allow(SimpleNavigation::ItemsProvider).to receive_messages(new: items_provider)
+ allow(container).to receive(:items=)
+ end
+
+ it 'creates a new Provider object for the specified provider' do
+ expect(ItemsProvider).to receive(:new).with(external_provider)
+ config.items(external_provider)
+ end
+
+ it 'calls items on the provider object' do
+ expect(items_provider).to receive(:items)
+ config.items(external_provider)
+ end
+
+ it 'sets the items on the container' do
+ expect(container).to receive(:items=).with(items)
+ config.items(external_provider)
+ end
+ end
+
+ context 'when items_provider is not specified' do
+ it "raises an exception" do
+ expect{ config.items }.to raise_error
+ end
+ end
+ end
+ end
+
+ describe '#loaded?' do
+ context 'when primary_nav is set' do
+ it 'returns true' do
+ config.instance_variable_set(:@primary_navigation, :bla)
+ expect(config).to be_loaded
+ end
+ end
+
+ context 'when primary_nav is not set' do
+ it 'returns false if no primary_nav is set' do
+ config.instance_variable_set(:@primary_navigation, nil)
+ expect(config).not_to be_loaded
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/helpers_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/helpers_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/helpers_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/helpers_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,429 @@
+module SimpleNavigation
+ describe Helpers do
+ subject(:controller) { test_controller_class.new }
+
+ let(:invoices_item) { navigation[:invoices] }
+ let(:item) { nil }
+ let(:navigation) { setup_navigation('nav_id', 'nav_class') }
+ let(:test_controller_class) do
+ Class.new { include SimpleNavigation::Helpers }
+ end
+ let(:unpaid_item) { invoices_item.sub_navigation[:unpaid] }
+
+ before do
+ allow(Configuration).to receive(:eval_config)
+ allow(SimpleNavigation).to receive_messages(load_config: nil,
+ primary_navigation: navigation,
+ config_file?: true,
+ context_for_eval: controller)
+
+ select_an_item(navigation[item]) if item
+ end
+
+ describe '#active_navigation_item_name' do
+ context 'when no item is selected' do
+ it 'returns an empty string for no parameters' do
+ expect(controller.active_navigation_item_name).to eq ''
+ end
+
+ it "returns an empty string for level: 1" do
+ item_name = controller.active_navigation_item_name(level: 1)
+ expect(item_name).to eq ''
+ end
+
+ it 'returns an empty string for level: 2' do
+ item_name = controller.active_navigation_item_name(level: 2)
+ expect(item_name).to eq ''
+ end
+
+ it 'returns an empty string for level: :all' do
+ item_name = controller.active_navigation_item_name(level: :all)
+ expect(item_name).to eq ''
+ end
+ end
+
+ context 'when an item is selected' do
+ context "and it's a primary item" do
+ let(:item) { :invoices }
+
+ it 'returns an empty string' do
+ expect(controller.active_navigation_item_name).to eq ''
+ end
+
+ it "returns the selected item's name for level: 1" do
+ item_name = controller.active_navigation_item_name(level: 1)
+ expect(item_name).to eq 'Invoices'
+ end
+
+ it 'returns an empty string for level: 2' do
+ item_name = controller.active_navigation_item_name(level: 2)
+ expect(item_name).to eq ''
+ end
+
+ it 'returns an empty string for level: :all' do
+ item_name = controller.active_navigation_item_name(level: :all)
+ expect(item_name).to eq ''
+ end
+ end
+
+ context "and it's a sub navigation item" do
+ before do
+ select_an_item(invoices_item)
+ select_an_item(unpaid_item)
+ end
+
+ it "returns the selected item's name" do
+ expect(controller.active_navigation_item_name).to eq 'Unpaid'
+ end
+
+ it "returns the selected item's parent name for level: 1" do
+ item_name = controller.active_navigation_item_name(level: 1)
+ expect(item_name).to eq 'Invoices'
+ end
+
+ it "returns the selected item's name for level: 2" do
+ item_name = controller.active_navigation_item_name(level: 2)
+ expect(item_name).to eq 'Unpaid'
+ end
+
+ it "returns the selected item's name for level: :all" do
+ item_name = controller.active_navigation_item_name(level: :all)
+ expect(item_name).to eq 'Unpaid'
+ end
+ end
+ end
+ end
+
+ describe '#active_navigation_item_key' do
+ context 'when no item is selected' do
+ it 'returns nil' do
+ expect(controller.active_navigation_item_key).to be_nil
+ end
+
+ it 'returns nil for no parameters' do
+ expect(controller.active_navigation_item_key).to be_nil
+ end
+
+ it "returns nil for level: 1" do
+ item_key = controller.active_navigation_item_key(level: 1)
+ expect(item_key).to be_nil
+ end
+
+ it 'returns nil for level: 2' do
+ item_key = controller.active_navigation_item_key(level: 2)
+ expect(item_key).to be_nil
+ end
+
+ it 'returns nil for level: :all' do
+ item_key = controller.active_navigation_item_key(level: :all)
+ expect(item_key).to be_nil
+ end
+ end
+
+ context 'when an item is selected' do
+ context "and it's a primary item" do
+ let(:item) { :invoices }
+
+ it 'returns nil for no parameters' do
+ expect(controller.active_navigation_item_key).to be_nil
+ end
+
+ it "returns the selected item's name for level: 1" do
+ item_key = controller.active_navigation_item_key(level: 1)
+ expect(item_key).to eq :invoices
+ end
+
+ it 'returns nil for level: 2' do
+ item_key = controller.active_navigation_item_key(level: 2)
+ expect(item_key).to be_nil
+ end
+
+ it 'returns nil for level: :all' do
+ item_key = controller.active_navigation_item_key(level: :all)
+ expect(item_key).to be_nil
+ end
+ end
+
+ context "and it's a sub navigation item" do
+ before do
+ select_an_item(invoices_item)
+ select_an_item(unpaid_item)
+ end
+
+ it "returns the selected item's name" do
+ expect(controller.active_navigation_item_key).to eq :unpaid
+ end
+
+ it "returns the selected item's parent name for level: 1" do
+ item_key = controller.active_navigation_item_key(level: 1)
+ expect(item_key).to eq :invoices
+ end
+
+ it "returns the selected item's name for level: 2" do
+ item_key = controller.active_navigation_item_key(level: 2)
+ expect(item_key).to eq :unpaid
+ end
+
+ it "returns the selected item's name for level: :all" do
+ item_key = controller.active_navigation_item_key(level: :all)
+ expect(item_key).to eq :unpaid
+ end
+ end
+ end
+ end
+
+ describe '#active_navigation_item' do
+ context 'when no item is selected' do
+ it 'returns nil for no parameters' do
+ expect(controller.active_navigation_item).to be_nil
+ end
+
+ it "returns nil for level: 1" do
+ item_key = controller.active_navigation_item(level: 1)
+ expect(item_key).to be_nil
+ end
+
+ it 'returns nil for level: 2' do
+ item_key = controller.active_navigation_item(level: 2)
+ expect(item_key).to be_nil
+ end
+
+ it 'returns nil for level: :all' do
+ item_key = controller.active_navigation_item(level: :all)
+ expect(item_key).to be_nil
+ end
+ end
+
+ context 'when an item is selected' do
+ context "and it's a primary item" do
+ let(:item) { :invoices }
+
+ it 'returns nil for no parameters' do
+ expect(controller.active_navigation_item).to be_nil
+ end
+
+ it "returns the selected item's name for level: 1" do
+ item_key = controller.active_navigation_item(level: 1)
+ expect(item_key).to be invoices_item
+ end
+
+ it 'returns nil for level: 2' do
+ item_key = controller.active_navigation_item(level: 2)
+ expect(item_key).to be_nil
+ end
+
+ it 'returns nil for level: :all' do
+ item_key = controller.active_navigation_item(level: :all)
+ expect(item_key).to be_nil
+ end
+ end
+
+ context "and it's a sub navigation item" do
+ before do
+ select_an_item(invoices_item)
+ select_an_item(unpaid_item)
+ end
+
+ it "returns the selected item's name for no parameters" do
+ expect(controller.active_navigation_item).to be unpaid_item
+ end
+
+ it "returns the selected item's parent name for level: 1" do
+ item_key = controller.active_navigation_item(level: 1)
+ expect(item_key).to be invoices_item
+ end
+
+ it "returns the selected item's name for level: 2" do
+ item_key = controller.active_navigation_item(level: 2)
+ expect(item_key).to eq unpaid_item
+ end
+
+ it "returns the selected item's name for level: :all" do
+ item_key = controller.active_navigation_item(level: :all)
+ expect(item_key).to eq unpaid_item
+ end
+ end
+ end
+ end
+
+ describe '#active_navigation_item_container' do
+ shared_examples 'returning items container' do
+ it 'returns the primary navigation for no parameters' do
+ expect(controller.active_navigation_item_container).to be navigation
+ end
+
+ it "returns the primary navigation for level: 1" do
+ item_container = controller.active_navigation_item_container(level: 1)
+ expect(item_container).to be navigation
+ end
+
+ it 'returns the primary navigation level: :all' do
+ item_container =
+ controller.active_navigation_item_container(level: :all)
+ expect(item_container).to be navigation
+ end
+ end
+
+ context 'when no item is selected' do
+ it_behaves_like 'returning items container'
+
+ it 'returns nil for level: 2' do
+ item_container = controller.active_navigation_item_container(level: 2)
+ expect(item_container).to be_nil
+ end
+ end
+
+ context 'when an item is selected' do
+ context "and it's a primary item" do
+ let(:item) { :invoices }
+
+ it_behaves_like 'returning items container'
+
+ it 'returns the invoices items container for level: 2' do
+ item_container =
+ controller.active_navigation_item_container(level: 2)
+ expect(item_container).to be invoices_item.sub_navigation
+ end
+ end
+
+ context "and it's a sub navigation item" do
+ before do
+ select_an_item(invoices_item)
+ select_an_item(unpaid_item)
+ end
+
+ it_behaves_like 'returning items container'
+
+ it 'returns the invoices items container for level: 2' do
+ item_container =
+ controller.active_navigation_item_container(level: 2)
+ expect(item_container).to be invoices_item.sub_navigation
+ end
+ end
+ end
+ end
+
+ describe '#render_navigation' do
+ it 'evaluates the configuration on every request' do
+ expect(SimpleNavigation).to receive(:load_config).twice
+ 2.times { controller.render_navigation }
+ end
+
+ it 'loads the :default configuration' do
+ expect(SimpleNavigation).to receive(:load_config).with(:default)
+ controller.render_navigation
+ end
+
+ it "doesn't set the items directly" do
+ expect(SimpleNavigation.config).not_to receive(:items)
+ controller.render_navigation
+ end
+
+ it 'looks up the active_item_container based on the level' do
+ expect(SimpleNavigation).to receive(:active_item_container_for)
+ .with(:all)
+ controller.render_navigation
+ end
+
+ context 'when the :context option is specified' do
+ it 'loads the configuration for the specified context' do
+ expect(SimpleNavigation).to receive(:load_config).with(:my_context)
+ controller.render_navigation(context: :my_context)
+ end
+ end
+
+ context 'when the :items option is specified' do
+ let(:items) { double(:items) }
+
+ it 'sets the items directly' do
+ expect(SimpleNavigation.config).to receive(:items).with(items)
+ controller.render_navigation(items: items)
+ end
+ end
+
+ context 'when the :level option is set' do
+ context 'and its value is 1' do
+ it 'calls render on the primary navigation' do
+ expect(navigation).to receive(:render).with(level: 1)
+ controller.render_navigation(level: 1)
+ end
+ end
+
+ context 'and its value is 2' do
+ context 'and the active_item_container is set' do
+ let(:item_container) { double(:container).as_null_object }
+
+ before do
+ allow(SimpleNavigation).to receive_messages(active_item_container_for: item_container)
+ end
+
+ it 'finds the selected sub navigation for the specified level' do
+ expect(SimpleNavigation).to receive(:active_item_container_for)
+ .with(2)
+ controller.render_navigation(level: 2)
+ end
+
+ it 'calls render on the active item_container' do
+ expect(item_container).to receive(:render).with(level: 2)
+ controller.render_navigation(level: 2)
+ end
+ end
+
+ context "and the active_item_container isn't set" do
+ it "doesn't raise an exception" do
+ expect{
+ controller.render_navigation(level: 2)
+ }.not_to raise_error
+ end
+ end
+ end
+
+ context "and its value isn't a valid level" do
+ it 'raises an exception' do
+ expect{
+ controller.render_navigation(level: :invalid)
+ }.to raise_error
+ end
+ end
+ end
+
+ context 'when the :levels option is set' do
+ before { allow(SimpleNavigation).to receive_messages(active_item_container_for: navigation) }
+
+ it 'treats it like the :level option' do
+ expect(navigation).to receive(:render).with(level: 2)
+ controller.render_navigation(levels: 2)
+ end
+ end
+
+ context 'when a block is given' do
+ it 'calls the block passing it an item container' do
+ expect{ |blk|
+ controller.render_navigation(&blk)
+ }.to yield_with_args(ItemContainer)
+ end
+ end
+
+ context 'when no primary configuration is defined' do
+ before { allow(SimpleNavigation).to receive_messages(primary_navigation: nil) }
+
+ it 'raises an exception' do
+ expect{controller.render_navigation}.to raise_error
+ end
+ end
+
+ context "when active_item_container is set" do
+ let(:active_item_container) { double(:container).as_null_object }
+
+ before do
+ allow(SimpleNavigation).to receive_messages(active_item_container_for: active_item_container)
+ end
+
+ it 'calls render on the active_item_container' do
+ expect(active_item_container).to receive(:render)
+ controller.render_navigation
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/item_adapter_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/item_adapter_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/item_adapter_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/item_adapter_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,188 @@
+module SimpleNavigation
+ describe ItemAdapter do
+ let(:item_adapter) { ItemAdapter.new(item) }
+
+ context 'when item is an object' do
+ let(:item) { double(:item, key: 'key', name: 'name', url: 'url') }
+
+ shared_examples 'delegating to item' do |meth|
+ it "delegates #{meth} to item" do
+ expect(item).to receive(meth)
+ item_adapter.public_send(meth)
+ end
+ end
+
+ it_behaves_like 'delegating to item', :key
+ it_behaves_like 'delegating to item', :url
+ it_behaves_like 'delegating to item', :name
+
+ describe '#initialize' do
+ it 'sets the item' do
+ expect(item_adapter.item).to be item
+ end
+ end
+
+ describe '#options' do
+ context 'when item responds to options' do
+ let(:options) { double(:options) }
+
+ before { allow(item).to receive_messages(options: options) }
+
+ it "returns the item's options" do
+ expect(item_adapter.options).to be options
+ end
+ end
+
+ context 'item does not respond to options' do
+ it 'returns an empty hash' do
+ expect(item_adapter.options).to eq({})
+ end
+ end
+ end
+
+ describe '#items' do
+ context 'when item responds to items' do
+ context 'and items is nil' do
+ before { allow(item).to receive_messages(items: nil) }
+
+ it 'returns nil' do
+ expect(item_adapter.items).to be_nil
+ end
+ end
+
+ context 'when items is not nil' do
+ context 'and items is empty' do
+ before { allow(item).to receive_messages(items: []) }
+
+ it 'returns nil' do
+ expect(item_adapter.items).to be_nil
+ end
+ end
+
+ context 'and items is not empty' do
+ let(:items) { [true] }
+
+ before { allow(item).to receive_messages(items: items) }
+
+ it 'returns the items' do
+ expect(item_adapter.items).to eq items
+ end
+ end
+ end
+ end
+
+ context "when item doesn't respond to items" do
+ it 'returns nil' do
+ expect(item_adapter.items).to be_nil
+ end
+ end
+ end
+
+ describe '#to_simple_navigation_item' do
+ let(:container) { double(:container) }
+
+ before { allow(item).to receive_messages(items: [], options: {}) }
+
+ it 'creates an Item' do
+ expect(Item).to receive(:new)
+ .with(container, 'key', 'name', 'url', {})
+ item_adapter.to_simple_navigation_item(container)
+ end
+ end
+ end
+
+ context 'when item is a kind of hash' do
+ class ModifiedHash < Hash; end
+
+ let(:item) { ModifiedHash[key: 'key', url: 'url', name: 'name'] }
+
+ shared_examples 'delegating to item' do |meth|
+ it "delegates #{meth} to item" do
+ expect(item_adapter.item).to receive(meth)
+ item_adapter.public_send(meth)
+ end
+ end
+
+ it_behaves_like 'delegating to item', :key
+ it_behaves_like 'delegating to item', :url
+ it_behaves_like 'delegating to item', :name
+
+ describe '#initialize' do
+ it 'sets the item' do
+ expect(item_adapter.item).not_to be_nil
+ end
+
+ it 'converts the item into an object' do
+ expect(item_adapter.item).to respond_to(:url)
+ end
+ end
+
+ describe '#options' do
+ context 'when item responds to options' do
+ before { item[:options] = { my: :options } }
+
+ it "returns the item's options" do
+ expect(item_adapter.options).to eq({ my: :options })
+ end
+ end
+
+ context 'when item does not respond to options' do
+ it 'returns an empty hash' do
+ expect(item_adapter.options).to eq({})
+ end
+ end
+ end
+
+ describe '#items' do
+ context 'when item responds to items' do
+ context 'and items is nil' do
+ before { item[:items] = nil }
+
+ it 'returns nil' do
+ expect(item_adapter.items).to be_nil
+ end
+ end
+
+ context 'when items is not nil' do
+ context 'and items is empty' do
+ it 'returns nil' do
+ expect(item_adapter.items).to be_nil
+ end
+ end
+
+ context 'and items is not empty' do
+ before { item[:items] = ['not', 'empty'] }
+
+ it 'returns the items' do
+ expect(item_adapter.items).to eq ['not', 'empty']
+ end
+ end
+ end
+ end
+
+ context 'when item does not respond to items' do
+ it 'returns nil' do
+ expect(item_adapter.items).to be_nil
+ end
+ end
+ end
+
+ describe '#to_simple_navigation_item' do
+ let(:container) { double(:container) }
+
+ before { item.merge(options: {}) }
+
+ it 'passes the right arguments to Item' do
+ expect(Item).to receive(:new)
+ .with(container, 'key', 'name', 'url', {})
+ item_adapter.to_simple_navigation_item(container)
+ end
+
+ it 'creates an Item' do
+ created_item = item_adapter.to_simple_navigation_item(container)
+ expect(created_item).to be_an(Item)
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/item_container_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/item_container_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/item_container_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/item_container_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,600 @@
+module SimpleNavigation
+ describe ItemContainer do
+ subject(:item_container) { ItemContainer.new }
+
+ shared_examples 'adding the item to the list' do
+ it 'adds the item to the list' do
+ allow(Item).to receive_messages(new: item)
+ item_container.item(*args)
+ expect(item_container.items).to include(item)
+ end
+ end
+
+ shared_examples 'not adding the item to the list' do
+ it "doesn't add the item to the list" do
+ allow(Item).to receive_messages(new: item)
+ item_container.item(*args)
+ expect(item_container.items).not_to include(item)
+ end
+ end
+
+ describe '#initialize' do
+ it 'sets an empty items array' do
+ expect(item_container.items).to be_empty
+ end
+ end
+
+ describe '#dom_attributes' do
+ let(:dom_attributes) {{ id: 'test_id', class: 'test_class' }}
+
+ before { item_container.dom_attributes = dom_attributes }
+
+ it "returns the container's dom_attributes" do
+ expect(item_container.dom_attributes).to eq dom_attributes
+ end
+
+ context 'when the dom_attributes do not contain any id or class' do
+ let(:dom_attributes) {{ test: 'test' }}
+
+ context "and the container hasn't any dom_id" do
+ it "returns the contaier's dom_attributes without any id" do
+ expect(item_container.dom_attributes).not_to include(:id)
+ end
+ end
+
+ context 'and the container has a dom_id' do
+ before { item_container.dom_id = 'test_id' }
+
+ it "returns the contaier's dom_attributes including the #dom_id" do
+ expect(item_container.dom_attributes).to include(id: 'test_id')
+ end
+ end
+
+ context "and the container hasn't any dom_class" do
+ it "returns the contaier's dom_attributes without any class" do
+ expect(item_container.dom_attributes).not_to include(:class)
+ end
+ end
+
+ context 'and the container has a dom_class' do
+ before { item_container.dom_class = 'test_class' }
+
+ it "returns the contaier's dom_attributes including the #dom_class" do
+ expect(item_container.dom_attributes).to include(class: 'test_class')
+ end
+ end
+ end
+ end
+
+ describe '#items=' do
+ let(:item) {{ key: :my_key, name: 'test', url: '/' }}
+ let(:items) { [item] }
+ let(:item_adapter) { double(:item_adapter).as_null_object }
+ let(:real_item) { double(:real_item) }
+
+ before do
+ allow(ItemAdapter).to receive_messages(new: item_adapter)
+ allow(item_adapter).to receive(:to_simple_navigation_item)
+ .with(item_container)
+ .and_return(real_item)
+ end
+
+ context 'when the item should be added' do
+ before { allow(item_container).to receive_messages(should_add_item?: true) }
+
+ it 'converts it to an Item and adds it to the items collection' do
+ item_container.items = items
+ expect(item_container.items).to include(real_item)
+ end
+ end
+
+ context 'when the item should not be added' do
+ before { allow(item_container).to receive_messages(should_add_item?: false) }
+
+ it "doesn't add it to the items collection" do
+ item_container.items = items
+ expect(item_container.items).not_to include(real_item)
+ end
+ end
+ end
+
+ describe '#selected?' do
+ let(:item_1) { double(:item, selected?: false) }
+ let(:item_2) { double(:item, selected?: false) }
+
+ before do
+ item_container.instance_variable_set(:@items, [item_1, item_2])
+ end
+
+ context 'when no item is selected' do
+ it 'returns nil' do
+ expect(item_container).not_to be_selected
+ end
+ end
+
+ context 'when an item is selected' do
+ it 'returns true' do
+ allow(item_1).to receive_messages(selected?: true)
+ expect(item_container).to be_selected
+ end
+ end
+ end
+
+ describe '#selected_item' do
+ let(:item_1) { double(:item, selected?: false) }
+ let(:item_2) { double(:item, selected?: false) }
+
+ before(:each) do
+ allow(SimpleNavigation).to receive_messages(current_navigation_for: :nav)
+ allow(item_container).to receive_messages(:[] => nil)
+ item_container.instance_variable_set(:@items, [item_1, item_2])
+ end
+
+ context "when navigation isn't explicitely set" do
+ context 'and no item is selected' do
+ it 'returns nil' do
+ expect(item_container.selected_item).to be_nil
+ end
+ end
+
+ context 'and an item selected' do
+ before { allow(item_1).to receive_messages(selected?: true) }
+
+ it 'returns the selected item' do
+ expect(item_container.selected_item).to be item_1
+ end
+ end
+ end
+ end
+
+ describe '#active_item_container_for' do
+ context "when the desired level is the same as the container's" do
+ it 'returns the container itself' do
+ expect(item_container.active_item_container_for(1)).to be item_container
+ end
+ end
+
+ context "when the desired level is different than the container's" do
+ context 'and no subnavigation is selected' do
+ before { allow(item_container).to receive_messages(selected_sub_navigation?: false) }
+
+ it 'returns nil' do
+ expect(item_container.active_item_container_for(2)).to be_nil
+ end
+ end
+
+ context 'and a subnavigation is selected' do
+ let(:sub_navigation) { double(:sub_navigation) }
+ let(:selected_item) { double(:selected_item) }
+
+ before do
+ allow(item_container).to \
+ receive_messages(selected_sub_navigation?: true, selected_item: selected_item)
+ allow(selected_item).to receive_messages(sub_navigation: sub_navigation)
+ end
+
+ it 'calls recursively on the sub_navigation' do
+ expect(sub_navigation).to receive(:active_item_container_for)
+ .with(2)
+ item_container.active_item_container_for(2)
+ end
+ end
+ end
+ end
+
+ describe '#active_leaf_container' do
+ context 'when the current container has a selected subnavigation' do
+ let(:sub_navigation) { double(:sub_navigation) }
+ let(:selected_item) { double(:selected_item) }
+
+ before do
+ allow(item_container).to receive_messages(selected_sub_navigation?: true,
+ selected_item: selected_item)
+ allow(selected_item).to receive_messages(sub_navigation: sub_navigation)
+ end
+
+ it 'calls recursively on the sub_navigation' do
+ expect(sub_navigation).to receive(:active_leaf_container)
+ item_container.active_leaf_container
+ end
+ end
+
+ context 'when the current container is the leaf already' do
+ before { allow(item_container).to receive_messages(selected_sub_navigation?: false) }
+
+ it 'returns itsself' do
+ expect(item_container.active_leaf_container).to be item_container
+ end
+ end
+ end
+
+ describe '#item' do
+ let(:options) { Hash.new }
+ let(:item) { double(:item) }
+
+ context 'when a block is given' do
+ let(:block) { proc{} }
+ let(:sub_container) { double(:sub_container) }
+
+ it 'yields a new ItemContainer' do
+ allow_any_instance_of(Item).to \
+ receive_messages(sub_navigation: sub_container)
+
+ expect{ |blk|
+ item_container.item('key', 'name', 'url', options, &blk)
+ }.to yield_with_args(sub_container)
+ end
+
+ it "creates a new Item with the given params and block" do
+ allow(Item).to receive(:new)
+ .with(item_container, 'key', 'name', 'url', options, &block)
+ .and_return(item)
+ item_container.item('key', 'name', 'url', options, &block)
+ expect(item_container.items).to include(item)
+ end
+
+ it 'adds the created item to the list of items' do
+ item_container.item('key', 'name', 'url', options) {}
+ expect(item_container.items).not_to include(item)
+ end
+ end
+
+ context 'when no block is given' do
+ it 'creates a new Item with the given params and no sub navigation' do
+ allow(Item).to receive(:new)
+ .with(item_container, 'key', 'name', 'url', options)
+ .and_return(item)
+ item_container.item('key', 'name', 'url', options)
+ expect(item_container.items).to include(item)
+ end
+
+ it 'adds the created item to the list of items' do
+ allow(Item).to receive_messages(new: item)
+ item_container.item('key', 'name', 'url', options) {}
+ expect(item_container.items).to include(item)
+ end
+ end
+
+ describe 'Optional url and optional options' do
+ context 'when item specifed without url or options' do
+ it_behaves_like 'adding the item to the list' do
+ let(:args) { ['key', 'name'] }
+ end
+ end
+
+ context 'when item is specified with only a url' do
+ it_behaves_like 'adding the item to the list' do
+ let(:args) { ['key', 'name', 'url'] }
+ end
+ end
+
+ context 'when item is specified with only options' do
+ context 'and options do not contain any condition' do
+ it_behaves_like 'adding the item to the list' do
+ let(:args) { ['key', 'name', { option: true }] }
+ end
+ end
+
+ context 'and options contains a negative condition' do
+ it_behaves_like 'not adding the item to the list' do
+ let(:args) { ['key', 'name', nil, { if: ->{ false }, option: true }] }
+ end
+ end
+
+ context 'and options contains a positive condition' do
+ it_behaves_like 'adding the item to the list' do
+ let(:args) { ['key', 'name', nil, { if: ->{ true }, option: true }] }
+ end
+ end
+ end
+
+ context 'when item is specified with a url and options' do
+ context 'and options do not contain any condition' do
+ it_behaves_like 'adding the item to the list' do
+ let(:args) { ['key', 'name', 'url', { option: true }] }
+ end
+ end
+
+ context 'and options contains a negative condition' do
+ it_behaves_like 'not adding the item to the list' do
+ let(:args) { ['key', 'name', 'url', { if: ->{ false }, option: true }] }
+ end
+ end
+
+ context 'and options contains a positive condition' do
+ it_behaves_like 'adding the item to the list' do
+ let(:args) { ['key', 'name', 'url', { if: ->{ true }, option: true }] }
+ end
+ end
+ end
+
+ context 'when a frozen options hash is given' do
+ let(:options) do
+ { html: { id: 'test' } }.freeze
+ end
+
+ it 'does not raise an exception' do
+ expect{
+ item_container.item('key', 'name', 'url', options)
+ }.not_to raise_error
+ end
+ end
+
+ describe "container options" do
+ before do
+ allow(item_container).to receive_messages(should_add_item?: add_item)
+ item_container.item :key, 'name', 'url', options
+ end
+
+ context 'when the container :id option is specified' do
+ let(:options) {{ container: { id: 'c_id' } }}
+
+ context 'and the item should be added' do
+ let(:add_item) { true }
+
+ it 'changes its dom_id' do
+ expect(item_container.dom_id).to eq 'c_id'
+ end
+ end
+
+ context "and the item shouldn't be added" do
+ let(:add_item) { false }
+
+ it "doesn't change its dom_id" do
+ expect(item_container.dom_id).to be_nil
+ end
+ end
+ end
+
+ context 'when the container :class option is specified' do
+ let(:options) {{ container: { class: 'c_class' } }}
+
+ context 'and the item should be added' do
+ let(:add_item) { true }
+
+ it 'changes its dom_class' do
+ expect(item_container.dom_class).to eq 'c_class'
+ end
+ end
+
+ context "and the item shouldn't be added" do
+ let(:add_item) { false }
+
+ it "doesn't change its dom_class" do
+ expect(item_container.dom_class).to be_nil
+ end
+ end
+ end
+
+ context 'when the container :attributes option is specified' do
+ let(:options) {{ container: { attributes: { option: true } } }}
+
+ context 'and the item should be added' do
+ let(:add_item) { true }
+
+ it 'changes its dom_attributes' do
+ expect(item_container.dom_attributes).to eq(option: true)
+ end
+ end
+
+ context "and the item shouldn't be added" do
+ let(:add_item) { false }
+
+ it "doesn't change its dom_attributes" do
+ expect(item_container.dom_attributes).to eq({})
+ end
+ end
+ end
+
+ context 'when the container :selected_class option is specified' do
+ let(:options) {{ container: { selected_class: 'sel_class' } }}
+
+ context 'and the item should be added' do
+ let(:add_item) { true }
+
+ it 'changes its selected_class' do
+ expect(item_container.selected_class).to eq 'sel_class'
+ end
+ end
+
+ context "and the item shouldn't be added" do
+ let(:add_item) { false }
+
+ it "doesn't change its selected_class" do
+ expect(item_container.selected_class).to be_nil
+ end
+ end
+ end
+ end
+ end
+
+ describe 'Conditions' do
+ context 'when an :if option is given' do
+ let(:options) {{ if: proc{condition} }}
+ let(:condition) { nil }
+
+ context 'and it evals to true' do
+ let(:condition) { true }
+
+ it 'creates a new Item' do
+ expect(Item).to receive(:new)
+ item_container.item('key', 'name', 'url', options)
+ end
+ end
+
+ context 'and it evals to false' do
+ let(:condition) { false }
+
+ it "doesn't create a new Item" do
+ expect(Item).not_to receive(:new)
+ item_container.item('key', 'name', 'url', options)
+ end
+ end
+
+ context 'and it is not a proc or a method' do
+ it 'raises an error' do
+ expect{
+ item_container.item('key', 'name', 'url', { if: 'text' })
+ }.to raise_error
+ end
+ end
+ end
+
+ context 'when an :unless option is given' do
+ let(:options) {{ unless: proc{condition} }}
+ let(:condition) { nil }
+
+ context 'and it evals to false' do
+ let(:condition) { false }
+
+ it 'creates a new Navigation-Item' do
+ expect(Item).to receive(:new)
+ item_container.item('key', 'name', 'url', options)
+ end
+ end
+
+ context 'and it evals to true' do
+ let(:condition) { true }
+
+ it "doesn't create a new Navigation-Item" do
+ expect(Item).not_to receive(:new)
+ item_container.item('key', 'name', 'url', options)
+ end
+ end
+ end
+ end
+ end
+
+ describe '#[]' do
+ before do
+ item_container.item(:first, 'first', 'bla')
+ item_container.item(:second, 'second', 'bla')
+ item_container.item(:third, 'third', 'bla')
+ end
+
+ it 'returns the item with the specified navi_key' do
+ expect(item_container[:second].name).to eq 'second'
+ end
+
+ context 'when no item exists for the specified navi_key' do
+ it 'returns nil' do
+ expect(item_container[:invalid]).to be_nil
+ end
+ end
+ end
+
+ describe '#render' do
+ # TODO
+ let(:renderer_instance) { double(:renderer).as_null_object }
+ let(:renderer_class) { double(:renderer_class, new: renderer_instance) }
+
+ context 'when renderer is specified as an option' do
+ context 'and is specified as a class' do
+ it 'instantiates the passed renderer_class with the options' do
+ expect(renderer_class).to receive(:new)
+ .with(renderer: renderer_class)
+ item_container.render(renderer: renderer_class)
+ end
+
+ it 'calls render on the renderer and passes self' do
+ expect(renderer_instance).to receive(:render).with(item_container)
+ item_container.render(renderer: renderer_class)
+ end
+ end
+
+ context 'and is specified as a symbol' do
+ before do
+ SimpleNavigation.registered_renderers = {
+ my_renderer: renderer_class
+ }
+ end
+
+ it "instantiates the passed renderer_class with the options" do
+ expect(renderer_class).to receive(:new).with(renderer: :my_renderer)
+ item_container.render(renderer: :my_renderer)
+ end
+
+ it 'calls render on the renderer and passes self' do
+ expect(renderer_instance).to receive(:render).with(item_container)
+ item_container.render(renderer: :my_renderer)
+ end
+ end
+ end
+
+ context 'when no renderer is specified' do
+ let(:options) { Hash.new }
+
+ before { allow(item_container).to receive_messages(renderer: renderer_class) }
+
+ it "instantiates the container's renderer with the options" do
+ expect(renderer_class).to receive(:new).with(options)
+ item_container.render(options)
+ end
+
+ it 'calls render on the renderer and passes self' do
+ expect(renderer_instance).to receive(:render).with(item_container)
+ item_container.render(options)
+ end
+ end
+ end
+
+ describe '#renderer' do
+ context 'when no renderer is set explicitly' do
+ it 'returns globally-configured renderer' do
+ expect(item_container.renderer).to be Configuration.instance.renderer
+ end
+ end
+
+ context 'when a renderer is set explicitly' do
+ let(:renderer) { double(:renderer) }
+
+ before { item_container.renderer = renderer }
+
+ it 'returns the specified renderer' do
+ expect(item_container.renderer).to be renderer
+ end
+ end
+ end
+
+ describe '#level_for_item' do
+ before(:each) do
+ item_container.item(:p1, 'p1', 'p1')
+ item_container.item(:p2, 'p2', 'p2') do |p2|
+ p2.item(:s1, 's1', 's1')
+ p2.item(:s2, 's2', 's2') do |s2|
+ s2.item(:ss1, 'ss1', 'ss1')
+ s2.item(:ss2, 'ss2', 'ss2')
+ end
+ p2.item(:s3, 's3', 's3')
+ end
+ item_container.item(:p3, 'p3', 'p3')
+ end
+
+ shared_examples 'returning the level of an item' do |item, level|
+ specify{ expect(item_container.level_for_item(item)).to eq level }
+ end
+
+ it_behaves_like 'returning the level of an item', :p1, 1
+ it_behaves_like 'returning the level of an item', :p3, 1
+ it_behaves_like 'returning the level of an item', :s1, 2
+ it_behaves_like 'returning the level of an item', :ss1, 3
+ it_behaves_like 'returning the level of an item', :x, nil
+ end
+
+ describe '#empty?' do
+ context 'when there are no items' do
+ it 'returns true' do
+ item_container.instance_variable_set(:@items, [])
+ expect(item_container).to be_empty
+ end
+ end
+
+ context 'when there are some items' do
+ it 'returns false' do
+ item_container.instance_variable_set(:@items, [double(:item)])
+ expect(item_container).not_to be_empty
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/item_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/item_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/item_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/item_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,467 @@
+module SimpleNavigation
+ describe Item do
+ let!(:item_container) { ItemContainer.new }
+
+ let(:adapter) { double(:adapter) }
+ let(:item_args) { [item_container, :my_key, 'name', url, options] }
+ let(:item) { Item.new(*item_args) }
+ let(:options) { Hash.new }
+ let(:url) { 'url' }
+
+ before { allow(SimpleNavigation).to receive_messages(adapter: adapter) }
+
+ describe '#highlights_on' do
+ let(:options) {{ highlights_on: :test }}
+
+ it "returns the item's highlights_on option" do
+ expect(item.highlights_on).to eq :test
+ end
+ end
+
+ describe '#initialize' do
+ context 'when there is a sub_navigation' do
+ let(:subnav_container) { double(:subnav_container).as_null_object }
+
+ shared_examples 'creating sub navigation container' do
+ it 'creates a sub navigation container with a level+1' do
+ expect(item.sub_navigation.level).to eq 2
+ end
+ end
+
+ context 'when a block is given' do
+ it_behaves_like 'creating sub navigation container' do
+ let(:item) { Item.new(*item_args) {} }
+ end
+
+ it 'calls the block' do
+ allow(ItemContainer).to receive_messages(new: subnav_container)
+
+ expect{ |blk|
+ Item.new(*item_args, &blk)
+ }.to yield_with_args(subnav_container)
+ end
+ end
+
+ context 'when no block is given' do
+ context 'and items are given' do
+ let(:items) { [] }
+ let(:options) {{ items: items }}
+
+ it_behaves_like 'creating sub navigation container'
+
+ it "sets the items on the subnav_container" do
+ expect(item.sub_navigation.items).to eq items
+ end
+ end
+
+ context 'and no items are given' do
+ it "doesn't create a new ItemContainer" do
+ item = Item.new(*item_args)
+ expect(item.sub_navigation).to be_nil
+ end
+ end
+ end
+ end
+
+ context 'when a :method option is given' do
+ let(:options) {{ method: :delete }}
+
+ it "sets the item's method" do
+ expect(item.method).to eq :delete
+ end
+ end
+
+ context 'when no :method option is given' do
+ it "sets the item's method to nil" do
+ expect(item.method).to be_nil
+ end
+ end
+
+ context 'when an :highlights_on option is given' do
+ let(:highlights_on) { double(:highlights_on) }
+ let(:options) {{ highlights_on: highlights_on }}
+
+ it "sets the item's highlights_on" do
+ expect(item.highlights_on).to eq highlights_on
+ end
+ end
+
+ context 'when no :highlights_on option is given' do
+ it "sets the item's highlights_on to nil" do
+ expect(item.highlights_on).to be_nil
+ end
+ end
+
+ context 'when a url is given' do
+ context 'and it is a string' do
+ it "sets the item's url accordingly" do
+ expect(item.url).to eq 'url'
+ end
+ end
+
+ context 'and it is a proc' do
+ let(:url) { proc{ "my_" + "url" } }
+
+ it "sets the item's url accordingly" do
+ expect(item.url).to eq 'my_url'
+ end
+ end
+
+ context 'and it is nil' do
+ let(:url) { nil }
+
+ it "sets the item's url accordingly" do
+ expect(item.url).to be_nil
+ end
+ end
+ end
+
+ context 'when no url nor options is specified' do
+ let(:item_args) { [item_container, :my_key, 'name'] }
+
+ it "sets the item's url to nil" do
+ expect(item.url).to be_nil
+ end
+ end
+
+ context 'when only a url is given' do
+ let(:item_args) { [item_container, :my_key, 'name', 'url'] }
+
+ it "set the item's url accordingly" do
+ expect(item.url).to eq 'url'
+ end
+ end
+
+ context 'when url and options are given' do
+ let(:options) {{ html: { option: true } }}
+
+ before { allow(adapter).to receive_messages(current_page?: false) }
+
+ it "set the item's url accordingly" do
+ expect(item.url).to eq 'url'
+ end
+
+ it "sets the item's html_options accordingly" do
+ allow(item).to \
+ receive_messages(selected_by_subnav?: false,
+ selected_by_condition?: false)
+ expect(item.html_options).to include(option: true)
+ end
+ end
+ end
+
+ describe '#link_html_options' do
+ let(:options) {{ link_html: :test }}
+
+ it "returns the item's link_html option" do
+ expect(item.link_html_options).to eq :test
+ end
+ end
+
+ describe '#method' do
+ let(:options) {{ method: :test }}
+
+ it "returns the item's method option" do
+ expect(item.method).to eq :test
+ end
+ end
+
+ describe '#name' do
+ before do
+ allow(SimpleNavigation.config).to \
+ receive_messages(name_generator: proc{ |name| "#{name}" })
+ end
+
+ context 'when no option is given' do
+ context 'and the name_generator uses only the name' do
+ it 'uses the default name_generator' do
+ expect(item.name).to eq 'name'
+ end
+ end
+
+ context 'and the name_generator uses only the item itself' do
+ before do
+ allow(SimpleNavigation.config).to \
+ receive_messages(name_generator: proc{ |name, item| "#{item.key}" })
+ end
+
+ it 'uses the default name_generator' do
+ expect(item.name).to eq 'my_key'
+ end
+ end
+ end
+
+ context 'when the :apply_generator is false' do
+ it "returns the item's name" do
+ expect(item.name(apply_generator: false)).to eq 'name'
+ end
+ end
+
+ context 'when a block is given' do
+ let(:item_args) { [item_container, :my_key, -> { 'Name in block' }, url, options] }
+
+ it "returns the item's name that is defined in the block" do
+ expect(item.name).to include 'Name in block'
+ end
+ end
+ end
+
+ describe '#selected?' do
+ context 'when the item has no :highlights_on option' do
+ before { allow(SimpleNavigation).to receive_messages(config: config) }
+
+ context 'and auto highlighting is off' do
+ let(:config) { double(:config, auto_highlight: false) }
+
+ it 'returns false' do
+ expect(item.selected?).to be false
+ end
+ end
+
+ context 'and auto highlighting is on' do
+ let(:config) { double(:config, ignore_query_params_on_auto_highlight: true, ignore_anchors_on_auto_highlight: true, auto_highlight: true) }
+
+ context "and the current url matches the item's url" do
+ before { allow(adapter).to receive_messages(current_page?: true) }
+
+ it 'returns true' do
+ expect(item.selected?).to be true
+ end
+ end
+
+ context "and the current url does not match the item's url" do
+ let(:config) do
+ double(:config, auto_highlight: false, highlight_on_subpath: false)
+ end
+
+ before { allow(adapter).to receive_messages(current_page?: false) }
+
+ it 'returns false' do
+ expect(item.selected?).to be false
+ end
+ end
+
+ context 'and highlights_on_subpath is on' do
+ let(:config) do
+ double(:config, auto_highlight: true, highlight_on_subpath: true, ignore_query_params_on_auto_highlight: true, ignore_anchors_on_auto_highlight: true)
+ end
+
+ context "and the current url is a sub path of the item's url" do
+ before do
+ allow(adapter).to \
+ receive_messages(current_page?: false, request_uri: 'url/test')
+ end
+
+ it 'returns true' do
+ expect(item.selected?).to be true
+ end
+ end
+
+ context "and the current url is not a sub path of the item's url" do
+ before do
+ allow(adapter).to \
+ receive_messages(current_page?: false, request_uri: 'other/test')
+ end
+
+ it 'returns false' do
+ expect(item.selected?).to be false
+ end
+ end
+ end
+ end
+ end
+
+ context 'when the item has a :highlights_on option' do
+ context 'and it is a regular expression' do
+ before { allow(adapter).to receive_messages(request_uri: '/test') }
+
+ context 'and the current url matches the expression' do
+ let(:options) {{ highlights_on: /test/ }}
+
+ it 'returns true' do
+ expect(item.selected?).to be true
+ end
+ end
+
+ context 'and the current url does not match the expression' do
+ let(:options) {{ highlights_on: /other/ }}
+
+ it 'returns false' do
+ expect(item.selected?).to be false
+ end
+ end
+ end
+
+ context 'and it is a callable object' do
+ context 'and the call returns true' do
+ let(:options) {{ highlights_on: -> { true } }}
+
+ it 'returns true' do
+ expect(item.selected?).to be true
+ end
+ end
+
+ context 'and the call returns false' do
+ let(:options) {{ highlights_on: -> { false } }}
+
+ it 'returns false' do
+ expect(item.selected?).to be false
+ end
+ end
+ end
+
+ context 'and it is the :subpath symbol' do
+ let(:options) {{ highlights_on: :subpath }}
+
+ context "and the current url is a sub path of the item's url" do
+ before do
+ allow(adapter).to receive_messages(request_uri: 'url/test')
+ end
+
+ it 'returns true' do
+ expect(item.selected?).to be true
+ end
+ end
+
+ context "and the current url is not a sub path of the item's url" do
+ before do
+ allow(adapter).to receive_messages(request_uri: 'other/test')
+ end
+
+ it 'returns false' do
+ expect(item.selected?).to be false
+ end
+ end
+ end
+
+ context 'and it is non usable' do
+ let(:options) {{ highlights_on: :hello }}
+
+ it 'raises an exception' do
+ expect{ item.selected? }.to raise_error
+ end
+ end
+ end
+ end
+
+ describe '#selected_class' do
+ context 'when the item is selected' do
+ before { allow(item).to receive_messages(selected?: true) }
+
+ it 'returns the default selected_class' do
+ expect(item.selected_class).to eq 'selected'
+ end
+
+ context 'and selected_class is defined in the context' do
+ before { allow(item_container).to receive_messages(selected_class: 'defined') }
+
+ it "returns the context's selected_class" do
+ expect(item.selected_class).to eq 'defined'
+ end
+ end
+ end
+
+ context 'when the item is not selected' do
+ before { allow(item).to receive_messages(selected?: false) }
+
+ it 'returns nil' do
+ expect(item.selected_class).to be_nil
+ end
+ end
+ end
+
+ describe ':html_options argument' do
+ let(:selected_classes) { 'selected simple-navigation-active-leaf' }
+
+ context 'when the :class option is given' do
+ let(:options) {{ html: { class: 'my_class' } }}
+
+ context 'and the item is selected' do
+ before { allow(item).to receive_messages(selected?: true, selected_by_condition?: true) }
+
+ it "adds the specified class to the item's html classes" do
+ expect(item.html_options[:class]).to include('my_class')
+ end
+
+ it "doesn't replace the default html classes of a selected item" do
+ expect(item.html_options[:class]).to include(selected_classes)
+ end
+ end
+
+ context "and the item isn't selected" do
+ before { allow(item).to receive_messages(selected?: false, selected_by_condition?: false) }
+
+ it "sets the specified class as the item's html classes" do
+ expect(item.html_options[:class]).to include('my_class')
+ end
+ end
+ end
+
+ context "when the :class option isn't given" do
+ context 'and the item is selected' do
+ before { allow(item).to receive_messages(selected?: true, selected_by_condition?: true) }
+
+ it "sets the default html classes of a selected item" do
+ expect(item.html_options[:class]).to include(selected_classes)
+ end
+ end
+
+ context "and the item isn't selected" do
+ before { allow(item).to receive_messages(selected?: false, selected_by_condition?: false) }
+
+ it "doesn't set any html class on the item" do
+ expect(item.html_options[:class]).to be_blank
+ end
+ end
+ end
+
+ shared_examples 'generating id' do |id|
+ it "sets the item's html id to the specified id" do
+ expect(item.html_options[:id]).to eq id
+ end
+ end
+
+ describe 'when the :id option is given' do
+ let(:options) {{ html: { id: 'my_id' } }}
+
+ before do
+ allow(SimpleNavigation.config).to receive_messages(autogenerate_item_ids: generate_ids)
+ allow(item).to receive_messages(selected?: false, selected_by_condition?: false)
+ end
+
+ context 'and :autogenerate_item_ids is true' do
+ let(:generate_ids) { true }
+
+ it_behaves_like 'generating id', 'my_id'
+ end
+
+ context 'and :autogenerate_item_ids is false' do
+ let(:generate_ids) { false }
+
+ it_behaves_like 'generating id', 'my_id'
+ end
+ end
+
+ context "when the :id option isn't given" do
+ before do
+ allow(SimpleNavigation.config).to receive_messages(autogenerate_item_ids: generate_ids)
+ allow(item).to receive_messages(selected?: false, selected_by_condition?: false)
+ end
+
+ context 'and :autogenerate_item_ids is true' do
+ let(:generate_ids) { true }
+
+ it_behaves_like 'generating id', 'my_key'
+ end
+
+ context 'and :autogenerate_item_ids is false' do
+ let(:generate_ids) { false }
+
+ it "doesn't set any html id on the item" do
+ expect(item.html_options[:id]).to be_blank
+ end
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/items_provider_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/items_provider_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/items_provider_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/items_provider_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,44 @@
+module SimpleNavigation
+ describe ItemsProvider do
+ let(:items_provider) { ItemsProvider.new(provider) }
+
+ describe '#items' do
+ let(:items) { double(:items) }
+
+ context 'when provider is a symbol' do
+ let(:context) { double(:context, provider_method: items) }
+ let(:provider) { :provider_method }
+
+ before { allow(SimpleNavigation).to receive_messages(context_for_eval: context) }
+
+ it 'retrieves the items from the evaluation context' do
+ expect(items_provider.items).to eq items
+ end
+ end
+
+ context 'when provider responds to :items' do
+ let(:provider) { double(:provider, items: items) }
+
+ it 'retrieves the items from the provider object' do
+ expect(items_provider.items).to eq items
+ end
+ end
+
+ context 'provider is a collection' do
+ let(:provider) { [] }
+
+ it 'retrieves the items by returning the provider' do
+ expect(items_provider.items).to eq provider
+ end
+ end
+
+ context 'when provider is something else' do
+ let(:provider) { double(:provider) }
+
+ it 'raises an exception' do
+ expect{ items_provider.items }.to raise_error
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/base_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/base_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/base_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/base_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,238 @@
+module SimpleNavigation
+ module Renderer
+ describe Base do
+ subject(:base) { Base.new(options) }
+
+ let(:adapter) { double(:adapter) }
+ let(:options) { Hash.new }
+
+ before { allow(SimpleNavigation).to receive_messages(adapter: adapter) }
+
+ it 'delegates the :link_to method to adapter' do
+ allow(adapter).to receive_messages(link_to: 'link_to')
+ expect(base.link_to).to eq 'link_to'
+ end
+
+ it 'delegates the :content_tag method to adapter' do
+ allow(adapter).to receive_messages(content_tag: 'content_tag')
+ expect(base.content_tag).to eq 'content_tag'
+ end
+
+ describe '#initialize' do
+ it "sets the renderer adapter to the SimpleNavigation one" do
+ expect(base.adapter).to be adapter
+ end
+ end
+
+ describe '#options' do
+ it "returns the renderer's options" do
+ expect(base.options).to be options
+ end
+ end
+
+ describe '#render' do
+ it "raise an exception to indicate it's a subclass responsibility" do
+ expect{ base.render(:container) }.to raise_error
+ end
+ end
+
+ describe '#expand_all?' do
+ context 'when :options is set' do
+ context 'and the :expand_all option is true' do
+ let(:options) {{ expand_all: true }}
+
+ it 'returns true' do
+ expect(base.expand_all?).to be true
+ end
+ end
+
+ context 'and the :expand_all option is false' do
+ let(:options) {{ expand_all: false }}
+
+ it 'returns false' do
+ expect(base.expand_all?).to be false
+ end
+ end
+ end
+
+ context "when :options isn't set" do
+ let(:options) { Hash.new }
+
+ it 'returns false' do
+ expect(base.expand_all?).to be false
+ end
+ end
+ end
+
+ describe '#skip_if_empty?' do
+ context 'when :options is set' do
+ context 'and the :skip_if_empty option is true' do
+ let(:options) {{ skip_if_empty: true }}
+
+ it 'returns true' do
+ expect(base.skip_if_empty?).to be true
+ end
+ end
+
+ context 'and the :skip_if_empty option is false' do
+ let(:options) {{ skip_if_empty: false }}
+
+ it 'returns true' do
+ expect(base.skip_if_empty?).to be false
+ end
+ end
+ end
+
+ context "when :options isn't set" do
+ let(:options) { Hash.new }
+
+ it 'returns true' do
+ expect(base.skip_if_empty?).to be false
+ end
+ end
+ end
+
+ describe '#level' do
+ context 'and the :level option is set' do
+ let(:options) {{ level: 1 }}
+
+ it 'returns the specified level' do
+ expect(base.level).to eq 1
+ end
+ end
+
+ context "and the :level option isn't set" do
+ let(:options) { Hash.new }
+
+ it 'returns :all' do
+ expect(base.level).to eq :all
+ end
+ end
+ end
+
+ describe '#consider_sub_navigation?' do
+ let(:item) { double(:item) }
+
+ before { allow(item).to receive_messages(sub_navigation: sub_navigation) }
+
+ context 'when the item has no sub navigation' do
+ let(:sub_navigation) { nil }
+
+ it 'returns false' do
+ expect(base.send(:consider_sub_navigation?, item)).to be false
+ end
+ end
+
+ context 'when the item has sub navigation' do
+ let(:sub_navigation) { double(:sub_navigation) }
+
+ context 'and the renderer has an unknown level' do
+ before { allow(base).to receive_messages(level: 'unknown') }
+
+ it 'returns false' do
+ expect(base.send(:consider_sub_navigation?, item)).to be false
+ end
+ end
+
+ context 'and the renderer has a level set to :all' do
+ before { allow(base).to receive_messages(level: :all) }
+
+ it 'returns false' do
+ expect(base.send(:consider_sub_navigation?, item)).to be true
+ end
+ end
+
+ context "when the renderer's level is a number" do
+ before { allow(base).to receive_messages(level: 2) }
+
+ it 'returns false' do
+ expect(base.send(:consider_sub_navigation?, item)).to be false
+ end
+ end
+
+ context "when the renderer's level is a Range" do
+ before { allow(base).to receive_messages(level: 2..3) }
+
+ context "and sub navigation's level is greater than range.max" do
+ before { allow(sub_navigation).to receive_messages(level: 4) }
+
+ it 'returns false' do
+ expect(base.send(:consider_sub_navigation?, item)).to be false
+ end
+ end
+
+ context "and sub navigation's level is equal to range.max" do
+ before { allow(sub_navigation).to receive_messages(level: 3) }
+
+ it 'returns true' do
+ expect(base.send(:consider_sub_navigation?, item)).to be true
+ end
+ end
+
+ context "and sub navigation's level is equal to range.min" do
+ before { allow(sub_navigation).to receive_messages(level: 2) }
+
+ it 'returns true' do
+ expect(base.send(:consider_sub_navigation?, item)).to be true
+ end
+ end
+ end
+ end
+ end
+
+ describe '#include_sub_navigation?' do
+ let(:item) { double(:item) }
+
+ context 'when consider_sub_navigation? is true' do
+ before { allow(base).to receive_messages(consider_sub_navigation?: true) }
+
+ context 'and expand_sub_navigation? is true' do
+ before { allow(base).to receive_messages(expand_sub_navigation?: true) }
+
+ it 'returns true' do
+ expect(base.include_sub_navigation?(item)).to be true
+ end
+ end
+
+ context 'and expand_sub_navigation? is false' do
+ before { allow(base).to receive_messages(expand_sub_navigation?: false) }
+
+ it 'returns false' do
+ expect(base.include_sub_navigation?(item)).to be false
+ end
+ end
+ end
+
+ context 'consider_sub_navigation? is false' do
+ before { allow(base).to receive_messages(consider_sub_navigation?: false) }
+
+ context 'and expand_sub_navigation? is true' do
+ before { allow(base).to receive_messages(expand_sub_navigation?: true) }
+
+ it 'returns false' do
+ expect(base.include_sub_navigation?(item)).to be false
+ end
+ end
+
+ context 'and expand_sub_navigation? is false' do
+ before { allow(base).to receive_messages(expand_sub_navigation?: false) }
+
+ it 'returns false' do
+ expect(base.include_sub_navigation?(item)).to be false
+ end
+ end
+ end
+ end
+
+ describe '#render_sub_navigation_for' do
+ let(:item) { double(:item, sub_navigation: sub_navigation) }
+ let(:sub_navigation) { double(:sub_navigation) }
+
+ it 'renders the sub navigation passing it the options' do
+ expect(sub_navigation).to receive(:render).with(options)
+ base.render_sub_navigation_for(item)
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/breadcrumbs_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/breadcrumbs_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/breadcrumbs_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/breadcrumbs_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,118 @@
+module SimpleNavigation
+ module Renderer
+ describe Breadcrumbs do
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
+
+ let(:item) { nil }
+ let(:options) {{ level: :all }}
+ let(:output) { HTML::Document.new(raw_output).root }
+ let(:raw_output) { renderer.render(navigation) }
+ let(:renderer) { Breadcrumbs.new(options) }
+
+ before { select_an_item(navigation[item]) if item }
+
+ describe '#render' do
+ it "renders a 'div' tag for the navigation" do
+ expect(output).to have_css('div')
+ end
+
+ it "sets the right html id on the rendered 'div' tag" do
+ expect(output).to have_css('div#nav_id')
+ end
+
+ it "sets the right html classes on the rendered 'div' tag" do
+ expect(output).to have_css('div.nav_class')
+ end
+
+ context 'when no item is selected' do
+ it "doesn't render any 'a' tag in the 'div' tag" do
+ expect(output).not_to have_css('div a')
+ end
+ end
+
+ context 'when an item is selected' do
+ let(:item) { :invoices }
+
+ it "renders the selected 'a' tag" do
+ expect(output).to have_css('div a')
+ end
+
+ it "remders the 'a' tag without any html id" do
+ expect(output).not_to have_css('div a[id]')
+ end
+
+ it "renders the 'a' tag without any html class" do
+ expect(output).not_to have_css('div a[class]')
+ end
+
+ context 'and the :allow_classes_and_ids option is true' do
+ let(:options) {{ level: :all, allow_classes_and_ids: true }}
+
+ it "renders the 'a' tag with the selected class" do
+ expect(output).to have_css('div a.selected')
+ end
+
+ context "and the item hasn't any id explicitly set" do
+ it "renders the 'a' tag without any html id" do
+ expect(output).not_to have_css('div a[id]')
+ end
+ end
+
+ context 'and the item has an explicitly set id' do
+ let(:item) { :users }
+
+ it "renders the 'a' tag with an html id" do
+ expect(output).to have_css('div a#breadcrumb_users_link_id')
+ end
+ end
+ end
+ end
+
+ context 'and the :prefix option is set' do
+ let(:options) {{ prefix: 'You are here: ' }}
+
+ context 'and there are no items to render' do
+ let(:item) { nil }
+
+ it "doesn't render the prefix before the breadcrumbs" do
+ expect(raw_output).not_to match(/^You are here: /)
+ end
+ end
+
+ context 'and there are items to render' do
+ let(:item) { :invoices }
+
+ it 'renders the prefix before the breadcrumbs' do
+ expect(raw_output).to match(/^You are here: /)
+ end
+ end
+ end
+
+ context 'when a sub navigation item is selected' do
+ before do
+ allow(navigation[:invoices]).to receive_messages(selected?: true)
+
+ allow(navigation[:invoices].sub_navigation[:unpaid]).to \
+ receive_messages(selected?: true, selected_by_condition?: true)
+ end
+
+ it 'renders all items as links' do
+ expect(output).to have_css('div a', 2)
+ end
+
+ context 'when the :static_leaf option is true' do
+ let(:options) {{ level: :all, static_leaf: true }}
+
+ it 'renders the items as links' do
+ expect(output).to have_css('div a')
+ end
+
+ it 'renders the last item as simple text' do
+ expect(output).to have_css('div span')
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/json_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/json_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/json_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/json_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,63 @@
+module SimpleNavigation
+ module Renderer
+ describe Json do
+ describe '#render' do
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
+
+ let(:item) { :invoices }
+ let(:options) {{ level: :all }}
+ let(:output) { renderer.render(navigation) }
+ let(:parsed_output) { JSON.parse(output) }
+ let(:renderer) { Json.new(options) }
+
+ before { select_an_item(navigation[item]) if item }
+
+ context 'when an item is selected' do
+
+ it 'renders the selected page' do
+ invoices_item = parsed_output.find { |item| item['name'] == 'Invoices' }
+ expect(invoices_item).to include('selected' => true)
+ end
+ end
+
+ # FIXME: not sure if :as_hash returning an array makes sense...
+ context 'when the :as_hash option is true' do
+ let(:options) {{ level: :all, as_hash: true }}
+
+ it 'returns a hash' do
+ expect(output).to be_an Array
+ end
+
+ it 'renders the selected page' do
+ invoices_item = output.find { |item| item[:name] == 'Invoices' }
+ expect(invoices_item).to include(selected: true)
+ end
+ end
+
+ context 'when a sub navigation item is selected' do
+ let(:invoices_item) do
+ parsed_output.find { |item| item['name'] == 'Invoices' }
+ end
+ let(:unpaid_item) do
+ invoices_item['items'].find { |item| item['name'] == 'Unpaid' }
+ end
+
+ before do
+ allow(navigation[:invoices]).to receive_messages(selected?: true)
+
+ allow(navigation[:invoices].sub_navigation[:unpaid]).to \
+ receive_messages(selected?: true, selected_by_condition?: true)
+ end
+
+ it 'marks all the parent items as selected' do
+ expect(invoices_item).to include('selected' => true)
+ end
+
+ it 'marks the item as selected' do
+ expect(unpaid_item).to include('selected' => true)
+ end
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/links_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/links_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/links_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/links_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,88 @@
+module SimpleNavigation
+ module Renderer
+ describe Links do
+ describe '#render' do
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
+
+ let(:item) { nil }
+ let(:options) {{ level: :all }}
+ let(:output) { HTML::Document.new(raw_output).root }
+ let(:raw_output) { renderer.render(navigation) }
+ let(:renderer) { Links.new(options) }
+
+ before { select_an_item(navigation[item]) if item }
+
+ it "renders a 'div' tag for the navigation" do
+ expect(output).to have_css('div')
+ end
+
+ it "sets the right html id on the rendered 'div' tag" do
+ expect(output).to have_css('div#nav_id')
+ end
+
+ it "sets the right html classes on the rendered 'div' tag" do
+ expect(output).to have_css('div.nav_class')
+ end
+
+ it "renders an 'a' tag for each item" do
+ expect(output).to have_css('a', 3)
+ end
+
+ it "renders the 'a' tags with the corresponding item's :html_options" do
+ expect(output).to have_css('a[style=float:right]')
+ end
+
+ context 'when an item has a specified id' do
+ it "renders the 'a' tags with the specified id" do
+ expect(output).to have_css('a#users_id')
+ end
+ end
+
+ context 'when an item has no specified id' do
+ it "uses a default id by stringifying the item's key" do
+ expect(output).to have_css('a#invoices')
+ end
+ end
+
+ context 'when no item is selected' do
+ it "renders items without the 'selected' class" do
+ expect(output).not_to have_css('a.selected')
+ end
+ end
+
+ context 'when an item is selected' do
+ let(:item) { :invoices }
+
+ it "renders the selected item with the 'selected' class" do
+ expect(output).to have_css('a#invoices.selected')
+ end
+ end
+
+ context "when the :join_with option is set" do
+ let(:options) {{ level: :all, join_with: ' | ' }}
+
+ it 'separates the items with the specified separator' do
+ expect(raw_output.scan(' | ').size).to eq 3
+ end
+ end
+
+ context 'when a sub navigation item is selected' do
+ before do
+ allow(navigation[:invoices]).to receive_messages(selected?: true)
+
+ allow(navigation[:invoices].sub_navigation[:unpaid]).to \
+ receive_messages(selected?: true, selected_by_condition?: true)
+ end
+
+ it 'renders the main parent as selected' do
+ expect(output).to have_css('a#invoices.selected')
+ end
+
+ it "doesn't render the nested item's link" do
+ expect(output).not_to have_css('a#unpaid')
+ end
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/list_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/list_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/list_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/list_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,96 @@
+module SimpleNavigation
+ module Renderer
+ describe List do
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
+
+ let(:item) { nil }
+ let(:options) {{ level: :all }}
+ let(:output) { HTML::Document.new(raw_output).root }
+ let(:raw_output) { renderer.render(navigation) }
+ let(:renderer) { List.new(options) }
+
+ before { select_an_item(navigation[item]) if item }
+
+ describe '#render' do
+ it "renders an 'ul' tag for the navigation" do
+ expect(output).to have_css('ul')
+ end
+
+ it "sets the right html id on the rendered 'ul' tag" do
+ expect(output).to have_css('ul#nav_id')
+ end
+
+ it "sets the right html classes on the rendered 'ul' tag" do
+ expect(output).to have_css('ul.nav_class')
+ end
+
+ context 'when an item has no specified id' do
+ it "renders the item's 'li' tag with the item's stingified key as id" do
+ expect(output).to have_css('li#invoices')
+ end
+ end
+
+ context 'when an item has a specified id' do
+ it "renders the item's 'li' tag with the specified id" do
+ expect(output).to have_css('li#users_id')
+ end
+ end
+
+ context 'when no item is selected' do
+ it "renders each item as 'li' tag without any selected class" do
+ expect(output).not_to have_css('ul li.selected')
+ end
+
+ it "renders each item as 'a' tag without any selected class" do
+ expect(output).not_to have_css('ul li a.selected')
+ end
+ end
+
+ context 'when an item is selected' do
+ let(:item) { :invoices }
+
+ it "renders the item's 'li' tag with its id and selected classes" do
+ expect(output).to have_css('li#invoices.selected')
+ end
+
+ it "renders the item's 'a' tag with the selected classes" do
+ expect(output).to have_css('li#invoices a.selected')
+ end
+ end
+
+ context 'when the :ordered option is true' do
+ let(:options) {{ level: :all, ordered: true }}
+
+ it "renders an 'ol' tag for the navigation" do
+ expect(output).to have_css('ol')
+ end
+
+ it "sets the right html id on the rendered 'ol' tag" do
+ expect(output).to have_css('ol#nav_id')
+ end
+
+ it "sets the right html classes on the rendered 'ol' tag" do
+ expect(output).to have_css('ol.nav_class')
+ end
+ end
+
+ context 'when a sub navigation item is selected' do
+ before do
+ allow(navigation[:invoices]).to receive_messages(selected?: true)
+
+ allow(navigation[:invoices].sub_navigation[:unpaid]).to \
+ receive_messages(selected?: true, selected_by_condition?: true)
+ end
+
+ it 'renders the parent items as selected' do
+ expect(output).to have_css('li#invoices.selected')
+ end
+
+ it "renders the selected nested item's link as selected" do
+ expect(output).to have_css('li#unpaid.selected')
+ end
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/text_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/text_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation/renderer/text_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation/renderer/text_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,51 @@
+module SimpleNavigation
+ module Renderer
+ describe Text do
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
+
+ let(:item) { nil }
+ let(:options) {{ level: :all }}
+ let(:output) { renderer.render(navigation) }
+ let(:renderer) { Text.new(options) }
+
+ before { select_an_item(navigation[item]) if item }
+
+ describe '#render' do
+ context 'when no item is selected' do
+ it 'renders an empty string' do
+ expect(output).to eq ''
+ end
+ end
+
+ context 'when an item is selected' do
+ let(:item) { :invoices }
+
+ it "renders the selected item's name" do
+ expect(output).to eq 'Invoices'
+ end
+ end
+
+ context 'when a sub navigation item is selected' do
+ before do
+ allow(navigation[:invoices]).to receive_messages(selected?: true)
+
+ allow(navigation[:invoices].sub_navigation[:unpaid]).to \
+ receive_messages(selected?: true, selected_by_condition?: true)
+ end
+
+ it 'separates the items with a space' do
+ expect(output).to eq 'Invoices Unpaid'
+ end
+
+ context "and the :join_with option is set" do
+ let(:options) {{ level: :all, join_with: ' | ' }}
+
+ it 'separates the items with the specified separator' do
+ expect(output).to eq 'Invoices | Unpaid'
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/simple_navigation_spec.rb ruby-simple-navigation-4.0.3/spec/simple_navigation_spec.rb
--- ruby-simple-navigation-3.11.0/spec/simple_navigation_spec.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/simple_navigation_spec.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,190 @@
+describe SimpleNavigation do
+ before { subject.config_file_path = 'path_to_config' }
+
+ describe 'config_file_path=' do
+ before { subject.config_file_paths = ['existing_path'] }
+
+ it 'overrides the config_file_paths' do
+ subject.config_file_path = 'new_path'
+ expect(subject.config_file_paths).to eq ['new_path']
+ end
+ end
+
+ describe '.default_config_file_path' do
+ before { allow(subject).to receive_messages(root: 'root') }
+
+ it 'returns the config file path according to :root setting' do
+ expect(subject.default_config_file_path).to eq 'root/config'
+ end
+ end
+
+ describe 'Regarding renderers' do
+ it 'registers the builtin renderers by default' do
+ expect(subject.registered_renderers).not_to be_empty
+ end
+
+ describe '.register_renderer' do
+ let(:renderer) { double(:renderer) }
+
+ it 'adds the specified renderer to the list of renderers' do
+ subject.register_renderer(my_renderer: renderer)
+ expect(subject.registered_renderers[:my_renderer]).to be renderer
+ end
+ end
+ end
+
+ describe '.set_env' do
+ before do
+ subject.config_file_paths = []
+ allow(subject).to receive_messages(default_config_file_path: 'default_path')
+ subject.set_env('root', 'my_env')
+ end
+
+ it 'sets the root' do
+ expect(subject.root).to eq 'root'
+ end
+
+ it 'sets the environment' do
+ expect(subject.environment).to eq 'my_env'
+ end
+
+ it 'adds the default-config path to the list of config_file_paths' do
+ expect(subject.config_file_paths).to eq ['default_path']
+ end
+ end
+
+ describe '.load_config', memfs: true do
+ let(:paths) { ['/path/one', '/path/two'] }
+
+ before do
+ FileUtils.mkdir_p(paths)
+ allow(subject).to receive_messages(config_file_paths: paths)
+ end
+
+ context 'when the config file for the context exists' do
+ before do
+ File.open('/path/two/navigation.rb', 'w') { |f| f.puts 'default content' }
+ File.open('/path/one/other_navigation.rb', 'w') { |f| f.puts 'other content' }
+ end
+
+ context 'when no context is provided' do
+ it 'stores the configuration in config_files for the default context' do
+ subject.load_config
+ expect(subject.config_files[:default]).to eq "default content\n"
+ end
+ end
+
+ context 'when a context is provided' do
+ it 'stores the configuration in config_files for the given context' do
+ subject.load_config(:other)
+ expect(subject.config_files[:other]).to eq "other content\n"
+ end
+ end
+
+ context 'and environment is production' do
+ before { allow(subject).to receive_messages(environment: 'production') }
+
+ it 'loads the config file only for the first call' do
+ subject.load_config
+ File.open('/path/two/navigation.rb', 'w') { |f| f.puts 'new content' }
+ subject.load_config
+ expect(subject.config_files[:default]).to eq "default content\n"
+ end
+ end
+
+ context "and environment isn't production" do
+ it 'loads the config file for every call' do
+ subject.load_config
+ File.open('/path/two/navigation.rb', 'w') { |f| f.puts 'new content' }
+ subject.load_config
+ expect(subject.config_files[:default]).to eq "new content\n"
+ end
+ end
+ end
+
+ context "when the config file for the context doesn't exists" do
+ it 'raises an exception' do
+ expect{ subject.load_config }.to raise_error
+ end
+ end
+ end
+
+ describe '.config' do
+ it 'returns the Configuration singleton instance' do
+ expect(subject.config).to be SimpleNavigation::Configuration.instance
+ end
+ end
+
+ describe '.active_item_container_for' do
+ let(:primary) { double(:primary) }
+
+ before { allow(subject.config).to receive_messages(primary_navigation: primary) }
+
+ context 'when level is :all' do
+ it 'returns the primary_navigation' do
+ nav = subject.active_item_container_for(:all)
+ expect(nav).to be primary
+ end
+ end
+
+ context 'when level is :leaves' do
+ it 'returns the currently active leaf-container' do
+ expect(primary).to receive(:active_leaf_container)
+ subject.active_item_container_for(:leaves)
+ end
+ end
+
+ context 'when level is a Range' do
+ it 'takes the min of the range to lookup the active container' do
+ expect(primary).to receive(:active_item_container_for).with(2)
+ subject.active_item_container_for(2..3)
+ end
+ end
+
+ context 'when level is an Integer' do
+ it 'considers the Integer to lookup the active container' do
+ expect(primary).to receive(:active_item_container_for).with(1)
+ subject.active_item_container_for(1)
+ end
+ end
+
+ context 'when level is something else' do
+ it 'raises an exception' do
+ expect{
+ subject.active_item_container_for('something else')
+ }.to raise_error
+ end
+ end
+ end
+
+ describe '.load_adapter' do
+ shared_examples 'loading the right adapter' do |framework, adapter|
+ context "when the context is #{framework}" do
+ before do
+ allow(subject).to receive_messages(framework: framework)
+ subject.load_adapter
+ end
+
+ it "returns the #{framework} adapter" do
+ adapter_class = SimpleNavigation::Adapters.const_get(adapter)
+ expect(subject.adapter_class).to be adapter_class
+ end
+ end
+ end
+
+ it_behaves_like 'loading the right adapter', :rails, :Rails
+ it_behaves_like 'loading the right adapter', :padrino, :Padrino
+ it_behaves_like 'loading the right adapter', :sinatra, :Sinatra
+ end
+
+ describe '.init_adapter_from' do
+ let(:adapter) { double(:adapter) }
+ let(:adapter_class) { double(:adapter_class, new: adapter) }
+
+ it 'sets the adapter to a new instance of adapter_class' do
+ subject.adapter_class = adapter_class
+ subject.init_adapter_from(:default)
+ expect(subject.adapter).to be adapter
+ end
+ end
+end
diff -Nru ruby-simple-navigation-3.11.0/spec/spec_helper.rb ruby-simple-navigation-4.0.3/spec/spec_helper.rb
--- ruby-simple-navigation-3.11.0/spec/spec_helper.rb 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/spec/spec_helper.rb 2015-04-16 17:17:37.000000000 +0000
@@ -1,108 +1,73 @@
-ENV["RAILS_ENV"] = "test"
-require 'rubygems'
-require 'rspec'
-require 'json_spec'
-require 'action_controller'
-
-module Rails
- module VERSION
- MAJOR = 2
+require 'initializers/have_css_matcher'
+require 'initializers/memfs'
+require 'initializers/coveralls'
+require 'initializers/rails'
+require 'initializers/rspec'
+require 'capybara/rspec'
+
+require 'bundler/setup'
+Bundler.require
+
+if defined? Rails
+ require 'fake_app/rails_app'
+ require 'rspec/rails'
+
+ Capybara.app = RailsApp::Application
+
+ RSpec.configure do |config|
+ config.before do
+ SimpleNavigation.config_files.clear
+ setup_adapter_for :rails
+ end
end
-end unless defined? Rails
-
-$:.unshift File.dirname(__FILE__)
-$:.unshift File.join(File.dirname(__FILE__), '../lib')
-
-require 'simple_navigation'
-
-# SimpleNavigation.root = './'
-RAILS_ROOT = './' unless defined?(RAILS_ROOT)
-RAILS_ENV = 'test' unless defined?(RAILS_ENV)
-
-
-RSpec.configure do |config|
- # == Mock Framework
- #
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
- #
- # config.mock_with :mocha
- # config.mock_with :flexmock
- # config.mock_with :rr
- config.mock_with :rspec
- config.include JsonSpec::Helpers
end
-# spec helper methods
-def sub_items
- [
- [:subnav1, 'subnav1', 'subnav1_url'],
- [:subnav2, 'subnav2', 'subnav2_url']
- ]
-end
+def setup_adapter_for(framework, context = double(:context))
+ if framework == :rails
+ allow(context).to receive_messages(view_context: ActionView::Base.new)
+ end
-def primary_items
- [
- [:users, 'users', 'first_url', {:id => 'my_id', :link => {:id => 'my_link_id'}}],
- [:invoices, 'invoices', 'second_url'],
- [:accounts, 'accounts', 'third_url', {:style => 'float:right', :link => {:style => 'float:left'}}],
- [:miscellany, 'miscellany']
- ]
+ allow(SimpleNavigation).to receive_messages(framework: framework)
+ SimpleNavigation.load_adapter
+ SimpleNavigation.init_adapter_from(context)
end
-def primary_container
- containers.first
+def select_an_item(item)
+ allow(item).to receive_messages(selected?: true)
end
-def containers
+def setup_container(dom_id, dom_class)
container = SimpleNavigation::ItemContainer.new(1)
- container.dom_id = 'nav_dom_id'
- container.dom_class = 'nav_dom_class'
- @items = primary_items.map {|params| SimpleNavigation::Item.new(container, *params)}
- @items.each {|i| i.stub!(:selected? => false, :selected_by_condition? => false)}
- container.instance_variable_set(:@items, @items)
- sub_container = subnav_container
- primary_item(:invoices) {|item| item.instance_variable_set(:@sub_navigation, sub_container)}
- [container,sub_container]
-end
-
-def primary_item(key)
- item = @items.find {|i| i.key == key}
- block_given? ? yield(item) : item
-end
-
-def sub_item(key)
- primary_item(:invoices).instance_variable_get(:@sub_navigation).items.find { |i| i.key == key}
-end
-
-def select_item(key)
- if(key == :subnav1)
- select_item(:invoices)
- primary_item(:invoices) do |item|
- item.instance_variable_get(:@sub_navigation).items.find { |i| i.key == key}.stub!(:selected? => true, :selected_by_condition? => true)
- end
- else
- primary_item(key) {|item| item.stub!(:selected? => true) unless item.frozen?}
- end
+ container.dom_id = dom_id
+ container.dom_class = dom_class
+ container
end
-def subnav_container
- container = SimpleNavigation::ItemContainer.new(2)
- items = sub_items.map {|params| SimpleNavigation::Item.new(container, *params)}
- items.each {|i| i.stub!(:selected? => false, :selected_by_condition? => false)}
- container.instance_variable_set(:@items, items)
+def setup_navigation(dom_id, dom_class)
+ setup_adapter_for :rails
+ container = setup_container(dom_id, dom_class)
+ setup_items(container)
container
end
-def setup_renderer_for(renderer_class, framework, options)
- setup_adapter_for framework
- @renderer = renderer_class.new(options)
-end
+# FIXME: adding the :link option for the list renderer messes up the other
+# renderers
+def setup_items(container)
+ container.item :users, 'Users', '/users', html: { id: 'users_id' }, link_html: { id: 'users_link_id' }
+ container.item :invoices, 'Invoices', '/invoices' do |invoices|
+ invoices.item :paid, 'Paid', '/invoices/paid'
+ invoices.item :unpaid, 'Unpaid', '/invoices/unpaid'
+ end
+ container.item :accounts, 'Accounts', '/accounts', html: { style: 'float:right' }
+ container.item :miscellany, 'Miscellany'
+
+ container.items.each do |item|
+ allow(item).to receive_messages(selected?: false, selected_by_condition?: false)
-def setup_adapter_for(framework)
- adapter = case framework
- when :rails
- SimpleNavigation::Adapters::Rails.new(stub(:context, :view_context => ActionView::Base.new))
+ if item.sub_navigation
+ item.sub_navigation.items.each do |item|
+ allow(item).to receive_messages(selected?: false, selected_by_condition?: false)
+ end
+ end
end
- SimpleNavigation.stub!(:adapter => adapter)
- adapter
end
diff -Nru ruby-simple-navigation-3.11.0/.travis.yml ruby-simple-navigation-4.0.3/.travis.yml
--- ruby-simple-navigation-3.11.0/.travis.yml 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/.travis.yml 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1,12 @@
+before_install:
+ - gem install bundler
+
+rvm:
+ - 2.0.0
+ - 2.1.5
+ - 2.2.1
+
+gemfile:
+ - gemfiles/rails-4-2-stable.gemfile
+ - gemfiles/rails-4-1-stable.gemfile
+ - gemfiles/rails-3-2-stable.gemfile
diff -Nru ruby-simple-navigation-3.11.0/uninstall.rb ruby-simple-navigation-4.0.3/uninstall.rb
--- ruby-simple-navigation-3.11.0/uninstall.rb 1970-01-01 00:00:00.000000000 +0000
+++ ruby-simple-navigation-4.0.3/uninstall.rb 2015-04-16 17:17:37.000000000 +0000
@@ -0,0 +1 @@
+# Uninstall hook code here
diff -Nru ruby-simple-navigation-3.11.0/VERSION ruby-simple-navigation-4.0.3/VERSION
--- ruby-simple-navigation-3.11.0/VERSION 2013-08-11 22:57:59.000000000 +0000
+++ ruby-simple-navigation-4.0.3/VERSION 1970-01-01 00:00:00.000000000 +0000
@@ -1 +0,0 @@
-3.11.0
\ No newline at end of file