Skip to content

Commit

Permalink
Ensures that the dsl is registered before before overrides are loaded…
Browse files Browse the repository at this point in the history
… and ensures that '.deface' files are picked up when looking for overrides.
  • Loading branch information
mscottford committed Mar 24, 2012
1 parent 2ae7304 commit ee74e24
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/deface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require "deface/override"
require "deface/parser"
require "deface/environment"
require "deface/dsl/loader"

module Deface
if defined?(Rails)
Expand Down
4 changes: 4 additions & 0 deletions lib/deface/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def find(*args)
def load_all(app)
#clear overrides before reloading them
app.config.deface.overrides.all.clear
Deface::DSL::Loader.register

# check application for specified overrides paths
override_paths = app.paths["app/overrides"]
Expand Down Expand Up @@ -53,6 +54,9 @@ def enumerate_and_load(paths, root)
Dir.glob(root.join path, "*.rb") do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
Dir.glob(root.join path, "*.deface") do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
end

end
Expand Down
8 changes: 7 additions & 1 deletion spec/deface/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ module Deface
before do
Rails.application.stub :root => Pathname.new(File.join(File.dirname(__FILE__), '..', "assets"))
Rails.application.stub :paths => {}
Rails.application.stub_chain :railties, :all => []
Rails.application.stub_chain :railties, :all => []

Deface::DSL::Loader.should_receive(:register)
end

it "should enumerate_and_load nil when app has no app/overrides path set" do
Expand Down Expand Up @@ -86,17 +88,21 @@ module Deface

it "should be enumerate default path when none supplied" do
Dir.should_receive(:glob).with(root.join "app/overrides", "*.rb")
Dir.should_receive(:glob).with(root.join "app/overrides", "*.deface")
Rails.application.config.deface.overrides.send(:enumerate_and_load, nil, root)
end

it "should be enumerate supplied path" do
Dir.should_receive(:glob).with(root.join "app/junk", "*.rb")
Dir.should_receive(:glob).with(root.join "app/junk", "*.deface")
Rails.application.config.deface.overrides.send(:enumerate_and_load, ["app/junk"], root)
end

it "should be enumerate supplied paths" do
Dir.should_receive(:glob).with(root.join "app/junk", "*.rb" )
Dir.should_receive(:glob).with(root.join "app/junk", "*.deface" )
Dir.should_receive(:glob).with(root.join "app/gold", "*.rb" )
Dir.should_receive(:glob).with(root.join "app/gold", "*.deface" )
Rails.application.config.deface.overrides.send(:enumerate_and_load, ["app/junk", "app/gold"], root)
end

Expand Down

0 comments on commit ee74e24

Please sign in to comment.