spec/lib/simple_navigation_spec.rb in simple-navigation-2.7.3 vs spec/lib/simple_navigation_spec.rb in simple-navigation-3.0.0.beta1
- old
+ new
@@ -1,9 +1,13 @@
require File.dirname(__FILE__) + '/../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
@@ -16,37 +20,10 @@
SimpleNavigation.config_file_name(:WhyWouldYouDoThis).should == 'why_would_you_do_this_navigation.rb'
end
end
end
- describe 'config_file_paths_sentence' do
- context 'no paths are set' do
- before(:each) do
- SimpleNavigation.config_file_paths = []
- end
- it {SimpleNavigation.config_file_paths_sentence.should == ''}
- end
- context 'one path is set' do
- before(:each) do
- SimpleNavigation.config_file_paths = ['first_path']
- end
- it {SimpleNavigation.config_file_paths_sentence.should == 'first_path'}
- end
- context 'two paths are set' do
- before(:each) do
- SimpleNavigation.config_file_paths = ['first_path', 'second_path']
- end
- it {SimpleNavigation.config_file_paths_sentence.should == 'first_path or second_path'}
- end
- context 'three pahts are set' do
- before(:each) do
- SimpleNavigation.config_file_paths = ['first_path', 'second_path', 'third_path']
- end
- it {SimpleNavigation.config_file_paths_sentence.should == 'first_path, second_path, or third_path'}
- 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
@@ -120,177 +97,51 @@
SimpleNavigation.stub!(:config_file => nil)
end
it {SimpleNavigation.config_file?.should be_false}
end
end
-
- describe 'set_template_from' do
- before(:each) do
- @context = stub :context
- SimpleNavigation.stub!(:extract_controller_from => @controller)
- end
- context 'regarding setting the controller' do
- it "should set the controller" do
- @controller = Object.new
- SimpleNavigation.should_receive(:extract_controller_from).with(@context).and_return(@controller)
- SimpleNavigation.should_receive(:controller=).with(@controller)
- SimpleNavigation.set_template_from @context
- end
- end
- context 'regarding setting the template' do
- before(:each) do
- @template = stub :template
- @controller = Object.new
- SimpleNavigation.stub!(:controller => @controller)
- end
- 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)
- end
- it {SimpleNavigation.should_receive(:template=).with(@template)}
- end
- context 'template is not set' do
- before(:each) do
- @controller.stub!(:instance_variable_get => nil)
- end
- it {SimpleNavigation.should_receive(:template=).with(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)
- end
- it {SimpleNavigation.should_receive(:template=).with(@template)}
- end
- context 'template is not set' do
- before(:each) do
- @controller.stub!(:view_context => nil)
- end
- it {SimpleNavigation.should_receive(:template=).with(nil)}
- end
- end
- after(:each) do
- SimpleNavigation.set_template_from @context
- end
-
- end
- end
- describe 'self.init_rails' do
- before(:each) do
- SimpleNavigation.config_file_paths = []
- SimpleNavigation.stub!(:default_config_file_path => 'default_path')
- ActionController::Base.stub!(:include)
- end
- context 'SimpleNavigation.config_file_path is already set' do
- before(:each) do
- SimpleNavigation.config_file_path = 'my_path'
- end
- it "should have both the default_path and the new path" do
- SimpleNavigation.init_rails
- SimpleNavigation.config_file_paths.should == ['my_path', 'default_path']
- end
- end
- context 'SimpleNavigation.config_file_paths are not set' do
- it "should set the config_file_path to the default" do
- SimpleNavigation.init_rails
- SimpleNavigation.config_file_paths.should == ['default_path']
- end
- end
- it "should extend the ActionController::Base" do
- ActionController::Base.should_receive(:include).with(SimpleNavigation::ControllerMethods)
- SimpleNavigation.init_rails
- end
- end
-
describe 'self.default_config_file_path' do
- it {SimpleNavigation.default_config_file_path.should == './config'}
- end
-
- describe 'self.extract_controller_from' do
before(:each) do
- @nav_context = stub(:nav_context)
+ SimpleNavigation.stub!(:root => 'root')
end
-
- context 'object responds to controller' do
- before(:each) do
- @controller = stub(:controller)
- @nav_context.stub!(:controller).and_return(@controller)
- end
-
- it "should return the controller" do
- SimpleNavigation.send(:extract_controller_from, @nav_context).should == @controller
- end
-
- end
-
- context 'object does not respond to controller' do
- it "should return the nav_context" do
- SimpleNavigation.send(:extract_controller_from, @nav_context).should == @nav_context
- end
- end
+ it {SimpleNavigation.default_config_file_path.should == 'root/config'}
end
- describe 'context_for_eval' do
- context 'controller is present' do
- before(:each) do
- @controller = stub(:controller)
- SimpleNavigation.stub!(:controller => @controller)
- end
- context 'template is present' do
- before(:each) do
- @template = stub(:template)
- SimpleNavigation.stub!(:template => @template)
- end
- it {SimpleNavigation.context_for_eval.should == @template}
- end
- context 'template is not present' do
- before(:each) do
- SimpleNavigation.stub!(:template => nil)
- end
- it {SimpleNavigation.context_for_eval.should == @controller}
- end
- end
- context 'controller is not present' do
- before(:each) do
- SimpleNavigation.stub!(:controller => nil)
- end
- context 'template is present' do
- before(:each) do
- @template = stub(:template)
- SimpleNavigation.stub!(:template => @template)
- end
- it {SimpleNavigation.context_for_eval.should == @template}
- end
- context 'template is not present' do
- before(:each) do
- SimpleNavigation.stub!(:template => nil)
- end
- it {lambda {SimpleNavigation.context_for_eval}.should raise_error}
- end
- end
- 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')
@@ -338,46 +189,46 @@
before(:each) do
IO.stub!(:read).and_return('file_content')
SimpleNavigation.config_file_path = 'path_to_config'
File.stub!(:exists? => true)
end
- context "RAILS_ENV undefined" do
+ context "environment undefined" do
before(:each) do
- SimpleNavigation.rails_env = nil
+ 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 "RAILS_ENV defined" do
+ context "environment defined" do
before(:each) do
- SimpleNavigation.rails_env = 'production'
+ SimpleNavigation.stub!(:environment => 'production')
end
- context "RAILS_ENV=production" do
+ 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 "RAILS_ENV=development" do
+ context "environment=development" do
before(:each) do
- SimpleNavigation.rails_env = 'development'
+ 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 "RAILS_ENV=test" do
+ context "environment=test" do
before(:each) do
- SimpleNavigation.rails_env = 'test'
+ SimpleNavigation.stub!(:environment => 'test')
end
it "should load the config file twice" do
IO.should_receive(:read).twice
SimpleNavigation.load_config
SimpleNavigation.load_config
@@ -388,63 +239,14 @@
SimpleNavigation.config_files = {}
end
end
end
- describe 'request' do
- context 'template is set' do
- before(:each) do
- @request = stub(:request)
- SimpleNavigation.stub!(:template => stub(:template, :request => @request))
- end
- it {SimpleNavigation.request.should == @request}
- end
- context 'template is not set' do
- it {SimpleNavigation.request.should be_nil}
- 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')
- SimpleNavigation.stub!(:request => @request)
- end
- it {SimpleNavigation.request_uri.should == '/fullpath'}
- end
- context 'fullpath is not defined on request' do
- before(:each) do
- @request = stub(:request, :request_uri => '/request_uri')
- SimpleNavigation.stub!(:request => @request)
- end
- it {SimpleNavigation.request_uri.should == '/request_uri'}
- end
- end
- context 'request is not set' do
- before(:each) do
- SimpleNavigation.stub!(:request => nil)
- end
- it {SimpleNavigation.request_uri.should == ''}
- end
- end
-
describe 'config' do
it {SimpleNavigation.config.should == SimpleNavigation::Configuration.instance}
end
- describe 'current_navigation_for' do
- before(:each) do
- @controller = stub(:controller)
- SimpleNavigation.stub!(:controller => @controller)
- 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
-
describe 'active_item_container_for' do
before(:each) do
@primary = stub(:primary)
SimpleNavigation.config.stub!(:primary_navigation => @primary)
end
@@ -470,79 +272,30 @@
lambda {SimpleNavigation.active_item_container_for('something else')}.should raise_error(ArgumentError)
end
end
end
- describe 'handle_explicit_navigation' do
- def args(*args)
- SimpleNavigation.stub!(:explicit_navigation_args => args.compact.empty? ? nil : args)
+ 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
-
- before(:each) do
- @controller = stub(:controller)
- SimpleNavigation.stub!(:controller => @controller)
- 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
+ context 'Padrino' do
+ before(:each) do
+ SimpleNavigation.stub!(:framework => :padrino)
+ SimpleNavigation.load_adapter
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 not raise an ArgumentError" do
- lambda {SimpleNavigation.handle_explicit_navigation}.should_not 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
+ it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Padrino}
end
- context 'without explicit navigation set' do
+ context 'Sinatra' do
before(:each) do
- args nil
+ SimpleNavigation.stub!(:framework => :sinatra)
+ SimpleNavigation.load_adapter
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
+ it {SimpleNavigation.adapter_class.should == SimpleNavigation::Adapters::Sinatra}
end
end
-
+
end