krasivotokak-simple-navigation 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,118 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+ require 'html/document' unless defined? HTML::Document
3
+
4
+ describe SimpleNavigation::Renderer::List do
5
+
6
+ describe 'render' do
7
+
8
+ def sub_items
9
+ [
10
+ SimpleNavigation::Item.new(:subnav1, 'subnav1', 'subnav1_url', {}, nil),
11
+ SimpleNavigation::Item.new(:subnav2, 'subnav2', 'subnav2_url', {}, nil)
12
+ ]
13
+ end
14
+
15
+ def primary_items
16
+ @item1 = SimpleNavigation::Item.new(:users, 'users', 'first_url', {:id => 'my_id'}, nil)
17
+ @item2 = SimpleNavigation::Item.new(:invoices, 'invoices', 'second_url', {}, nil)
18
+ @item3 = SimpleNavigation::Item.new(:accounts, 'accounts', 'third_url', {:style => 'float:right'}, nil)
19
+ @item2.instance_variable_set(:@sub_navigation, item_container(sub_items))
20
+ [@item1, @item2, @item3]
21
+ end
22
+
23
+ def item_container(items)
24
+ container = SimpleNavigation::ItemContainer.new
25
+ container.dom_id = 'nav_dom_id'
26
+ container.dom_class = 'nav_dom_class'
27
+ container.instance_variable_set(:@items, items)
28
+ container
29
+ end
30
+
31
+ def primary_navigation
32
+ @item_container = item_container(primary_items)
33
+ @item_container
34
+ end
35
+
36
+ def render(current_navigation=nil, include_subnav=false)
37
+ @renderer = SimpleNavigation::Renderer::List.new(current_navigation)
38
+ HTML::Document.new(@renderer.render(primary_navigation, include_subnav)).root
39
+ end
40
+
41
+ it "should render a ul-tag around the items" do
42
+ HTML::Selector.new('ul').select(render).should have(1).entries
43
+ end
44
+ it "the rendered ul-tag should have the specified dom_id" do
45
+ HTML::Selector.new('ul.nav_dom_id').select(render).should have(1).entries
46
+ end
47
+ it "the rendered ul-tag should have the specified class" do
48
+ HTML::Selector.new('ul.nav_dom_class').select(render).should have(1).entries
49
+ end
50
+ it "should render a li tag for each item" do
51
+ HTML::Selector.new('li').select(render).should have(3).entries
52
+ end
53
+ it "should render an a-tag inside each li-tag" do
54
+ HTML::Selector.new('li a').select(render).should have(3).entries
55
+ end
56
+ it "should pass the specified html_options to the li element" do
57
+ HTML::Selector.new('li[style=float:right]').select(render).should have(1).entries
58
+ end
59
+ it "should give the li the id specified in the html_options" do
60
+ HTML::Selector.new('li#my_id').select(render).should have(1).entries
61
+ end
62
+ it "should give the li the default id (stringified key) if no id is specified in the html_options" do
63
+ HTML::Selector.new('ul li.invoices').select(render).should have(1).entries
64
+ end
65
+ it "should not apply the the default id where there is an id specified in the html_options" do
66
+ HTML::Selector.new('ul li#users').select(render).should be_empty
67
+ end
68
+
69
+ context 'with current_navigation set' do
70
+ it "should mark the matching li-item as selected (with the css_class specified in configuration)" do
71
+ HTML::Selector.new('li.selected').select(render(:invoices)).should have(1).entries
72
+ end
73
+ it "should also mark the links inside the selected li's as selected" do
74
+ HTML::Selector.new('li.selected a.selected').select(render(:invoices)).should have(1).entries
75
+ end
76
+
77
+ end
78
+
79
+ context 'without current_navigation set' do
80
+ it "should not mark any of the items as selected" do
81
+ HTML::Selector.new('li.selected').select(render).should be_empty
82
+ end
83
+ it "should not mark any links as selected" do
84
+ HTML::Selector.new('a.selected').select(render).should be_empty
85
+ end
86
+ end
87
+
88
+ context 'nested sub_navigation' do
89
+ it "should nest the current_primary's subnavigation inside the selected li-element" do
90
+ HTML::Selector.new('li.selected ul li').select(render(:invoices, true)).should have(2).entries
91
+ end
92
+ it "should be possible to identify sub items using an html selector (using ids)" do
93
+ HTML::Selector.new('.invoices .subnav1').select(render(:invoices, true)).should have(1).entries
94
+ end
95
+ context 'render_all_levels = false' do
96
+ before(:each) do
97
+ SimpleNavigation.config.render_all_levels = false
98
+ end
99
+ it "should not render the invoices submenu if the user-primary is active" do
100
+ HTML::Selector.new('.invoices .subnav1').select(render(:users, true)).should be_empty
101
+ HTML::Selector.new('.invoices .subnav2').select(render(:users, true)).should be_empty
102
+ end
103
+ end
104
+
105
+ context 'render_all_levels = true' do
106
+ before(:each) do
107
+ SimpleNavigation.config.render_all_levels = true
108
+ end
109
+ it "should render the invoices submenu even if the user-primary is active" do
110
+ HTML::Selector.new('.invoices .subnav1').select(render(:users, true)).should have(1).entry
111
+ HTML::Selector.new('.invoices .subnav2').select(render(:users, true)).should have(1).entry
112
+ end
113
+ end
114
+
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,140 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SimpleNavigation do
4
+
5
+ describe 'config_files' do
6
+ before(:each) do
7
+ SimpleNavigation.config_files = {}
8
+ end
9
+ it "should be an empty hash after loading the module" do
10
+ SimpleNavigation.config_files.should == {}
11
+ end
12
+ end
13
+
14
+ describe 'config_file_name' do
15
+ before(:each) do
16
+ SimpleNavigation.config_file_path = 'path_to_config'
17
+ end
18
+ context 'for :default navigation_context' do
19
+ it "should return the path to default config file" do
20
+ SimpleNavigation.config_file_name.should == 'path_to_config/navigation.rb'
21
+ end
22
+ end
23
+
24
+ context 'for other navigation_context' do
25
+ it "should return the path to the config file matching the specified context" do
26
+ SimpleNavigation.config_file_name(:my_other_context).should == 'path_to_config/my_other_context_navigation.rb'
27
+ end
28
+ it "should convert camelcase-contexts to underscore" do
29
+ SimpleNavigation.config_file_name(:WhyWouldYouDoThis).should == 'path_to_config/why_would_you_do_this_navigation.rb'
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'load_config' do
35
+ context 'config_file_path is set' do
36
+ before(:each) do
37
+ SimpleNavigation.config_file_path = 'path_to_config'
38
+ #SimpleNavigation.stub!(:config_file_name => 'path_to_config/navigation.rb')
39
+ end
40
+
41
+ context 'config_file does exist' do
42
+ before(:each) do
43
+ File.stub!(:exists?).and_return(true)
44
+ IO.stub!(:read).and_return('file_content')
45
+ end
46
+ it "should not raise an error" do
47
+ lambda{SimpleNavigation.load_config}.should_not raise_error
48
+ end
49
+ it "should read the specified config file from disc" do
50
+ IO.should_receive(:read).with('path_to_config/navigation.rb')
51
+ SimpleNavigation.load_config
52
+ end
53
+ it "should store the read content in the module (default context)" do
54
+ SimpleNavigation.should_receive(:config_file_name).with(:default).twice
55
+ SimpleNavigation.load_config
56
+ SimpleNavigation.config_files[:default].should == 'file_content'
57
+ end
58
+ it "should store the content in the module (non default context)" do
59
+ SimpleNavigation.should_receive(:config_file_name).with(:my_context).twice
60
+ SimpleNavigation.load_config(:my_context)
61
+ SimpleNavigation.config_files[:my_context].should == 'file_content'
62
+ end
63
+ end
64
+
65
+ context 'config_file does not exist' do
66
+ before(:each) do
67
+ File.stub!(:exists?).and_return(false)
68
+ end
69
+ it {lambda{SimpleNavigation.load_config}.should raise_error}
70
+ end
71
+ end
72
+
73
+ context 'config_file_path is not set' do
74
+ before(:each) do
75
+ SimpleNavigation.config_file_path = nil
76
+ end
77
+ it {lambda{SimpleNavigation.load_config}.should raise_error}
78
+ end
79
+
80
+ describe 'regarding caching of the config-files' do
81
+ before(:each) do
82
+ IO.stub!(:read).and_return('file_content')
83
+ SimpleNavigation.config_file_path = 'path_to_config'
84
+ File.stub!(:exists? => true)
85
+ end
86
+ context "RAILS_ENV undefined" do
87
+ before(:each) do
88
+ ::RAILS_ENV = nil
89
+ end
90
+ it "should load the config file twice" do
91
+ IO.should_receive(:read).twice
92
+ SimpleNavigation.load_config
93
+ SimpleNavigation.load_config
94
+ end
95
+ end
96
+ context "RAILS_ENV defined" do
97
+ before(:each) do
98
+ ::RAILS_ENV = 'production'
99
+ end
100
+ context "RAILS_ENV=production" do
101
+ it "should load the config file only once" do
102
+ IO.should_receive(:read).once
103
+ SimpleNavigation.load_config
104
+ SimpleNavigation.load_config
105
+ end
106
+ end
107
+
108
+ context "RAILS_ENV=development" do
109
+ before(:each) do
110
+ ::RAILS_ENV = 'development'
111
+ end
112
+ it "should load the config file twice" do
113
+ IO.should_receive(:read).twice
114
+ SimpleNavigation.load_config
115
+ SimpleNavigation.load_config
116
+ end
117
+ end
118
+
119
+ context "RAILS_ENV=test" do
120
+ before(:each) do
121
+ ::RAILS_ENV = 'test'
122
+ end
123
+ it "should load the config file twice" do
124
+ IO.should_receive(:read).twice
125
+ SimpleNavigation.load_config
126
+ SimpleNavigation.load_config
127
+ end
128
+ end
129
+ end
130
+ after(:each) do
131
+ SimpleNavigation.config_files = {}
132
+ end
133
+ end
134
+ end
135
+
136
+ describe 'config' do
137
+ it {SimpleNavigation.config.should == SimpleNavigation::Configuration.instance}
138
+ end
139
+
140
+ end
@@ -0,0 +1,25 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ RAILS_ENV = "test" unless defined? RAILS_ENV
3
+ require 'rubygems'
4
+ require 'spec'
5
+ require 'active_support'
6
+ require 'action_controller'
7
+
8
+ RAILS_ROOT = './' unless defined? RAILS_ROOT
9
+
10
+ $:.unshift File.dirname(__FILE__)
11
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
12
+
13
+ require 'simple_navigation/configuration'
14
+ require 'simple_navigation/helpers'
15
+ require 'simple_navigation/controller_methods'
16
+ require 'simple_navigation/item'
17
+ require 'simple_navigation/item_container'
18
+ require 'simple_navigation/renderer/base'
19
+ require 'simple_navigation/renderer/list'
20
+
21
+ require 'simple_navigation'
22
+
23
+ # Spec::Runner.configure do |config|
24
+ # no special config
25
+ # endx
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: krasivotokak-simple-navigation
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Andi Schacke
8
+ - Alexander Semyonov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-08-31 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Simple Navigation is a ruby library for creating a navigation (optionally with sub navigation) for your rails app.
18
+ email: andreas.schacke@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README
25
+ files:
26
+ - .gitignore
27
+ - CHANGELOG
28
+ - README
29
+ - Rakefile
30
+ - VERSION.yml
31
+ - generators/navigation_config/USAGE
32
+ - generators/navigation_config/navigation_config_generator.rb
33
+ - generators/navigation_config/templates/config/navigation.rb
34
+ - init.rb
35
+ - install.rb
36
+ - lib/simple_navigation.rb
37
+ - lib/simple_navigation/configuration.rb
38
+ - lib/simple_navigation/controller_methods.rb
39
+ - lib/simple_navigation/helpers.rb
40
+ - lib/simple_navigation/item.rb
41
+ - lib/simple_navigation/item_container.rb
42
+ - lib/simple_navigation/renderer/base.rb
43
+ - lib/simple_navigation/renderer/list.rb
44
+ - rails/init.rb
45
+ - simple-navigation.gemspec
46
+ - spec/lib/simple_navigation/configuration_spec.rb
47
+ - spec/lib/simple_navigation/controller_methods_spec.rb
48
+ - spec/lib/simple_navigation/helpers_spec.rb
49
+ - spec/lib/simple_navigation/item_container_spec.rb
50
+ - spec/lib/simple_navigation/item_spec.rb
51
+ - spec/lib/simple_navigation/renderer/base_spec.rb
52
+ - spec/lib/simple_navigation/renderer/list_spec.rb
53
+ - spec/lib/simple_navigation_spec.rb
54
+ - spec/spec_helper.rb
55
+ - uninstall.rb
56
+ has_rdoc: false
57
+ homepage: http://github.com/andi/simple-navigation
58
+ licenses:
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --inline-source
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project: andi
80
+ rubygems_version: 1.3.5
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Simple Navigation is a ruby library for creating a navigation (optionally with sub navigation) for your rails app.
84
+ test_files:
85
+ - spec/lib/simple_navigation/item_spec.rb
86
+ - spec/lib/simple_navigation/controller_methods_spec.rb
87
+ - spec/lib/simple_navigation/item_container_spec.rb
88
+ - spec/lib/simple_navigation/helpers_spec.rb
89
+ - spec/lib/simple_navigation/configuration_spec.rb
90
+ - spec/lib/simple_navigation/renderer/list_spec.rb
91
+ - spec/lib/simple_navigation/renderer/base_spec.rb
92
+ - spec/lib/simple_navigation_spec.rb
93
+ - spec/spec_helper.rb