Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reverse view paths order in extension loader. [[radiant#49] state:res…
…olved]
  • Loading branch information
seancribbs committed Mar 4, 2009
1 parent cab11d9 commit f909ad1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,8 @@

=== Edge

* Reverse view paths order in extension loader. [Sean Cribbs, Brent
Kroeker]
* Remove obviated Ruby 1.8.7 compatibility patch. [Sean Cribbs]
* Adjust StandardTags#relative_url_for for case when relative_url_root
is nil. [Sean Cribbs]
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -6,6 +6,7 @@ core:

=== Edge

* Brent Kroeker
* Sean Cribbs

=== 0.7.1 Engraving
Expand Down
2 changes: 1 addition & 1 deletion lib/radiant/extension_loader.rb
Expand Up @@ -61,7 +61,7 @@ def add_controller_paths
end

def view_paths
extensions.map { |extension| "#{extension.root}/app/views" }.select { |d| File.directory?(d) }
extensions.map { |extension| "#{extension.root}/app/views" }.select { |d| File.directory?(d) }.reverse
end

# Load the extensions
Expand Down
55 changes: 32 additions & 23 deletions spec/lib/radiant/extension_loader_spec.rb
Expand Up @@ -12,7 +12,7 @@
@initializer.stub!(:admin).and_return(@admin)
@instance = Radiant::ExtensionLoader.send(:new)
@instance.initializer = @initializer

@extensions = %w{01_basic 02_overriding load_order_blue load_order_green load_order_red}
@extension_paths = @extensions.map do |ext|
File.expand_path("#{RADIANT_ROOT}/test/fixtures/extensions/#{ext}")
Expand All @@ -27,75 +27,75 @@
it "should have the initializer's configuration" do
@initializer.should_receive(:configuration).and_return(@configuration)
@instance.configuration.should == @configuration
end
end

it "should only load extensions specified in the configuration" do
@configuration.should_receive(:extensions).at_least(:once).and_return([:basic])
@instance.stub!(:all_extension_roots).and_return(@extension_paths)
@instance.send(:select_extension_roots).should == [File.expand_path("#{RADIANT_ROOT}/test/fixtures/extensions/01_basic")]
@instance.send(:select_extension_roots).should == [File.expand_path("#{RADIANT_ROOT}/test/fixtures/extensions/01_basic")]
end

it "should select extensions in an explicit order from the configuration" do
extensions = [:load_order_red, :load_order_blue, :load_order_green]
extension_roots = extensions.map {|ext| File.expand_path("#{RADIANT_ROOT}/test/fixtures/extensions/#{ext}") }
@instance.stub!(:all_extension_roots).and_return(@extension_paths)
@configuration.should_receive(:extensions).at_least(:once).and_return(extensions)
@instance.send(:select_extension_roots).should == extension_roots
end

it "should insert all unspecified extensions into the paths at position of :all in configuration" do
extensions = [:load_order_red, :all, :load_order_green]
extension_roots = @extension_paths[0..-2].unshift(@extension_paths[-1])
@instance.stub!(:all_extension_roots).and_return(@extension_paths)
@configuration.should_receive(:extensions).at_least(:once).and_return(extensions)
@instance.send(:select_extension_roots).should == extension_roots
end

it "should raise an error when an extension named in the configuration cannot be found" do
extensions = [:foobar]
@instance.stub!(:all_extension_roots).and_return(@extension_paths)
@configuration.should_receive(:extensions).at_least(:once).and_return(extensions)
lambda { @instance.send(:select_extension_roots) }.should raise_error(LoadError)
end

it "should determine load paths from an extension path" do
@instance.send(:load_paths_for, "#{RADIANT_ROOT}/vendor/extensions/archive").should == %W{
#{RADIANT_ROOT}/vendor/extensions/archive/lib
#{RADIANT_ROOT}/vendor/extensions/archive/app/models
#{RADIANT_ROOT}/vendor/extensions/archive/test/helpers
#{RADIANT_ROOT}/vendor/extensions/archive}
end

it "should have load paths" do
@instance.stub!(:load_extension_roots).and_return(@extension_paths)
@instance.should respond_to(:extension_load_paths)
@instance.extension_load_paths.should be_instance_of(Array)
@instance.extension_load_paths.all? {|f| File.directory?(f) }.should be_true
end

it "should have plugin paths" do
@instance.stub!(:load_extension_roots).and_return(@extension_paths)
@instance.should respond_to(:plugin_paths)
@instance.plugin_paths.should be_instance_of(Array)
@instance.plugin_paths.all? {|f| File.directory?(f) }.should be_true
end

it "should add extension paths to the configuration" do
load_paths = []
@instance.should_receive(:extension_load_paths).and_return(@extension_paths)
@configuration.should_receive(:load_paths).at_least(:once).and_return(load_paths)
@instance.add_extension_paths
load_paths.should == @extension_paths
end

it "should add plugin paths to the configuration" do
plugin_paths = []
@instance.should_receive(:plugin_paths).and_return([@extension_paths.first + "/vendor/plugins"])
@configuration.should_receive(:plugin_paths).and_return(plugin_paths)
@instance.add_plugin_paths
plugin_paths.should == [@extension_paths.first + "/vendor/plugins"]
end

it "should add plugin paths in the same order as the extension load order" do
plugin_paths = []
ext_plugin_paths = @extension_paths[0..1].map {|e| e + "/vendor/plugins" }
Expand All @@ -104,25 +104,34 @@
@instance.add_plugin_paths
plugin_paths.should == ext_plugin_paths
end

it "should have controller paths" do
@instance.should respond_to(:controller_paths)
@instance.controller_paths.should be_instance_of(Array)
@instance.controller_paths.all? {|f| File.directory?(f) }.should be_true
end

it "should add controller paths to the configuration" do
controller_paths = []
@instance.stub!(:extensions).and_return([BasicExtension])
@configuration.should_receive(:controller_paths).and_return(controller_paths)
@instance.add_controller_paths
controller_paths.should include(BasicExtension.root + "/app/controllers")
end

it "should have view paths" do
@instance.should respond_to(:view_paths)
@instance.view_paths.should be_instance_of(Array)
@instance.view_paths.all? {|f| File.directory?(f) }.should be_true
@instance.view_paths.all? {|f| File.directory?(f) }.should be_true
end

it "should return the view paths in inverse order to the loaded" do
extensions = [BasicExtension, OverridingExtension]
@instance.extensions = extensions
@instance.view_paths.should == [
"#{RAILS_ROOT}/test/fixtures/extensions/02_overriding/app/views",
"#{RAILS_ROOT}/test/fixtures/extensions/01_basic/app/views"
]
end

it "should load and initialize extensions when discovering" do
Expand All @@ -134,14 +143,14 @@
ext_class.root.should_not be_nil
end
end

it "should deactivate extensions" do
extensions = [BasicExtension, OverridingExtension]
@instance.extensions = extensions
@instance.deactivate_extensions
extensions.any?(&:active?).should be_false
end

it "should activate extensions" do
@initializer.should_receive(:initialize_default_admin_tabs)
@initializer.should_receive(:initialize_framework_views)
Expand All @@ -151,7 +160,7 @@
@instance.activate_extensions
extensions.all?(&:active?).should be_true
end

it "should (re)load Page subclasses activation" do
@initializer.should_receive(:initialize_default_admin_tabs)
@initializer.should_receive(:initialize_framework_views)
Expand All @@ -173,17 +182,17 @@
it "should be a MethodObserver" do
@observer.should be_kind_of(MethodObserver)
end

it "should attach to the clear method" do
@observer.should respond_to(:before_clear)
@observer.should respond_to(:after_clear)
end

it "should deactivate extensions before clear" do
Radiant::ExtensionLoader.should_receive(:deactivate_extensions)
@observer.before_clear
end

it "should load and activate extensions after clear" do
Radiant::ExtensionLoader.should_receive(:load_extensions)
Radiant::ExtensionLoader.should_receive(:activate_extensions)
Expand Down

0 comments on commit f909ad1

Please sign in to comment.