simple-navigation 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ *1.1.2
2
+
3
+ * Bugfix: config now gets evaluated on every render_navigation call. Credits to Joël Azémar.
4
+ * Config file gets reloaded on every render_navigation call in development mode. Only load config file on server start in production mode.
5
+
6
+
1
7
  *1.1.1
2
8
 
3
9
  * Change plugin into a GemPlugin
data/Rakefile CHANGED
@@ -52,7 +52,7 @@ begin
52
52
  )
53
53
 
54
54
  host = "#{config['username']}@rubyforge.org"
55
- remote_dir = "/var/www/gforge-projects/simple-navigation/"
55
+ remote_dir = "/var/www/gforge-projects/andi/"
56
56
  local_dir = 'rdoc'
57
57
 
58
58
  Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :patch: 1
4
2
  :major: 1
3
+ :minor: 1
4
+ :patch: 2
@@ -23,7 +23,8 @@ module SimpleNavigation
23
23
  #
24
24
  # :primary which only renders the primary_navigation (also see render_primary_navigation) and :secondary which only renders the sub_navigation (see render_sub_navigation).
25
25
  def render_navigation(level = :nested)
26
- SimpleNavigation::Configuration.eval_config(self) unless SimpleNavigation.config.loaded?
26
+ SimpleNavigation.load_config unless ::RAILS_ENV == 'production'
27
+ SimpleNavigation::Configuration.eval_config(self)
27
28
  case level
28
29
  when :primary:
29
30
  SimpleNavigation.primary_navigation.render(@current_primary_navigation)
@@ -2,10 +2,13 @@
2
2
  module SimpleNavigation
3
3
 
4
4
  mattr_accessor :config_file
5
+ mattr_accessor :config_file_path
5
6
 
6
7
  # Reads the specified config_file and stores it for later evaluation.
7
- def self.load_config(config_file)
8
- self.config_file = IO.read(config_file)
8
+ def self.load_config
9
+ raise "config_file_path is not set!" unless self.config_file_path
10
+ raise "Config file '#{config_file_path}' does not exists!" unless File.exists?(self.config_file_path)
11
+ self.config_file = IO.read(self.config_file_path)
9
12
  end
10
13
 
11
14
  # Returns the singleton instance of the SimpleNavigation::Configuration
data/rails/init.rb CHANGED
@@ -1,3 +1,4 @@
1
- config_file_path = File.join(RAILS_ROOT, 'config', 'navigation.rb')
2
- SimpleNavigation.load_config(config_file_path) if File.exists?(config_file_path)
1
+ default_config_file_path = File.join(RAILS_ROOT, 'config', 'navigation.rb')
2
+ SimpleNavigation.config_file_path = default_config_file_path unless SimpleNavigation.config_file_path
3
+ SimpleNavigation.load_config
3
4
  ActionController::Base.send(:include, SimpleNavigation::ControllerMethods)
@@ -1,29 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe SimpleNavigation do
4
-
5
- describe 'load_config' do
6
-
7
- before(:each) do
8
- @config_file = '"my_navigation_config"'
9
- IO.stub!(:read).and_return(@config_file)
10
- end
11
-
12
- it "should load the navigation-configfile into a string" do
13
- IO.should_receive(:read).with('./config/navigation.rb')
14
- SimpleNavigation.load_config('./config/navigation.rb')
15
- end
16
- it "should store that string in a module-var" do
17
- SimpleNavigation.load_config('./config/navigation.rb')
18
- SimpleNavigation.config_file.should == @config_file
19
- end
20
- end
21
-
22
- describe 'config' do
23
- it {SimpleNavigation.config.should == SimpleNavigation::Configuration.instance}
24
- end
25
-
26
- end
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
27
2
 
28
3
  describe SimpleNavigation::Configuration do
29
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  ActionController::Base.send(:include, SimpleNavigation::ControllerMethods)
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Helpers do
4
4
  class ControllerMock
@@ -7,12 +7,61 @@ describe SimpleNavigation::Helpers do
7
7
 
8
8
  before(:each) do
9
9
  @controller = ControllerMock.new
10
- SimpleNavigation.config.stub!(:loaded?).and_return(true)
11
- @primary_navigation = stub(:primary_navigation)
10
+ SimpleNavigation.stub!(:load_config)
11
+ SimpleNavigation::Configuration.stub!(:eval_config)
12
+ @primary_navigation = stub(:primary_navigation, :null_object => true)
12
13
  SimpleNavigation.stub!(:primary_navigation).and_return(@primary_navigation)
13
14
  end
14
15
 
15
16
  describe 'render_navigation' do
17
+ describe 'regarding loading of the config-file' do
18
+ context "RAILS_ENV undefined" do
19
+ before(:each) do
20
+ ::RAILS_ENV = nil
21
+ end
22
+ it "should load the config file" do
23
+ SimpleNavigation.should_receive(:load_config)
24
+ @controller.render_navigation
25
+ end
26
+ end
27
+ context "RAILS_ENV defined" do
28
+ before(:each) do
29
+ ::RAILS_ENV = 'production'
30
+ end
31
+ context "RAILS_ENV=production" do
32
+ it "should not load the config file" do
33
+ SimpleNavigation.should_not_receive(:load_config)
34
+ @controller.render_navigation
35
+ end
36
+ end
37
+
38
+ context "RAILS_ENV=development" do
39
+ before(:each) do
40
+ ::RAILS_ENV = 'development'
41
+ end
42
+ it "should load the config file" do
43
+ SimpleNavigation.should_receive(:load_config)
44
+ @controller.render_navigation
45
+ end
46
+ end
47
+
48
+ context "RAILS_ENV=test" do
49
+ before(:each) do
50
+ ::RAILS_ENV = 'test'
51
+ end
52
+ it "should load the config file" do
53
+ SimpleNavigation.should_receive(:load_config)
54
+ @controller.render_navigation
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ it "should eval the config on every request" do
61
+ SimpleNavigation::Configuration.should_receive(:eval_config).with(@controller)
62
+ @controller.render_navigation
63
+ end
64
+
16
65
  context 'primary' do
17
66
  before(:each) do
18
67
  @controller.instance_variable_set(:@current_primary_navigation, :current_primary)
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::ItemContainer do
4
4
  before(:each) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Item do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Renderer::Base do
4
4
  before(:each) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
  require 'html/document' unless defined? HTML::Document
3
3
 
4
4
  describe SimpleNavigation::Renderer::List do
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SimpleNavigation do
4
+ describe 'load_config' do
5
+ context 'config_file_path is set' do
6
+ before(:each) do
7
+ SimpleNavigation.config_file_path = 'path_to_config'
8
+ end
9
+
10
+ context 'config_file does exist' do
11
+ before(:each) do
12
+ File.stub!(:exists?).and_return(true)
13
+ IO.stub!(:read).and_return('file_content')
14
+ end
15
+ it "should not raise an error" do
16
+ lambda{SimpleNavigation.load_config}.should_not raise_error
17
+ end
18
+ it "should read the config file from disc" do
19
+ IO.should_receive(:read).with('path_to_config')
20
+ SimpleNavigation.load_config
21
+ end
22
+ it "should store the read content in the module" do
23
+ SimpleNavigation.should_receive(:config_file=).with('file_content')
24
+ SimpleNavigation.load_config
25
+ end
26
+ end
27
+
28
+ context 'config_file does not exist' do
29
+ before(:each) do
30
+ File.stub!(:exists?).and_return(false)
31
+ end
32
+ it {lambda{SimpleNavigation.load_config}.should raise_error}
33
+ end
34
+ end
35
+
36
+ context 'config_file_path is not set' do
37
+ before(:each) do
38
+ SimpleNavigation.config_file_path = nil
39
+ end
40
+ it {lambda{SimpleNavigation.load_config}.should raise_error}
41
+ end
42
+ end
43
+
44
+ describe 'config' do
45
+ it {SimpleNavigation.config.should == SimpleNavigation::Configuration.instance}
46
+ end
47
+
48
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
+ RAILS_ENV = "test"
2
3
  require 'rubygems'
3
4
  require 'spec'
4
5
  require 'active_support'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-navigation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andi Schacke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-14 00:00:00 +02:00
12
+ date: 2009-04-18 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -37,13 +37,14 @@ files:
37
37
  - lib/simple_navigation/renderer/base.rb
38
38
  - lib/simple_navigation/renderer/list.rb
39
39
  - rails/init.rb
40
- - spec/lib/configuration_spec.rb
41
- - spec/lib/controller_methods_spec.rb
42
- - spec/lib/helpers_spec.rb
43
- - spec/lib/item_container_spec.rb
44
- - spec/lib/item_spec.rb
45
- - spec/lib/renderer/base_spec.rb
46
- - spec/lib/renderer/list_spec.rb
40
+ - spec/lib/simple_navigation/configuration_spec.rb
41
+ - spec/lib/simple_navigation/controller_methods_spec.rb
42
+ - spec/lib/simple_navigation/helpers_spec.rb
43
+ - spec/lib/simple_navigation/item_container_spec.rb
44
+ - spec/lib/simple_navigation/item_spec.rb
45
+ - spec/lib/simple_navigation/renderer/base_spec.rb
46
+ - spec/lib/simple_navigation/renderer/list_spec.rb
47
+ - spec/lib/simple_navigation_spec.rb
47
48
  - spec/spec_helper.rb
48
49
  - README
49
50
  has_rdoc: true
@@ -74,11 +75,12 @@ signing_key:
74
75
  specification_version: 2
75
76
  summary: Simple Navigation is a ruby library for creating a navigation (optionally with sub navigation) for your rails app.
76
77
  test_files:
77
- - spec/lib/configuration_spec.rb
78
- - spec/lib/controller_methods_spec.rb
79
- - spec/lib/helpers_spec.rb
80
- - spec/lib/item_container_spec.rb
81
- - spec/lib/item_spec.rb
82
- - spec/lib/renderer/base_spec.rb
83
- - spec/lib/renderer/list_spec.rb
78
+ - spec/lib/simple_navigation/configuration_spec.rb
79
+ - spec/lib/simple_navigation/controller_methods_spec.rb
80
+ - spec/lib/simple_navigation/helpers_spec.rb
81
+ - spec/lib/simple_navigation/item_container_spec.rb
82
+ - spec/lib/simple_navigation/item_spec.rb
83
+ - spec/lib/simple_navigation/renderer/base_spec.rb
84
+ - spec/lib/simple_navigation/renderer/list_spec.rb
85
+ - spec/lib/simple_navigation_spec.rb
84
86
  - spec/spec_helper.rb